当前位置: 首页>>代码示例>>Java>>正文


Java PsiSearchHelper.isCheapEnoughToSearch方法代码示例

本文整理汇总了Java中com.intellij.psi.search.PsiSearchHelper.isCheapEnoughToSearch方法的典型用法代码示例。如果您正苦于以下问题:Java PsiSearchHelper.isCheapEnoughToSearch方法的具体用法?Java PsiSearchHelper.isCheapEnoughToSearch怎么用?Java PsiSearchHelper.isCheapEnoughToSearch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.search.PsiSearchHelper的用法示例。


在下文中一共展示了PsiSearchHelper.isCheapEnoughToSearch方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUsageClass

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
/**
 * @return the class the specified method is used from, or null if it is
 *         used from 0 or more than 1 other classes.
 */
@Nullable
public PsiClass getUsageClass(final PsiMethod method) {
  final ProgressManager progressManager = ProgressManager.getInstance();
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject());
  final String name = method.getName();
  final GlobalSearchScope scope = GlobalSearchScope.allScope(method.getProject());
  if (searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator())
      == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
    return null;
  }
  progressManager.runProcess(new Runnable() {
    @Override
    public void run() {
      final Query<PsiReference> query = MethodReferencesSearch.search(method);
      if (!query.forEach(UsageProcessor.this)) {
        foundClass.set(null);
      }
    }
  }, null);
  return foundClass.get();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:StaticMethodOnlyUsedInOneClassInspectionBase.java

示例2: isTooExpensiveToSearch

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
public static boolean isTooExpensiveToSearch(PsiNamedElement element, boolean zeroResult)
{
	final String name = element.getName();
	if(name == null)
	{
		return true;
	}
	final ProgressManager progressManager = ProgressManager.getInstance();
	final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
	final SearchScope useScope = element.getUseScope();
	if(!(useScope instanceof GlobalSearchScope))
	{
		return zeroResult;
	}
	final PsiSearchHelper.SearchCostResult cost = searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope) useScope, null, progressManager.getProgressIndicator());
	if(cost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES)
	{
		return zeroResult;
	}
	return cost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:DeclarationSearchUtils.java

示例3: initOccurrencesNumber

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:InlineOptionsDialog.java

示例4: isOnlyAccessedFromInnerClass

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
public boolean isOnlyAccessedFromInnerClass() {
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject());
  final ProgressManager progressManager = ProgressManager.getInstance();
  final ProgressIndicator progressIndicator = progressManager.getProgressIndicator();
  final PsiSearchHelper.SearchCostResult searchCost =
    searchHelper.isCheapEnoughToSearch(method.getName(), method.getResolveScope(), null, progressIndicator);
  if (searchCost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES ||
      searchCost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES) {
    return onlyAccessedFromInnerClass;
  }
  final Query<PsiReference> query = ReferencesSearch.search(method);
  query.forEach(this);
  return onlyAccessedFromInnerClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:MethodOnlyUsedFromInnerClassInspection.java

