Java 类com.intellij.psi.scope.util.PsiScopesUtil 实例源码

项目:intellij-ce-playground    文件:ClsMethodImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null) return true;

  if (!PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place)) return false;

  final PsiParameter[] parameters = getParameterList().getParameters();
  for (PsiParameter parameter : parameters) {
    if (!processor.execute(parameter, state)) return false;
  }

  return true;
}
项目:intellij-ce-playground    文件:PsiResolveHelperImpl.java   
@NotNull
@Override
public CandidateInfo[] getReferencedMethodCandidates(@NotNull PsiCallExpression expr,
                                                     boolean dummyImplicitConstructor,
                                                     final boolean checkVarargs) {
  PsiFile containingFile = expr.getContainingFile();
  final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(expr, containingFile) {
    @Override
    protected boolean acceptVarargs() {
      return checkVarargs;
    }
  };
  try {
    PsiScopesUtil.setupAndRunProcessor(processor, expr, dummyImplicitConstructor);
  }
  catch (MethodProcessorSetupFailedException e) {
    return CandidateInfo.EMPTY_ARRAY;
  }
  return processor.getCandidates();
}
项目:intellij-ce-playground    文件:PsiJavaCodeReferenceElementImpl.java   
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode) {
  PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl)ref;
  int kind = referenceElement.getKind(containingFile);
  JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);

  if (incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND) {
    VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
    PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, true);
    result = processor.getResult();
    if (result.length == 0 && kind == CLASS_NAME_KIND) {
      result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
    }
  }

  JavaResolveUtil.substituteResults(referenceElement, result);

  return result;
}
项目:intellij-ce-playground    文件:PsiCatchSectionImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null || lastParent.getParent() != this)
    // Parent element should not see our vars
    return true;

  final PsiParameter catchParameter = getParameter();
  if (catchParameter != null) {
    return processor.execute(catchParameter, state);
  }

  return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
