com.intellij.psi.search.PsiSearchHelper源码实例Demo

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

下面列出了com.intellij.psi.search.PsiSearchHelper 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * @param project project
 * @param key     environment variable key
 * @return All key usages, like getenv('KEY')
 */
@NotNull
public static PsiElement[] getKeyUsages(Project project, String key) {
    List<PsiElement> targets = new ArrayList<>();

    PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project);

    Processor<PsiFile> psiFileProcessor = psiFile -> {
        for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) {
            targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile)));
        }

        return true;
    };

    searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true);
    searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor);

    return targets.toArray(PsiElement.EMPTY_ARRAY);
}
 
@RequiredReadAction
public static boolean mayRenameInplace(@Nonnull PsiElement elementToRename, @Nullable final PsiElement nameSuggestionContext)
{
	if(nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile())
	{
		return false;
	}
	if(elementToRename instanceof CSharpTupleVariable || elementToRename instanceof CSharpTupleElementImpl)
	{
		return true;
	}
	if(elementToRename instanceof DotNetNamespaceAsElement)
	{
		return true;
	}
	if(!(elementToRename instanceof CSharpLocalVariable) && !(elementToRename instanceof DotNetParameter) && !(elementToRename instanceof
			CSharpLambdaParameter))
	{
		return false;
	}
	SearchScope useScope = PsiSearchHelper.getInstance(elementToRename.getProject()).getUseScope(elementToRename);
	if(!(useScope instanceof LocalSearchScope))
	{
		return false;
	}
	PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope();
	if(scopeElements.length > 1)
	{
		return false;    // ... and badly scoped resource variables
	}
	PsiFile containingFile = elementToRename.getContainingFile();
	return PsiTreeUtil.isAncestor(containingFile, scopeElements[0], false);
}
 
源代码3 项目: consulo   文件: DefinitionsScopedSearch.java
@Nonnull
public SearchScope getScope() {
  return ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
    @Override
    public SearchScope compute() {
      return myScope.intersectWith(PsiSearchHelper.SERVICE.getInstance(myElement.getProject()).getUseScope(myElement));
    }
  });
}
 
源代码4 项目: consulo   文件: InplaceRefactoring.java
@Nullable
protected PsiElement checkLocalScope() {
  final SearchScope searchScope = PsiSearchHelper.SERVICE.getInstance(myElementToRename.getProject()).getUseScope(myElementToRename);
  if (searchScope instanceof LocalSearchScope) {
    final PsiElement[] elements = ((LocalSearchScope)searchScope).getScope();
    return PsiTreeUtil.findCommonParent(elements);
  }

  return null;
}
 
源代码5 项目: consulo   文件: InlineOptionsDialog.java
protected static int initOccurrencesNumber(PsiNameIdentifierOwner nameIdentifierOwner) {
  final ProgressManager progressManager = ProgressManager.getInstance();
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(nameIdentifierOwner.getProject());
  final GlobalSearchScope scope = GlobalSearchScope.projectScope(nameIdentifierOwner.getProject());
  final String name = nameIdentifierOwner.getName();
  final boolean isCheapToSearch =
   name != null && searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
  return isCheapToSearch ? ReferencesSearch.search(nameIdentifierOwner).findAll().size() : - 1;
}
 
源代码6 项目: intellij   文件: FindUsages.java
/**
 * Search scope taken from PsiSearchHelper::getUseScope, which incorporates UseScopeEnlarger /
 * UseScopeOptimizer EPs.
 */
public static PsiReference[] findReferencesInElementScope(PsiElement element) {
  return findReferencesInScope(
      element, PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element));
}
 
源代码7 项目: consulo   文件: TargetElementUtil.java
public static SearchScope getSearchScope(Editor editor, PsiElement element) {
  return PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element);
}
 
源代码8 项目: consulo   文件: CommonFindUsagesDialog.java
@Override
protected boolean isInFileOnly() {
  return super.isInFileOnly() ||
         PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement) instanceof LocalSearchScope;
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法