Document (final String text) { GroovyCodeFragment fragment = new GroovyCodeFragment(myProject, text); fragment.setContext(myContext); return PsiDocumentManager.getInstance(myProject).getDocument(fragment); }