项目:intellij-ce-playground    文件:ReuseVariableDeclarationFix.java   
@Nullable
private PsiVariable findPreviousVariable() {
  PsiElement scope = myVariable.getParent();
  while (scope != null) {
    if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return null;

  PsiIdentifier nameIdentifier = myVariable.getNameIdentifier();
  if (nameIdentifier == null) {
    return null;
  }

  final VariablesNotProcessor processor = new VariablesNotProcessor(myVariable, false);
  PsiScopesUtil.treeWalkUp(processor, nameIdentifier, scope);
  return processor.size() > 0 ? processor.getResult(0) : null;
}
项目:intellij-ce-playground    文件:MacroUtil.java   
@NotNull public static PsiVariable[] getVariablesVisibleAt(@Nullable final PsiElement place, String prefix) {
  if (place == null) {
    return new PsiVariable[0];
  }

  final Set<String> usedNames = ContainerUtil.newHashSet();
  final List<PsiVariable> list = new ArrayList<PsiVariable>();
  VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
    @Override
    public boolean execute(@NotNull PsiElement pe, @NotNull ResolveState state) {
      if (pe instanceof PsiVariable) {
        if (!usedNames.add(((PsiVariable)pe).getName())) {
          return false;
        }
        //exclude variables that are initialized in 'place'
        final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
        if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
      }
      return pe instanceof PsiField && !PsiUtil.isAccessible((PsiField)pe, place, null) || super.execute(pe, state);
    }
  };
  PsiScopesUtil.treeWalkUp(varproc, place, null);
  return varproc.getResultsAsArray();
}
项目:intellij-ce-playground    文件:ReassignVariableUtil.java   
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
  VariablesProcessor proc = new VariablesProcessor(false) {
    @Override
    protected boolean check(PsiVariable var, ResolveState state) {
      for (PsiElement element : declaration.getDeclaredElements()) {
        if (element == var) return false;
      }
      return TypeConversionUtil.isAssignable(var.getType(), type);
    }
  };
  PsiElement scope = declaration;
  while (scope != null) {
    if (scope instanceof PsiFile || 
        scope instanceof PsiMethod || 
        scope instanceof PsiLambdaExpression ||
        scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return proc;
  PsiScopesUtil.treeWalkUp(proc, declaration, scope);
  return proc;
}
项目:intellij-ce-playground    文件:JavaI18nUtil.java   
private static void addAvailableMethodsOfType(final PsiClassType type, final PsiLiteralExpression context, final Collection<String> result) {
  PsiScopesUtil.treeWalkUp(new PsiScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
      if (element instanceof PsiMethod) {
        PsiMethod method = (PsiMethod)element;
        PsiType returnType = method.getReturnType();
        if (returnType != null && TypeConversionUtil.isAssignable(type, returnType)
            && method.getParameterList().getParametersCount() == 0) {
          result.add(method.getName() + "()");
        }
      }
      return true;
    }

    @Override
    public <T> T getHint(@NotNull Key<T> hintKey) {
      return null;
    }

    @Override
    public void handleEvent(@NotNull Event event, Object associated) {

    }
  }, context, null);
}
项目:eddy    文件:EnvironmentProcessor.java   
public EnvironmentProcessor(final @NotNull Converter converter, final @NotNull PsiElement place, final int lastEdit) {
  final Place where = new Place(converter.project,place);

  // Walk up the PSI tree, also processing import statements
  final EddyThread thread = EddyThread.getEddyThread();
  final Processor P = new Processor(thread,where);
  pushScope("tree walking");
  if (thread != null) thread.pushSoftInterrupts();
  try {
    PsiScopesUtil.treeWalkUp(P, place, place.getContainingFile());
  } finally {
    popScope();
    if (thread != null) thread.popSoftInterrupts();
  }
  // only do this if we got through the processor
  pushScope("fillLocalInfo");
  try {
    this.placeInfo = fillLocalInfo(P,where,converter,lastEdit);
  } finally { popScope(); }
}
项目:tools-idea    文件:ClsMethodImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null) return true;

  if (!PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place)) return false;

  final PsiParameter[] parameters = getParameterList().getParameters();
  for (PsiParameter parameter : parameters) {
    if (!processor.execute(parameter, state)) return false;
  }

  return true;
}
项目:tools-idea    文件:PsiJavaCodeReferenceElementImpl.java   
@NotNull
@Override
public JavaResolveResult[] resolve(@NotNull PsiJavaReference ref, boolean incompleteCode) {
  PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl)ref;
  int kind = referenceElement.getKind();
  PsiFile containingFile = referenceElement.getContainingFile();
  JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);

  if (incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND) {
    VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
    PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, incompleteCode);
    result = processor.getResult();
    if (result.length == 0 && kind == CLASS_NAME_KIND) {
      result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
    }
  }

  JavaResolveUtil.substituteResults((PsiJavaCodeReferenceElement)ref, result);

  return result;
}
项目:tools-idea    文件:PsiCatchSectionImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null || lastParent.getParent() != this)
    // Parent element should not see our vars
    return true;

  final PsiParameter catchParameter = getParameter();
  if (catchParameter != null) {
    return processor.execute(catchParameter, state);
  }

  return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
