Java 类com.intellij.psi.scope.processor.MethodCandidatesProcessor 实例源码

项目: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();
}
项目: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    文件: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()]);
}
项目: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();
}
项目: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    文件: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();
}
项目:consulo-java    文件: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    文件:PsiDiamondTypeImpl.java   
@Nullable
private static PsiMethod findConstructorStaticFactory(final PsiClass containingClass, PsiNewExpression newExpression) {
  final PsiExpressionList argumentList = newExpression.getArgumentList();
  if (argumentList == null) return null;

  final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(newExpression);
  final List<CandidateInfo> conflicts = new ArrayList<CandidateInfo>();
  PsiMethod[] constructors = containingClass.getConstructors();
  if (constructors.length == 0) {
    //default constructor
    constructors = new PsiMethod[] {null};
  }

  final PsiConflictResolver[] conflictResolvers = {new JavaMethodsConflictResolver(argumentList, languageLevel)};
  final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(argumentList, argumentList.getContainingFile(), conflictResolvers, conflicts) {
    @Override
    protected boolean isAccepted(PsiMethod candidate) {
      return true;
    }

    @Override
    protected PsiClass getContainingClass(PsiMethod method) {
      return containingClass;
    }

    @Override
    protected boolean acceptVarargs() {
      return true;
    }
  };
  processor.setArgumentList(argumentList);

  for (PsiMethod constructor : constructors) {
    final PsiTypeParameter[] params = getAllTypeParams(constructor, containingClass);
    final PsiMethod staticFactory = generateStaticFactory(constructor, containingClass, params, newExpression.getClassReference());
    if (staticFactory != null) {
      processor.add(staticFactory, PsiSubstitutor.EMPTY);
    }
  }

  final JavaResolveResult[] result = processor.getResult();
  return result.length == 1 ? (PsiMethod)result[0].getElement() : null;
}
项目:consulo-java    文件:PsiDiamondTypeImpl.java   
@Nullable
public static JavaResolveResult[] collectStaticFactories(PsiNewExpression newExpression, final PsiConflictResolver... conflictResolvers)
{
    PsiExpressionList argumentList = newExpression.getArgumentList();
    if(argumentList == null)
    {
        return null;
    }

    final PsiClass psiClass = findClass(newExpression);
    if(psiClass == null)
    {
        //should not happens: unresolved class reference would be first and inference won't start
        return null;
    }

    final List<CandidateInfo> candidates = new ArrayList<CandidateInfo>();
    PsiMethod[] constructors = psiClass.getConstructors();
    if(constructors.length == 0)
    {
        //default constructor
        constructors = new PsiMethod[]{null};
    }

    final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(argumentList, argumentList.getContainingFile(), conflictResolvers, candidates)
    {
        @Override
        protected boolean isAccepted(PsiMethod candidate)
        {
            return true;
        }

        @Override
        protected PsiClass getContainingClass(PsiMethod method)
        {
            return psiClass;
        }

        @Override
        protected boolean acceptVarargs()
        {
            return true;
        }
    };
    processor.setArgumentList(argumentList);

    for(PsiMethod constructor : constructors)
    {
        final PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass);
        final PsiMethod staticFactory = generateStaticFactory(constructor, psiClass, params, newExpression.getClassReference());
        if(staticFactory != null)
        {
            processor.add(staticFactory, PsiSubstitutor.EMPTY);
        }
    }

    return processor.getResult();
}