Search in sources :

Example 6 with JSExpression

use of com.intellij.lang.javascript.psi.JSExpression 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 7 with JSExpression

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

the class JstdGenerateNewTestAction method buildGenerator.

@Nullable
private static Runnable buildGenerator(@NotNull JstdTestFileStructure fileStructure, @NotNull GenerateActionContext context) {
    int caretOffset = context.getDocumentCaretOffset();
    JstdTestCaseStructure jstdTestCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
    if (jstdTestCaseStructure != null) {
        JSObjectLiteralExpression testsObjectLiteral = jstdTestCaseStructure.getTestsObjectsLiteral();
        if (testsObjectLiteral != null) {
            return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
        } else {
            if (jstdTestCaseStructure.getTestCount() == 0) {
                JSCallExpression callExpression = jstdTestCaseStructure.getEnclosingCallExpression();
                JSArgumentList argumentList = callExpression.getArgumentList();
                JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
                if (arguments.length == 1 && arguments[0] != null) {
                    return new TestGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
                }
            }
        }
    } else {
        for (JstdTestCaseStructure testCaseStructure : fileStructure.getTestCaseStructures()) {
            JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
            if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
                return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
            }
        }
    }
    return null;
}
Also used : JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSArgumentList(com.intellij.lang.javascript.psi.JSArgumentList) JstdTestCaseStructure(com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure) JSObjectLiteralExpression(com.intellij.lang.javascript.psi.JSObjectLiteralExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with JSExpression

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

the class JstdTestFileStructure method postProcess.

void postProcess() {
    myNameByPsiElementMap = Collections.emptyMap();
    myPrototypeBasedTestElements = Collections.emptyMap();
    if (myTestCaseStructures.isEmpty()) {
        return;
    }
    int totalCount = 0;
    int prototypeBasedTestCount = 0;
    for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
        totalCount += testCaseStructure.getTestCount() + 1;
        for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
            if (testStructure.getWholeLeftDefExpr() != null) {
                prototypeBasedTestCount++;
            }
        }
    }
    myNameByPsiElementMap = new IdentityHashMap<>(totalCount);
    if (prototypeBasedTestCount > 0) {
        myPrototypeBasedTestElements = new IdentityHashMap<>(prototypeBasedTestCount);
    }
    for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
        JSExpression testCaseMethodExpr = testCaseStructure.getEnclosingCallExpression().getMethodExpression();
        if (testCaseMethodExpr != null) {
            myNameByPsiElementMap.put(testCaseMethodExpr, testCaseStructure.getName());
        }
        for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
            PsiElement anchor = testStructure.getTestMethodNameDeclaration();
            myNameByPsiElementMap.put(anchor, testStructure.getName());
            JSDefinitionExpression wholeLeftDefExpr = testStructure.getWholeLeftDefExpr();
            if (wholeLeftDefExpr != null) {
                myPrototypeBasedTestElements.put(wholeLeftDefExpr, null);
            }
        }
    }
}
Also used : JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSExpression (com.intellij.lang.javascript.psi.JSExpression)8 PsiElement (com.intellij.psi.PsiElement)4 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 JstdTestCaseStructure (com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure)1 CompletionContributor (com.intellij.codeInsight.completion.CompletionContributor)1 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 JSTokenTypes (com.intellij.lang.javascript.JSTokenTypes)1 JSArgumentList (com.intellij.lang.javascript.psi.JSArgumentList)1 JSDefinitionExpression (com.intellij.lang.javascript.psi.JSDefinitionExpression)1 JSElement (com.intellij.lang.javascript.psi.JSElement)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1 JSProperty (com.intellij.lang.javascript.psi.JSProperty)1 JSType (com.intellij.lang.javascript.psi.JSType)1