@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; }
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; }
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(); } }; }
@NotNull public JavaResolveResult[] getResult() { if (myCachedResult == 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 = conflicts.toArray(new JavaResolveResult[conflicts.size()]); } return myCachedResult; }
public VariableResolverProcessor(@NotNull PsiJavaCodeReferenceElement place, PsiFile placeFile) { super(place.getText(), ourFilter, new PsiConflictResolver[]{new JavaVariableConflictResolver()}, new SmartList<CandidateInfo>(), place, placeFile); PsiElement referenceName = place.getReferenceNameElement(); if (referenceName instanceof PsiIdentifier){ setName(referenceName.getText()); } 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(element.getProject()).getElementFactory(); final PsiClassType type = factory.createType((PsiTypeParameter)element); final PsiType accessType = accessClass.getSubstitutor().substitute(type); if (accessType instanceof PsiArrayType) { LanguageLevel languageLevel = PsiUtil.getLanguageLevel(qualifier); access = factory.getArrayClass(languageLevel); } else if (accessType instanceof PsiClassType) access = ((PsiClassType)accessType).resolve(); } else if (element instanceof PsiClass) access = (PsiClass)element; } myAccessClass = access; }
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(); } }; }
@NotNull public JavaResolveResult[] getResult() { JavaResolveResult[] cachedResult = myCachedResult; if(cachedResult == null) { List<CandidateInfo> conflicts = getResults(); if(!conflicts.isEmpty()) { 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; }
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()]); }
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; }
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); }
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); }
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); }
protected PsiConflictResolver createResolver(PsiMethodReferenceExpressionImpl referenceExpression, PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult, PsiMethod interfaceMethod, MethodSignature signature) { return new MethodReferenceConflictResolver(referenceExpression, qualifierResolveResult, signature, interfaceMethod != null && interfaceMethod.isVarArgs()); }
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); }
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(); } }; }
@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; }
public MethodCandidatesProcessor(@NotNull PsiElement place, PsiFile placeFile, @NotNull PsiConflictResolver[] resolvers, @NotNull List<CandidateInfo> container) { super(resolvers, container, place, placeFile); }
public MethodCandidatesProcessor(@NotNull PsiElement place, PsiFile placeFile) { super(new PsiConflictResolver[]{DuplicateConflictResolver.INSTANCE}, new SmartList<CandidateInfo>(), place, placeFile); }
public MethodResolverProcessor(@NotNull PsiElement place, @NotNull PsiFile placeFile, @NotNull PsiConflictResolver[] resolvers) { super(place, placeFile, resolvers, new SmartList<CandidateInfo>()); }
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); }
@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(); }
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); }