PsiTypeElement[] (@NotNull PsiJavaCodeReferenceElement referenceElement, Boolean replaceDiamondWithExplicitTypes) { final PsiReferenceParameterList referenceElementParameterList = referenceElement.getParameterList(); if (referenceElementParameterList == null) { return null; } final PsiTypeElement[] typeParameterElements = referenceElementParameterList.getTypeParameterElements(); if (typeParameterElements.length != 1 || replaceDiamondWithExplicitTypes == Boolean.FALSE) { return typeParameterElements; } final PsiType type = typeParameterElements[0].getType(); if (!(type instanceof PsiDiamondType diamondType)) { return typeParameterElements; } if (replaceDiamondWithExplicitTypes == null) { return null; } final PsiDiamondType.DiamondInferenceResult inferenceResult = diamondType.resolveInferredTypes(); final StringBuilder text = new StringBuilder(referenceElement.getQualifiedName()); text.append('<'); boolean comma = false; for (PsiType inferredType : inferenceResult.getInferredTypes()) { if (comma) { text.append(','); } else { comma = true; } text.append(inferredType.getCanonicalText()); } text.append('>'); final PsiJavaCodeReferenceElement newReferenceElement = JavaPsiFacade.getElementFactory(referenceElement.getProject()).createReferenceFromText(text.toString(), referenceElement); final PsiReferenceParameterList newParameterList = newReferenceElement.getParameterList(); return newParameterList == null ? null : newParameterList.getTypeParameterElements(); }