PsiElement (PsiElement element) { if (!(element instanceof PsiTypeElement typeElement)) { return element; } if (typeElement.getType() instanceof PsiDisjunctionType) { // getInnermostComponentReferenceElement() doesn't make sense for disjunction type return typeElement; } if (typeElement.isInferredType()) { // replace inferred type with explicit type if possible final PsiType type = typeElement.getType(); if (type == PsiTypes.nullType() || type instanceof PsiLambdaParameterType || type instanceof PsiLambdaExpressionType) { return typeElement; } final String canonicalText = type.getCanonicalText(); typeElement = JavaPsiFacade.getElementFactory(typeElement.getProject()).createTypeElementFromText(canonicalText, typeElement); } final PsiJavaCodeReferenceElement referenceElement = typeElement.getInnermostComponentReferenceElement(); return (referenceElement != null) ? referenceElement : getInnermostComponentTypeElement(typeElement); }