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