Java 类com.intellij.psi.scope.BaseScopeProcessor 实例源码

项目:intellij-ce-playground    文件:ExpressionGenerator.java   
@Nullable
private static PsiType inferCastType(@NotNull GrExpression caller, @NotNull PsiMethod method, @NotNull GroovyPsiElement context) {
  final PsiType type = caller.getType();
  if (type instanceof PsiIntersectionType) {
    final PsiType[] conjuncts = ((PsiIntersectionType)type).getConjuncts();
    for (PsiType conjunct : conjuncts) {
      final GenerationUtil.CheckProcessElement processor = new GenerationUtil.CheckProcessElement(method);
      ResolveUtil.processAllDeclarationsSeparately(conjunct, processor, new BaseScopeProcessor() {
        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
          return false;
        }
      }, ResolveState.initial(), context);
      if (processor.isFound()) return conjunct;
    }
  }
  return type;
}
项目:tools-idea    文件:ExpressionGenerator.java   
@Nullable
private static PsiType inferCastType(@NotNull GrExpression caller, @NotNull PsiMethod method, @NotNull GroovyPsiElement context) {
  final PsiType type = caller.getType();
  if (type instanceof PsiIntersectionType) {
    final PsiType[] conjuncts = ((PsiIntersectionType)type).getConjuncts();
    for (PsiType conjunct : conjuncts) {
      final CheckProcessElement processor = new CheckProcessElement(method);
      ResolveUtil.processAllDeclarationsSeparately(conjunct, processor, new BaseScopeProcessor() {
        @Override
        public boolean execute(@NotNull PsiElement element, ResolveState state) {
          return false;
        }
      }, ResolveState.initial(), context);
      if (processor.isFound()) return conjunct;
    }
  }
  return type;
}
项目:intellij-ce-playground    文件:GdslClosureCompleter.java   
private static void processExecutors(PsiType qtype, GrReferenceExpression ref, final ArrayList<ClosureDescriptor> descriptors) {
  GroovyDslFileIndex.processExecutors(qtype, ref, new BaseScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
      if (element instanceof ClosureDescriptor) {
        descriptors.add((ClosureDescriptor)element);
      }
      return true;
    }
  }, ResolveState.initial());
}
项目:intellij-ce-playground    文件:GenerationUtil.java   
public static boolean isCastNeeded(@NotNull GrExpression qualifier, @NotNull final PsiMember member, ExpressionContext context) {
  PsiType declared = getDeclaredType(qualifier, context);
  if (declared == null) return false;

  final CheckProcessElement checker = new CheckProcessElement(member);
  ResolveUtil.processAllDeclarationsSeparately(declared, checker, new BaseScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
      return false;
    }
  }, ResolveState.initial(), qualifier);
  return !checker.isFound();
}
项目:tools-idea    文件:GdslClosureCompleter.java   
private static void processExecutors(PsiType qtype, GrReferenceExpression ref, final ArrayList<ClosureDescriptor> descriptors) {
  GroovyDslFileIndex.processExecutors(qtype, ref, new BaseScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, ResolveState state) {
      if (element instanceof ClosureDescriptor) {
        descriptors.add((ClosureDescriptor)element);
      }
      return true;
    }
  }, ResolveState.initial());
}
项目:tools-idea    文件:GenerationUtil.java   
public static boolean isCastNeeded(@NotNull GrExpression qualifier, @NotNull final PsiMember member, ExpressionContext context) {
  PsiType declared = getDeclaredType(qualifier, context);
  if (declared == null) return false;

  final CheckProcessElement checker = new CheckProcessElement(member);
  ResolveUtil.processAllDeclarationsSeparately(declared, checker, new BaseScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, ResolveState state) {
      return false;
    }
  }, ResolveState.initial(), qualifier);
  return !checker.isFound();
}
项目:consulo-csharp    文件:ExpectedUsingInfo.java   
@RequiredReadAction
private boolean isUsedNamespace(String namespace, PsiElement target, PsiElement element)
{
    return !CSharpResolveUtil.walkUsing(new BaseScopeProcessor()
    {
        @Override
        @RequiredReadAction
        public boolean execute(@NotNull PsiElement psiElement, ResolveState resolveState)
        {
            if(psiElement instanceof CSharpUsingTypeStatement)
            {
                DotNetTypeResolveResult typeResolveResult = ((CSharpUsingTypeStatement) psiElement).getTypeRef().resolve();
                if(target.isEquivalentTo(typeResolveResult.getElement()))
                {
                    return false;
                }
            }
            else if(psiElement instanceof CSharpUsingNamespaceStatement)
            {
                String referenceText = ((CSharpUsingNamespaceStatement) psiElement).getReferenceText();
                if(Objects.equals(namespace, referenceText))
                {
                    return false;
                }
            }
            return true;
        }
    }, element, null, ResolveState.initial());
}
项目:intellij-ce-playground    文件:RenameWrongRefFix.java   
private LookupElement[] collectItems() {
  Set<LookupElement> items = new LinkedHashSet<LookupElement>();
  boolean qualified = myRefExpr.getQualifierExpression() != null;

  if (!qualified && !(myRefExpr.getParent() instanceof PsiMethodCallExpression)) {
    PsiVariable[] vars = CreateFromUsageUtils.guessMatchingVariables(myRefExpr);
    for (PsiVariable var : vars) {
      items.add(LookupElementBuilder.create(var.getName()));
    }
  } else {
    class MyScopeProcessor extends BaseScopeProcessor {
      ArrayList<PsiElement> myResult = new ArrayList<PsiElement>();
      boolean myFilterMethods;
      boolean myFilterStatics = false;

      MyScopeProcessor(PsiReferenceExpression refExpression) {
        myFilterMethods = refExpression.getParent() instanceof PsiMethodCallExpression;
        PsiExpression qualifier = refExpression.getQualifierExpression();
        if (qualifier instanceof PsiReferenceExpression) {
          PsiElement e = ((PsiReferenceExpression) qualifier).resolve();
          myFilterStatics = e instanceof PsiClass;
        } else if (qualifier == null) {
          PsiModifierListOwner scope = PsiTreeUtil.getParentOfType(refExpression, PsiModifierListOwner.class);
          myFilterStatics = scope != null && scope.hasModifierProperty(PsiModifier.STATIC);
        }
      }

      @Override
      public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
        if (element instanceof PsiNamedElement
            && element instanceof PsiModifierListOwner
            && myFilterMethods == element instanceof PsiMethod) {
          if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC) == myFilterStatics) {
            myResult.add(element);
          }
        }
        return true;
      }

      public PsiElement[] getVariants () {
        return PsiUtilCore.toPsiElementArray(myResult);
      }
    }

    items.add(LookupElementBuilder.create(myRefExpr.getReferenceName()));
    MyScopeProcessor processor = new MyScopeProcessor(myRefExpr);
    myRefExpr.processVariants(processor);
    PsiElement[] variants = processor.getVariants();
    for (PsiElement variant : variants) {
      items.add(LookupElementBuilder.create(((PsiNamedElement)variant).getName()));
    }
  }

  return items.toArray(new LookupElement[items.size()]);
}
项目:tools-idea    文件:RenameWrongRefFix.java   
private LookupElement[] collectItems() {
  Set<LookupElement> items = new LinkedHashSet<LookupElement>();
  boolean qualified = myRefExpr.getQualifierExpression() != null;

  if (!qualified && !(myRefExpr.getParent() instanceof PsiMethodCallExpression)) {
    PsiVariable[] vars = CreateFromUsageUtils.guessMatchingVariables(myRefExpr);
    for (PsiVariable var : vars) {
      items.add(LookupElementBuilder.create(var.getName()));
    }
  } else {
    class MyScopeProcessor extends BaseScopeProcessor {
      ArrayList<PsiElement> myResult = new ArrayList<PsiElement>();
      boolean myFilterMethods;
      boolean myFilterStatics = false;

      MyScopeProcessor(PsiReferenceExpression refExpression) {
        myFilterMethods = refExpression.getParent() instanceof PsiMethodCallExpression;
        PsiExpression qualifier = refExpression.getQualifierExpression();
        if (qualifier instanceof PsiReferenceExpression) {
          PsiElement e = ((PsiReferenceExpression) qualifier).resolve();
          myFilterStatics = e instanceof PsiClass;
        } else if (qualifier == null) {
          PsiModifierListOwner scope = PsiTreeUtil.getParentOfType(refExpression, PsiModifierListOwner.class);
          myFilterStatics = scope != null && scope.hasModifierProperty(PsiModifier.STATIC);
        }
      }

      @Override
      public boolean execute(@NotNull PsiElement element, ResolveState state) {
        if (element instanceof PsiNamedElement
            && element instanceof PsiModifierListOwner
            && myFilterMethods == element instanceof PsiMethod) {
          if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC) == myFilterStatics) {
            myResult.add(element);
          }
        }
        return true;
      }

      public PsiElement[] getVariants () {
        return PsiUtilCore.toPsiElementArray(myResult);
      }
    }

    items.add(LookupElementBuilder.create(myRefExpr.getReferenceName()));
    MyScopeProcessor processor = new MyScopeProcessor(myRefExpr);
    myRefExpr.processVariants(processor);
    PsiElement[] variants = processor.getVariants();
    for (PsiElement variant : variants) {
      items.add(LookupElementBuilder.create(((PsiNamedElement)variant).getName()));
    }
  }

  return items.toArray(new LookupElement[items.size()]);
}
项目:consulo-java    文件:RenameWrongRefFix.java   
private LookupElement[] collectItems() {
  Set<LookupElement> items = new LinkedHashSet<LookupElement>();
  boolean qualified = myRefExpr.getQualifierExpression() != null;

  if (!qualified && !(myRefExpr.getParent() instanceof PsiMethodCallExpression)) {
    PsiVariable[] vars = CreateFromUsageUtils.guessMatchingVariables(myRefExpr);
    for (PsiVariable var : vars) {
      items.add(LookupElementBuilder.create(var.getName()));
    }
  } else {
    class MyScopeProcessor extends BaseScopeProcessor {
      ArrayList<PsiElement> myResult = new ArrayList<PsiElement>();
      boolean myFilterMethods;
      boolean myFilterStatics = false;

      MyScopeProcessor(PsiReferenceExpression refExpression) {
        myFilterMethods = refExpression.getParent() instanceof PsiMethodCallExpression;
        PsiExpression qualifier = refExpression.getQualifierExpression();
        if (qualifier instanceof PsiReferenceExpression) {
          PsiElement e = ((PsiReferenceExpression) qualifier).resolve();
          myFilterStatics = e instanceof PsiClass;
        } else if (qualifier == null) {
          PsiModifierListOwner scope = PsiTreeUtil.getParentOfType(refExpression, PsiModifierListOwner.class);
          myFilterStatics = scope != null && scope.hasModifierProperty(PsiModifier.STATIC);
        }
      }

      @Override
      public boolean execute(@NotNull PsiElement element, ResolveState state) {
        if (element instanceof PsiNamedElement
            && element instanceof PsiModifierListOwner
            && myFilterMethods == element instanceof PsiMethod) {
          if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC) == myFilterStatics) {
            myResult.add(element);
          }
        }
        return true;
      }

      public PsiElement[] getVariants () {
        return PsiUtilCore.toPsiElementArray(myResult);
      }
    }

    items.add(LookupElementBuilder.create(myRefExpr.getReferenceName()));
    MyScopeProcessor processor = new MyScopeProcessor(myRefExpr);
    myRefExpr.processVariants(processor);
    PsiElement[] variants = processor.getVariants();
    for (PsiElement variant : variants) {
      items.add(LookupElementBuilder.create(((PsiNamedElement)variant).getName()));
    }
  }

  return items.toArray(new LookupElement[items.size()]);
}