IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { PsiFile containingFile = ref.getContainingFile(); if (!(containingFile instanceof GroovyFile)) { return IntentionPreviewInfo.EMPTY; } String fileName = containingFile.getName(); GrImportStatement[] imports = ((GroovyFile)containingFile).getImportStatements(); StringBuilder builder = new StringBuilder(); for (GrImportStatement importStmt : imports) { builder.append(importStmt.getText()); builder.append("\n"); } String before = builder.toString(); builder.append("import package1.package2.").append(ref.getReferenceName()); String after = builder.toString(); return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, fileName, before, after); }