PsiType (PsiType type, Project project) { if (!(type instanceof PsiClassType)) return null; final PsiClassType.ClassResolveResult result = ((PsiClassType)type).resolveGenerics(); final PsiClass element = result.getElement(); if (element == null) return null; final PsiType[] parameters = ((PsiClassType)type).getParameters(); boolean changed = false; final PsiType[] newParameters = new PsiType[parameters.length]; for (int i = 0; i < parameters.length; i++) { PsiType parameter = parameters[i]; if (parameter == null) continue; final Ref<PsiType> newParam = new Ref<>(); parameter.accept(new PsiTypeVisitorEx<>() { @Nullable @Override public Object visitClassType(@NotNull PsiClassType classType) { newParam.set(classType.rawType()); return null; } @Nullable @Override public Object visitCapturedWildcardType(@NotNull PsiCapturedWildcardType capturedWildcardType) { newParam.set(capturedWildcardType.getWildcard().getBound()); return null; } @Nullable @Override public Object visitWildcardType(@NotNull PsiWildcardType wildcardType) { newParam.set(wildcardType.getBound()); return null; } }); if (!newParam.isNull()) { changed = true; newParameters[i] = newParam.get(); } } if (!changed) return null; return JavaPsiFacade.getElementFactory(project).createType(element, newParameters); }