Java源码示例:com.intellij.psi.search.ProjectScope
示例1
public static List<XmlTag> findFlowRefsForFlow(@NotNull XmlTag flow) {
List<XmlTag> flowRefs = new ArrayList<>();
final Project project = flow.getProject();
final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE);
Collection<VirtualFile> vFiles = FileTypeIndex.getFiles(StdFileTypes.XML, ProjectScope.getContentScope(project));
for (VirtualFile virtualFile : vFiles) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile != null) {
XmlFile xmlFile = (XmlFile) psiFile;
XmlTag mule = xmlFile.getRootTag();
FlowRefsFinder finder = new FlowRefsFinder(flowName);
mule.accept(finder);
flowRefs.addAll(finder.getFlowRefs());
}
}
return flowRefs;
}
示例2
@Override
public boolean shouldInspect(@Nonnull PsiElement psiRoot) {
if (ApplicationManager.getApplication().isUnitTestMode()) return true;
if (!shouldHighlight(psiRoot)) return false;
final Project project = psiRoot.getProject();
final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
if (virtualFile == null || !virtualFile.isValid()) return false;
if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;
if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;
final FileHighlightingSetting settingForRoot = getHighlightingSettingForRoot(psiRoot);
return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
示例3
public static boolean shouldInspect(@Nonnull PsiElement psiRoot) {
if (ApplicationManager.getApplication().isUnitTestMode()) return true;
if (!shouldHighlight(psiRoot)) return false;
final Project project = psiRoot.getProject();
final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
if (virtualFile == null || !virtualFile.isValid()) return false;
if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;
if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;
final HighlightingSettingsPerFile component = HighlightingSettingsPerFile.getInstance(project);
if (component == null) return true;
final FileHighlightingSetting settingForRoot = component.getHighlightingSettingForRoot(psiRoot);
return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
示例4
@Nonnull
private static SearchScope calcScope(@Nonnull 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;
}
示例5
/**
* Return a list of {@link PsiClass}s annotated with the specified annotation
* @param project - Project reference to narrow the search inside.
* @param annotation - the full qualify annotation name to search for
* @return a list of classes annotated with the specified annotation.
*/
@NotNull
private Collection<PsiClass> getClassesAnnotatedWith(Project project, String annotation) {
PsiClass stepClass = JavaPsiFacade.getInstance(project).findClass(annotation, ProjectScope.getLibrariesScope(project));
if (stepClass != null) {
final Query<PsiClass> psiMethods = AnnotatedElementsSearch.searchPsiClasses(stepClass, GlobalSearchScope.allScope(project));
return psiMethods.findAll();
}
return Collections.emptyList();
}
示例6
@Override
public GlobalSearchScope getResolveScope(ScopeType scopeType) {
// Bazel projects have either a workspace module, or a resource module. In both cases, we just
// want to ignore the currently specified module level dependencies and use the global set of
// dependencies. This is because when we artificially split up the Java code (into workspace
// module) and resources (into a separate module each), we introduce a circular dependency,
// which essentially means that all modules end up depending on all other modules. If we
// expressed this circular dependency, IntelliJ blows up due to the large heavily connected
// dependency graph. Instead, we just redirect the scopes in the few places that we need.
return ProjectScope.getAllScope(module.getProject());
}
示例7
@NotNull
@Override
public Collection<PsiElement> getPsiTargets(PsiElement psiElement) {
Collection<PsiElement> targets = new ArrayList<>();
String directiveName = psiElement.getText().substring(1);
FileBasedIndex.getInstance().getFilesWithKey(
BladeCustomDirectivesStubIndex.KEY,
Collections.singleton(directiveName),
virtualFile -> {
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(virtualFile);
if(psiFile == null) {
return true;
}
psiFile.acceptChildren(new BladeCustomDirectivesVisitor(hit -> {
if(directiveName.equals(hit.second)) {
targets.add(hit.first);
}
}));
return true;
},
ProjectScope.getAllScope(getProject()));
return targets;
}
示例8
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options,
@NotNull Project project) {
SearchScope scope = options.searchScope;
if (scope == null) return ProjectScope.getAllScope(project);
return scope;
}
示例9
@Nullable
private LineMarkerInfo getNavigationLineMarker(@NotNull final PsiIdentifier element, @Nullable ButterKnifeLink link) {
if (link == null) {
return null;
}
final PsiAnnotation srcAnnotation = getAnnotation(element.getParent(), link.srcAnnotation);
if (srcAnnotation != null) {
final PsiAnnotationParameterList annotationParameters = srcAnnotation.getParameterList();
if (annotationParameters.getAttributes().length > 0) {
final PsiAnnotationMemberValue value = annotationParameters.getAttributes()[0].getValue();
if (value == null) {
return null;
}
final String resourceId = value.getText();
final PsiClass dstAnnotationClass = JavaPsiFacade.getInstance(element.getProject())
.findClass(link.dstAnnotation, ProjectScope.getLibrariesScope(element.getProject()));
if (dstAnnotationClass == null) {
return null;
}
final ClassMemberProcessor processor = new ClassMemberProcessor(resourceId, link);
AnnotatedMembersSearch.search(dstAnnotationClass,
GlobalSearchScope.fileScope(element.getContainingFile())).forEach(processor);
final PsiMember dstMember = processor.getResultMember();
if (dstMember != null) {
return new NavigationMarker.Builder().from(element).to(dstMember).build();
}
}
}
return null;
}
示例10
ModuleWithDependentsScope(@Nonnull Module module) {
super(module.getProject());
myModule = module;
myProjectFileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
myProjectScope = ProjectScope.getProjectScope(module.getProject());
myModules = buildDependents(myModule);
}
示例11
@Nonnull
public static GlobalSearchScope searchScopeFor(@Nullable Project project, boolean searchInLibraries) {
GlobalSearchScope baseScope = project == null ? new EverythingGlobalScope() : searchInLibraries ? ProjectScope.getAllScope(project) : ProjectScope.getProjectScope(project);
return baseScope.intersectWith(new EverythingGlobalScope(project) {
@Override
public boolean contains(@Nonnull VirtualFile file) {
return !(file.getFileSystem() instanceof HiddenFileSystem);
}
});
}
示例12
BlazeAndroidBinaryRunConfigurationStateEditor(
RunConfigurationStateEditor commonStateEditor,
AndroidProfilersPanelCompat profilersPanelCompat,
Project project) {
this.commonStateEditor = commonStateEditor;
this.profilersPanelCompat = profilersPanelCompat;
setupUI(project);
userIdField.setMinValue(0);
activityField.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!project.isInitialized()) {
return;
}
// We find all Activity classes in the module for the selected variant
// (or any of its deps).
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
PsiClass activityBaseClass =
facade.findClass(
AndroidUtils.ACTIVITY_BASE_CLASS_NAME, ProjectScope.getAllScope(project));
if (activityBaseClass == null) {
Messages.showErrorDialog(
mainContainer, AndroidBundle.message("cant.find.activity.class.error"));
return;
}
GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
PsiClass initialSelection =
facade.findClass(activityField.getChildComponent().getText(), searchScope);
TreeClassChooser chooser =
TreeClassChooserFactory.getInstance(project)
.createInheritanceClassChooser(
"Select Activity Class",
searchScope,
activityBaseClass,
initialSelection,
null);
chooser.showDialog();
PsiClass selClass = chooser.getSelected();
if (selClass != null) {
// This must be done because Android represents
// inner static class paths differently than java.
String qualifiedActivityName =
ActivityLocatorUtils.getQualifiedActivityName(selClass);
activityField.getChildComponent().setText(qualifiedActivityName);
}
}
});
ActionListener listener = e -> updateEnabledState();
launchCustomButton.addActionListener(listener);
launchDefaultButton.addActionListener(listener);
launchNothingButton.addActionListener(listener);
useMobileInstallCheckBox.addActionListener(
e -> PropertiesComponent.getInstance(project).setValue(MI_NEVER_ASK_AGAIN, true));
useWorkProfileIfPresentCheckBox.addActionListener(listener);
}
示例13
protected SearchScope getReferencesSearchScope(VirtualFile file) {
return file == null || ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)
? ProjectScope.getProjectScope(myElementToRename.getProject())
: new LocalSearchScope(myElementToRename.getContainingFile());
}
示例14
@Override
protected SearchScope getReferencesSearchScope(VirtualFile file) {
PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
return currentFile != null ? new LocalSearchScope(currentFile)
: ProjectScope.getProjectScope(myProject);
}
示例15
private void findEventsViaMethodsAnnotatedSubscribe() {
GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
for (SubscriberMetadata subscriberMetadata : SubscriberMetadata.getAllSubscribers()) {
performSearch(projectScope, subscriberMetadata.getSubscriberAnnotationClassName());
}
}
示例16
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options, @NotNull Project project) {
SearchScope scope = options.searchScope;
if (scope == null) return ProjectScope.getAllScope(project);
return scope;
}