use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class FindPopupScopeUIImpl method initComponents.
public void initComponents() {
Module[] modules = ModuleManager.getInstance(myProject).getModules();
String[] names = new String[modules.length];
for (int i = 0; i < modules.length; i++) {
names[i] = modules[i].getName();
}
Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
myModuleComboBox = new ComboBox<>(names);
ActionListener restartSearchListener = e -> scheduleResultsUpdate();
myModuleComboBox.addActionListener(restartSearchListener);
myDirectoryChooser = new FindPopupDirectoryChooser(myFindPopupPanel);
myScopeCombo = new ScopeChooserCombo();
myScopeCombo.init(myProject, true, true, FindSettings.getInstance().getDefaultScopeName(), new Condition<ScopeDescriptor>() {
final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");
final String moduleFilesScopeName;
{
String moduleScopeName = PsiBundle.message("search.scope.module", "");
final int ind = moduleScopeName.indexOf(' ');
moduleFilesScopeName = moduleScopeName.substring(0, ind + 1);
}
@Override
public boolean value(ScopeDescriptor descriptor) {
final String display = descriptor.getDisplay();
return !projectFilesScopeName.equals(display) && !display.startsWith(moduleFilesScopeName);
}
});
myScopeCombo.setBrowseListener(new ScopeChooserCombo.BrowseListener() {
private FindModel myModelSnapshot;
@Override
public void onBeforeBrowseStarted() {
myModelSnapshot = myHelper.getModel();
myFindPopupPanel.getCanClose().set(false);
}
@Override
public void onAfterBrowseFinished() {
if (myModelSnapshot != null) {
SearchScope scope = myScopeCombo.getSelectedScope();
if (scope != null) {
myModelSnapshot.setCustomScope(scope);
}
myFindPopupPanel.getCanClose().set(true);
}
}
});
myScopeCombo.getComboBox().addActionListener(restartSearchListener);
Disposer.register(myFindPopupPanel.getDisposable(), myScopeCombo);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class PsiElement2UsageTargetAdapter method getLongDescriptiveName.
@NotNull
@Override
public String getLongDescriptiveName() {
SearchScope searchScope = myOptions.searchScope;
String scopeString = searchScope.getDisplayName();
PsiElement psiElement = getElement();
return psiElement == null ? UsageViewBundle.message("node.invalid") : FindBundle.message("recent.find.usages.action.popup", StringUtil.capitalize(UsageViewUtil.getType(psiElement)), DescriptiveNameUtil.getDescriptiveName(psiElement), scopeString);
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class PsiElement2UsageTargetAdapter method highlightUsages.
@Override
public void highlightUsages(@NotNull PsiFile file, @NotNull Editor editor, boolean clearHighlights) {
PsiElement target = getElement();
if (file instanceof PsiCompiledFile)
file = ((PsiCompiledFile) file).getDecompiledPsiFile();
Project project = target.getProject();
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(target, true);
// in case of injected file, use host file to highlight all occurrences of the target in each injected file
PsiFile context = InjectedLanguageManager.getInstance(project).getTopLevelFile(file);
SearchScope searchScope = new LocalSearchScope(context);
Collection<PsiReference> refs = handler == null ? ReferencesSearch.search(target, searchScope, false).findAll() : handler.findReferencesToHighlight(target, searchScope);
new HighlightUsagesHandler.DoHighlightRunnable(new ArrayList<>(refs), project, target, editor, context, clearHighlights).run();
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class FindUsagesHandler method processElementUsages.
public boolean processElementUsages(@NotNull final PsiElement element, @NotNull final Processor<UsageInfo> processor, @NotNull final FindUsagesOptions options) {
final ReadActionProcessor<PsiReference> refProcessor = new ReadActionProcessor<PsiReference>() {
@Override
public boolean processInReadAction(final PsiReference ref) {
TextRange rangeInElement = ref.getRangeInElement();
return processor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false));
}
};
final SearchScope scope = options.searchScope;
final boolean searchText = options.isSearchForTextOccurrences && scope instanceof GlobalSearchScope;
if (options.isUsages) {
boolean success = ReferencesSearch.search(new ReferencesSearch.SearchParameters(element, scope, false, options.fastTrack)).forEach(refProcessor);
if (!success)
return false;
}
if (searchText) {
if (options.fastTrack != null) {
options.fastTrack.searchCustom(consumer -> processUsagesInText(element, processor, (GlobalSearchScope) scope));
} else {
return processUsagesInText(element, processor, (GlobalSearchScope) scope);
}
}
return true;
}
use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.
the class PsiImplUtil method getMemberUseScope.
@NotNull
public static SearchScope getMemberUseScope(@NotNull PsiMember member) {
PsiFile file = member.getContainingFile();
PsiElement topElement = file == null ? member : file;
Project project = topElement.getProject();
final GlobalSearchScope maximalUseScope = ResolveScopeManager.getInstance(project).getUseScope(topElement);
if (isInServerPage(file))
return maximalUseScope;
PsiClass aClass = member.getContainingClass();
if (aClass instanceof PsiAnonymousClass && !(aClass instanceof PsiEnumConstantInitializer && member instanceof PsiMethod && member.hasModifierProperty(PsiModifier.PUBLIC) && ((PsiMethod) member).findSuperMethods().length > 0)) {
//member from anonymous class can be called from outside the class
PsiElement methodCallExpr = PsiUtil.isLanguageLevel8OrHigher(aClass) ? PsiTreeUtil.getTopmostParentOfType(aClass, PsiStatement.class) : PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class);
return new LocalSearchScope(methodCallExpr != null ? methodCallExpr : aClass);
}
PsiModifierList modifierList = member.getModifierList();
int accessLevel = modifierList == null ? PsiUtil.ACCESS_LEVEL_PUBLIC : PsiUtil.getAccessLevel(modifierList);
if (accessLevel == PsiUtil.ACCESS_LEVEL_PUBLIC || accessLevel == PsiUtil.ACCESS_LEVEL_PROTECTED) {
// class use scope doesn't matter, since another very visible class can inherit from aClass
return maximalUseScope;
}
if (accessLevel == PsiUtil.ACCESS_LEVEL_PRIVATE) {
PsiClass topClass = PsiUtil.getTopLevelClass(member);
return topClass != null ? new LocalSearchScope(topClass) : file == null ? maximalUseScope : new LocalSearchScope(file);
}
if (file instanceof PsiJavaFile) {
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(((PsiJavaFile) file).getPackageName());
if (aPackage != null) {
SearchScope scope = PackageScope.packageScope(aPackage, false);
return scope.intersectWith(maximalUseScope);
}
}
return maximalUseScope;
}
Aggregations