use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class AntResolveTest method doPropertyTest.
private void doPropertyTest() throws Exception {
PsiReference ref = configure();
PsiElement target = ref.resolve();
assertTrue((target instanceof PomTargetPsiElement && ((PomTargetPsiElement) target).getTarget().canNavigateToSource()) || (target instanceof XmlTag && ("project".equalsIgnoreCase(((XmlTag) target).getName()) || "buildnumber".equalsIgnoreCase(((XmlTag) target).getName()))));
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class SearchInLibsTest method doTest.
private void doTest(String classNameToSearch, String[] expectedFileNames, SearchScope scope) throws Exception {
final PsiClass aClass = myJavaFacade.findClass(classNameToSearch);
assertNotNull(aClass);
PsiReference[] refs = ReferencesSearch.search(aClass, scope, false).toArray(PsiReference.EMPTY_ARRAY);
ArrayList<PsiFile> files = new ArrayList<>();
for (PsiReference ref : refs) {
PsiFile file = ref.getElement().getContainingFile();
if (!files.contains(file)) {
files.add(file);
}
}
assertEquals("files count", expectedFileNames.length, files.size());
Collections.sort(files, (o1, o2) -> o1.getName().compareTo(o2.getName()));
Arrays.sort(expectedFileNames);
for (int i = 0; i < expectedFileNames.length; i++) {
String name = expectedFileNames[i];
PsiFile file = files.get(i);
assertEquals(name, file.getName());
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class ConvertAbsolutePathToRelativeIntentionAction method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
final int offset = editor.getCaretModel().getOffset();
final PsiElement element = file.findElementAt(offset);
if (element == null || element instanceof PsiWhiteSpace) {
return false;
}
final PsiReference reference = file.findReferenceAt(offset);
final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
if (fileReference != null) {
final FileReferenceSet set = fileReference.getFileReferenceSet();
final FileReference lastReference = set.getLastReference();
return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null;
}
return false;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class ConvertAbsolutePathToRelativeIntentionAction method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
if (fileReference != null) {
final FileReference lastReference = fileReference.getFileReferenceSet().getLastReference();
if (lastReference != null)
lastReference.bindToElement(lastReference.resolve(), !isConvertToRelative());
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class InlineSuperClassRefactoringHandler method inlineElement.
public void inlineElement(final Project project, final Editor editor, final PsiElement element) {
PsiClass superClass = (PsiClass) element;
if (!superClass.getManager().isInProject(superClass)) {
CommonRefactoringUtil.showErrorHint(project, editor, "Cannot inline non-project class", REFACTORING_NAME, null);
return;
}
PsiClass chosen = null;
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
if (reference != null) {
final PsiElement resolve = reference.resolve();
if (resolve == superClass) {
final PsiElement referenceElement = reference.getElement();
if (referenceElement != null) {
final PsiElement parent = referenceElement.getParent();
if (parent instanceof PsiReferenceList) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiClass) {
chosen = (PsiClass) gParent;
}
}
}
}
}
new InlineSuperClassRefactoringDialog(project, superClass, chosen).show();
}
Aggregations