@NotNull private static PsiFile getRootByClasses(@NotNull PsiFile file, @NotNull Class[] classes) { final Project project = file.getProject(); SoftFactoryMap<Class[], PsiFile> map = project.getUserData(PATTERN_INJECTION_CONTEXT); if (map == null) { map = new SoftFactoryMap<Class[], PsiFile>() { @Override protected PsiFile create(Class[] key) { String text = PatternCompilerFactory.getFactory().getPatternCompiler(key).dumpContextDeclarations(); return PsiFileFactory.getInstance(project).createFileFromText("context.groovy", GroovyFileType.GROOVY_FILE_TYPE, text); } }; project.putUserData(PATTERN_INJECTION_CONTEXT, map); } return map.get(classes); }