void () { JavaPsiFacadeEx facade = JavaPsiFacadeEx.getInstanceEx(getProject()); PsiElementFactory factory = facade.getElementFactory(); PsiClass aClass = factory.createClass("X"); PsiMethod methodFromText = factory.createMethodFromText(""" void method() { IntelliJIDEARulezz<> }""", null); PsiMethod method = (PsiMethod)aClass.add(methodFromText); PsiCodeBlock body = method.getBody(); assertNotNull(body); PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)body.getStatements()[0]; PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)declarationStatement.getFirstChild().getFirstChild(); PsiClass javaUtilListClass = facade.findClass(CommonClassNames.JAVA_UTIL_LIST); assertNotNull(javaUtilListClass); PsiElement resultingElement = referenceElement.bindToElement(javaUtilListClass); assertEquals("List<>", resultingElement.getText()); assertEquals(""" void method() { List<> }""", method.getText()); }