diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AddImportOnSelectionTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AddImportOnSelectionTests.groovy index 8a2b8cbc2b..5c91437a89 100644 --- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AddImportOnSelectionTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AddImportOnSelectionTests.groovy @@ -1260,4 +1260,20 @@ final class AddImportOnSelectionTests extends GroovyEditorTestSuite { assertEditorContents 'def x = UnresolvableClassName.WHATEVER' assertStatusLineText 'Type \'UnresolvableClassName\' could not be found or is not visible.' } + + @Test + void testScriptNotOnBuildPath() { + def file = addPlainText('java.util.regex.Pattern p = ~/.../\n', "../${nextUnitName()}.groovy") + editor = (org.codehaus.groovy.eclipse.editor.GroovyEditor) \ + openInEditor(file.getAdapter(org.eclipse.jdt.core.ICompilationUnit)) + editor.setHighlightRange(18, 0, true) + editor.setFocus() + editor.getAction('AddImport').run() + + assertEditorContents """\ + |import java.util.regex.Pattern + | + |Pa${CARET}ttern p = ~/.../ + |""".stripMargin() + } } diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/refactoring/actions/AddImportOnSelectionAdapter.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/refactoring/actions/AddImportOnSelectionAdapter.java index 27346ec586..9ea31e7f87 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/refactoring/actions/AddImportOnSelectionAdapter.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/refactoring/actions/AddImportOnSelectionAdapter.java @@ -24,7 +24,6 @@ import org.eclipse.jdt.groovy.core.util.ReflectionUtils; import org.eclipse.jdt.internal.corext.codemanipulation.AddImportsOperation.IChooseImportQuery; import org.eclipse.jdt.internal.ui.JavaPlugin; -import org.eclipse.jdt.internal.ui.actions.ActionUtil; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.util.ElementValidator; import org.eclipse.jdt.internal.ui.util.ExceptionHandler; @@ -56,7 +55,7 @@ public final void run() { if (cu == null || editor == null) return; - if (!ActionUtil.isEditable(editor)) + if (!editor.validateEditorInputState()) return; if (!ElementValidator.checkValidateEdit(cu, shell, "Add Import")) return;