Search in sources :

Example 81 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class FindUsagesOptions method calcScope.

@NotNull
private static SearchScope calcScope(@NotNull Project project, @Nullable DataContext dataContext) {
    String defaultScopeName = FindSettings.getInstance().getDefaultScopeName();
    List<SearchScope> predefined = PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(project, dataContext, true, false, false, false);
    SearchScope resultScope = null;
    for (SearchScope scope : predefined) {
        if (scope.getDisplayName().equals(defaultScopeName)) {
            resultScope = scope;
            break;
        }
    }
    if (resultScope == null) {
        resultScope = ProjectScope.getProjectScope(project);
    }
    return resultScope;
}
Also used : SearchScope(com.intellij.psi.search.SearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class SliceUtil method processFieldUsages.

private static boolean processFieldUsages(@NotNull final PsiField field, @NotNull final JavaSliceUsage parent, @NotNull final PsiSubstitutor parentSubstitutor, @NotNull final Processor<SliceUsage> processor) {
    if (field.hasInitializer()) {
        PsiExpression initializer = field.getInitializer();
        if (initializer != null && !(field instanceof PsiCompiledElement)) {
            if (!handToProcessor(initializer, processor, parent, parentSubstitutor, parent.indexNesting, ""))
                return false;
        }
    }
    SearchScope searchScope = parent.getScope().toSearchScope();
    return ReferencesSearch.search(field, searchScope).forEach(reference -> {
        ProgressManager.checkCanceled();
        PsiElement element = reference.getElement();
        if (element instanceof PsiCompiledElement) {
            element = element.getNavigationElement();
            if (!parent.getScope().contains(element))
                return true;
        }
        if (element instanceof PsiReferenceExpression) {
            final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) element;
            PsiElement parentExpr = referenceExpression.getParent();
            if (PsiUtil.isOnAssignmentLeftHand(referenceExpression)) {
                PsiExpression rExpression = ((PsiAssignmentExpression) parentExpr).getRExpression();
                PsiType rtype = rExpression.getType();
                PsiType ftype = field.getType();
                PsiType subFType = parentSubstitutor.substitute(ftype);
                PsiType subRType = parentSubstitutor.substitute(rtype);
                if (subFType != null && subRType != null && TypeConversionUtil.isAssignable(subFType, subRType)) {
                    return handToProcessor(rExpression, processor, parent, parentSubstitutor, parent.indexNesting, "");
                }
            }
            if (parentExpr instanceof PsiPrefixExpression && ((PsiPrefixExpression) parentExpr).getOperand() == referenceExpression && (((PsiPrefixExpression) parentExpr).getOperationTokenType() == JavaTokenType.PLUSPLUS || ((PsiPrefixExpression) parentExpr).getOperationTokenType() == JavaTokenType.MINUSMINUS)) {
                PsiPrefixExpression prefixExpression = (PsiPrefixExpression) parentExpr;
                return handToProcessor(prefixExpression, processor, parent, parentSubstitutor, parent.indexNesting, "");
            }
            if (parentExpr instanceof PsiPostfixExpression && ((PsiPostfixExpression) parentExpr).getOperand() == referenceExpression && (((PsiPostfixExpression) parentExpr).getOperationTokenType() == JavaTokenType.PLUSPLUS || ((PsiPostfixExpression) parentExpr).getOperationTokenType() == JavaTokenType.MINUSMINUS)) {
                PsiPostfixExpression postfixExpression = (PsiPostfixExpression) parentExpr;
                return handToProcessor(postfixExpression, processor, parent, parentSubstitutor, parent.indexNesting, "");
            }
        }
        return processIfInForeignLanguage(parent, parentSubstitutor, 0, "", processor, element);
    });
}
Also used : SearchScope(com.intellij.psi.search.SearchScope)

Example 83 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 84 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 85 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)

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