项目:tools-idea    文件:ReuseVariableDeclarationFix.java   
@Nullable
private PsiVariable findPreviousVariable() {
  PsiElement scope = myVariable.getParent();
  while (scope != null) {
    if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return null;

  PsiIdentifier nameIdentifier = myVariable.getNameIdentifier();
  if (nameIdentifier == null) {
    return null;
  }

  final VariablesNotProcessor processor = new VariablesNotProcessor(myVariable, false);
  PsiScopesUtil.treeWalkUp(processor, nameIdentifier, scope);
  return processor.size() > 0 ? processor.getResult(0) : null;
}
项目:tools-idea    文件:MacroUtil.java   
@NotNull public static PsiVariable[] getVariablesVisibleAt(@Nullable final PsiElement place, String prefix) {
  if (place == null) {
    return new PsiVariable[0];
  }

  final Set<String> usedNames = ContainerUtil.newHashSet();
  final List<PsiVariable> list = new ArrayList<PsiVariable>();
  VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
    @Override
    public boolean execute(@NotNull PsiElement pe, ResolveState state) {
      if (pe instanceof PsiVariable) {
        if (!usedNames.add(((PsiVariable)pe).getName())) {
          return false;
        }
        //exclude variables that are initialized in 'place'
        final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
        if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
      }
      return pe instanceof PsiField && !PsiUtil.isAccessible((PsiField)pe, place, null) || super.execute(pe, state);
    }
  };
  PsiScopesUtil.treeWalkUp(varproc, place, null);
  return varproc.getResultsAsArray();
}
项目:tools-idea    文件:ReassignVariableUtil.java   
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
  VariablesProcessor proc = new VariablesProcessor(false) {
    @Override
    protected boolean check(PsiVariable var, ResolveState state) {
      for (PsiElement element : declaration.getDeclaredElements()) {
        if (element == var) return false;
      }
      return TypeConversionUtil.isAssignable(var.getType(), type);
    }
  };
  PsiElement scope = declaration;
  while (scope != null) {
    if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return proc;
  PsiScopesUtil.treeWalkUp(proc, declaration, scope);
  return proc;
}
项目:tools-idea    文件:JavaI18nUtil.java   
private static void addAvailableMethodsOfType(final PsiClassType type, final PsiLiteralExpression context, final Collection<String> result) {
  PsiScopesUtil.treeWalkUp(new PsiScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, ResolveState state) {
      if (element instanceof PsiMethod) {
        PsiMethod method = (PsiMethod)element;
        PsiType returnType = method.getReturnType();
        if (returnType != null && TypeConversionUtil.isAssignable(type, returnType)
            && method.getParameterList().getParametersCount() == 0) {
          result.add(method.getName() + "()");
        }
      }
      return true;
    }

    @Override
    public <T> T getHint(@NotNull Key<T> hintKey) {
      return null;
    }

    @Override
    public void handleEvent(Event event, Object associated) {

    }
  }, context, null);
}
项目:consulo-java    文件:ClsMethodImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place)
{
    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
    if(lastParent == null)
    {
        return true;
    }

    if(!PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place))
    {
        return false;
    }

    final PsiParameter[] parameters = getParameterList().getParameters();
    for(PsiParameter parameter : parameters)
    {
        if(!processor.execute(parameter, state))
        {
            return false;
        }
    }

    return true;
}
项目:consulo-java    文件:PsiResolveHelperImpl.java   
@NotNull
@Override
public CandidateInfo[] getReferencedMethodCandidates(@NotNull PsiCallExpression expr, boolean dummyImplicitConstructor, final boolean checkVarargs)
{
    PsiFile containingFile = expr.getContainingFile();
    final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(expr, containingFile)
    {
        @Override
        protected boolean acceptVarargs()
        {
            return checkVarargs;
        }
    };
    try
    {
        PsiScopesUtil.setupAndRunProcessor(processor, expr, dummyImplicitConstructor);
    }
    catch(MethodProcessorSetupFailedException e)
    {
        return CandidateInfo.EMPTY_ARRAY;
    }
    return processor.getCandidates();
}
项目:consulo-java    文件:PsiJavaCodeReferenceElementImpl.java   
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode)
{
    PsiJavaCodeReferenceElementImpl referenceElement = (PsiJavaCodeReferenceElementImpl) ref;
    int kind = referenceElement.getKind(containingFile);
    JavaResolveResult[] result = referenceElement.resolve(kind, containingFile);

    if(incompleteCode && result.length == 0 && kind != CLASS_FQ_NAME_KIND && kind != CLASS_FQ_OR_PACKAGE_NAME_KIND)
    {
        VariableResolverProcessor processor = new VariableResolverProcessor(referenceElement, containingFile);
        PsiScopesUtil.resolveAndWalk(processor, referenceElement, null, true);
        result = processor.getResult();
        if(result.length == 0 && kind == CLASS_NAME_KIND)
        {
            result = referenceElement.resolve(PACKAGE_NAME_KIND, containingFile);
        }
    }

    JavaResolveUtil.substituteResults(referenceElement, result);

    return result;
}
项目:consulo-java    文件:PsiCatchSectionImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null || lastParent.getParent() != this)
    // Parent element should not see our vars
    return true;

  final PsiParameter catchParameter = getParameter();
  if (catchParameter != null) {
    return processor.execute(catchParameter, state);
  }

  return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
