DiamondInferenceResult (final PsiNewExpression newExpression, final PsiElement context) { final JavaResolveResult staticFactoryCandidateInfo = getStaticFactory(newExpression, context); if (staticFactoryCandidateInfo == null) { return DiamondInferenceResult.NULL_RESULT; } if (!(staticFactoryCandidateInfo instanceof MethodCandidateInfo)) { return DiamondInferenceResult.UNRESOLVED_CONSTRUCTOR; } LOG.assertTrue(!PsiMethodCallExpressionImpl.doWePerformGenericMethodOverloadResolutionNow(newExpression, PsiUtil.getLanguageLevel(newExpression)), "diamond evaluation during overload resolution"); PsiSubstitutor substitutor = staticFactoryCandidateInfo.getSubstitutor(); String errorMessage = ((MethodCandidateInfo)staticFactoryCandidateInfo).getInferenceErrorMessageAssumeAlreadyComputed(); //15.9.3 Choosing the Constructor and its Arguments //The return type and throws clause of cj are the same as the return type and throws clause determined for mj (p15.12.2.6) if (errorMessage == null && ((MethodCandidateInfo)staticFactoryCandidateInfo).isErased()) { return DiamondInferenceResult.RAW_RESULT; } final PsiMethod staticFactory = ((MethodCandidateInfo)staticFactoryCandidateInfo).getElement(); final PsiTypeParameter[] parameters = staticFactory.getTypeParameters(); final PsiElement staticFactoryContext = staticFactory.getContext(); final PsiClass psiClass = PsiTreeUtil.getContextOfType(staticFactoryContext, PsiClass.class, false); if (psiClass == null) { LOG.error("failed for expression:" + newExpression); return DiamondInferenceResult.NULL_RESULT; } final PsiTypeParameter[] classParameters = psiClass.getTypeParameters(); final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference(); LOG.assertTrue(classOrAnonymousClassReference != null); final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>") { @Override public String getErrorMessage() { return errorMessage != null ? DiamondInferenceResult.NULL_RESULT.getErrorMessage() : super.getErrorMessage(); } }; if (errorMessage == null && PsiUtil.isRawSubstitutor(staticFactory, substitutor)) { //http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html#A999198 REF 7144506 if (!PsiUtil.isLanguageLevel8OrHigher(newExpression) && PsiUtil.skipParenthesizedExprUp(newExpression.getParent()) instanceof PsiExpressionList) { for (PsiTypeParameter ignored : parameters) { result.addInferredType(PsiType.getJavaLangObject(newExpression.getManager(), GlobalSearchScope.allScope(newExpression.getProject()))); } } return result; } for (PsiTypeParameter parameter : parameters) { for (PsiTypeParameter classParameter : classParameters) { if (Comparing.strEqual(classParameter.getName(), parameter.getName())) { result.addInferredType(substitutor.substitute(parameter)); break; } } } return result; }