Search in sources :

Example 6 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 7 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)

Example 8 with JSProperty

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

the class KarmaBasePathFinder method buildBasePath.

@Nullable
private static String buildBasePath(@NotNull JSFile jsFile) {
    final Ref<String> basePathRef = Ref.create(null);
    JSElementVisitor visitor = new JSElementVisitor() {

        @Override
        public void visitJSProperty(JSProperty property) {
            String name = JsPsiUtils.getPropertyName(property);
            if (BASE_PATH_VAR_NAME.equals(name)) {
                JSLiteralExpression value = ObjectUtils.tryCast(property.getValue(), JSLiteralExpression.class);
                if (value != null && value.isQuotedLiteral()) {
                    basePathRef.set(StringUtil.unquoteString(value.getText()));
                }
            }
        }

        @Override
        public void visitElement(PsiElement element) {
            ProgressIndicatorProvider.checkCanceled();
            if (basePathRef.isNull()) {
                element.acceptChildren(this);
            }
        }
    };
    visitor.visitJSFile(jsFile);
    return basePathRef.get();
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression) JSProperty(com.intellij.lang.javascript.psi.JSProperty) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with JSProperty

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

the class InnerJsTypeEvaluator method addTypeFromAmdModuleReference.

@Override
protected boolean addTypeFromAmdModuleReference(@NotNull JSParameter parameter) {
    JSProperty macro;
    JSType type;
    // macro first parameter
    if ((macro = checkMacroFirstParameter(parameter)) != null) {
        addType(getMacroFirstParameterType(macro));
        return true;
    } else // function parameter
    if ((type = parameter.getJSType()) != null) {
        type.accept(new SimplifiedClassNameResolver(myContext.targetFile));
    }
    return super.addTypeFromAmdModuleReference(parameter);
}
Also used : JSType(com.intellij.lang.javascript.psi.JSType) JSProperty(com.intellij.lang.javascript.psi.JSProperty)

Example 10 with JSProperty

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

the class OxyTemplateHelper method getUsedJsMacros.

@NotNull
public static Map<PsiElement, JSElement> getUsedJsMacros(@NotNull PsiFile psiFile) {
    final Map<PsiElement, JSElement> usedMacros = new HashMap<>();
    new MacroNameVisitor() {

        @Override
        public void visitMacroName(@NotNull MacroName macroName) {
            PsiElement reference;
            if (macroName.getReference() != null && (reference = macroName.getReference().resolve()) != null && OxyTemplateIndexUtil.getJsMacroNameReferences(macroName.getName(), macroName.getProject()).size() > 0) {
                usedMacros.put(macroName, (JSElement) reference);
            }
        }
    }.visitFile(psiFile);
    new JSRecursiveWalkingElementVisitor() {

        @Override
        public void visitJSCallExpression(@NotNull JSCallExpression node) {
            if (node.getFirstChild() instanceof JSReferenceExpression) {
                JSReferenceExpression referenceExpression = (JSReferenceExpression) node.getFirstChild();
                PsiElement reference;
                if (referenceExpression.getReference() != null && (reference = referenceExpression.getReference().resolve()) != null && reference instanceof JSProperty && OxyTemplateIndexUtil.isMacro(reference)) {
                    usedMacros.put(referenceExpression, (JSElement) reference);
                }
            }
            super.visitJSCallExpression(node);
        }
    }.visitFile(psiFile.getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE));
    return usedMacros;
}
Also used : JSRecursiveWalkingElementVisitor(com.intellij.lang.javascript.psi.JSRecursiveWalkingElementVisitor) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) HashMap(java.util.HashMap) JSElement(com.intellij.lang.javascript.psi.JSElement) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) MacroNameVisitor(ool.intellij.plugin.psi.visitor.MacroNameVisitor) JSProperty(com.intellij.lang.javascript.psi.JSProperty) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSProperty (com.intellij.lang.javascript.psi.JSProperty)11 PsiElement (com.intellij.psi.PsiElement)5 Nullable (org.jetbrains.annotations.Nullable)4 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 JSElement (com.intellij.lang.javascript.psi.JSElement)2 JSFunctionExpression (com.intellij.lang.javascript.psi.JSFunctionExpression)2 JSLiteralExpression (com.intellij.lang.javascript.psi.JSLiteralExpression)2 PsiReference (com.intellij.psi.PsiReference)2 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)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 JSRecursiveWalkingElementVisitor (com.intellij.lang.javascript.psi.JSRecursiveWalkingElementVisitor)1 JSType (com.intellij.lang.javascript.psi.JSType)1 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)1 UsageInfo (com.intellij.usageView.UsageInfo)1 HashMap (java.util.HashMap)1 MacroCall (ool.intellij.plugin.psi.MacroCall)1 MacroName (ool.intellij.plugin.psi.MacroName)1 MacroNameVisitor (ool.intellij.plugin.psi.visitor.MacroNameVisitor)1