use of com.intellij.find.FindModel in project android by JetBrains.
the class SearchInBuildFilesHyperlink method searchInBuildFiles.
public static void searchInBuildFiles(@NotNull String text, @NotNull final Project project) {
FindManager findManager = FindManager.getInstance(project);
UsageViewManager usageViewManager = UsageViewManager.getInstance(project);
FindModel findModel = findManager.getFindInProjectModel().clone();
findModel.setStringToFind(text);
findModel.setReplaceState(false);
findModel.setOpenInNewTabVisible(true);
findModel.setOpenInNewTabEnabled(true);
findModel.setOpenInNewTab(true);
findModel.setFileFilter(SdkConstants.FN_BUILD_GRADLE);
findManager.getFindInProjectModel().copyFrom(findModel);
final FindModel findModelCopy = findModel.clone();
UsageViewPresentation presentation = setupViewPresentation(findModel.isOpenInNewTabEnabled(), findModelCopy);
boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
final FindUsagesProcessPresentation processPresentation = setupProcessPresentation(project, showPanelIfOnlyOneUsage, presentation);
UsageTarget usageTarget = new StringUsageTarget(project, findModel);
usageViewManager.searchAndShowUsages(new UsageTarget[] { usageTarget }, new Factory<UsageSearcher>() {
@Override
public UsageSearcher create() {
return new UsageSearcher() {
@Override
public void generate(@NotNull final Processor<Usage> processor) {
AdapterProcessor<UsageInfo, Usage> consumer = new AdapterProcessor<UsageInfo, Usage>(processor, UsageInfo2UsageAdapter.CONVERTER);
findUsages(findModelCopy, project, consumer, processPresentation);
}
};
}
}, processPresentation, presentation, null);
}
use of com.intellij.find.FindModel in project intellij-community by JetBrains.
the class ExpressionOccurrenceManager method findExpressionOccurrences.
public PsiExpression[] findExpressionOccurrences() {
if (myMainOccurence instanceof PsiLiteralExpression && !myMainOccurence.isPhysical()) {
final FindManager findManager = FindManager.getInstance(getScope().getProject());
final FindModel findModel = (FindModel) findManager.getFindInFileModel().clone();
findModel.setCaseSensitive(true);
findModel.setRegularExpressions(false);
String value = StringUtil.stripQuotesAroundValue(myMainOccurence.getText());
if (value.length() > 0) {
findModel.setStringToFind(value);
final List<PsiExpression> results = new ArrayList<>();
final PsiFile file = getScope().getContainingFile();
final String text = getScope().getText();
final int offset = getScope().getTextRange().getStartOffset();
FindResult result = findManager.findString(text, 0, findModel);
final Set<PsiLiteralExpression> literals = new HashSet<>();
while (result.isStringFound()) {
final int startOffset = offset + result.getStartOffset();
final int endOffset = result.getEndOffset();
final PsiLiteralExpression literalExpression = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), PsiLiteralExpression.class);
if (literalExpression != null && !literals.contains(literalExpression)) {
//enum. occurrences inside string literals
final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(file.getProject(), file, startOffset, offset + endOffset);
if (expression != null && IntroduceVariableBase.getErrorMessage(expression) == null) {
results.add(expression);
literals.add(literalExpression);
}
}
result = findManager.findString(text, endOffset, findModel);
}
return results.toArray(new PsiExpression[results.size()]);
}
}
return CodeInsightUtil.findExpressionOccurrences(myScope, myMainOccurence);
}
use of com.intellij.find.FindModel in project intellij-community by JetBrains.
the class FindInProjectTask method searchInFiles.
private void searchInFiles(@NotNull Collection<VirtualFile> virtualFiles, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull final Processor<UsageInfo> consumer) {
AtomicInteger occurrenceCount = new AtomicInteger();
AtomicInteger processedFileCount = new AtomicInteger();
Processor<VirtualFile> processor = virtualFile -> {
if (!virtualFile.isValid())
return true;
long fileLength = UsageViewManagerImpl.getFileLength(virtualFile);
if (fileLength == -1)
return true;
final boolean skipProjectFile = ProjectUtil.isProjectOrWorkspaceFile(virtualFile) && !myFindModel.isSearchInProjectFiles();
if (skipProjectFile && !Registry.is("find.search.in.project.files"))
return true;
if (fileLength > SINGLE_FILE_SIZE_LIMIT) {
myLargeFiles.add(virtualFile);
return true;
}
myProgress.checkCanceled();
if (myProgress.isRunning()) {
double fraction = (double) processedFileCount.incrementAndGet() / virtualFiles.size();
myProgress.setFraction(fraction);
}
String text = FindBundle.message("find.searching.for.string.in.file.progress", myFindModel.getStringToFind(), virtualFile.getPresentableUrl());
myProgress.setText(text);
myProgress.setText2(FindBundle.message("find.searching.for.string.in.file.occurrences.progress", occurrenceCount));
Pair.NonNull<PsiFile, VirtualFile> pair = ReadAction.compute(() -> findFile(virtualFile));
if (pair == null)
return true;
PsiFile psiFile = pair.first;
VirtualFile sourceVirtualFile = pair.second;
int countInFile = FindInProjectUtil.processUsagesInFile(psiFile, sourceVirtualFile, myFindModel, info -> skipProjectFile || consumer.process(info));
if (countInFile > 0 && skipProjectFile) {
processPresentation.projectFileUsagesFound(() -> {
FindModel model = myFindModel.clone();
model.setSearchInProjectFiles(true);
FindInProjectManager.getInstance(myProject).startFindInProject(model);
});
return true;
}
occurrenceCount.addAndGet(countInFile);
if (countInFile > 0) {
if (myTotalFilesSize.addAndGet(fileLength) > FILES_SIZE_LIMIT && myWarningShown.compareAndSet(false, true)) {
String message = FindBundle.message("find.excessive.total.size.prompt", UsageViewManagerImpl.presentableSize(myTotalFilesSize.longValue()), ApplicationNamesInfo.getInstance().getProductName());
UsageLimitUtil.showAndCancelIfAborted(myProject, message, processPresentation.getUsageViewPresentation());
}
}
return true;
};
PsiSearchHelperImpl.processFilesConcurrentlyDespiteWriteActions(myProject, new ArrayList<>(virtualFiles), myProgress, processor);
}
use of com.intellij.find.FindModel in project intellij-community by JetBrains.
the class FindInProjectManager method startFindInProject.
public void startFindInProject(@NotNull FindModel findModel) {
if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
return;
}
com.intellij.usages.UsageViewManager manager = com.intellij.usages.UsageViewManager.getInstance(myProject);
if (manager == null)
return;
final FindManager findManager = FindManager.getInstance(myProject);
findManager.getFindInProjectModel().copyFrom(findModel);
final FindModel findModelCopy = findModel.clone();
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(FindSettings.getInstance().isShowResultsInSeparateView(), findModelCopy);
final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
ConfigurableUsageTarget usageTarget = new FindInProjectUtil.StringUsageTarget(myProject, findModel);
((FindManagerImpl) FindManager.getInstance(myProject)).getFindUsagesManager().addToHistory(usageTarget);
manager.searchAndShowUsages(new UsageTarget[] { usageTarget }, () -> processor -> {
myIsFindInProgress = true;
try {
Processor<UsageInfo> consumer = info -> {
Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon();
return processor.process(usage);
};
FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
} finally {
myIsFindInProgress = false;
}
}, processPresentation, presentation, null);
}
use of com.intellij.find.FindModel in project intellij-community by JetBrains.
the class RestorePreviousSettingsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
FindModel findModel = e.getRequiredData(EditorSearchSession.SESSION_KEY).getFindModel();
findModel.copyFrom(FindManager.getInstance(e.getProject()).getPreviousFindModel());
}
Aggregations