示例5: isCheapEnoughToSearch

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
private boolean isCheapEnoughToSearch(PsiNamedElement element) {
  final String name = element.getName();
  if (name == null) {
    return false;
  }
  final ProgressManager progressManager =
    ProgressManager.getInstance();
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
  final SearchScope useScope = element.getUseScope();
  if (useScope instanceof GlobalSearchScope) {
    return searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope)useScope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:DeclareCollectionAsInterfaceInspection.java

示例6: isCheapEnoughToSearch

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
private boolean isCheapEnoughToSearch(PsiNamedElement element) {
  final String name = element.getName();
  if (name == null) {
    return false;
  }
  final ProgressManager progressManager =
    ProgressManager.getInstance();
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
  final GlobalSearchScope scope =
    GlobalSearchScope.projectScope(element.getProject());
  return searchHelper.isCheapEnoughToSearch(name, scope, null,
                                            progressManager.getProgressIndicator()) !=
         PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:DeclareCollectionAsInterfaceInspection.java

示例7: isCheapEnoughToSearch

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
private static boolean isCheapEnoughToSearch(PsiField field, String name)
{
	SearchScope scope = field.getUseScope();
	if(!(scope instanceof GlobalSearchScope))
	{
		return true;
	}

	PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(field.getProject());
	PsiSearchHelper.SearchCostResult result = helper.isCheapEnoughToSearch(name, (GlobalSearchScope) scope, field.getContainingFile(), null);
	return result != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:NullnessUtil.java

示例8: processUsages

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
public static boolean processUsages(@NotNull Project project,
                                    @NotNull PsiFile containingFile,
                                    @NotNull PsiMember member,
                                    @NotNull ProgressIndicator progress,
                                    @Nullable PsiFile ignoreFile,
                                    @NotNull Processor<UsageInfo> usageInfoProcessor) {
  String name = member.getName();
  if (name == null) {
    log("* "+member.getName()+" no name; false");
    return false;
  }
  SearchScope useScope = member.getUseScope();
  PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
  if (useScope instanceof GlobalSearchScope) {
    // some classes may have references from within XML outside dependent modules, e.g. our actions
    if (member instanceof PsiClass) {
      useScope = GlobalSearchScope.projectScope(project).uniteWith((GlobalSearchScope)useScope);
    }

    // if we've resolved all references, find usages will be fast
    PsiSearchHelper.SearchCostResult cheapEnough = RefResolveService.ENABLED && RefResolveService.getInstance(project).isUpToDate() ? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES :
                                                   searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope)useScope, ignoreFile, progress);
    if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
      log("* "+member.getName()+" too many usages; false");
      return false;
    }

    //search usages if it cheap
    //if count is 0 there is no usages since we've called myRefCountHolder.isReferenced() before
    if (cheapEnough == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES && !canBeReferencedViaWeirdNames(member, containingFile)) {
      log("* "+member.getName()+" 0 usages; true");
      return true;
    }

    if (member instanceof PsiMethod) {
      String propertyName = PropertyUtil.getPropertyName(member);
      if (propertyName != null) {
        SearchScope fileScope = containingFile.getUseScope();
        if (fileScope instanceof GlobalSearchScope &&
            searchHelper.isCheapEnoughToSearch(propertyName, (GlobalSearchScope)fileScope, ignoreFile, progress) ==
            PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
          log("* "+member.getName()+" too many prop usages; false");
          return false;
        }
      }
    }
  }
  FindUsagesOptions options;
  if (member instanceof PsiPackage) {
    options = new JavaPackageFindUsagesOptions(project);
    options.isSearchForTextOccurrences = true;
  }
  else if (member instanceof PsiClass) {
    options = new JavaClassFindUsagesOptions(project);
    options.isSearchForTextOccurrences = true;
  }
  else if (member instanceof PsiMethod) {
    PsiMethod method = (PsiMethod)member;
    options = new JavaMethodFindUsagesOptions(project);
    options.isSearchForTextOccurrences = method.isConstructor();
  }
  else if (member instanceof PsiVariable) {
    options = new JavaVariableFindUsagesOptions(project);
    options.isSearchForTextOccurrences = false;
  }
  else {
    options = new FindUsagesOptions(project);
    options.isSearchForTextOccurrences = true;
  }
  options.isUsages = true;
  options.searchScope = useScope;
  return JavaFindUsagesHelper.processElementUsages(member, options, usageInfoProcessor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:74,代码来源:UnusedSymbolUtil.java

示例9: weAreSureThereAreNoUsages

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
private static boolean weAreSureThereAreNoUsages(@NotNull PsiMember member, ProgressIndicator progress, GlobalUsageHelper helper) {
  if (!helper.shouldCheckUsages(member)) return false;

  String name = member.getName();
  if (name == null) return false;
  SearchScope useScope = member.getUseScope();
  Project project = member.getProject();
  if (useScope instanceof GlobalSearchScope) {
    // some classes may have references from within XML outside dependent modules, e.g. our actions
    if (member instanceof PsiClass) {
      useScope = GlobalSearchScope.projectScope(project).uniteWith((GlobalSearchScope)useScope);
    }

    PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
    PsiFile file = member.getContainingFile();
    PsiFile ignoreFile = helper.isCurrentFileAlreadyChecked() ? file : null;
    PsiSearchHelper.SearchCostResult cheapEnough = searchHelper.isCheapEnoughToSearch(name, (GlobalSearchScope)useScope, ignoreFile, progress);
    if (cheapEnough == TOO_MANY_OCCURRENCES) return false;

    //search usages if it cheap
    //if count is 0 there is no usages since we've called myRefCountHolder.isReferenced() before
    if (cheapEnough == ZERO_OCCURRENCES) {
      if (!canBeReferencedViaWeirdNames(member)) return true;
    }

    if (member instanceof PsiMethod) {
      String propertyName = PropertyUtil.getPropertyName(member);
      if (propertyName != null && file != null) {
        SearchScope fileScope = file.getUseScope();
        if (fileScope instanceof GlobalSearchScope &&
            searchHelper.isCheapEnoughToSearch(propertyName, (GlobalSearchScope)fileScope, ignoreFile, progress) == TOO_MANY_OCCURRENCES) {
          return false;
        }
      }
    }
  }
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = new JavaFindUsagesHandler(member, new JavaFindUsagesHandlerFactory(project));
  FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions().clone();
  findUsagesOptions.searchScope = useScope;
  findUsagesOptions.isSearchForTextOccurrences = true;
  return !findUsagesManager.isUsed(member, findUsagesOptions);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:44,代码来源:PostHighlightingPass.java

示例10: isSuperCallWithSameArguments

import com.intellij.psi.search.PsiSearchHelper; //导入方法依赖的package包/类
private boolean isSuperCallWithSameArguments(PsiCodeBlock body, PsiMethod method, PsiMethod superMethod)
{
	final PsiStatement[] statements = body.getStatements();
	if(statements.length != 1)
	{
		return false;
	}
	final PsiStatement statement = statements[0];
	final PsiExpression expression;
	if(PsiType.VOID.equals(method.getReturnType()))
	{
		if(statement instanceof PsiExpressionStatement)
		{
			final PsiExpressionStatement expressionStatement = (PsiExpressionStatement) statement;
			expression = expressionStatement.getExpression();
		}
		else
		{
			return false;
		}
	}
	else
	{
		if(statement instanceof PsiReturnStatement)
		{
			final PsiReturnStatement returnStatement = (PsiReturnStatement) statement;
			expression = ParenthesesUtils.stripParentheses(returnStatement.getReturnValue());
		}
		else
		{
			return false;
		}
	}
	if(!(expression instanceof PsiMethodCallExpression))
	{
		return false;
	}
	final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
	if(!MethodCallUtils.isSuperMethodCall(methodCallExpression, method))
	{
		return false;
	}

	if(superMethod.hasModifierProperty(PsiModifier.PROTECTED))
	{
		final PsiJavaFile file = (PsiJavaFile) method.getContainingFile();
		// implementing a protected method in another package makes it available to that package.
		PsiJavaPackage aPackage = JavaPsiFacade.getInstance(method.getProject()).findPackage(file.getPackageName());
		if(aPackage == null)
		{
			return false; // when package statement is incorrect
		}
		final PackageScope scope = new PackageScope(aPackage, false, false);
		if(isOnTheFly())
		{
			final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject());
			final PsiSearchHelper.SearchCostResult cost = searchHelper.isCheapEnoughToSearch(method.getName(), scope, null, null);
			if(cost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES)
			{
				return true;
			}
			if(cost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES)
			{
				return false;
			}
		}
		final Query<PsiReference> search = ReferencesSearch.search(method, scope);
		final PsiClass containingClass = method.getContainingClass();
		for(PsiReference reference : search)
		{
			if(!PsiTreeUtil.isAncestor(containingClass, reference.getElement(), true))
			{
				return false;
			}
		}
	}

	return areSameArguments(methodCallExpression, method);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:80,代码来源:RedundantMethodOverrideInspection.java


注:本文中的com.intellij.psi.search.PsiSearchHelper.isCheapEnoughToSearch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。