项目:consulo-java    文件:JavaI18nUtil.java   
private static void addAvailableMethodsOfType(final PsiClassType type, final PsiLiteralExpression context, final Collection<String> result) {
  PsiScopesUtil.treeWalkUp(new PsiScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, ResolveState state) {
      if (element instanceof PsiMethod) {
        PsiMethod method = (PsiMethod)element;
        PsiType returnType = method.getReturnType();
        if (returnType != null && TypeConversionUtil.isAssignable(type, returnType)
            && method.getParameterList().getParametersCount() == 0) {
          result.add(method.getName() + "()");
        }
      }
      return true;
    }

    @Override
    public <T> T getHint(@NotNull Key<T> hintKey) {
      return null;
    }

    @Override
    public void handleEvent(Event event, Object associated) {

    }
  }, context, null);
}
项目:consulo-java    文件:MethodParameterInfoHandler.java   
private static CandidateInfo[] getCandidates(PsiCallExpression call)
{
    final MethodCandidatesProcessor processor = new MethodResolverProcessor(call, call.getContainingFile(), new PsiConflictResolver[0])
    {
        @Override
        protected boolean acceptVarargs()
        {
            return false;
        }
    };

    try
    {
        PsiScopesUtil.setupAndRunProcessor(processor, call, true);
    }
    catch(MethodProcessorSetupFailedException e)
    {
        return CandidateInfo.EMPTY_ARRAY;
    }
    final List<CandidateInfo> results = processor.getResults();
    return results.toArray(new CandidateInfo[results.size()]);
}
项目:consulo-java    文件:ReuseVariableDeclarationFix.java   
@Nullable
private PsiVariable findPreviousVariable() {
  PsiElement scope = myVariable.getParent();
  while (scope != null) {
    if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return null;

  PsiIdentifier nameIdentifier = myVariable.getNameIdentifier();
  if (nameIdentifier == null) {
    return null;
  }

  final VariablesNotProcessor processor = new VariablesNotProcessor(myVariable, false);
  PsiScopesUtil.treeWalkUp(processor, nameIdentifier, scope);
  return processor.size() > 0 ? processor.getResult(0) : null;
}
项目:consulo-java    文件:ReassignVariableUtil.java   
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
  VariablesProcessor proc = new VariablesProcessor(false) {
    @Override
    protected boolean check(PsiVariable var, ResolveState state) {
      for (PsiElement element : declaration.getDeclaredElements()) {
        if (element == var) return false;
      }
      return TypeConversionUtil.isAssignable(var.getType(), type);
    }
  };
  PsiElement scope = declaration;
  while (scope != null) {
    if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return proc;
  PsiScopesUtil.treeWalkUp(proc, declaration, scope);
  return proc;
}
项目:intellij-ce-playground    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref,
                                          boolean[] problemWithAccess,
                                          boolean[] problemWithStatic
) {

  /*
  long time1 = System.currentTimeMillis();
  */

  final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);

  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveVariableTime += (time2 - time1);
  Statistics.resolveVariableCount++;
  */
  final JavaResolveResult[] result = processor.getResult();
  if (result.length != 1) return null;
  final PsiVariable refVar = (PsiVariable)result[0].getElement();

  if (problemWithAccess != null) {
    problemWithAccess[0] = !result[0].isAccessible();
  }
  if (problemWithStatic != null) {
    problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
  }


  return refVar;
}
项目:intellij-ce-playground    文件:ProcessCandidateParameterTypeInferencePolicy.java   
@NotNull
protected JavaResolveResult[] getResults(@NotNull PsiCallExpression contextCall, final int exprIdx) throws MethodProcessorSetupFailedException {
  PsiFile containingFile = contextCall.getContainingFile();
  final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(contextCall, containingFile);
  //can't call resolve() since it obtains full substitution, that may result in infinite recursion
  PsiScopesUtil.setupAndRunProcessor(processor, contextCall, false);
  return processor.getResult();
}
项目:intellij-ce-playground    文件:PsiReferenceExpressionImpl.java   
@NotNull
private JavaResolveResult[] resolveToMethod(@NotNull PsiFile containingFile) {
  final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)getParent();
  final MethodResolverProcessor processor = new MethodResolverProcessor(methodCall, containingFile);
  try {
    PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false);
  }
  catch (MethodProcessorSetupFailedException e) {
    return JavaResolveResult.EMPTY_ARRAY;
  }
  return processor.getResult();
}
项目:intellij-ce-playground    文件:PsiReferenceExpressionImpl.java   
@NotNull
private JavaResolveResult[] resolveToClass(@NotNull PsiElement classNameElement, @NotNull PsiFile containingFile) {
  final String className = classNameElement.getText();

  final ClassResolverProcessor processor = new ClassResolverProcessor(className, this, containingFile);
  PsiScopesUtil.resolveAndWalk(processor, this, null);
  return processor.getResult();
}
项目:intellij-ce-playground    文件:PsiForStatementImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null || lastParent.getParent() != this)
    // Parent element should not see our vars
    return true;

  return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
