PsiClass (Project project, String text, String prefix) { String enumText = prefix + " {" + text + "}"; PsiJavaFile file = (PsiJavaFile)PsiFileFactory.getInstance(project) .createFileFromText("_DUMMY_", JavaFileType.INSTANCE, enumText); PsiClass[] classes = file.getClasses(); if (classes.length != 1) return null; return classes[0]; }