diff --git a/ide-test/org.codehaus.groovy.eclipse.codeassist.test/src/org/codehaus/groovy/eclipse/codeassist/tests/AnnotationCompletionTests.groovy b/ide-test/org.codehaus.groovy.eclipse.codeassist.test/src/org/codehaus/groovy/eclipse/codeassist/tests/AnnotationCompletionTests.groovy index 1e3e631daf..b3e7f36dc5 100644 --- a/ide-test/org.codehaus.groovy.eclipse.codeassist.test/src/org/codehaus/groovy/eclipse/codeassist/tests/AnnotationCompletionTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.codeassist.test/src/org/codehaus/groovy/eclipse/codeassist/tests/AnnotationCompletionTests.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -954,6 +954,7 @@ final class AnnotationCompletionTests extends CompletionTestSuite { | public static final String VALUE = 'nls' |} |'''.stripMargin() + setJavaPreference(CODEASSIST_ADDIMPORT, false) checkProposalApplication(contents, expected, getIndexOf(contents, '(V'), 'VALUE', false) } diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AliasingOrganizeImportsTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AliasingOrganizeImportsTests.groovy index 1a057ab959..61235ef159 100644 --- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AliasingOrganizeImportsTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/AliasingOrganizeImportsTests.groovy @@ -15,6 +15,8 @@ */ package org.codehaus.groovy.eclipse.test.actions +import groovy.transform.NotYetImplemented + import org.junit.Test /** @@ -470,6 +472,52 @@ final class AliasingOrganizeImportsTests extends OrganizeImportsTestSuite { doContentsCompareTest(contents) } + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainStaticAlias12() { + addJavaSource('class C { static Object f }', 'C', '') + String contents = '''\ + |import static C.f as v + |print v + |''' + doContentsCompareTest(contents) + } + + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainStaticAlias13() { + addJavaSource('class C { static void m() {} }', 'C', '') + String contents = '''\ + |import static C.m as f + |f('x') + |''' + doContentsCompareTest(contents) + } + + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainStaticAlias14() { + addJavaSource('class C { static void m() {} }', 'C', '') + String contents = '''\ + |import static C.m as f + |f 'x' + |''' + doContentsCompareTest(contents) + } + + @Test @NotYetImplemented // https://github.com/groovy/groovy-eclipse/issues/732 + void testRetainStaticAlias15() { + addJavaSource('class A { public static boolean isSomething(String s) { return true; } }', 'A', 'p') + addJavaSource('class B { public static boolean isPoorlyNamed(Iterable i) { return true; } }', 'B', 'p') + + String contents = '''\ + |import static p.A.isSomething + |import static p.B.isPoorlyNamed as isSomething + |String s + |Iterable i + |isSomething(s) + |isSomething(i) + |''' + doContentsCompareTest(contents) + } + @Test void testRemoveStaticAlias1() { String originalContents = '''\ diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/OrganizeImportsTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/OrganizeImportsTests.groovy index 672dc334c9..2d62e8b036 100644 --- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/OrganizeImportsTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/actions/OrganizeImportsTests.groovy @@ -628,6 +628,39 @@ final class OrganizeImportsTests extends OrganizeImportsTestSuite { doContentsCompareTest(contents) } + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainImport20() { + addJavaSource('class C { static Object f }', 'C', '') + + String contents = '''\ + |import static C.f + |print f + |''' + doContentsCompareTest(contents) + } + + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainImport21() { + addJavaSource('class C { static void m() {} }', 'C', '') + + String contents = '''\ + |import static C.m + |m('x') + |''' + doContentsCompareTest(contents) + } + + @Test // https://github.com/groovy/groovy-eclipse/issues/1244 + void testRetainImport22() { + addJavaSource('class C { static void m() {} }', 'C', '') + + String contents = '''\ + |import static C.m + |m 'x' + |''' + doContentsCompareTest(contents) + } + @Test void testChoices() { String contents = '''\ diff --git a/jdt-patch/e410/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e410/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 1e01c1214f..beee25cf29 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2018 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e411/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e411/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 1e01c1214f..beee25cf29 100644 --- a/jdt-patch/e411/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e411/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2018 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e412/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e412/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index c9a89edb63..10edb362f2 100644 --- a/jdt-patch/e412/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e412/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e413/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e413/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index c9a89edb63..10edb362f2 100644 --- a/jdt-patch/e413/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e413/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e414/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e414/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 2814267000..53529a65e9 100644 --- a/jdt-patch/e414/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e414/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e415/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e415/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 2814267000..53529a65e9 100644 --- a/jdt-patch/e415/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e415/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e416/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e416/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 2e423f8145..e0a2271c9d 100644 --- a/jdt-patch/e416/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e416/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e417/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e417/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 039ba29027..206502beda 100644 --- a/jdt-patch/e417/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e417/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * @@ -1177,7 +1178,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e418/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e418/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index c330b62155..fe62b5cd53 100644 --- a/jdt-patch/e418/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e418/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2020 IBM Corporation and others. * @@ -1177,7 +1178,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index c330b62155..0d5662bcce 100644 --- a/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2020 IBM Corporation and others. * @@ -1177,7 +1178,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { @@ -1317,7 +1319,7 @@ public final TextEdit rewriteImports(IProgressMonitor monitor) throws CoreExcept CompilationUnit usedAstRoot= this.astRoot; if (usedAstRoot == null) { - ASTParser parser= ASTParser.newParser(AST.JLS15); + ASTParser parser= ASTParser.newParser(AST.JLS_Latest); parser.setSource(this.compilationUnit); parser.setFocalPosition(0); // reduced AST parser.setResolveBindings(false); diff --git a/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 1be071ab64..12e2877007 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2021 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) { diff --git a/jdt-patch/e49/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/jdt-patch/e49/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index 1e01c1214f..beee25cf29 100644 --- a/jdt-patch/e49/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/jdt-patch/e49/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,3 +1,4 @@ +// GROOVY PATCHED /******************************************************************************* * Copyright (c) 2000, 2018 IBM Corporation and others. * @@ -1176,7 +1177,8 @@ public String addStaticImport(String declaringTypeName, String simpleName, boole */ public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { String key = declaringTypeName + '.' + simpleName; - if (declaringTypeName.indexOf('.') == -1) { + // GROOVY add -- Groovy allows static import of default-package elements + if (declaringTypeName.indexOf('.') == -1 && !this.compilationUnit.getClass().getName().contains("Groovy")) { //$NON-NLS-1$ return key; } if (context == null) {