Search in sources :

Example 1 with JSReferenceExpression

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

the class ActionScriptResolveTest method testResolveIt.

public void testResolveIt() throws Exception {
    String fileText = "package {\n" + "\n" + "public class Test {\n" + "  public function Test() {\n" + "    var describeType:XML = describe<ref>Type(Test);\n" + "  }\n" + "}\n" + "function describeType(x) {}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
    assertTrue(ref.resolve() instanceof JSLocalVariable);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSLocalVariable(com.intellij.lang.javascript.psi.JSLocalVariable)

Example 2 with JSReferenceExpression

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

the class ActionScriptResolveTest method testResolveInClass.

public void testResolveInClass() throws Exception {
    String fileText = "class A { function get aaa() {} function foo() {\n" + "  var aaa = a<ref>aa;\n}" + "}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
    assertTrue(ref.resolve() instanceof JSFunction);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction)

Example 3 with JSReferenceExpression

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

the class FlexRenameTest method testRenameClassTwoTimes.

public void testRenameClassTwoTimes() throws Exception {
    final String name = getTestName(false);
    VirtualFile file = getVirtualFile(getBasePath() + name + "/mytest/foo/" + name + "_2.js2");
    VirtualFile[] files = { getVirtualFile(getBasePath() + name + "/mytest/boo/" + name + ".js2"), file };
    configureByFiles(new File(getTestDataPath() + getBasePath() + name), files);
    int referencesCount = findRenamedRefsToReferencedElementAtCaret().length;
    performAction(name + "_3", true);
    checkResultByFile(getBasePath() + name + "_after.js2");
    assertEquals(referencesCount, findRenamedRefsToReferencedElementAtCaret().length);
    performAction(name + "_4", true);
    checkResultByFile(getBasePath() + name + "_after2.js2");
    PsiReference[] refs = findRenamedRefsToReferencedElementAtCaret();
    assertEquals(referencesCount, refs.length);
    for (PsiReference ref : refs) {
        PsiElement refElement = ref.getElement();
        PsiElement refElementParent = refElement.getParent();
        assertFalse(refElementParent instanceof JSReferenceExpression);
        if (!(refElementParent instanceof JSImportStatement)) {
            assertEquals(name + "_4", refElement.getText());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) PsiReference(com.intellij.psi.PsiReference) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Example 4 with JSReferenceExpression

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

the class JSShortenFQNamesProcessor method processText.

public void processText(final Project project, final Template template, final Document document, final RangeMarker templateRange, final Editor editor) {
    if (!template.isToShortenLongNames())
        return;
    try {
        final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
        psiDocumentManager.commitDocument(document);
        final PsiFile hostFile = PsiUtilBase.getPsiFileInEditor(editor, project);
        final PsiFile file = (hostFile != null && JavaScriptSupportLoader.isFlexMxmFile(hostFile)) ? InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, templateRange.getStartOffset()) : hostFile;
        if (file instanceof JSFile && file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4)) {
            final ActionScriptUnusedImportsHelper.Results unusedImportsResults = ActionScriptUnusedImportsHelper.getUnusedImports(file);
            for (final JSReferenceExpression reference : unusedImportsResults.fqnsToReplaceWithShortName) {
                final TextRange range = InjectedLanguageManager.getInstance(project).injectedToHost(file, reference.getTextRange());
                if (TextRange.create(templateRange).contains(range)) {
                    final String shortName = StringUtil.getShortName(reference.getReferencedName());
                    final String resolved = JSImportHandlingUtil.resolveTypeName(shortName, reference);
                    // insert import statement if needed
                    if (shortName.equals(resolved)) {
                        final FormatFixer fixer = ImportUtils.insertImportStatements(reference, Collections.singletonList(reference.getText()));
                        if (fixer != null) {
                            fixer.fixFormat();
                        }
                    }
                    // shorten FQN
                    reference.replace(JSChangeUtil.createExpressionFromText(project, shortName).getPsi());
                }
            }
            psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
        }
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ActionScriptUnusedImportsHelper(com.intellij.lang.javascript.validation.ActionScriptUnusedImportsHelper) JSFile(com.intellij.lang.javascript.psi.JSFile) FormatFixer(com.intellij.lang.javascript.refactoring.FormatFixer) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 5 with JSReferenceExpression

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

the class FlexMoveClassProcessor method retargetUsages.

@Override
protected void retargetUsages(UsageInfo[] usages, Map<PsiElement, PsiElement> oldToNewMap) {
    super.retargetUsages(usages, oldToNewMap);
    for (UsageInfo usage : usages) {
        if (usage instanceof JSRefactoringUtil.ConstructorUsageInfo) {
            final JSRefactoringUtil.ConstructorUsageInfo constuctorUsage = (JSRefactoringUtil.ConstructorUsageInfo) usage;
            final JSReferenceExpression ref = constuctorUsage.getElement();
            if (ref != null && constuctorUsage.getSubject().isValid()) {
                ref.bindToElement(constuctorUsage.getSubject().getContainingFile());
            }
        }
    }
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSRefactoringUtil(com.intellij.lang.javascript.refactoring.util.JSRefactoringUtil)

Aggregations

JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)24 PsiElement (com.intellij.psi.PsiElement)10 JSFunction (com.intellij.lang.javascript.psi.JSFunction)7 JSFile (com.intellij.lang.javascript.psi.JSFile)6 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 NotNull (org.jetbrains.annotations.NotNull)4 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)3 JSExpression (com.intellij.lang.javascript.psi.JSExpression)3 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)3 TextRange (com.intellij.openapi.util.TextRange)3 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)2 FormatFixer (com.intellij.lang.javascript.refactoring.FormatFixer)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ResolveResult (com.intellij.psi.ResolveResult)2 XmlFile (com.intellij.psi.xml.XmlFile)2 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)2 Expression (com.intellij.codeInsight.template.Expression)1