Search in sources :

Example 1 with JSProperty

use of com.intellij.lang.javascript.psi.JSProperty in project intellij-plugins by JetBrains.

the class AngularUiRouterTest method emptyViewNavigatesToFilesDefaultView.

private void emptyViewNavigatesToFilesDefaultView(PsiFile file, String str) {
    final PsiElement inObj = getElement(file, str);
    Assert.assertTrue(inObj.getParent() instanceof JSLiteralExpression);
    Assert.assertTrue(inObj.getParent().getParent() instanceof JSProperty);
    final JSProperty templateUrl = (JSProperty) inObj.getParent().getParent();
    Assert.assertEquals("templateUrl", templateUrl.getName());
    final PsiElement parentProperty = templateUrl.getParent().getParent();
    Assert.assertTrue(parentProperty instanceof JSProperty);
    final PsiReference reference = parentProperty.getReference();
    Assert.assertNotNull(reference);
    Assert.assertEquals("", reference.getCanonicalText());
    final PsiElement resolve = reference.resolve();
    Assert.assertNotNull(resolve);
    Assert.assertEquals(StringUtil.unquoteString(str), resolve.getContainingFile().getName());
    Assert.assertEquals("", ((JSPsiNamedElementBase) resolve).getName());
    final PsiElement element = ((JSOffsetBasedImplicitElement) resolve).getElementAtOffset();
    Assert.assertEquals("ui-view", element.getText());
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression) JSOffsetBasedImplicitElement(com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement) JSProperty(com.intellij.lang.javascript.psi.JSProperty)

Example 2 with JSProperty

use of com.intellij.lang.javascript.psi.JSProperty in project oxy-template-support-plugin by mutant-industries.

the class MacroParamDocumentationProvider method getCustomDocumentationElement.

@Nullable
@Override
public PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement) {
    PsiElement element;
    PsiReference reference;
    if (contextElement != null) {
        if (contextElement.getNode().getElementType() == OxyTemplateTypes.T_MACRO_PARAM_NAME) {
            return contextElement;
        } else if ((contextElement.getNode().getElementType() == JSTokenTypes.IDENTIFIER || contextElement.getNode().getElementType() == JSTokenTypes.COLON) && (((element = PsiTreeUtil.getParentOfType(contextElement, JSReferenceExpression.class)) != null && (element = ((JSReferenceExpression) element).resolve()) != null) || (element = contextElement.getParent()) instanceof JSProperty) && element instanceof JSProperty && OxyTemplateIndexUtil.isMacro(element)) {
            return new FakeDocumentationPsiElement((JSProperty) element);
        } else if (contextElement.getNode().getElementType() == OxyTemplateTypes.T_MACRO_NAME && (element = PsiTreeUtil.getParentOfType(contextElement, MacroName.class)) != null && (reference = element.getReference()) != null && (element = reference.resolve()) != null && element instanceof JSProperty && OxyTemplateIndexUtil.isMacro(element)) {
            return new FakeDocumentationPsiElement((JSProperty) element);
        }
    }
    return null;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiReference(com.intellij.psi.PsiReference) JSProperty(com.intellij.lang.javascript.psi.JSProperty) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with JSProperty

use of com.intellij.lang.javascript.psi.JSProperty in project oxy-template-support-plugin by mutant-industries.

the class InnerJsTypeEvaluator method checkMacroFirstParameter.

/**
 * @param parameter
 * @return macro, if parameter is its first parameter, null otherwise
 */
@Nullable
private static JSProperty checkMacroFirstParameter(@Nullable JSParameter parameter) {
    JSProperty macro;
    JSFunctionExpression functionExpression;
    if ((macro = PsiTreeUtil.getParentOfType(parameter, JSProperty.class)) != null && OxyTemplateIndexUtil.isMacro(macro) && macro.getLastChild() instanceof JSFunctionExpression) {
        functionExpression = (JSFunctionExpression) macro.getLastChild();
        if (functionExpression.getParameters().length > 0 && functionExpression.getParameters()[0].isEquivalentTo(parameter)) {
            return macro;
        }
    }
    return null;
}
Also used : JSFunctionExpression(com.intellij.lang.javascript.psi.JSFunctionExpression) JSProperty(com.intellij.lang.javascript.psi.JSProperty) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with JSProperty

use of com.intellij.lang.javascript.psi.JSProperty in project intellij-plugins by JetBrains.

the class JstdStructureTest method matchTest.

private static void matchTest(@NotNull MarkedTestStructure markedTestStructure, @NotNull JstdTestStructure testStructure) {
    Assert.assertEquals("Build test name is not equal to the marked one", markedTestStructure.getName(), testStructure.getName());
    String testName = testStructure.getName();
    JSProperty markedJsProperty = markedTestStructure.getPropertyPsiElement();
    if (markedJsProperty != null) {
        matchPsiElement(testName, "property", markedJsProperty, testStructure.getJsProperty());
    } else {
        matchPsiElement(testName, "declaration", markedTestStructure.getDeclarationPsiElement(), testStructure.getTestMethodNameDeclaration());
        matchPsiElement(testName, "body", markedTestStructure.getBodyPsiElement(), testStructure.getTestMethodBody());
    }
}
Also used : JSProperty(com.intellij.lang.javascript.psi.JSProperty)

Example 5 with JSProperty

use of com.intellij.lang.javascript.psi.JSProperty in project intellij-plugins by JetBrains.

the class AngularJSDirectiveRenameProcessor method renameElement.

@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
    final boolean isAngular2 = DirectiveUtil.isAngular2Directive(element);
    final PsiNamedElement directive = (PsiNamedElement) element;
    final String attributeName = isAngular2 ? newName : DirectiveUtil.getAttributeName(newName);
    for (UsageInfo usage : usages) {
        RenameUtil.rename(usage, attributeName);
    }
    if (isAngular2) {
        final JSProperty selector = AngularJS2IndexingHandler.getSelector(element.getParent());
        final JSExpression value = selector != null ? selector.getValue() : null;
        if (value != null) {
            if (value.getText().contains("["))
                newName = "[" + newName + "]";
            ElementManipulators.getManipulator(value).handleContentChange(value, newName);
        }
    } else {
        directive.setName(DirectiveUtil.attributeToDirective(element, newName));
    }
    if (listener != null) {
        listener.elementRenamed(element);
    }
}
Also used : JSProperty(com.intellij.lang.javascript.psi.JSProperty) JSExpression(com.intellij.lang.javascript.psi.JSExpression) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

JSProperty (com.intellij.lang.javascript.psi.JSProperty)9 PsiElement (com.intellij.psi.PsiElement)4 Nullable (org.jetbrains.annotations.Nullable)3 JSFunctionExpression (com.intellij.lang.javascript.psi.JSFunctionExpression)2 JSLiteralExpression (com.intellij.lang.javascript.psi.JSLiteralExpression)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSElement (com.intellij.lang.javascript.psi.JSElement)1 JSElementVisitor (com.intellij.lang.javascript.psi.JSElementVisitor)1 JSExpression (com.intellij.lang.javascript.psi.JSExpression)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1 JSRecursiveElementVisitor (com.intellij.lang.javascript.psi.JSRecursiveElementVisitor)1 JSType (com.intellij.lang.javascript.psi.JSType)1 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)1 PsiReference (com.intellij.psi.PsiReference)1 UsageInfo (com.intellij.usageView.UsageInfo)1 HashMap (java.util.HashMap)1 MacroNameVisitor (ool.intellij.plugin.psi.visitor.MacroNameVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1