void () { final PsiManager manager = PsiManager.getInstance(myProject); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject()); final PsiClass classFromText = factory.createClassFromText( "class Z {} class W{}" + "class Y<A, B> {} " + "class X extends Y<Z, W> {}", null); WriteCommandAction.runWriteCommandAction(null, () -> { try { classFromText.setName("Q"); } catch (IncorrectOperationException e) { LOG.error(e); } }); final PsiClass classX = classFromText.getInnerClasses()[3]; final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements(); assertEquals(1, extendsOfX.length); final PsiJavaCodeReferenceElement ref = extendsOfX[0]; assertEquals("Q.Y<Q.Z,Q.W>", ref.getCanonicalText()); assertEquals("Y", ref.getReferenceName()); final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements(); assertEquals(2, refParams.length); assertEquals("Q.Z", refParams[0].getType().getCanonicalText()); assertEquals("Q.W", refParams[1].getType().getCanonicalText()); final PsiType refType = factory.createType(ref); assertEquals("Q.Y<Q.Z,Q.W>", refType.getCanonicalText()); final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference(); assertEquals("Q.Y<Q.Z,Q.W>", reference.getCanonicalText()); }