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