예제 #1
0
  public static boolean isAnnoRefAnywhereInXml(
      @NotNull Project project, @NotNull Module module, @NotNull String refId) {
    if (module == null) {
      throw new IllegalArgumentException(
          String.format(
              "Argument %s for @NotNull parameter of %s.%s must not be null",
              new Object[] {
                "0",
                "com.idi.intellij.plugin.query.sqlref.util.AnnoRefModelUtil",
                "isAnnoRefAnywhereInXml"
              }));
    }
    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    GlobalSearchScope searchScope =
        GlobalSearchScope.getScopeRestrictedByFileTypes(scope, XmlFileType.INSTANCE);
    PsiFile[] files =
        CacheManager.SERVICE
            .getInstance(module.getProject())
            .getFilesWithWord(refId, Short.valueOf("255"), searchScope, true);

    for (PsiFile file : files) {
      if (((file instanceof XmlFile))
          && (AnnRefApplication.getInstance(project, SQLRefDataAccessor.class)
              .isPropitiousXmlFile(file))) {
        return true;
      }
    }
    return false;
  }
  @NotNull
  protected Collection<HighlightInfo> checkHighlighting(
      @NotNull final ExpectedHighlightingData data) {
    data.init();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    // to load text
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                TreeUtil.clearCaches((TreeElement) myFile.getNode());
              }
            });

    // to initialize caches
    if (!DumbService.isDumb(getProject())) {
      CacheManager.SERVICE
          .getInstance(myProject)
          .getFilesWithWord(
              "XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true);
    }
    final JavaPsiFacadeEx facade = getJavaFacade();
    if (facade != null) {
      facade.setAssertOnFileLoadingFilter(
          myFileTreeAccessFilter, myTestRootDisposable); // check repository work
    }

    try {
      Collection<HighlightInfo> infos = doHighlighting();

      String text = myEditor.getDocument().getText();
      data.checkLineMarkers(
          DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text);
      data.checkResult(infos, text);
      return infos;
    } finally {
      if (facade != null) {
        facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
      }
    }
  }
 private static Set<String> calcDevPatternClassNames(@NotNull final Project project) {
   final List<String> roots = ContainerUtil.createLockFreeCopyOnWriteList();
   JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
   PsiClass beanClass =
       psiFacade.findClass(PatternClassBean.class.getName(), GlobalSearchScope.allScope(project));
   if (beanClass != null) {
     GlobalSearchScope scope =
         GlobalSearchScope.getScopeRestrictedByFileTypes(
             GlobalSearchScope.allScope(project), StdFileTypes.XML);
     final TextOccurenceProcessor occurenceProcessor =
         new TextOccurenceProcessor() {
           @Override
           public boolean execute(@NotNull PsiElement element, int offsetInElement) {
             XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
             String className = tag == null ? null : tag.getAttributeValue("className");
             if (StringUtil.isNotEmpty(className) && tag.getLocalName().endsWith("patternClass")) {
               roots.add(className);
             }
             return true;
           }
         };
     final StringSearcher searcher = new StringSearcher("patternClass", true, true);
     CacheManager.SERVICE
         .getInstance(beanClass.getProject())
         .processFilesWithWord(
             new Processor<PsiFile>() {
               @Override
               public boolean process(PsiFile psiFile) {
                 LowLevelSearchUtil.processElementsContainingWordInElement(
                     occurenceProcessor, psiFile, searcher, true, new EmptyProgressIndicator());
                 return true;
               }
             },
             searcher.getPattern(),
             UsageSearchContext.IN_FOREIGN_LANGUAGES,
             scope,
             searcher.isCaseSensitive());
   }
   return ContainerUtil.newHashSet(roots);
 }
  @NotNull
  private Set<PsiFile> getFilesForFastWordSearch() {
    String stringToFind = myFindModel.getStringToFind();
    if (stringToFind.isEmpty() || DumbService.getInstance(myProject).isDumb()) {
      return Collections.emptySet();
    }

    SearchScope customScope = myFindModel.getCustomScope();
    GlobalSearchScope scope =
        myPsiDirectory != null
            ? GlobalSearchScopesCore.directoryScope(myPsiDirectory, true)
            : myModule != null
                ? myModule.getModuleContentScope()
                : customScope instanceof GlobalSearchScope
                    ? (GlobalSearchScope) customScope
                    : toGlobal(customScope);
    if (scope == null) {
      scope = ProjectScope.getContentScope(myProject);
    }

    final Set<PsiFile> resultFiles = new LinkedHashSet<PsiFile>();

    if (TrigramIndex.ENABLED) {
      final Set<Integer> keys = ContainerUtil.newTroveSet();
      TrigramBuilder.processTrigrams(
          stringToFind,
          new TrigramBuilder.TrigramProcessor() {
            @Override
            public boolean execute(int value) {
              keys.add(value);
              return true;
            }
          });

      if (!keys.isEmpty()) {
        final List<VirtualFile> hits = new ArrayList<VirtualFile>();
        final GlobalSearchScope finalScope = scope;
        ApplicationManager.getApplication()
            .runReadAction(
                new Runnable() {
                  @Override
                  public void run() {
                    FileBasedIndex.getInstance()
                        .getFilesWithKey(
                            TrigramIndex.INDEX_ID,
                            keys,
                            new CommonProcessors.CollectProcessor<VirtualFile>(hits),
                            finalScope);
                  }
                });

        for (VirtualFile hit : hits) {
          if (myFileMask.value(hit)) {
            PsiFile file = findFile(hit);
            if (file != null) {
              resultFiles.add(file);
            }
          }
        }

        return resultFiles;
      }
    }

    PsiSearchHelperImpl helper =
        (PsiSearchHelperImpl) PsiSearchHelper.SERVICE.getInstance(myProject);
    helper.processFilesWithText(
        scope,
        UsageSearchContext.ANY,
        myFindModel.isCaseSensitive(),
        stringToFind,
        new Processor<VirtualFile>() {
          @Override
          public boolean process(VirtualFile file) {
            if (myFileMask.value(file)) {
              ContainerUtil.addIfNotNull(resultFiles, findFile(file));
            }
            return true;
          }
        });

    // in case our word splitting is incorrect
    CacheManager cacheManager = CacheManager.SERVICE.getInstance(myProject);
    PsiFile[] filesWithWord =
        cacheManager.getFilesWithWord(
            stringToFind, UsageSearchContext.ANY, scope, myFindModel.isCaseSensitive());
    for (PsiFile file : filesWithWord) {
      if (myFileMask.value(file.getVirtualFile())) {
        resultFiles.add(file);
      }
    }

    return resultFiles;
  }