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;
}
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()));
}
}
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);
}
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);
}
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;
}
Aggregations