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(); } }; }
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(); } }; }
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()]); }
@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(); }
@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(); }
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 static List<PsiClassType> getUnhandledExceptions(@NotNull final PsiCallExpression methodCall, @Nullable final PsiElement topElement, final boolean includeSelfCalls) { //exceptions only influence the invocation type after overload resolution is complete if (MethodCandidateInfo.isOverloadCheck()) { return Collections.emptyList(); } final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(methodCall.getArgumentList()); final JavaResolveResult result = properties != null ? properties.getInfo() : methodCall.resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); if (method == null) { return Collections.emptyList(); } final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); if (!includeSelfCalls && method == containingMethod) { return Collections.emptyList(); } final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes(); if (thrownExceptions.length == 0) { return Collections.emptyList(); } final PsiSubstitutor substitutor = getSubstitutor(result, methodCall); if (!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { final PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile(); final MethodResolverProcessor processor = new MethodResolverProcessor((PsiMethodCallExpression)methodCall, containingFile); try { PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false); final List<Pair<PsiMethod, PsiSubstitutor>> candidates = ContainerUtil.mapNotNull( processor.getResults(), new Function<CandidateInfo, Pair<PsiMethod, PsiSubstitutor>>() { @Override public Pair<PsiMethod, PsiSubstitutor> fun(CandidateInfo info) { PsiElement element = info.getElement(); if (element instanceof PsiMethod && MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod)element) && !MethodSignatureUtil.isSuperMethod((PsiMethod)element, method)) { return Pair.create((PsiMethod)element, getSubstitutor(info, methodCall)); } return null; } }); if (candidates.size() > 1) { GlobalSearchScope scope = methodCall.getResolveScope(); final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions, scope); for (Pair<PsiMethod, PsiSubstitutor> pair : candidates) { final PsiClassType[] exceptions = pair.first.getThrowsList().getReferencedTypes(); if (exceptions.length == 0) { return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, PsiClassType.EMPTY_ARRAY); } retainExceptions(ex, collectSubstituted(pair.second, exceptions, scope)); } return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, ex.toArray(new PsiClassType[ex.size()])); } } catch (MethodProcessorSetupFailedException ignore) { return Collections.emptyList(); } } return getUnhandledExceptions(method, methodCall, topElement, substitutor); }
@NotNull public static List<PsiClassType> getUnhandledExceptions(@NotNull final PsiCallExpression methodCall, @Nullable final PsiElement topElement, boolean includeSelfCalls) { final JavaResolveResult result = methodCall.resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); if (!includeSelfCalls && method == containingMethod) { return Collections.emptyList(); } final PsiSubstitutor substitutor = result.getSubstitutor(); if (method != null && !isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes(); if (thrownExceptions.length > 0) { PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile(); final MethodResolverProcessor processor = new MethodResolverProcessor((PsiMethodCallExpression)methodCall, containingFile); try { PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false); final List<CandidateInfo> results = processor.getResults(); if (results.size() > 1) { final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions); for (CandidateInfo info : results) { final PsiElement element = info.getElement(); if (element instanceof PsiMethod && MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod)element)) { final PsiClassType[] exceptions = ((PsiMethod)element).getThrowsList().getReferencedTypes(); if (exceptions.length == 0) { return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, PsiClassType.EMPTY_ARRAY); } retainExceptions(ex, collectSubstituted(info.getSubstitutor(), exceptions)); } } return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, ex.toArray(new PsiClassType[ex.size()])); } } catch (MethodProcessorSetupFailedException ignore) { return Collections.emptyList(); } } } return getUnhandledExceptions(method, methodCall, topElement, substitutor); }
@NotNull public static List<PsiClassType> getUnhandledExceptions(@NotNull final PsiCallExpression methodCall, @Nullable final PsiElement topElement, final boolean includeSelfCalls) { //exceptions only influence the invocation type after overload resolution is complete if(MethodCandidateInfo.isOverloadCheck()) { return Collections.emptyList(); } final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(methodCall.getArgumentList()); final JavaResolveResult result = properties != null ? properties.getInfo() : PsiDiamondType.getDiamondsAwareResolveResult(methodCall); final PsiElement element = result.getElement(); final PsiMethod method = element instanceof PsiMethod ? (PsiMethod) element : null; if(method == null) { return Collections.emptyList(); } final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); if(!includeSelfCalls && method == containingMethod) { return Collections.emptyList(); } if(properties != null) { PsiUtilCore.ensureValid(method); } final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes(); if(thrownExceptions.length == 0) { return Collections.emptyList(); } final PsiSubstitutor substitutor = result.getSubstitutor(); if(!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { final PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile(); final MethodResolverProcessor processor = new MethodResolverProcessor((PsiMethodCallExpression) methodCall, containingFile); try { PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false); final List<Pair<PsiMethod, PsiSubstitutor>> candidates = ContainerUtil.mapNotNull(processor.getResults(), info -> { PsiElement element1 = info.getElement(); if(info instanceof MethodCandidateInfo && element1 != method && //don't check self MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod) element1) && !MethodSignatureUtil.isSuperMethod((PsiMethod) element1, method) && !(((MethodCandidateInfo) info) .isToInferApplicability() && !((MethodCandidateInfo) info).isApplicable())) { return Pair.create((PsiMethod) element1, ((MethodCandidateInfo) info).getSubstitutor(false)); } return null; }); if(!candidates.isEmpty()) { GlobalSearchScope scope = methodCall.getResolveScope(); final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions, scope); for(Pair<PsiMethod, PsiSubstitutor> pair : candidates) { final PsiClassType[] exceptions = pair.first.getThrowsList().getReferencedTypes(); if(exceptions.length == 0) { return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, PsiClassType.EMPTY_ARRAY); } retainExceptions(ex, collectSubstituted(pair.second, exceptions, scope)); } return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, ex.toArray(new PsiClassType[ex.size()])); } } catch(MethodProcessorSetupFailedException ignore) { return Collections.emptyList(); } } return getUnhandledExceptions(method, methodCall, topElement, substitutor); }