com.intellij.psi.search.ProjectScope Java Examples

The following examples show how to use com.intellij.psi.search.ProjectScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: HighlightingSettingsPerFile.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: HighlightLevelUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: FindUsagesOptions.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: JavaClassUtils.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #6
Source File: BlazeModuleSystem.java    From intellij with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #7
Source File: BladeDirectiveReferences.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@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;
}
 
Example #8
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options,
    @NotNull Project project) {
  SearchScope scope = options.searchScope;
  if (scope == null) return ProjectScope.getAllScope(project);
  return scope;
}
 
Example #9
Source File: NavigationMarkerProvider.java    From android-butterknife-zelezny with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: ModuleWithDependentsScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
ModuleWithDependentsScope(@Nonnull Module module) {
  super(module.getProject());
  myModule = module;

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

  myModules = buildDependents(myModule);
}
 
Example #11
Source File: FindSymbolParameters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
    }
  });
}
 
Example #12
Source File: BlazeAndroidBinaryRunConfigurationStateEditor.java    From intellij with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #13
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected SearchScope getReferencesSearchScope(VirtualFile file) {
  return file == null || ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)
         ? ProjectScope.getProjectScope(myElementToRename.getProject())
         : new LocalSearchScope(myElementToRename.getContainingFile());
}
 
Example #14
Source File: MemberInplaceRenamer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected SearchScope getReferencesSearchScope(VirtualFile file) {
  PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
  return currentFile != null ? new LocalSearchScope(currentFile)
                             : ProjectScope.getProjectScope(myProject);
}
 
Example #15
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void findEventsViaMethodsAnnotatedSubscribe() {
  GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
  for (SubscriberMetadata subscriberMetadata : SubscriberMetadata.getAllSubscribers()) {
    performSearch(projectScope, subscriberMetadata.getSubscriberAnnotationClassName());
  }
}
 
Example #16
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
private static SearchScope notNullizeScope(@NotNull FindUsagesOptions options, @NotNull Project project) {
  SearchScope scope = options.searchScope;
  if (scope == null) return ProjectScope.getAllScope(project);
  return scope;
}