类com.intellij.psi.search.ProjectScope源码实例Demo

下面列出了怎么用com.intellij.psi.search.ProjectScope的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mule-intellij-plugins   文件: MuleConfigUtils.java
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 项目: consulo   文件: HighlightingSettingsPerFile.java
@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 项目: consulo   文件: HighlightLevelUtil.java
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 项目: consulo   文件: FindUsagesOptions.java
@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 项目: camel-idea-plugin   文件: JavaClassUtils.java
/**
 * 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 项目: intellij   文件: BlazeModuleSystem.java
@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());
}
 
@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 项目: dagger-intellij-plugin   文件: ShowUsagesAction.java
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options,
    @NotNull Project project) {
  SearchScope scope = options.searchScope;
  if (scope == null) return ProjectScope.getAllScope(project);
  return scope;
}
 
@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 项目: consulo   文件: ModuleWithDependentsScope.java
ModuleWithDependentsScope(@Nonnull Module module) {
  super(module.getProject());
  myModule = module;

  myProjectFileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
  myProjectScope = ProjectScope.getProjectScope(module.getProject());

  myModules = buildDependents(myModule);
}
 
源代码11 项目: consulo   文件: FindSymbolParameters.java
@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);
    }
  });
}
 
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 项目: consulo   文件: InplaceRefactoring.java
protected SearchScope getReferencesSearchScope(VirtualFile file) {
  return file == null || ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)
         ? ProjectScope.getProjectScope(myElementToRename.getProject())
         : new LocalSearchScope(myElementToRename.getContainingFile());
}
 
源代码14 项目: consulo   文件: MemberInplaceRenamer.java
@Override
protected SearchScope getReferencesSearchScope(VirtualFile file) {
  PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
  return currentFile != null ? new LocalSearchScope(currentFile)
                             : ProjectScope.getProjectScope(myProject);
}
 
源代码15 项目: otto-intellij-plugin   文件: OttoProjectHandler.java
private void findEventsViaMethodsAnnotatedSubscribe() {
  GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
  for (SubscriberMetadata subscriberMetadata : SubscriberMetadata.getAllSubscribers()) {
    performSearch(projectScope, subscriberMetadata.getSubscriberAnnotationClassName());
  }
}
 
源代码16 项目: otto-intellij-plugin   文件: ShowUsagesAction.java
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options, @NotNull Project project) {
  SearchScope scope = options.searchScope;
  if (scope == null) return ProjectScope.getAllScope(project);
  return scope;
}
 
 类所在包
 类方法
 同包方法