Java 类com.intellij.psi.impl.search.PsiSearchHelperImpl 实例源码

项目:intellij-ce-playground    文件:FindUsagesHelper.java   
protected static boolean processUsagesInText(@NotNull final PsiElement element,
                                             @NotNull Collection<String> stringToSearch,
                                             @NotNull GlobalSearchScope searchScope,
                                             @NotNull Processor<UsageInfo> processor) {
  final TextRange elementTextRange = ApplicationManager.getApplication().runReadAction(new NullableComputable<TextRange>() {
    @Override
    public TextRange compute() {
      if (!element.isValid() || element instanceof PsiCompiledElement) return null;
      return element.getTextRange();
    }
  });
  UsageInfoFactory factory = new UsageInfoFactory() {
    @Override
    public UsageInfo createUsageInfo(@NotNull PsiElement usage, int startOffset, int endOffset) {
      if (elementTextRange != null
          && usage.getContainingFile() == element.getContainingFile()
          && elementTextRange.contains(startOffset)
          && elementTextRange.contains(endOffset)) {
        return null;
      }

      PsiReference someReference = usage.findReferenceAt(startOffset);
      if (someReference != null) {
        PsiElement refElement = someReference.getElement();
        for (PsiReference ref : PsiReferenceService.getService().getReferences(refElement, new PsiReferenceService.Hints(element, null))) {
          if (element.getManager().areElementsEquivalent(ref.resolve(), element)) {
            TextRange range = ref.getRangeInElement().shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset());
            return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true);
          }
        }
      }

      return new UsageInfo(usage, startOffset, endOffset, true);
    }
  };
  for (String s : stringToSearch) {
    if (!PsiSearchHelperImpl.processTextOccurrences(element, s, searchScope, processor, factory)) return false;
  }
  return true;
}
项目:intellij-ce-playground    文件:TextOccurrencesUtil.java   
public static void addTextOccurences(@NotNull PsiElement element,
                                     @NotNull String stringToSearch,
                                     @NotNull GlobalSearchScope searchScope,
                                     @NotNull final Collection<UsageInfo> results,
                                     @NotNull final UsageInfoFactory factory) {
  PsiSearchHelperImpl.processTextOccurrences(element, stringToSearch, searchScope, new Processor<UsageInfo>() {
    @Override
    public boolean process(UsageInfo t) {
      results.add(t);
      return true;
    }
  }, factory);
}
项目:consulo    文件:FindUsagesHelper.java   
public static boolean processUsagesInText(@Nonnull final PsiElement element,
                                             @Nonnull Collection<String> stringToSearch,
                                             @Nonnull GlobalSearchScope searchScope,
                                             @Nonnull Processor<UsageInfo> processor) {
  final TextRange elementTextRange = ApplicationManager.getApplication().runReadAction(new NullableComputable<TextRange>() {
    @Override
    public TextRange compute() {
      if (!element.isValid() || element instanceof PsiCompiledElement) return null;
      return element.getTextRange();
    }
  });
  UsageInfoFactory factory = new UsageInfoFactory() {
    @Override
    public UsageInfo createUsageInfo(@Nonnull PsiElement usage, int startOffset, int endOffset) {
      if (elementTextRange != null
          && usage.getContainingFile() == element.getContainingFile()
          && elementTextRange.contains(startOffset)
          && elementTextRange.contains(endOffset)) {
        return null;
      }

      PsiReference someReference = usage.findReferenceAt(startOffset);
      if (someReference != null) {
        PsiElement refElement = someReference.getElement();
        for (PsiReference ref : PsiReferenceService.getService().getReferences(refElement, new PsiReferenceService.Hints(element, null))) {
          if (element.getManager().areElementsEquivalent(ref.resolve(), element)) {
            TextRange range = ref.getRangeInElement().shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset());
            return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true);
          }
        }
      }

      return new UsageInfo(usage, startOffset, endOffset, true);
    }
  };
  for (String s : stringToSearch) {
    if (!PsiSearchHelperImpl.processTextOccurrences(element, s, searchScope, processor, factory)) return false;
  }
  return true;
}
项目:intellij-ce-playground    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor,
                                                  PsiManager psiManager,
                                                  final Property property,
                                                  final GlobalSearchScope globalSearchScope,
                                                  final LocalSearchScope filterScope) {
  final Project project = psiManager.getProject();

  final GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
  String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      return property.getName();
    }
  });
  if (name == null) return true;

  psiManager.startBatchFilesProcessingMode();

  try {
    CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<VirtualFile>() {
      @Override
      protected boolean accept(VirtualFile virtualFile) {
        return virtualFile.getFileType() == StdFileTypes.GUI_DESIGNER_FORM;
      }
    };
    ((PsiSearchHelperImpl)PsiSearchHelper.SERVICE.getInstance(project)).processFilesWithText(
      scope, UsageSearchContext.IN_PLAIN_TEXT, true, name, collector
    );

    for (final VirtualFile vfile:collector.getResults()) {
      ProgressManager.checkCanceled();

      PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
        @Override
        public PsiFile compute() {
          return PsiManager.getInstance(project).findFile(vfile);
        }
      });
      if (!processReferences(processor, file, name, property, filterScope)) return false;
    }
  }
  finally {
    psiManager.finishBatchFilesProcessingMode();
  }

  return true;
}
项目:tools-idea    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor,
                                                 final Property property,
                                                 final GlobalSearchScope globalSearchScope,
                                                 final LocalSearchScope filterScope) {

  final Project project = property.getProject();
  final GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
  final PsiManagerImpl manager = (PsiManagerImpl)property.getManager();
  String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      return property.getName();
    }
  });
  if (name == null) return true;

  manager.startBatchFilesProcessingMode();

  try {
    CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<VirtualFile>() {
      @Override
      protected boolean accept(VirtualFile virtualFile) {
        return virtualFile.getFileType() == StdFileTypes.GUI_DESIGNER_FORM;
      }
    };
    ((PsiSearchHelperImpl)PsiSearchHelper.SERVICE.getInstance(project)).processFilesWithText(
      scope, UsageSearchContext.IN_PLAIN_TEXT, true, name, collector
    );

    for (final VirtualFile vfile:collector.getResults()) {
      ProgressManager.checkCanceled();

      PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
        @Override
        public PsiFile compute() {
          return PsiManager.getInstance(project).findFile(vfile);
        }
      });
      if (!processReferences(processor, file, name, property, filterScope)) return false;
    }
  }
  finally {
    manager.finishBatchFilesProcessingMode();
  }

  return true;
}
项目:consulo-ui-designer    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor, final Property property, final GlobalSearchScope globalSearchScope, final LocalSearchScope filterScope)
{

    final Project project = property.getProject();
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
    final PsiManagerImpl manager = (PsiManagerImpl) property.getManager();
    String name = ApplicationManager.getApplication().runReadAction(new Computable<String>()
    {
        @Override
        public String compute()
        {
            return property.getName();
        }
    });
    if(name == null)
    {
        return true;
    }

    manager.startBatchFilesProcessingMode();

    try
    {
        CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<VirtualFile>()
        {
            @Override
            protected boolean accept(VirtualFile virtualFile)
            {
                return virtualFile.getFileType() == GuiFormFileType.INSTANCE;
            }
        };
        ((PsiSearchHelperImpl) PsiSearchHelper.SERVICE.getInstance(project)).processFilesWithText(scope, UsageSearchContext.IN_PLAIN_TEXT, true, name, collector);

        for(final VirtualFile vfile : collector.getResults())
        {
            ProgressManager.checkCanceled();

            PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>()
            {
                @Override
                public PsiFile compute()
                {
                    return PsiManager.getInstance(project).findFile(vfile);
                }
            });
            if(!processReferences(processor, file, name, property, filterScope))
            {
                return false;
            }
        }
    }
    finally
    {
        manager.finishBatchFilesProcessingMode();
    }

    return true;
}