项目:intellij-ce-playground    文件:PsiCodeBlockImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null) {
    // Parent element should not see our vars
    return true;
  }
  Couple<Set<String>> pair = buildMaps();
  boolean conflict = pair == null;
  final Set<String> classesSet = conflict ? null : pair.getFirst();
  final Set<String> variablesSet = conflict ? null : pair.getSecond();
  final NameHint hint = processor.getHint(NameHint.KEY);
  if (hint != null && !conflict) {
    final ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
    final String name = hint.getName(state);
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) && classesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) && variablesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
  }
  else {
    return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
  }
  return true;
}
项目:intellij-ce-playground    文件:ExtractMethodProcessor.java   
@Nullable
private PsiVariable getArtificialOutputVariable() {
  if (myOutputVariables.length == 0 && myExitStatements.isEmpty()) {
    if (myCanBeChainedConstructor) {
      final Set<PsiField> fields = new HashSet<PsiField>();
      for (PsiElement element : myElements) {
        element.accept(new JavaRecursiveElementWalkingVisitor() {
          @Override
          public void visitReferenceExpression(PsiReferenceExpression expression) {
            super.visitReferenceExpression(expression);
            final PsiElement resolve = expression.resolve();
            if (resolve instanceof PsiField && ((PsiField)resolve).hasModifierProperty(PsiModifier.FINAL) &&
                PsiUtil.isAccessedForWriting(expression)) {
              fields.add((PsiField)resolve);
            }
          }
        });
      }
      if (!fields.isEmpty()) {
        return fields.size() == 1 ? fields.iterator().next() : null;
      }
    }
    final VariablesProcessor processor = new VariablesProcessor(true) {
      @Override
      protected boolean check(PsiVariable var, ResolveState state) {
        return isDeclaredInside(var);
      }
    };
    PsiScopesUtil.treeWalkUp(processor, myElements[myElements.length - 1], myCodeFragmentMember);
    if (processor.size() == 1) {
      return processor.getResult(0);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:IntroduceVariableBase.java   
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression expr, PsiElement tempContainer) {
  boolean skipForStatement = true;
  final PsiForStatement forStatement = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class);
  if (forStatement != null) {
    final VariablesProcessor variablesProcessor = new VariablesProcessor(false) {
      @Override
      protected boolean check(PsiVariable var, ResolveState state) {
        return PsiTreeUtil.isAncestor(forStatement.getInitialization(), var, true);
      }
    };
    PsiScopesUtil.treeWalkUp(variablesProcessor, expr, null);
    skipForStatement = variablesProcessor.size() == 0;
  }

  PsiElement containerParent = tempContainer;
  PsiElement lastScope = tempContainer;
  while (true) {
    if (containerParent instanceof PsiFile) break;
    if (containerParent instanceof PsiMethod) break;
    if (containerParent instanceof PsiLambdaExpression) break;
    if (!skipForStatement && containerParent instanceof PsiForStatement) break;
    containerParent = containerParent.getParent();
    if (containerParent instanceof PsiCodeBlock) {
      lastScope = containerParent;
    }
  }

  return new ExpressionOccurrenceManager(expr, lastScope, NotInSuperCallOccurrenceFilter.INSTANCE);
}
项目:eddy    文件:EnvironmentProcessorTest.java   
public EnvironmentProcessorTest(@NotNull Project project, PsiElement place, boolean honorPrivate) {
  this.project = project;
  this.place = place;
  this.honorPrivate = honorPrivate;

  // this is set to null when we go to java.lang
  this.currentFileContext = place;

  logger.setLevel(Level.DEBUG);

  PsiScopesUtil.treeWalkUp(this, place, this.place.getContainingFile());

  // TODO: find import statements and add those to scope
}
项目:tools-idea    文件:PsiResolveHelperImpl.java   
@Override
@NotNull
public CandidateInfo[] getReferencedMethodCandidates(@NotNull PsiCallExpression expr, boolean dummyImplicitConstructor) {
  PsiFile containingFile = expr.getContainingFile();
  final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(expr, containingFile);
  try {
    PsiScopesUtil.setupAndRunProcessor(processor, expr, dummyImplicitConstructor);
  }
  catch (MethodProcessorSetupFailedException e) {
    return CandidateInfo.EMPTY_ARRAY;
  }
  return processor.getCandidates();
}
项目:tools-idea    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref,
                                          boolean[] problemWithAccess,
                                          boolean[] problemWithStatic
) {

  /*
  long time1 = System.currentTimeMillis();
  */

  final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);

  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveVariableTime += (time2 - time1);
  Statistics.resolveVariableCount++;
  */
  final JavaResolveResult[] result = processor.getResult();
  if (result.length != 1) return null;
  final PsiVariable refVar = (PsiVariable)result[0].getElement();

  if (problemWithAccess != null) {
    problemWithAccess[0] = !result[0].isAccessible();
  }
  if (problemWithStatic != null) {
    problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
  }


  return refVar;
}
项目:tools-idea    文件:ProcessCandidateParameterTypeInferencePolicy.java   
@NotNull
protected JavaResolveResult[] getResults(@NotNull PsiCallExpression contextCall, final int exprIdx) throws MethodProcessorSetupFailedException {
  PsiFile containingFile = contextCall.getContainingFile();
  final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(contextCall, containingFile);
  //can't call resolve() since it obtains full substitution, that may result in infinite recursion
  PsiScopesUtil.setupAndRunProcessor(processor, contextCall, false);
  return processor.getResult();
}
项目:tools-idea    文件:PsiReferenceExpressionImpl.java   
@NotNull
private JavaResolveResult[] resolveToMethod(@NotNull PsiFile containingFile) {
  final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)getParent();
  final MethodResolverProcessor processor = new MethodResolverProcessor(methodCall, containingFile);
  try {
    PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false);
  }
  catch (MethodProcessorSetupFailedException e) {
    return JavaResolveResult.EMPTY_ARRAY;
  }
  return processor.getResult();
}
项目:tools-idea    文件:PsiReferenceExpressionImpl.java   
@NotNull
private JavaResolveResult[] resolveToClass(@NotNull PsiElement classNameElement, PsiFile containingFile) {
  final String className = classNameElement.getText();

  final ClassResolverProcessor processor = new ClassResolverProcessor(className, this, containingFile);
  PsiScopesUtil.resolveAndWalk(processor, this, null);
  return processor.getResult();
}
项目:tools-idea    文件:PsiForStatementImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null || lastParent.getParent() != this)
    // Parent element should not see our vars
    return true;

  return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
项目:tools-idea    文件:PsiCodeBlockImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null) {
    // Parent element should not see our vars
    return true;
  }
  Pair<Set<String>, Set<String>> pair = buildMaps();
  boolean conflict = pair == null;
  final Set<String> classesSet = conflict ? null : pair.getFirst();
  final Set<String> variablesSet = conflict ? null : pair.getSecond();
  final NameHint hint = processor.getHint(NameHint.KEY);
  if (hint != null && !conflict) {
    final ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
    final String name = hint.getName(state);
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) && classesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) && variablesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
  }
  else {
    return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
  }
  return true;
}