Search in sources :

Example 6 with PsiPolyVariantReference

use of com.intellij.psi.PsiPolyVariantReference in project intellij-community by JetBrains.

the class TextOccurrencesUtil method processTextIn.

private static boolean processTextIn(PsiElement scope, String stringToSearch, final boolean ignoreReferences, PairProcessor<PsiElement, TextRange> processor) {
    String text = scope.getText();
    for (int offset = 0; offset < text.length(); offset++) {
        offset = text.indexOf(stringToSearch, offset);
        if (offset < 0)
            break;
        final PsiReference referenceAt = scope.findReferenceAt(offset);
        if (!ignoreReferences && referenceAt != null && (referenceAt.resolve() != null || referenceAt instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) referenceAt).multiResolve(true).length > 0))
            continue;
        if (offset > 0) {
            char c = text.charAt(offset - 1);
            if (Character.isJavaIdentifierPart(c) && c != '$') {
                //escape sequence
                if (offset < 2 || text.charAt(offset - 2) != '\\')
                    continue;
            }
        }
        if (offset + stringToSearch.length() < text.length()) {
            char c = text.charAt(offset + stringToSearch.length());
            if (Character.isJavaIdentifierPart(c) && c != '$') {
                continue;
            }
        }
        TextRange textRange = new TextRange(offset, offset + stringToSearch.length());
        if (!processor.process(scope, textRange)) {
            return false;
        }
        offset += stringToSearch.length();
    }
    return true;
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 7 with PsiPolyVariantReference

use of com.intellij.psi.PsiPolyVariantReference in project intellij-plugins by JetBrains.

the class LinkDestinationReferenceTest method assertGoodReference.

private static void assertGoodReference(PsiFile file, int app) {
    final PsiReference reference = file.findReferenceAt(app);
    assertNotNull(reference);
    if (reference instanceof PsiPolyVariantReference) {
        assertTrue(((PsiPolyVariantReference) reference).multiResolve(false).length > 0);
    } else {
        assertNotNull(reference.resolve());
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.info(String.valueOf(reference.resolve().getClass()));
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 8 with PsiPolyVariantReference

use of com.intellij.psi.PsiPolyVariantReference in project intellij-elixir by KronicDeth.

the class ImportTest method testImportModule.

/*
     * Tests
     */
public void testImportModule() {
    myFixture.configureByFiles("import_module.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertEquals("imported", call.functionName());
    assertEquals(0, call.resolvedFinalArity());
    PsiReference reference = call.getReference();
    assertNotNull(reference);
    assertInstanceOf(reference, PsiPolyVariantReference.class);
    PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
    ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
    assertEquals(2, resolveResults.length);
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 9 with PsiPolyVariantReference

use of com.intellij.psi.PsiPolyVariantReference in project intellij-elixir by KronicDeth.

the class ImportTest method testImportModuleOnlyNameArity.

public void testImportModuleOnlyNameArity() {
    myFixture.configureByFiles("import_module_only_name_arity.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertEquals("imported", call.functionName());
    assertEquals(0, call.resolvedFinalArity());
    PsiReference reference = call.getReference();
    assertNotNull(reference);
    assertInstanceOf(reference, PsiPolyVariantReference.class);
    PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
    ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
    assertEquals(2, resolveResults.length);
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 10 with PsiPolyVariantReference

use of com.intellij.psi.PsiPolyVariantReference in project intellij-plugins by JetBrains.

the class FlexReferenceImporter method doAutoImportReferenceAt.

private static boolean doAutoImportReferenceAt(final Editor editor, final PsiFile file, final int offset) {
    if (!ActionScriptAutoImportOptionsProvider.isAddUnambiguousImportsOnTheFly())
        return false;
    if (!(file instanceof JSFile) || file.getLanguage() != JavaScriptSupportLoader.ECMA_SCRIPT_L4)
        return false;
    Document document = editor.getDocument();
    int lineNumber = document.getLineNumber(offset);
    int startOffset = document.getLineStartOffset(lineNumber);
    int endOffset = document.getLineEndOffset(lineNumber);
    List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffset);
    for (PsiElement element : elements) {
        if (element instanceof JSReferenceExpression && ((JSReferenceExpression) element).getQualifier() == null) {
            if (((JSReferenceExpression) element).multiResolve(false).length == 0) {
                new AddImportECMAScriptClassOrFunctionAction(editor, (PsiPolyVariantReference) element, true).execute();
                return true;
            }
        }
    }
    return false;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFile(com.intellij.lang.javascript.psi.JSFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Aggregations

PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)20 PsiElement (com.intellij.psi.PsiElement)17 ResolveResult (com.intellij.psi.ResolveResult)10 PsiReference (com.intellij.psi.PsiReference)7 Call (org.elixir_lang.psi.call.Call)3 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)2 ASTNode (com.intellij.lang.ASTNode)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 Document (com.intellij.openapi.editor.Document)1 TextRange (com.intellij.openapi.util.TextRange)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1