use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class ScopeBasedTodosTreeStructure method accept.
@Override
public boolean accept(final PsiFile psiFile) {
if (!psiFile.isValid())
return false;
SearchScope scope = myScopes.getSelectedScope();
VirtualFile file = psiFile.getVirtualFile();
boolean isAffected = scope != null && file != null && scope.contains(file);
return isAffected && (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) || (myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0));
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class GroovyScopeUtil method getEffectiveScope.
public static SearchScope getEffectiveScope(PsiMethod... methods) {
SearchScope accessScope = methods[0].getUseScope();
for (int i = 1; i < methods.length; i++) {
PsiMethod method1 = methods[i];
accessScope = accessScope.union(method1.getUseScope());
}
return accessScope;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class AccessorMethodReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = queryParameters.getMethod();
final String propertyName;
if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) {
final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null);
propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod) cat);
} else {
propertyName = GroovyPropertyUtils.getPropertyName(method);
}
if (propertyName == null)
return;
final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope(), GroovyScopeUtil.getEffectiveScope(method));
queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
if (!GroovyPropertyUtils.isPropertyName(propertyName)) {
queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
}
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class JavaFxMethodSearcher method searchMethod.
private static void searchMethod(@NotNull PsiMethod psiMethod, @NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final Project project = PsiUtilCore.getProjectInReadAction(psiMethod);
final SearchScope scope = ReadAction.compute(queryParameters::getEffectiveSearchScope);
if (scope instanceof LocalSearchScope) {
final VirtualFile[] vFiles = ((LocalSearchScope) scope).getVirtualFiles();
for (VirtualFile vFile : vFiles) {
if (JavaFxFileTypeFactory.isFxml(vFile)) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
if (psiFile != null) {
final Boolean goOn = ReadAction.compute(() -> searchMethodInFile(psiMethod, psiFile, consumer));
if (!goOn)
break;
}
}
}
} else if (scope instanceof GlobalSearchScope) {
final String propertyName = ReadAction.compute(() -> PropertyUtil.getPropertyName(psiMethod.getName()));
if (propertyName == null)
return;
final String className = ReadAction.compute(() -> {
final PsiClass psiClass = psiMethod.getContainingClass();
return psiClass != null ? psiClass.getName() : null;
});
if (className == null)
return;
final GlobalSearchScope fxmlScope = new JavaFxScopeEnlarger.GlobalFxmlSearchScope((GlobalSearchScope) scope);
final VirtualFile[] filteredFiles = ReadAction.compute(() -> CacheManager.SERVICE.getInstance(project).getVirtualFilesWithWord(className, UsageSearchContext.IN_PLAIN_TEXT, fxmlScope, true));
if (ArrayUtil.isEmpty(filteredFiles))
return;
final GlobalSearchScope filteredScope = GlobalSearchScope.filesScope(project, ContainerUtil.newHashSet(filteredFiles));
ApplicationManager.getApplication().runReadAction((Runnable) () -> CacheManager.SERVICE.getInstance(project).processFilesWithWord(file -> searchMethodInFile(psiMethod, file, consumer), propertyName, UsageSearchContext.IN_PLAIN_TEXT, filteredScope, true));
}
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class ExtractMethodProcessor method doRefactoring.
/**
* Invoked in command and in atomic action
*/
public void doRefactoring() throws IncorrectOperationException {
initDuplicates();
chooseAnchor();
LogicalPosition pos1;
if (myEditor != null) {
int col = myEditor.getCaretModel().getLogicalPosition().column;
int line = myEditor.getCaretModel().getLogicalPosition().line;
pos1 = new LogicalPosition(line, col);
LogicalPosition pos = new LogicalPosition(0, 0);
myEditor.getCaretModel().moveToLogicalPosition(pos);
} else {
pos1 = null;
}
final SearchScope processConflictsScope = myMethodVisibility.equals(PsiModifier.PRIVATE) ? new LocalSearchScope(myTargetClass) : GlobalSearchScope.projectScope(myProject);
final Map<PsiMethodCallExpression, PsiMethod> overloadsResolveMap = new HashMap<>();
final Runnable collectOverloads = () -> ApplicationManager.getApplication().runReadAction(() -> {
Map<PsiMethodCallExpression, PsiMethod> overloads = ExtractMethodUtil.encodeOverloadTargets(myTargetClass, processConflictsScope, myMethodName, myCodeFragmentMember);
overloadsResolveMap.putAll(overloads);
});
final Runnable extract = () -> {
doExtract();
ExtractMethodUtil.decodeOverloadTargets(overloadsResolveMap, myExtractedMethod, myCodeFragmentMember);
};
if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
collectOverloads.run();
extract.run();
} else {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(collectOverloads, "Collect overloads...", true, myProject))
return;
ApplicationManager.getApplication().runWriteAction(extract);
}
if (myEditor != null) {
myEditor.getCaretModel().moveToLogicalPosition(pos1);
int offset = myMethodCall.getMethodExpression().getTextRange().getStartOffset();
myEditor.getCaretModel().moveToOffset(offset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
myEditor.getSelectionModel().removeSelection();
}
}
Aggregations