Skip to content

Commit

Permalink
Fix for #1212: reduce validation strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 30, 2020
1 parent c4318f7 commit 6adb76e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6adb76e

Please sign in to comment.