Java 类com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver 实例源码

项目:intellij-ce-playground    文件:JavaMethodResolveHelper.java   
public JavaMethodResolveHelper(@NotNull final PsiElement argumentList, PsiFile containingFile, @Nullable final PsiType[] argumentTypes) {
  myArgumentTypes = argumentTypes;
  final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(argumentList);
  final PsiConflictResolver resolver = argumentTypes == null ? DuplicateConflictResolver.INSTANCE : new JavaMethodsConflictResolver(argumentList, argumentTypes,
                                                                                                                                    languageLevel);
  myProcessor = new MethodResolverProcessor(argumentList, containingFile, new PsiConflictResolver[]{resolver}) {
    @Override
    protected MethodCandidateInfo createCandidateInfo(@NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor,
                                                      final boolean staticProblem,
                                                      final boolean accessible, final boolean varargs) {
      return JavaMethodResolveHelper.this
        .createCandidateInfo(method, substitutor, staticProblem, myCurrentFileContext, !accessible, argumentList, argumentTypes,
                             languageLevel);
    }

    @Override
    protected boolean isAccepted(final PsiMethod candidate) {
      return !candidate.isConstructor();
    }
  };
}
项目:tools-idea    文件:JavaMethodResolveHelper.java   
public JavaMethodResolveHelper(@NotNull final PsiElement argumentList, PsiFile containingFile, @Nullable final PsiType[] argumentTypes) {
  myArgumentTypes = argumentTypes;
  final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(argumentList);
  final PsiConflictResolver resolver = argumentTypes == null ? DuplicateConflictResolver.INSTANCE : new JavaMethodsConflictResolver(argumentList, argumentTypes,
                                                                                                                                    languageLevel);
  myProcessor = new MethodResolverProcessor(argumentList, containingFile, new PsiConflictResolver[]{resolver}) {
    @Override
    protected MethodCandidateInfo createCandidateInfo(final PsiMethod method, final PsiSubstitutor substitutor,
                                                      final boolean staticProblem,
                                                      final boolean accessible) {
      return JavaMethodResolveHelper.this
        .createCandidateInfo(method, substitutor, staticProblem, myCurrentFileContext, !accessible, argumentList, argumentTypes,
                             languageLevel);
    }

    @Override
    protected boolean isAccepted(final PsiMethod candidate) {
      return !candidate.isConstructor();
    }
  };
}
项目:intellij-ce-playground    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(@NotNull PsiCallExpression place,
                               @NotNull PsiExpressionList argumentList, 
                               @NotNull PsiFile placeFile){
  this(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile))});
  setArgumentList(argumentList);
  obtainTypeArguments(place);
}
项目:intellij-ce-playground    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(PsiClass classConstr, @NotNull PsiExpressionList argumentList, @NotNull PsiElement place, @NotNull PsiFile placeFile) {
  super(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList,
                                                                                    PsiUtil.getLanguageLevel(placeFile))}, new SmartList<CandidateInfo>());
  setIsConstructor(true);
  setAccessClass(classConstr);
  setArgumentList(argumentList);
}
项目:intellij-ce-playground    文件:RedundantLambdaCodeBlockInspection.java   
public static PsiExpression isCodeBlockRedundant(PsiExpression expression, PsiElement body) {
  if (body instanceof PsiCodeBlock) {
    PsiExpression psiExpression = LambdaUtil.extractSingleExpressionFromBody(body);
    if (psiExpression != null && !findCommentsOutsideExpression(body, psiExpression)) {
      if (LambdaUtil.isExpressionStatementExpression(psiExpression)) {
        final PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
        if (parent instanceof PsiExpressionList) {
          final PsiElement gParent = parent.getParent();
          if (gParent instanceof PsiCallExpression) {
            final CandidateInfo[] candidates = PsiResolveHelper.SERVICE.getInstance(gParent.getProject())
              .getReferencedMethodCandidates((PsiCallExpression)gParent, false, true);
            if (candidates.length > 1) {
              final List<CandidateInfo> info = new ArrayList<CandidateInfo>(Arrays.asList(candidates));
              final LanguageLevel level = PsiUtil.getLanguageLevel(parent);
              final JavaMethodsConflictResolver conflictResolver = new JavaMethodsConflictResolver((PsiExpressionList)parent, level);
              final PsiExpressionList argumentList = ((PsiCallExpression)gParent).getArgumentList();
              if (argumentList == null) {
                return null;
              }
              conflictResolver.checkParametersNumber(info, argumentList.getExpressions().length, false);
              conflictResolver.checkSpecifics(info, MethodCandidateInfo.ApplicabilityLevel.VARARGS, level);
              if (info.size() > 1) {
                return null;
              }
            }
          }
        }
      }
      return psiExpression;
    }
  }
  return null;
}
项目:tools-idea    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(PsiClass classConstr, @NotNull PsiExpressionList argumentList, @NotNull PsiElement place, @NotNull PsiFile placeFile) {
  super(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList,
                                                                                    PsiUtil.getLanguageLevel(placeFile))}, new SmartList<CandidateInfo>());
  setIsConstructor(true);
  setAccessClass(classConstr);
  setArgumentList(argumentList);
}
项目:consulo-java    文件:PsiDiamondTypeImpl.java   
private static JavaResolveResult getStaticFactoryCandidateInfo(final PsiNewExpression newExpression, final PsiElement context)
{
    return ourDiamondGuard.doPreventingRecursion(context, false, new Computable<JavaResolveResult>()
    {
        @Override
        public JavaResolveResult compute()
        {

            final PsiExpressionList argumentList = newExpression.getArgumentList();
            if(argumentList == null)
            {
                //token expected diagnostic is provided by parser
                return null;
            }

            final JavaMethodsConflictResolver resolver = new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(newExpression));
            final JavaResolveResult[] result = collectStaticFactories(newExpression, resolver);
            final PsiMethod staticFactory = result != null && result.length == 1 ? (PsiMethod) result[0].getElement() : null;
            if(staticFactory == null)
            {
                //additional diagnostics: inference fails due to unresolved constructor
                return JavaResolveResult.EMPTY;
            }

            final MethodCandidateInfo staticFactoryCandidateInfo = createMethodCandidate(staticFactory, context, false, argumentList);
            if(!staticFactory.isVarArgs())
            {
                return staticFactoryCandidateInfo;
            }

            final ArrayList<CandidateInfo> conflicts = new ArrayList<CandidateInfo>();
            conflicts.add(staticFactoryCandidateInfo);
            conflicts.add(createMethodCandidate(staticFactory, context, true, argumentList));
            return resolver.resolveConflict(conflicts);
        }
    });
}
项目:consulo-java    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(PsiClass classConstr, @NotNull PsiExpressionList argumentList, @NotNull PsiElement place, @NotNull PsiFile placeFile)
{
    super(place, placeFile, new PsiConflictResolver[]{
            new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile))
    }, new SmartList<CandidateInfo>());
    setIsConstructor(true);
    setAccessClass(classConstr);
    setArgumentList(argumentList);
}
项目:consulo-java    文件:JavaMethodResolveHelper.java   
public JavaMethodResolveHelper(@NotNull final PsiElement argumentList,
        PsiFile containingFile,
        @Nullable final PsiType[] argumentTypes)
{
    myArgumentTypes = argumentTypes;
    final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(argumentList);
    final PsiConflictResolver resolver = argumentTypes == null ? DuplicateConflictResolver.INSTANCE : new
            JavaMethodsConflictResolver(argumentList, argumentTypes, languageLevel);
    myProcessor = new MethodResolverProcessor(argumentList, containingFile, new PsiConflictResolver[]{resolver})
    {
        @Override
        protected MethodCandidateInfo createCandidateInfo(@NotNull final PsiMethod method,
                @NotNull final PsiSubstitutor substitutor,
                final boolean staticProblem,
                final boolean accessible,
                final boolean varargs)
        {
            return JavaMethodResolveHelper.this.createCandidateInfo(method, substitutor, staticProblem,
                    myCurrentFileContext, !accessible, argumentList, argumentTypes, languageLevel);
        }

        @Override
        protected boolean isAccepted(final PsiMethod candidate)
        {
            return !candidate.isConstructor();
        }
    };
}
项目: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;
}
项目:tools-idea    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(@NotNull PsiMethodCallExpression place, @NotNull PsiFile placeFile){
  this(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(place.getArgumentList(),
                                                                                   PsiUtil.getLanguageLevel(placeFile))});
  setArgumentList(place.getArgumentList());
  obtainTypeArguments(place);
}
项目:consulo-java    文件:MethodResolverProcessor.java   
public MethodResolverProcessor(@NotNull PsiCallExpression place, @NotNull PsiExpressionList argumentList, @NotNull PsiFile placeFile)
{
    this(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile))});
    setArgumentList(argumentList);
    obtainTypeArguments(place);
}