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();
}
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;
}
};
}
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());
}
}
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);
}
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);
}
Aggregations