Search in sources :

Example 46 with SearchScope

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);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) ModuleManager(com.intellij.openapi.module.ModuleManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.find(com.intellij.find) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Disposer(com.intellij.openapi.util.Disposer) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Condition(com.intellij.openapi.util.Condition) PsiBundle(com.intellij.psi.PsiBundle) javax.swing(javax.swing) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) ActionListener(java.awt.event.ActionListener) SearchScope(com.intellij.psi.search.SearchScope) Module(com.intellij.openapi.module.Module)

Example 47 with SearchScope

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);
}
Also used : SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with SearchScope

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();
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) HighlightUsagesHandler(com.intellij.codeInsight.highlighting.HighlightUsagesHandler) ArrayList(java.util.ArrayList) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) Project(com.intellij.openapi.project.Project) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 49 with SearchScope

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;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) UsageInfo(com.intellij.usageView.UsageInfo) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor)

Example 50 with SearchScope

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;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) ElementClassHint(com.intellij.psi.scope.ElementClassHint) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SearchScope (com.intellij.psi.search.SearchScope)90 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)39 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)36 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiElement (com.intellij.psi.PsiElement)16 PsiClass (com.intellij.psi.PsiClass)8 Processor (com.intellij.util.Processor)8 com.intellij.psi (com.intellij.psi)6 PsiMethod (com.intellij.psi.PsiMethod)6 HashMap (com.intellij.util.containers.HashMap)6 ClassInheritorsSearch (com.intellij.psi.search.searches.ClassInheritorsSearch)5 Nullable (org.jetbrains.annotations.Nullable)5 AnalysisScope (com.intellij.analysis.AnalysisScope)4 ProgressManager (com.intellij.openapi.progress.ProgressManager)4 TextRange (com.intellij.openapi.util.TextRange)4 PsiFile (com.intellij.psi.PsiFile)4 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)4 QueryExecutor (com.intellij.util.QueryExecutor)4