本文整理汇总了Java中com.intellij.psi.search.PsiSearchHelper.SearchCostResult方法的典型用法代码示例。如果您正苦于以下问题:Java PsiSearchHelper.SearchCostResult方法的具体用法?Java PsiSearchHelper.SearchCostResult怎么用?Java PsiSearchHelper.SearchCostResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.PsiSearchHelper
的用法示例。
在下文中一共展示了PsiSearchHelper.SearchCostResult方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}