com.intellij.psi.search.PsiSearchHelper Java Examples

The following examples show how to use com.intellij.psi.search.PsiSearchHelper. 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: EnvironmentVariablesApi.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
/**
 * @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);
}
 
Example #2
Source File: CSharpRefactoringSupportProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #3
Source File: DefinitionsScopedSearch.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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));
    }
  });
}
 
Example #4
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: InlineOptionsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: FindUsages.java    From intellij with Apache License 2.0 4 votes vote down vote up
/**
 * 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));
}
 
Example #7
Source File: TargetElementUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static SearchScope getSearchScope(Editor editor, PsiElement element) {
  return PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element);
}
 
Example #8
Source File: CommonFindUsagesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isInFileOnly() {
  return super.isInFileOnly() ||
         PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement) instanceof LocalSearchScope;
}