Document (final String text, Project project) { final PsiPackage defaultPackage = JavaPsiFacade.getInstance(project).findPackage(""); final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project); final JavaCodeFragment fragment = factory.createTypeCodeFragment(text, defaultPackage, true); fragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE); return PsiDocumentManager.getInstance(project).getDocument(fragment); }