Search in sources :

Example 51 with SearchScope

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

the class BackwardDependenciesAction method analyze.

@Override
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
    //find library usages in project
    scope.setSearchInLibraries(true);
    final SearchScope selectedScope = myPanel.myCombo.getSelectedScope();
    new BackwardDependenciesHandler(project, scope, selectedScope != null ? new AnalysisScope(selectedScope, project) : new AnalysisScope(project)).analyze();
    dispose();
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 52 with SearchScope

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

the class ScopeChooserCombo method init.

public void init(final Project project, final boolean suggestSearchInLibs, final boolean prevSearchWholeFiles, final String preselect, @Nullable Condition<ScopeDescriptor> scopeFilter) {
    mySuggestSearchInLibs = suggestSearchInLibs;
    myPrevSearchFiles = prevSearchWholeFiles;
    myProject = project;
    myScopeListener = () -> {
        final SearchScope selectedScope = getSelectedScope();
        rebuildModel();
        if (selectedScope != null) {
            selectScope(selectedScope.getDisplayName());
        }
    };
    myScopeFilter = scopeFilter;
    myNamedScopeManager = NamedScopeManager.getInstance(project);
    myNamedScopeManager.addScopeListener(myScopeListener);
    myValidationManager = DependencyValidationManager.getInstance(project);
    myValidationManager.addScopeListener(myScopeListener);
    addActionListener(createScopeChooserListener());
    final JComboBox<ScopeDescriptor> combo = getComboBox();
    combo.setRenderer(new ScopeDescriptionWithDelimiterRenderer());
    rebuildModel();
    selectScope(preselect);
    new ComboboxSpeedSearch(combo) {

        @Override
        protected String getElementText(Object element) {
            if (element instanceof ScopeDescriptor) {
                final ScopeDescriptor descriptor = (ScopeDescriptor) element;
                return descriptor.getDisplay();
            }
            return null;
        }
    };
}
Also used : SearchScope(com.intellij.psi.search.SearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ComboboxSpeedSearch(com.intellij.ui.ComboboxSpeedSearch)

Example 53 with SearchScope

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

the class SearchDialog method doOKAction.

// Performs ok action
@Override
protected void doOKAction() {
    SearchScope selectedScope = getSelectedScope();
    if (selectedScope == null)
        return;
    myDoingOkAction = true;
    boolean result = isValid();
    myDoingOkAction = false;
    if (!result)
        return;
    myAlarm.cancelAllRequests();
    super.doOKAction();
    if (!myRunFindActionOnClose)
        return;
    final FindSettings findSettings = FindSettings.getInstance();
    findSettings.setDefaultScopeName(selectedScope.getDisplayName());
    findSettings.setShowResultsInSeparateView(openInNewTab.isSelected());
    try {
        final Configuration configuration = model.getConfig();
        if (model.getShadowConfig() != null) {
            if (model.getShadowConfig().isPredefined()) {
                configuration.setName(model.getShadowConfig().getName());
            }
        //else {
        //  // user template, save it
        //  setValuesToConfig(model.getShadowConfig());
        //}
        }
        filterOutUnusedVariableConstraints(configuration);
        existingTemplatesComponent.addConfigurationToHistory(configuration);
        startSearching();
    } catch (MalformedPatternException ex) {
        reportMessage("this.pattern.is.malformed.message", searchCriteriaEdit, ex.getMessage());
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) FindSettings(com.intellij.find.FindSettings)

Example 54 with SearchScope

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

the class UnusedSymbolUtil method processUsages.

// return false if can't process usages (weird member of too may usages) or processor returned false
public static boolean processUsages(@NotNull Project project, @NotNull PsiFile containingFile, @NotNull PsiMember member, @NotNull ProgressIndicator progress, @Nullable PsiFile ignoreFile, @NotNull Processor<UsageInfo> usageInfoProcessor) {
    String name = member.getName();
    if (name == null) {
        log("* " + member.getName() + " no name; false");
        return false;
    }
    SearchScope useScope = member.getUseScope();
    PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
    if (useScope instanceof GlobalSearchScope) {
        // some classes may have references from within XML outside dependent modules, e.g. our actions
        if (member instanceof PsiClass) {
            useScope = GlobalSearchScope.projectScope(project).uniteWith((GlobalSearchScope) useScope);
        }
        // if we've resolved all references, find usages will be fast
        PsiSearchHelper.SearchCostResult cheapEnough = RefResolveService.ENABLED && RefResolveService.getInstance(project).isUpToDate() ? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES : searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope) useScope, ignoreFile, progress);
        if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
            log("* " + member.getName() + " too many usages; false");
            return false;
        }
        //if count is 0 there is no usages since we've called myRefCountHolder.isReferenced() before
        if (cheapEnough == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES && !canBeReferencedViaWeirdNames(member, containingFile)) {
            log("* " + member.getName() + " 0 usages; true");
            return true;
        }
        if (member instanceof PsiMethod) {
            String propertyName = PropertyUtil.getPropertyName(member);
            if (propertyName != null) {
                SearchScope fileScope = containingFile.getUseScope();
                if (fileScope instanceof GlobalSearchScope && searchHelper.isCheapEnoughToSearch(propertyName, (GlobalSearchScope) fileScope, ignoreFile, progress) == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
                    log("* " + member.getName() + " too many prop usages; false");
                    return false;
                }
            }
        }
    }
    FindUsagesOptions options;
    if (member instanceof PsiPackage) {
        options = new JavaPackageFindUsagesOptions(useScope);
        options.isSearchForTextOccurrences = true;
    } else if (member instanceof PsiClass) {
        options = new JavaClassFindUsagesOptions(useScope);
        options.isSearchForTextOccurrences = true;
    } else if (member instanceof PsiMethod) {
        PsiMethod method = (PsiMethod) member;
        options = new JavaMethodFindUsagesOptions(useScope);
        options.isSearchForTextOccurrences = method.isConstructor();
    } else if (member instanceof PsiVariable) {
        options = new JavaVariableFindUsagesOptions(useScope);
        options.isSearchForTextOccurrences = false;
    } else {
        options = new FindUsagesOptions(useScope);
        options.isSearchForTextOccurrences = true;
    }
    options.isUsages = true;
    return JavaFindUsagesHelper.processElementUsages(member, options, usageInfoProcessor);
}
Also used : PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 55 with SearchScope

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

the class JavaRefactoringSupportProvider method mayRenameInplace.

public static boolean mayRenameInplace(PsiElement elementToRename, final PsiElement nameSuggestionContext) {
    if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile())
        return false;
    if (!(elementToRename instanceof PsiLocalVariable) && !(elementToRename instanceof PsiParameter) && !(elementToRename instanceof PsiLabeledStatement)) {
        return false;
    }
    SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(elementToRename.getProject()).getUseScope(elementToRename);
    if (!(useScope instanceof LocalSearchScope))
        return false;
    PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope();
    if (// assume there are no elements with use scopes with holes in them
    scopeElements.length > 1 && // ... except a case of element and it's doc comment
    !isElementWithComment(scopeElements) && !isResourceVariable(scopeElements)) {
        // ... and badly scoped resource variables
        return false;
    }
    PsiFile containingFile = elementToRename.getContainingFile();
    return PsiTreeUtil.isAncestor(containingFile, scopeElements[0], false);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) 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