Java 类com.intellij.psi.infos.CandidateInfo 实例源码

项目:intellij-ce-playground    文件:ConflictFilterProcessor.java   
@NotNull
public JavaResolveResult[] getResult() {
  JavaResolveResult[] cachedResult = myCachedResult;
  if (cachedResult == null) {
    final List<CandidateInfo> conflicts = getResults();
    for (PsiConflictResolver resolver : myResolvers) {
      CandidateInfo candidate = resolver.resolveConflict(conflicts);
      if (candidate != null) {
        conflicts.clear();
        conflicts.add(candidate);
        break;
      }
    }
    myCachedResult = cachedResult = conflicts.toArray(new JavaResolveResult[conflicts.size()]);
  }

  return cachedResult;
}
项目:intellij-ce-playground    文件:GrClassImplUtil.java   
@NotNull
public static List<Pair<PsiMethod, PsiSubstitutor>> findMethodsAndTheirSubstitutorsByName(GrTypeDefinition grType,
                                                                                          String name,
                                                                                          boolean checkBases) {
  final ArrayList<Pair<PsiMethod, PsiSubstitutor>> result = new ArrayList<Pair<PsiMethod, PsiSubstitutor>>();

  if (!checkBases) {
    final PsiMethod[] methods = grType.findMethodsByName( name, false);
    for (PsiMethod method : methods) {
      result.add(Pair.create(method, PsiSubstitutor.EMPTY));
    }
  }
  else {
    final Map<String, List<CandidateInfo>> map = CollectClassMembersUtil.getAllMethods(grType, true);
    final List<CandidateInfo> candidateInfos = map.get(name);
    if (candidateInfos != null) {
      for (CandidateInfo info : candidateInfos) {
        final PsiElement element = info.getElement();
        result.add(Pair.create((PsiMethod)element, info.getSubstitutor()));
      }
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:DuplicateConflictResolver.java   
@Override
public CandidateInfo resolveConflict(@NotNull List<CandidateInfo> conflicts){
  if (conflicts.size() == 1) return conflicts.get(0);
  final Map<Object, CandidateInfo> uniqueItems = new HashMap<Object, CandidateInfo>();
  for (CandidateInfo info : conflicts) {
    final PsiElement element = info.getElement();
    Object key;
    if (info instanceof MethodCandidateInfo) {
      key = ((PsiMethod)element).getSignature(((MethodCandidateInfo)info).getSubstitutor(false));
    }
    else {
      key = PsiUtilCore.getName(element);
    }

    if (!uniqueItems.containsKey(key)) {
      uniqueItems.put(key, info);
    }
  }

  if(uniqueItems.size() == 1) return uniqueItems.values().iterator().next();
  return null;
}
项目:intellij-ce-playground    文件:JavaMethodsConflictResolver.java   
@Override
public final CandidateInfo resolveConflict(@NotNull final List<CandidateInfo> conflicts){
  /*
  //non-default policies
  final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(myArgumentsList);
  if (properties != null) {
    final PsiMethod method = properties.getMethod();
    LOG.error("Recursive conflict resolution for:" + method + "; " + myArgumentsList.getText() + "; file="
              + (method == null ? "<unknown>" : method.getContainingFile()));
  }*/
  return MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(myArgumentsList, true, new Computable<CandidateInfo>() {
    @Override
    public CandidateInfo compute() {
      return guardedOverloadResolution(conflicts);
    }
  });
}
项目:intellij-ce-playground    文件:JavaMethodsConflictResolver.java   
protected static void checkAccessStaticLevels(@NotNull List<CandidateInfo> conflicts, boolean checkAccessible) {
  int conflictsCount = conflicts.size();

  int maxCheckLevel = -1;
  int[] checkLevels = new int[conflictsCount];
  int index = 0;
  for (final CandidateInfo conflict : conflicts) {
    ProgressManager.checkCanceled();
    final MethodCandidateInfo method = (MethodCandidateInfo)conflict;
    final int level = checkAccessible ? getCheckAccessLevel(method) : getCheckStaticLevel(method);
    checkLevels[index++] = level;
    maxCheckLevel = Math.max(maxCheckLevel, level);
  }

  for (int i = conflictsCount - 1; i >= 0; i--) {
    // check for level
    if (checkLevels[i] < maxCheckLevel) {
      conflicts.remove(i);
    }
  }
}
项目:intellij-ce-playground    文件:JavaMethodsConflictResolver.java   
/**
 * choose to accept static interface methods during search to get "Static interface methods must be invoked on containing interface class only" error
 * instead of non clear javac message that symbol not found
 * 
 * but these methods should be ignored during overload resolution if another methods are present
 */
private void checkStaticMethodsOfInterfaces(@NotNull List<CandidateInfo> conflicts) {
  if (!(myArgumentsList instanceof PsiExpressionList)) return;
  PsiClass qualifierClass = null;
  for (Iterator<CandidateInfo> iterator = conflicts.iterator(); iterator.hasNext(); ) {
    CandidateInfo conflict = iterator.next();
    if (!(conflict instanceof MethodCandidateInfo)) continue;
    final PsiMethod method = ((MethodCandidateInfo)conflict).getElement();
    if (method.hasModifierProperty(PsiModifier.STATIC)) {
      if (conflict.getCurrentFileResolveScope() instanceof PsiImportStaticStatement) continue;
      final PsiClass containingClass = method.getContainingClass();
      if (containingClass != null && containingClass.isInterface()) {
        if (qualifierClass == null) {
          qualifierClass = getQualifiedClass(method);
          if (qualifierClass == null) return;
        }
        if (!containingClass.getManager().areElementsEquivalent(containingClass, qualifierClass)) {
          iterator.remove();
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:LightClassReference.java   
@Override
@NotNull
public JavaResolveResult advancedResolve(boolean incompleteCode){
  final PsiElement resolved = resolve();
  if (resolved == null) {
    return JavaResolveResult.EMPTY;
  }
  PsiSubstitutor substitutor = mySubstitutor;
  if (substitutor == null) {
    if (resolved instanceof PsiClass) {
      substitutor = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createRawSubstitutor((PsiClass) resolved);
    } else {
      substitutor = PsiSubstitutor.EMPTY;
    }
  }
  return new CandidateInfo(resolved, substitutor);
}
项目: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    文件:JavaResolveUtil.java   
public static void substituteResults(@NotNull final PsiJavaCodeReferenceElement ref, @NotNull JavaResolveResult[] result) {
  if (result.length > 0 && result[0].getElement() instanceof PsiClass) {
    for (int i = 0; i < result.length; i++) {
      final CandidateInfo resolveResult = (CandidateInfo)result[i];
      final PsiElement resultElement = resolveResult.getElement();
      if (resultElement instanceof PsiClass && ((PsiClass)resultElement).hasTypeParameters()) {
        PsiSubstitutor substitutor = resolveResult.getSubstitutor();
        result[i] = new CandidateInfo(resolveResult, substitutor) {
          @NotNull
          @Override
          public PsiSubstitutor getSubstitutor() {
            final PsiType[] parameters = ref.getTypeParameters();
            return super.getSubstitutor().putAll((PsiClass)resultElement, parameters);
          }
        };
      }
    }
  }
}
项目:intellij-ce-playground    文件:VariableResolverProcessor.java   
public VariableResolverProcessor(@NotNull PsiJavaCodeReferenceElement place, @NotNull PsiFile placeFile) {
  super(place.getReferenceName(), ourFilter, new PsiConflictResolver[]{new JavaVariableConflictResolver()}, new SmartList<CandidateInfo>(), place, placeFile);

  PsiClass access = null;
  PsiElement qualifier = place.getQualifier();
  if (qualifier instanceof PsiExpression) {
    final JavaResolveResult accessClass = PsiUtil.getAccessObjectClass((PsiExpression)qualifier);
    final PsiElement element = accessClass.getElement();
    if (element instanceof PsiTypeParameter) {
      PsiElementFactory factory = JavaPsiFacade.getInstance(placeFile.getProject()).getElementFactory();
      final PsiClassType type = factory.createType((PsiTypeParameter)element);
      final PsiType accessType = accessClass.getSubstitutor().substitute(type);
      if (accessType instanceof PsiArrayType) {
        LanguageLevel languageLevel = PsiUtil.getLanguageLevel(placeFile);
        access = factory.getArrayClass(languageLevel);
      }
      else if (accessType instanceof PsiClassType) {
        access = ((PsiClassType)accessType).resolve();
      }
    }
    else if (element instanceof PsiClass) {
      access = (PsiClass)element;
    }
  }
  myAccessClass = access;
}
项目:intellij-ce-playground    文件:PsiReferenceExpressionImpl.java   
@NotNull
private JavaResolveResult[] resolveToPackage(@NotNull PsiFile containingFile) {
  final String packageName = getCachedNormalizedText();
  Project project = containingFile.getProject();
  JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiPackage aPackage = psiFacade.findPackage(packageName);
  if (aPackage == null) {
    return psiFacade.isPartOfPackagePrefix(packageName)
           ? CandidateInfo.RESOLVE_RESULT_FOR_PACKAGE_PREFIX_PACKAGE
           : JavaResolveResult.EMPTY_ARRAY;
  }
  // check that all qualifiers must resolve to package parts, to prevent local vars shadowing corresponding package case
  PsiExpression qualifier = getQualifierExpression();
  if (qualifier instanceof PsiReferenceExpression && !(((PsiReferenceExpression)qualifier).resolve() instanceof PsiPackage)) {
    return JavaResolveResult.EMPTY_ARRAY;
  }
  return new JavaResolveResult[]{new CandidateInfo(aPackage, PsiSubstitutor.EMPTY)};
}
项目:intellij-ce-playground    文件:MethodReferenceResolver.java   
private boolean resolveConflicts(List<CandidateInfo> firstCandidates, List<CandidateInfo> secondCandidates, int applicabilityLevel) {

      final int firstApplicability = checkApplicability(firstCandidates);
      checkSpecifics(firstCandidates, applicabilityLevel, myLanguageLevel);

      final int secondApplicability = checkApplicability(secondCandidates);
      checkSpecifics(secondCandidates, applicabilityLevel, myLanguageLevel);

      if (firstApplicability < secondApplicability) {
        return secondCandidates.size() == 1;
      }

      if (secondApplicability < firstApplicability) {
        return firstCandidates.size() == 1;
      }

      return firstCandidates.size() + secondCandidates.size() == 1;
    }
项目:intellij-ce-playground    文件:GrClassImplUtil.java   
private static PsiMethod[] findMethodsByName(GrTypeDefinition grType,
                                             String name,
                                             boolean checkBases,
                                             boolean includeSyntheticAccessors) {
  if (!checkBases) {
    List<PsiMethod> result = new ArrayList<PsiMethod>();
    for (PsiMethod method : CollectClassMembersUtil.getMethods(grType, includeSyntheticAccessors)) {
      if (name.equals(method.getName())) result.add(method);
    }

    return result.toArray(new PsiMethod[result.size()]);
  }

  Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, includeSyntheticAccessors);
  return PsiImplUtil.mapToMethods(methodsMap.get(name));
}
项目:intellij-ce-playground    文件:HighlightMethodUtil.java   
static boolean isDummyConstructorCall(PsiMethodCallExpression methodCall,
                                      PsiResolveHelper resolveHelper,
                                      PsiExpressionList list,
                                      PsiReferenceExpression referenceToMethod) {
  boolean isDummy = false;
  boolean isThisOrSuper = referenceToMethod.getReferenceNameElement() instanceof PsiKeyword;
  if (isThisOrSuper) {
    // super(..) or this(..)
    if (list.getExpressions().length == 0) { // implicit ctr call
      CandidateInfo[] candidates = resolveHelper.getReferencedMethodCandidates(methodCall, true);
      if (candidates.length == 1 && !candidates[0].getElement().isPhysical()) {
        isDummy = true;// dummy constructor
      }
    }
  }
  return isDummy;
}
项目:intellij-ce-playground    文件:ChangeStringLiteralToCharInMethodCallFix.java   
public static void registerFixes(@NotNull final CandidateInfo[] candidates,
                                 @NotNull final PsiMethodCallExpression methodCall,
                                 @Nullable final HighlightInfo info) {
  if (info == null) return;
  final Set<PsiLiteralExpression> literals = new HashSet<PsiLiteralExpression>();
  boolean exactMatch = false;
  for (CandidateInfo candidate : candidates) {
    if (candidate instanceof MethodCandidateInfo) {
      final PsiMethod method = ((MethodCandidateInfo) candidate).getElement();
      exactMatch |= findMatchingExpressions(methodCall.getArgumentList().getExpressions(), method, literals);
    }
  }
  if (!exactMatch) {
    processLiterals(literals, methodCall, info);
  }
}
项目:intellij-ce-playground    文件:MethodParameterInfoHandler.java   
@Override
public void updateUI(final Object p, @NotNull final ParameterInfoUIContext context) {
  if (p instanceof CandidateInfo) {
    CandidateInfo info = (CandidateInfo)p;
    PsiMethod method = (PsiMethod)info.getElement();
    if (!method.isValid()) {
      context.setUIComponentEnabled(false);
      return;
    }

    updateMethodPresentation(method, getCandidateInfoSubstitutor(info), context);
  }
  else {
    updateMethodPresentation((PsiMethod)p, null, context);
  }
}
项目:intellij-ce-playground    文件:OverrideImplementUtil.java   
public static void chooseAndOverrideOrImplementMethods(final Project project,
                                                       final Editor editor,
                                                       final PsiClass aClass,
                                                       final boolean toImplement) {
  LOG.assertTrue(aClass.isValid());
  ApplicationManager.getApplication().assertReadAccessAllowed();

  Collection<CandidateInfo> candidates = getMethodsToOverrideImplement(aClass, toImplement);
  Collection<CandidateInfo> secondary = toImplement || aClass.isInterface() ?
                                        ContainerUtil.<CandidateInfo>newArrayList() : getMethodsToOverrideImplement(aClass, true);

  final MemberChooser<PsiMethodMember> chooser = showOverrideImplementChooser(editor, aClass, toImplement, candidates, secondary);
  if (chooser == null) return;

  final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
  if (selectedElements == null || selectedElements.isEmpty()) return;

  LOG.assertTrue(aClass.isValid());
  new WriteCommandAction(project, aClass.getContainingFile()) {
    @Override
    protected void run(@NotNull final Result result) throws Throwable {
      overrideOrImplementMethodsInRightPlace(editor, aClass, selectedElements, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
    }
  }.execute();
}
项目:intellij-ce-playground    文件:MethodCallFixer.java   
@Nullable
private static Integer getUnambiguousParameterCount(PsiCallExpression call) {
  int argCount = -1;
  for (CandidateInfo candidate : PsiResolveHelper.SERVICE.getInstance(call.getProject()).getReferencedMethodCandidates(call, false)) {
    PsiElement element = candidate.getElement();
    if (!(element instanceof PsiMethod)) return null;
    if (((PsiMethod)element).isVarArgs()) return null;

    int count = ((PsiMethod)element).getParameterList().getParametersCount();
    if (argCount == -1) {
      argCount = count;
    } else if (argCount != count) {
      return null;
    }
  }
  return argCount;
}
项目:intellij-ce-playground    文件:ExpectedTypesProvider.java   
@Override public void visitExpressionList(@NotNull PsiExpressionList list) {
  PsiResolveHelper helper = JavaPsiFacade.getInstance(list.getProject()).getResolveHelper();
  if (list.getParent() instanceof PsiMethodCallExpression) {
    PsiMethodCallExpression methodCall = (PsiMethodCallExpression)list.getParent();
    CandidateInfo[] candidates = helper.getReferencedMethodCandidates(methodCall, false, true);
    Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, list, myExpr, myForCompletion));
  }
  else if (list.getParent() instanceof PsiEnumConstant) {
    getExpectedArgumentsTypesForEnumConstant((PsiEnumConstant)list.getParent(), list);
  }
  else if (list.getParent() instanceof PsiNewExpression) {
    getExpectedArgumentsTypesForNewExpression((PsiNewExpression)list.getParent(), list);
  }
  else if (list.getParent() instanceof PsiAnonymousClass) {
    getExpectedArgumentsTypesForNewExpression((PsiNewExpression)list.getParent().getParent(), list);
  }
}
项目:intellij-ce-playground    文件:GrClassImplUtil.java   
private static boolean processMethod(@NotNull GrTypeDefinition grType,
                                     @NotNull PsiScopeProcessor processor,
                                     @NotNull ResolveState state,
                                     @NotNull PsiElement place,
                                     boolean processInstanceMethods,
                                     @NotNull PsiSubstitutor substitutor,
                                     @NotNull PsiElementFactory factory,
                                     @NotNull LanguageLevel level,
                                     boolean placeGroovy,
                                     @NotNull CandidateInfo info) {
  PsiMethod method = (PsiMethod)info.getElement();
  if (!processInstanceMember(processInstanceMethods, method) || isSameDeclaration(place, method) || !isMethodVisible(placeGroovy, method)) {
    return true;
  }
  LOG.assertTrue(method.getContainingClass() != null);
  final PsiSubstitutor finalSubstitutor = PsiClassImplUtil.obtainFinalSubstitutor(method.getContainingClass(), info.getSubstitutor(), grType, substitutor, factory, level);

  return processor.execute(method, state.put(PsiSubstitutor.KEY, finalSubstitutor));
}
项目:intellij-ce-playground    文件:ConflictFilterProcessor.java   
public ConflictFilterProcessor(String name,
                               @NotNull ElementFilter filter,
                               @NotNull PsiConflictResolver[] resolvers,
                               @NotNull List<CandidateInfo> container,
                               @NotNull PsiElement place,
                               PsiFile placeFile) {
  super(filter, container);
  myResolvers = resolvers;
  myName = name;
  myPlace = place;
  myPlaceFile = placeFile;
}
项目:intellij-ce-playground    文件:MethodsProcessor.java   
public MethodsProcessor(@NotNull PsiConflictResolver[] resolvers,
                        @NotNull List<CandidateInfo> container,
                        @NotNull PsiElement place,
                        @NotNull PsiFile placeFile) {
  super(null, ourFilter, resolvers, container, place, placeFile);
  myLanguageLevel = PsiUtil.getLanguageLevel(placeFile);
}
项目:intellij-ce-playground    文件:GrTypeDefinitionMembersCache.java   
@NotNull
private List<GrMethod> getExpandingMethods(@NotNull CandidateInfo candidateInfo) {
  PsiMethod method = (PsiMethod)candidateInfo.getElement();
  GrLightMethodBuilder implementation = GrTraitMethod.create(method, candidateInfo.getSubstitutor()).setContainingClass(myDefinition);
  implementation.getModifierList().removeModifier(ABSTRACT_MASK);

  GrReflectedMethod[] reflectedMethods = implementation.getReflectedMethods();
  return reflectedMethods.length > 0 ? Arrays.<GrMethod>asList(reflectedMethods) : Collections.<GrMethod>singletonList(implementation);
}
项目:intellij-ce-playground    文件:MethodCandidatesProcessor.java   
public CandidateInfo[] getCandidates() {
  final JavaResolveResult[] resolveResult = getResult();
  if (resolveResult.length == 0) return CandidateInfo.EMPTY_ARRAY;
  final CandidateInfo[] infos = new CandidateInfo[resolveResult.length];
  //noinspection SuspiciousSystemArraycopy
  System.arraycopy(resolveResult, 0, infos, 0, resolveResult.length);
  return infos;
}
项目: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    文件:GrClassImplUtil.java   
@NotNull
public static List<Pair<PsiMethod, PsiSubstitutor>> getAllMethodsAndTheirSubstitutors(GrTypeDefinition grType) {
  final Map<String, List<CandidateInfo>> allMethodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
  List<Pair<PsiMethod, PsiSubstitutor>> result = new ArrayList<Pair<PsiMethod, PsiSubstitutor>>();
  for (List<CandidateInfo> infos : allMethodsMap.values()) {
    for (CandidateInfo info : infos) {
      result.add(Pair.create((PsiMethod)info.getElement(), info.getSubstitutor()));
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:JavaMethodsConflictResolver.java   
public void checkSpecifics(@NotNull List<CandidateInfo> conflicts,
                           @MethodCandidateInfo.ApplicabilityLevelConstant int applicabilityLevel,
                           FactoryMap<MethodCandidateInfo, PsiSubstitutor> map, 
                           @NotNull LanguageLevel languageLevel) {
  final boolean applicable = applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;

  int conflictsCount = conflicts.size();
  // Specifics
  if (applicable) {
    final CandidateInfo[] newConflictsArray = conflicts.toArray(new CandidateInfo[conflicts.size()]);
    for (int i = 1; i < conflictsCount; i++) {
      final CandidateInfo method = newConflictsArray[i];
      for (int j = 0; j < i; j++) {
        ProgressManager.checkCanceled();
        final CandidateInfo conflict = newConflictsArray[j];
        if (nonComparable(method, conflict, applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY)) continue; 
        switch (isMoreSpecific((MethodCandidateInfo)method, (MethodCandidateInfo)conflict, applicabilityLevel, map, languageLevel)) {
          case FIRST:
            conflicts.remove(conflict);
            break;
          case SECOND:
            conflicts.remove(method);
            break;
          case NEITHER:
            break;
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:JavaMethodsConflictResolver.java   
@Nullable
private static PsiType getFunctionalType(int functionalTypeIdx, @NotNull CandidateInfo candidateInfo) {
  final PsiMethod psiMethod = (PsiMethod)candidateInfo.getElement();
  LOG.assertTrue(true);
  final PsiParameter[] methodParameters = psiMethod.getParameterList().getParameters();
  if (methodParameters.length == 0) return null;
  final PsiParameter param = functionalTypeIdx < methodParameters.length ? methodParameters[functionalTypeIdx] : methodParameters[methodParameters.length - 1];
  return ((MethodCandidateInfo)candidateInfo).getSiteSubstitutor().substitute(param.getType());
}
项目:intellij-ce-playground    文件:LightMemberReference.java   
@Override
@NotNull
public JavaResolveResult advancedResolve(boolean incompleteCode){
  final PsiElement resolved = resolve();
  PsiSubstitutor substitutor = mySubstitutor;
  if (substitutor == null) {
      substitutor = PsiSubstitutor.EMPTY;
  }
  return new CandidateInfo(resolved, substitutor);
}
项目:intellij-ce-playground    文件:ClsJavaCodeReferenceElementImpl.java   
private JavaResolveResult advancedResolveImpl(@NotNull PsiFile containingFile) {
  PsiTypeElement[] typeElements = myRefParameterList == null ? PsiTypeElement.EMPTY_ARRAY : myRefParameterList.getTypeParameterElements();
  PsiElement resolve = resolveElement(containingFile);
  if (resolve == null) return null;
  if (resolve instanceof PsiClass) {
    Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter, PsiType>();
    int index = 0;
    for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable((PsiClass)resolve)) {
      if (index >= typeElements.length) {
        PsiTypeParameterListOwner parameterOwner = parameter.getOwner();
        if (parameterOwner == resolve) {
          substitutionMap.put(parameter, null);
        }
        else if (parameterOwner instanceof PsiClass) {
          PsiElement containingClass = myParent;
          while ((containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true)) != null) {
            PsiSubstitutor superClassSubstitutor =
              TypeConversionUtil.getClassSubstitutor((PsiClass)parameterOwner, (PsiClass)containingClass, PsiSubstitutor.EMPTY);
            if (superClassSubstitutor != null) {
              substitutionMap.put(parameter, superClassSubstitutor.substitute(parameter));
              break;
            }
          }
        }
      }
      else {
        substitutionMap.put(parameter, typeElements[index].getType());
      }
      index++;
    }
    collectOuterClassTypeArgs((PsiClass)resolve, myCanonicalText, substitutionMap);
    return new CandidateInfo(resolve, PsiSubstitutorImpl.createSubstitutor(substitutionMap));
  }
  else {
    return new CandidateInfo(resolve, PsiSubstitutor.EMPTY);
  }
}
项目:intellij-ce-playground    文件:ClassResolverProcessor.java   
@NotNull
public JavaResolveResult[] getResult() {
  if (myResult != null) return myResult;
  if (myCandidates == null) return myResult = JavaResolveResult.EMPTY_ARRAY;
  if (myHasAccessibleCandidate && myHasInaccessibleCandidate) {
    for (Iterator<ClassCandidateInfo> iterator = myCandidates.iterator(); iterator.hasNext();) {
      CandidateInfo info = iterator.next();
      if (!info.isAccessible()) iterator.remove();
    }
    myHasInaccessibleCandidate = false;
  }

  myResult = myCandidates.toArray(new JavaResolveResult[myCandidates.size()]);
  return myResult;
}
项目:intellij-ce-playground    文件:MethodReferenceResolver.java   
@Override
protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict, boolean fixedArity) {
  if (method == conflict) return true;
  PsiElement psiElement = method.getElement();
  PsiElement conflictElement = conflict.getElement();
  if (psiElement instanceof PsiMethod && conflictElement instanceof PsiMethod) {
    if (fixedArity && ((PsiMethod)psiElement).getParameterList().getParametersCount() != ((PsiMethod)conflictElement).getParameterList().getParametersCount()) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:GrMethodOverrideCompletionProvider.java   
private static void addSuperMethods(final GrTypeDefinition psiClass, CompletionResultSet completionResultSet, boolean toImplement) {
  final Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(psiClass, toImplement);
  for (CandidateInfo candidateInfo : candidates) {
    final PsiMethod method = (PsiMethod)candidateInfo.getElement();
    if (method.isConstructor()) continue;

    RowIcon icon = new RowIcon(2);
    icon.setIcon(method.getIcon(0), 0);
    icon.setIcon(toImplement ? AllIcons.Gutter.ImplementingMethod : AllIcons.Gutter.OverridingMethod, 1);

    PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
    String parameters = PsiFormatUtil.formatMethod(method, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);
    String visibility = VisibilityUtil.getVisibilityModifier(method.getModifierList());
    String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");
    PsiType type = substitutor.substitute(method.getReturnType());
    String parentClassName = psiClass == null ? "" : psiClass.getName();
    String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + method.getName();

    LookupElementBuilder lookupElement = LookupElementBuilder.create(method, signature)
      .appendTailText(parameters, false)
      .appendTailText("{...}", true)
      .withTypeText(parentClassName)
      .withIcon(icon)
      .withInsertHandler(new GroovyMethodOverrideHandler(psiClass));
    completionResultSet.addElement(lookupElement);
  }
}
项目: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;
}
项目:intellij-ce-playground    文件:HighlightMethodUtil.java   
private static void registerMethodCallIntentions(@Nullable HighlightInfo highlightInfo,
                                                 PsiMethodCallExpression methodCall,
                                                 PsiExpressionList list,
                                                 PsiResolveHelper resolveHelper) {
  TextRange fixRange = getFixRange(methodCall);
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreateMethodFromUsageFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreateAbstractMethodFromUsageFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreateConstructorFromSuperFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreateConstructorFromThisFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreatePropertyFromUsageFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createCreateGetterSetterPropertyFromUsageFix(methodCall));
  CandidateInfo[] methodCandidates = resolveHelper.getReferencedMethodCandidates(methodCall, false);
  CastMethodArgumentFix.REGISTRAR.registerCastActions(methodCandidates, methodCall, highlightInfo, fixRange);
  PermuteArgumentsFix.registerFix(highlightInfo, methodCall, methodCandidates, fixRange);
  AddTypeArgumentsFix.REGISTRAR.registerCastActions(methodCandidates, methodCall, highlightInfo, fixRange);
  WrapArrayToArraysAsListFix.REGISTAR.registerCastActions(methodCandidates, methodCall, highlightInfo, fixRange);
  registerMethodAccessLevelIntentions(methodCandidates, methodCall, list, highlightInfo);
  registerChangeMethodSignatureFromUsageIntentions(methodCandidates, list, highlightInfo, fixRange);
  RemoveRedundantArgumentsFix.registerIntentions(methodCandidates, list, highlightInfo, fixRange);
  ConvertDoubleToFloatFix.registerIntentions(methodCandidates, list, highlightInfo, fixRange);
  WrapExpressionFix.registerWrapAction(methodCandidates, list.getExpressions(), highlightInfo);
  registerChangeParameterClassFix(methodCall, list, highlightInfo);
  if (methodCandidates.length == 0) {
    QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createStaticImportMethodFix(methodCall));
    QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.addMethodQualifierFix(methodCall));
  }
  for (IntentionAction action : QUICK_FIX_FACTORY.getVariableTypeFromCallFixes(methodCall, list)) {
    QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, action);
  }
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createReplaceAddAllArrayToCollectionFix(methodCall));
  QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QUICK_FIX_FACTORY.createSurroundWithArrayFix(methodCall, null));
  QualifyThisArgumentFix.registerQuickFixAction(methodCandidates, methodCall, highlightInfo, fixRange);

  CandidateInfo[] candidates = resolveHelper.getReferencedMethodCandidates(methodCall, true);
  ChangeStringLiteralToCharInMethodCallFix.registerFixes(candidates, methodCall, highlightInfo);
}
项目:intellij-ce-playground    文件:GrClassImplUtil.java   
public static PsiField[] getAllFields(GrTypeDefinition grType) {
  Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
  return ContainerUtil.map2Array(fieldsMap.values(), PsiField.class, new Function<CandidateInfo, PsiField>() {
    @Override
    public PsiField fun(CandidateInfo entry) {
      return (PsiField)entry.getElement();
    }
  });
}
项目:intellij-ce-playground    文件:PermuteArgumentsFix.java   
public static void registerFix(HighlightInfo info, PsiCall callExpression, final CandidateInfo[] candidates, final TextRange fixRange) {
  PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
  if (expressions.length < 2) return;
  List<PsiCall> permutations = new ArrayList<PsiCall>();

  for (CandidateInfo candidate : candidates) {
    if (candidate instanceof MethodCandidateInfo) {
      MethodCandidateInfo methodCandidate = (MethodCandidateInfo)candidate;
      PsiMethod method = methodCandidate.getElement();
      PsiSubstitutor substitutor = methodCandidate.getSubstitutor();

      PsiParameter[] parameters = method.getParameterList().getParameters();
      if (expressions.length != parameters.length || parameters.length ==0) continue;
      int minIncompatibleIndex = parameters.length;
      int maxIncompatibleIndex = 0;
      int incompatibilitiesCount = 0;
      for (int i = 0; i < parameters.length; i++) {
        PsiParameter parameter = parameters[i];
        PsiType type = substitutor.substitute(parameter.getType());
        if (TypeConversionUtil.areTypesAssignmentCompatible(type, expressions[i])) continue;
        if (minIncompatibleIndex == parameters.length) minIncompatibleIndex = i;
        maxIncompatibleIndex = i;
        incompatibilitiesCount++;
      }

      try {
        registerSwapFixes(expressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
        registerShiftFixes(expressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  }
  if (permutations.size() == 1) {
    PermuteArgumentsFix fix = new PermuteArgumentsFix(callExpression, permutations.get(0));
    QuickFixAction.registerQuickFixAction(info, fixRange, fix);
  }
}
项目:intellij-ce-playground    文件:ConstructorParametersFixer.java   
public static void registerFixActions(@NotNull PsiJavaCodeReferenceElement ctrRef, PsiConstructorCall constructorCall, HighlightInfo highlightInfo,
                                       final TextRange fixRange) {
  JavaResolveResult resolved = ctrRef.advancedResolve(false);
  PsiClass aClass = (PsiClass) resolved.getElement();
  if (aClass == null) return;
  PsiMethod[] methods = aClass.getConstructors();
  CandidateInfo[] candidates = new CandidateInfo[methods.length];
  for (int i = 0; i < candidates.length; i++) {
    candidates[i] = new CandidateInfo(methods[i], resolved.getSubstitutor());
  }
  CastMethodArgumentFix.REGISTRAR.registerCastActions(candidates, constructorCall, highlightInfo, fixRange);
  AddTypeArgumentsFix.REGISTRAR.registerCastActions(candidates, constructorCall, highlightInfo, fixRange);
}
项目:intellij-ce-playground    文件:MethodParameterInfoHandler.java   
private static PsiExpressionList findMethodsForArgumentList(final CreateParameterInfoContext context,
                                                            @NotNull final PsiExpressionList argumentList) {

  CandidateInfo[] candidates = getMethods(argumentList);
  if (candidates.length == 0) {
    DaemonCodeAnalyzer.getInstance(context.getProject()).updateVisibleHighlighters(context.getEditor());
    return null;
  }
  context.setItemsToShow(candidates);
  return argumentList;
}
项目:intellij-ce-playground    文件:JavaGenerateMemberCompletionContributor.java   
private static void addSuperSignatureElements(final PsiClass parent, boolean implemented, CompletionResultSet result, Set<MethodSignature> addedSignatures) {
  for (CandidateInfo candidate : OverrideImplementExploreUtil.getMethodsToOverrideImplement(parent, implemented)) {
    PsiMethod baseMethod = (PsiMethod)candidate.getElement();
    PsiClass baseClass = baseMethod.getContainingClass();
    PsiSubstitutor substitutor = candidate.getSubstitutor();
    if (!baseMethod.isConstructor() && baseClass != null && addedSignatures.add(baseMethod.getSignature(substitutor))) {
      result.addElement(createOverridingLookupElement(implemented, baseMethod, baseClass, substitutor));
    }
  }
}