From 3239180ff972ae9f300f086fc3b05dffe7e39552 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sun, 10 Nov 2019 17:59:54 -0600 Subject: [PATCH] Fix for #990: use redirect for reference comparison --- .../org/codehaus/groovy/ast/ClassHelper.java | 9 +++++++++ .../org/codehaus/groovy/ast/ClassHelper.java | 6 ++++++ .../org/codehaus/groovy/ast/ClassHelper.java | 6 ++++++ .../jdt/groovy/core/util/GroovyUtils.java | 2 +- .../test/ui/SemanticHighlightingTests.groovy | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassHelper.java b/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassHelper.java index 19b037769d..09925a8efb 100644 --- a/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassHelper.java +++ b/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassHelper.java @@ -347,6 +347,9 @@ public static ClassNode getUnwrapper(ClassNode cn) { * @see #make(String) */ public static boolean isPrimitiveType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == boolean_TYPE || cn == char_TYPE || cn == byte_TYPE || @@ -371,6 +374,9 @@ public static boolean isPrimitiveType(ClassNode cn) { * @see #make(String) */ public static boolean isStaticConstantInitializerType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == int_TYPE || cn == float_TYPE || cn == long_TYPE || @@ -383,6 +389,9 @@ public static boolean isStaticConstantInitializerType(ClassNode cn) { } public static boolean isNumberType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == Byte_TYPE || cn == Short_TYPE || cn == Integer_TYPE || diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassHelper.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassHelper.java index c3111b941a..32d32c8295 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassHelper.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassHelper.java @@ -355,6 +355,9 @@ public static boolean isPrimitiveType(ClassNode cn) { * @see #make(String) */ public static boolean isStaticConstantInitializerType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == int_TYPE || cn == float_TYPE || cn == long_TYPE || @@ -367,6 +370,9 @@ public static boolean isStaticConstantInitializerType(ClassNode cn) { } public static boolean isNumberType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == Byte_TYPE || cn == Short_TYPE || cn == Integer_TYPE || diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassHelper.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassHelper.java index 1857c60909..7cb3ecca3c 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassHelper.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassHelper.java @@ -384,6 +384,9 @@ public static boolean isPrimitiveType(ClassNode cn) { * @see #make(String) */ public static boolean isStaticConstantInitializerType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == int_TYPE || cn == float_TYPE || cn == long_TYPE || @@ -396,6 +399,9 @@ public static boolean isStaticConstantInitializerType(ClassNode cn) { } public static boolean isNumberType(ClassNode cn) { + // GRECLIPSE add + cn = cn.redirect(); + // GRECLIPSE end return cn == Byte_TYPE || cn == Short_TYPE || cn == Integer_TYPE || diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/GroovyUtils.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/GroovyUtils.java index 4be10764fc..f716539302 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/GroovyUtils.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/GroovyUtils.java @@ -263,7 +263,7 @@ public static String getTypeSignatureWithoutGenerics(ClassNode node, boolean qua } public static ClassNode getWrapperTypeIfPrimitive(ClassNode type) { - if (ClassHelper.isPrimitiveType(type) && !ClassHelper.VOID_TYPE.equals(type)) { + if (type != null && ClassHelper.isPrimitiveType(type) && !ClassHelper.VOID_TYPE.equals(type)) { return ClassHelper.getWrapper(type); } return type; diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy index fd7a25d349..9f9c2fded6 100644 --- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy @@ -978,6 +978,24 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite { new HighlightedTypedPosition(contents.lastIndexOf('zero'), 4, METHOD_CALL)) } + @Test + void testMultiAssign1() { + String contents = '''\ + |@groovy.transform.CompileStatic + |void meth() { + | def (Integer i, String s) = [123, 'abc'] + |} + |'''.stripMargin() + + assertHighlighting(contents, + new HighlightedTypedPosition(contents.indexOf('meth'), 4, METHOD), + new HighlightedTypedPosition(contents.indexOf('Integer'), 7, CLASS), + new HighlightedTypedPosition(contents.indexOf('i,'), 1, VARIABLE), + new HighlightedTypedPosition(contents.indexOf('String'), 6, CLASS), + new HighlightedTypedPosition(contents.indexOf('s)'), 1, VARIABLE), + new HighlightedTypedPosition(contents.indexOf('123'), 3, NUMBER)) + } + @Test void testCatchParam() { // don't want PARAMETER