use of com.intellij.find.findUsages.JavaFindUsagesHandler in project intellij-community by JetBrains.
the class FindUsagesTest method testNonCodeClassUsages.
public void testNonCodeClassUsages() throws Exception {
final TempDirTestFixture tdf = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
tdf.setUp();
try {
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA.getId());
moduleModel.commit();
tdf.createFile("plugin.xml", "<document>\n" + " <action class=\"com.Foo\" />\n" + " <action class=\"com.Foo.Bar\" />\n" + " <action class=\"com.Foo$Bar\" />\n" + "</document>");
PsiTestUtil.addContentRoot(ModuleManager.getInstance(getProject()).findModuleByName("independent"), tdf.getFile(""));
}
}.execute();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiClass foo = myJavaFacade.findClass("com.Foo", scope);
PsiClass bar = myJavaFacade.findClass("com.Foo.Bar", scope);
final int[] count = { 0 };
Processor<UsageInfo> processor = usageInfo -> {
int navigationOffset = usageInfo.getNavigationOffset();
assertTrue(navigationOffset > 0);
String textAfter = usageInfo.getFile().getText().substring(navigationOffset);
assertTrue(textAfter, textAfter.startsWith("Foo") || textAfter.startsWith("Bar") || textAfter.startsWith("com.Foo.Bar"));
count[0]++;
return true;
};
JavaFindUsagesHandler handler = new JavaFindUsagesHandler(bar, JavaFindUsagesHandlerFactory.getInstance(getProject()));
count[0] = 0;
handler.processUsagesInText(foo, processor, scope);
assertEquals(3, count[0]);
count[0] = 0;
handler.processUsagesInText(bar, processor, scope);
assertEquals(2, count[0]);
} finally {
tdf.tearDown();
}
}
use of com.intellij.find.findUsages.JavaFindUsagesHandler in project intellij-community by JetBrains.
the class GroovyFieldFindUsagesHandlerFactory method createFindUsagesHandler.
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
return new JavaFindUsagesHandler(element, this) {
@NotNull
@Override
public PsiElement[] getSecondaryElements() {
PsiElement element = getPsiElement();
final PsiField field = (PsiField) element;
PsiClass containingClass = field.getContainingClass();
if (containingClass != null) {
PsiMethod[] getters = GroovyPropertyUtils.getAllGettersByField(field);
PsiMethod[] setters = GroovyPropertyUtils.getAllSettersByField(field);
if (getters.length + setters.length > 0) {
final boolean doSearch;
if (arePhysical(getters) || arePhysical(setters)) {
if (ApplicationManager.getApplication().isUnitTestMode())
return PsiElement.EMPTY_ARRAY;
doSearch = Messages.showYesNoDialog(FindBundle.message("find.field.accessors.prompt", field.getName()), FindBundle.message("find.field.accessors.title"), Messages.getQuestionIcon()) == Messages.YES;
} else {
doSearch = true;
}
if (doSearch) {
final List<PsiElement> elements = new ArrayList<>();
for (PsiMethod getter : getters) {
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(getter, ACTION_STRING));
}
for (PsiMethod setter : setters) {
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(setter, ACTION_STRING));
}
for (Iterator<PsiElement> iterator = elements.iterator(); iterator.hasNext(); ) {
if (iterator.next() instanceof GrAccessorMethod)
iterator.remove();
}
return PsiUtilCore.toPsiElementArray(elements);
} else {
return PsiElement.EMPTY_ARRAY;
}
}
}
return super.getSecondaryElements();
}
};
}
Aggregations