use of com.intellij.find.impl.FindManagerImpl in project smali by JesusFreke.
the class FindUsagesTest method findUsages.
private Collection<UsageInfo> findUsages(@NotNull PsiElement element) {
FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(element, false);
Assert.assertNotNull(findUsagesHandler);
final FindUsagesOptions options = findUsagesHandler.getFindUsagesOptions();
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
for (PsiElement primaryElement : findUsagesHandler.getPrimaryElements()) {
findUsagesHandler.processElementUsages(primaryElement, processor, options);
}
for (PsiElement secondaryElement : findUsagesHandler.getSecondaryElements()) {
findUsagesHandler.processElementUsages(secondaryElement, processor, options);
}
return processor.getResults();
}
use of com.intellij.find.impl.FindManagerImpl in project intellij-plugins by JetBrains.
the class DartServerFindUsagesTest method testFileUsage.
public void testFileUsage() {
final PsiFile barFile = myFixture.configureByText("bar.dart", "");
// it is important that foo.dart is not open in the editor
myFixture.addFileToProject("foo.dart", "import '" + barFile.getName() + "';");
// warm up
myFixture.doHighlighting();
final FindUsagesManager manager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
final FindUsagesHandler handler = manager.getFindUsagesHandler(getFile(), false);
assertNotNull(handler);
assertFalse(handler instanceof DartServerFindUsagesHandler);
final Collection<PsiReference> usages = handler.findReferencesToHighlight(getFile(), GlobalSearchScope.allScope(getProject()));
assertSize(1, usages);
final PsiReference reference = usages.iterator().next();
assertInstanceOf(reference, DartFileReference.class);
assertEquals("foo.dart", reference.getElement().getContainingFile().getName());
assertEquals("import '" + barFile.getName() + "';", reference.getElement().getParent().getText());
}
use of com.intellij.find.impl.FindManagerImpl in project intellij-plugins by JetBrains.
the class DartServerFindUsagesTest method findUsages.
@NotNull
private Collection<UsageInfo> findUsages(@NotNull final SearchScope scope) {
final PsiElement elementToSearch = getFile().findElementAt(getEditor().getCaretModel().getOffset());
assertNotNull(elementToSearch);
final FindUsagesManager manager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
final FindUsagesHandler handler = manager.getFindUsagesHandler(elementToSearch, false);
assertInstanceOf(handler, DartServerFindUsagesHandler.class);
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
handler.processElementUsages(elementToSearch, processor, new FindUsagesOptions(scope));
return processor.getResults();
}
use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.
the class TextOccurrencesUtil method isSearchTextOccurencesEnabled.
public static boolean isSearchTextOccurencesEnabled(@NotNull PsiElement element) {
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(element.getProject())).getFindUsagesManager();
final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, true);
return FindUsagesUtil.isSearchForTextOccurrencesAvailable(element, false, handler);
}
use of com.intellij.find.impl.FindManagerImpl in project intellij-community by JetBrains.
the class ChangeMethodSignatureFromUsageFix method performChange.
public static List<ParameterInfoImpl> performChange(final Project project, final Editor editor, final PsiFile file, final PsiMethod method, final int minUsagesNumber, final ParameterInfoImpl[] newParametersInfo, final boolean changeAllUsages, final boolean allowDelegation) {
if (!FileModificationService.getInstance().prepareFileForWrite(method.getContainingFile()))
return null;
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(method, false);
//on failure or cancel (e.g. cancel of super methods dialog)
if (handler == null)
return null;
final JavaMethodFindUsagesOptions options = new JavaMethodFindUsagesOptions(project);
options.isImplementingMethods = true;
options.isOverridingMethods = true;
options.isUsages = true;
options.isSearchForTextOccurrences = false;
final int[] usagesFound = new int[1];
Runnable runnable = () -> {
Processor<UsageInfo> processor = t -> ++usagesFound[0] < minUsagesNumber;
handler.processElementUsages(method, processor, options);
};
String progressTitle = QuickFixBundle.message("searching.for.usages.progress.title");
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, project))
return null;
if (ApplicationManager.getApplication().isUnitTestMode() || usagesFound[0] < minUsagesNumber) {
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(), newParametersInfo) {
@Override
@NotNull
protected UsageInfo[] findUsages() {
return changeAllUsages ? super.findUsages() : UsageInfo.EMPTY_ARRAY;
}
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
CommandProcessor.getInstance().setCurrentCommandName(getCommandName());
super.performRefactoring(usages);
}
};
processor.run();
ApplicationManager.getApplication().runWriteAction(() -> UndoUtil.markPsiFileForUndo(file));
return Arrays.asList(newParametersInfo);
} else {
final List<ParameterInfoImpl> parameterInfos = newParametersInfo != null ? new ArrayList<>(Arrays.asList(newParametersInfo)) : new ArrayList<>();
final PsiReferenceExpression refExpr = JavaTargetElementEvaluator.findReferenceExpression(editor);
JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, allowDelegation, refExpr);
dialog.setParameterInfos(parameterInfos);
dialog.show();
return dialog.isOK() ? dialog.getParameters() : null;
}
}
Aggregations