use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class ResolveTestCase method configureByFileText.
protected PsiReference configureByFileText(String fileText, String fileName, @Nullable VirtualFile parentDir) throws Exception {
int offset = fileText.indexOf(MARKER);
assertTrue(offset >= 0);
fileText = fileText.substring(0, offset) + fileText.substring(offset + MARKER.length());
if (parentDir == null) {
myFile = createFile(myModule, fileName, fileText);
} else {
VirtualFile existing = parentDir.findChild(fileName);
if (existing != null) {
myDocument = FileDocumentManager.getInstance().getDocument(existing);
assertNotNull(myDocument);
final String finalFileText = fileText;
ApplicationManager.getApplication().runWriteAction(() -> myDocument.setText(finalFileText));
myFile = PsiManager.getInstance(getProject()).findFile(existing);
assertNotNull(myFile);
assertEquals(fileText, myFile.getText());
} else {
myFile = createFile(myModule, parentDir, fileName, fileText);
}
}
PsiReference ref = myFile.findReferenceAt(offset);
assertNotNull(ref);
return ref;
}
use of com.intellij.psi.PsiReference in project intellij-plugins by JetBrains.
the class CfmlFileReferenceInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new PsiElementVisitor() {
public void visitElement(final PsiElement element) {
PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
return;
}
}
final PsiReference[] refs = element.getParent().getReferences();
for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
PsiReference ref = refs[i];
if (!(ref instanceof FileReference))
continue;
if (ref.resolve() == null) {
PsiDirectory dir;
if (i > 0) {
final PsiElement target = refs[i - 1].resolve();
dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
} else {
dir = element.getContainingFile().getParent();
}
holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
// ProblemHighlightType.ERROR);
break;
}
}
}
}
};
}
use of com.intellij.psi.PsiReference in project intellij-plugins by JetBrains.
the class DartControlFlow method analyze.
public static DartControlFlow analyze(PsiElement[] elements) {
final PsiElement scope = PsiTreeUtil.getTopmostParentOfType(elements[0], DartExecutionScope.class);
final PsiElement lastElement = elements[elements.length - 1];
final int lastElementEndOffset = lastElement.getTextRange().getEndOffset();
final int firstElementStartOffset = elements[0].getTextRange().getStartOffset();
// find out params
assert scope != null;
final LocalSearchScope localSearchScope = new LocalSearchScope(scope);
final List<DartComponentName> outDeclarations = ContainerUtil.filter(DartControlFlowUtil.getSimpleDeclarations(elements, null, false), componentName -> {
for (PsiReference usage : ReferencesSearch.search(componentName, localSearchScope, false).findAll()) {
if (usage.getElement().getTextRange().getStartOffset() > lastElementEndOffset) {
return true;
}
}
return false;
});
// find params
final DartReferenceVisitor dartReferenceVisitor = new DartReferenceVisitor();
for (PsiElement element : elements) {
element.accept(dartReferenceVisitor);
}
final List<DartComponentName> inComponentNames = ContainerUtil.filter(dartReferenceVisitor.getComponentNames(), componentName -> {
final int offset = componentName.getTextRange().getStartOffset();
final boolean declarationInElements = firstElementStartOffset <= offset && offset < lastElementEndOffset;
return !declarationInElements;
});
return new DartControlFlow(inComponentNames, outDeclarations);
}
use of com.intellij.psi.PsiReference in project intellij-plugins by JetBrains.
the class FlexCssNavigationTest method findTargetElements.
@NotNull
private PsiElement[] findTargetElements(@NotNull String... filenames) throws Exception {
String[] fileNamesWithBasePath = new String[filenames.length];
for (int i = 0, filenamesLength = filenames.length; i < filenamesLength; i++) {
fileNamesWithBasePath[i] = BASE_PATH + filenames[i];
}
configureByFiles(null, fileNamesWithBasePath);
Collection<PsiElement> targets;
PsiReference reference = TargetElementUtil.findReference(myEditor);
if (reference == null) {
reference = JSTestUtils.findReferenceFromInjected(myEditor, myFile);
}
assertNotNull(reference);
if (reference instanceof PsiMultiReference) {
targets = new ArrayList<>();
for (PsiReference ref : ((PsiMultiReference) reference).getReferences()) {
targets.addAll(TargetElementUtil.getInstance().getTargetCandidates(ref));
}
} else {
targets = TargetElementUtil.getInstance().getTargetCandidates(reference);
}
assertTrue("Target elements not found", targets.size() > 0);
return PsiUtilCore.toPsiElementArray(targets);
}
use of com.intellij.psi.PsiReference in project intellij-plugins by JetBrains.
the class ActionScriptResolveTest method testResolve26.
@JSTestOptions({ JSTestOption.WithIndex })
public void testResolve26() throws Exception {
String fileText = "dynamic class Object {}\n" + "package {\n" + "\timport flash.display.Sprite;\n" + "\tpublic class DoubleInterfaceResolve extends Sprite {\n" + "\t}\n" + "}\n" + "import flash.display.Sprite;\n" + "class FooView extends Sprite {\n" + "}\n" + "\n" + "interface ItfA {\n" + " function f():It<ref>fB;\n" + "}\n" + "interface ItfB {}";
PsiReference ref = configureByFileText(fileText, "sample.js2");
PsiElement resolved = ref.resolve();
assertTrue(resolved instanceof JSClass);
}
Aggregations