You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2019/11/11 01:59:16 UTC

[groovy] branch master updated (936baeb -> 3b7fffa)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 936baeb  fix generics
     new 9ee678b  minor edits
     new 3b7fffa  use redirect for reference comparison

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/codehaus/groovy/ast/ClassHelper.java  | 88 ++++++++++++----------
 .../groovy/classgen/asm/BytecodeHelper.java        |  4 +-
 .../groovy/tools/javac/JavaStubGenerator.java      |  5 +-
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 33 +++++++-
 4 files changed, 80 insertions(+), 50 deletions(-)


[groovy] 02/02: use redirect for reference comparison

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3b7fffa60762730dfa6c8f4a09df51151188f37b
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Nov 10 19:59:04 2019 -0600

    use redirect for reference comparison
---
 .../java/org/codehaus/groovy/ast/ClassHelper.java  |  2 ++
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 33 ++++++++++++++++++++--
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index c71f786..b5f7fac 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -364,6 +364,7 @@ public class ClassHelper {
      * @see #make(String)
      */
     public static boolean isStaticConstantInitializerType(ClassNode cn) {
+        cn = cn.redirect();
         return cn == int_TYPE ||
                 cn == float_TYPE ||
                 cn == long_TYPE ||
@@ -376,6 +377,7 @@ public class ClassHelper {
     }
 
     public static boolean isNumberType(ClassNode cn) {
+        cn = cn.redirect();
         return cn == Byte_TYPE ||
                 cn == Short_TYPE ||
                 cn == Integer_TYPE ||
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 66eda6c..ce29a78 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -196,7 +196,7 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
             @groovy.transform.CompileStatic
             class Main {
                 void test() {
-                    @ASTTest(phase=INSTRUCTION_SELECTION, value= {
+                    @ASTTest(phase=INSTRUCTION_SELECTION, value={
                         assert node.rightExpression.getNodeMetaData(INFERRED_TYPE).nameWithoutPackage == 'Sql'
                     })
                     def sql = Sql.newInstance("a", "b", "c", "d")
@@ -720,7 +720,7 @@ import groovy.transform.TypeCheckingMode
         shouldFailWithMessages '''
             def fieldMatcher = '[x=1] [a=b] [foo=bar]' =~ ~"\\\\[([^=\\\\[]+)=([^\\\\]]+)\\\\]"
             assert fieldMatcher instanceof java.util.regex.Matcher
-            @ASTTest(phase=INSTRUCTION_SELECTION, value = {
+            @ASTTest(phase=INSTRUCTION_SELECTION, value={
                 assert node.getNodeMetaData(INFERRED_TYPE) == OBJECT_TYPE
             })
             def value = fieldMatcher[0]
@@ -1470,7 +1470,6 @@ println someInt
         assertScript '''
             import static java.nio.file.AccessMode.*
 
-            @groovy.transform.CompileStatic
             class Dummy {
                 static main() {
                     // more than 5 to match `of(E first, E[] rest)` variant
@@ -1481,4 +1480,32 @@ println someInt
             assert Dummy.main() == [READ, WRITE, EXECUTE].toSet()
         '''
     }
+
+    void testNumberWrapperMultiAssign() {
+        assertScript '''
+            import org.codehaus.groovy.ast.CodeVisitorSupport
+            import org.codehaus.groovy.ast.expr.ConstantExpression
+
+            void test() {
+                @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                    node.visit(new CodeVisitorSupport() {
+                        @Override
+                        void visitConstantExpression(ConstantExpression expr) {
+                            switch (expr.text) {
+                            case '123':
+                            case '456':
+                                assert ClassHelper.isNumberType(expr.type)
+                                break
+                            default:
+                                assert false : "unexpected constant: $expr"
+                            }
+                        }
+                    })
+                })
+                def (Integer i, Long j) = [123, 456L]
+            }
+
+            test()
+        '''
+    }
 }


[groovy] 01/02: minor edits

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9ee678ba4d2e33d569e54d97ab5349dd39436a0e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Nov 10 19:31:21 2019 -0600

    minor edits
---
 .../java/org/codehaus/groovy/ast/ClassHelper.java  | 86 +++++++++++-----------
 .../groovy/classgen/asm/BytecodeHelper.java        |  4 +-
 .../groovy/tools/javac/JavaStubGenerator.java      |  5 +-
 3 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index b5b5170..c71f786 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -69,10 +69,9 @@ import java.util.Map;
 import java.util.regex.Pattern;
 
 /**
- * This class is a Helper for ClassNode and classes handling ClassNodes.
- * It does contain a set of predefined ClassNodes for the most used
- * types and some code for cached ClassNode creation and basic
- * ClassNode handling
+ * Helper for {@link ClassNode} and classes handling them.  Contains a set of
+ * pre-defined instances for the most used types and some code for cached node
+ * creation and basic handling.
  */
 public class ClassHelper {
 
@@ -87,57 +86,68 @@ public class ClassHelper {
             Iterator.class, GeneratedClosure.class, GeneratedLambda.class, GroovyObjectSupport.class
     };
 
-    public static final Class[] TUPLE_CLASSES = new Class[] {
+    public static final Class[] TUPLE_CLASSES = new Class[]{
             Tuple0.class, Tuple1.class, Tuple2.class, Tuple3.class, Tuple4.class, Tuple5.class, Tuple6.class,
             Tuple7.class, Tuple8.class, Tuple9.class, Tuple10.class, Tuple11.class, Tuple12.class, Tuple13.class,
             Tuple14.class, Tuple15.class, Tuple16.class
     };
 
     private static final String[] primitiveClassNames = new String[]{
-            "", "boolean", "char", "byte", "short",
-            "int", "long", "double", "float", "void"
+            "", "boolean", "char", "byte", "short", "int", "long", "double", "float", "void"
     };
 
     public static final ClassNode
-            DYNAMIC_TYPE = makeCached(Object.class), OBJECT_TYPE = DYNAMIC_TYPE,
-            VOID_TYPE = makeCached(Void.TYPE),
+            DYNAMIC_TYPE = makeCached(Object.class),
+            OBJECT_TYPE = DYNAMIC_TYPE,
             CLOSURE_TYPE = makeCached(Closure.class),
-            GSTRING_TYPE = makeCached(GString.class), LIST_TYPE = makeWithoutCaching(List.class),
-            TUPLE_TYPE = makeWithoutCaching(Tuple.class),
-            MAP_TYPE = makeWithoutCaching(Map.class), RANGE_TYPE = makeCached(Range.class),
-            PATTERN_TYPE = makeCached(Pattern.class), STRING_TYPE = makeCached(String.class),
-            SCRIPT_TYPE = makeCached(Script.class), REFERENCE_TYPE = makeWithoutCaching(Reference.class),
+            GSTRING_TYPE = makeCached(GString.class),
+            RANGE_TYPE = makeCached(Range.class),
+            PATTERN_TYPE = makeCached(Pattern.class),
+            STRING_TYPE = makeCached(String.class),
+            SCRIPT_TYPE = makeCached(Script.class),
             BINDING_TYPE = makeCached(Binding.class),
 
-    boolean_TYPE = makeCached(boolean.class), char_TYPE = makeCached(char.class),
-            byte_TYPE = makeCached(byte.class), int_TYPE = makeCached(int.class),
-            long_TYPE = makeCached(long.class), short_TYPE = makeCached(short.class),
-            double_TYPE = makeCached(double.class), float_TYPE = makeCached(float.class),
-            Byte_TYPE = makeCached(Byte.class), Short_TYPE = makeCached(Short.class),
-            Integer_TYPE = makeCached(Integer.class), Long_TYPE = makeCached(Long.class),
-            Character_TYPE = makeCached(Character.class), Float_TYPE = makeCached(Float.class),
-            Double_TYPE = makeCached(Double.class), Boolean_TYPE = makeCached(Boolean.class),
+            boolean_TYPE = makeCached(boolean.class),
+            char_TYPE = makeCached(char.class),
+            byte_TYPE = makeCached(byte.class),
+            int_TYPE = makeCached(int.class),
+            long_TYPE = makeCached(long.class),
+            short_TYPE = makeCached(short.class),
+            double_TYPE = makeCached(double.class),
+            float_TYPE = makeCached(float.class),
+            Byte_TYPE = makeCached(Byte.class),
+            Short_TYPE = makeCached(Short.class),
+            Integer_TYPE = makeCached(Integer.class),
+            Long_TYPE = makeCached(Long.class),
+            Character_TYPE = makeCached(Character.class),
+            Float_TYPE = makeCached(Float.class),
+            Double_TYPE = makeCached(Double.class),
+            Boolean_TYPE = makeCached(Boolean.class),
             BigInteger_TYPE = makeCached(java.math.BigInteger.class),
             BigDecimal_TYPE = makeCached(java.math.BigDecimal.class),
             Number_TYPE = makeCached(Number.class),
 
-    void_WRAPPER_TYPE = makeCached(Void.class), METACLASS_TYPE = makeCached(MetaClass.class),
+            VOID_TYPE = makeCached(Void.TYPE),
+            void_WRAPPER_TYPE = makeCached(Void.class),
+            METACLASS_TYPE = makeCached(MetaClass.class),
             Iterator_TYPE = makeCached(Iterator.class),
-            AUTOCLOSEABLE_TYPE = makeCached(AutoCloseable.class),
-
-    Enum_Type = makeWithoutCaching(Enum.class),
             Annotation_TYPE = makeCached(Annotation.class),
             ELEMENT_TYPE_TYPE = makeCached(ElementType.class),
+            AUTOCLOSEABLE_TYPE = makeCached(AutoCloseable.class),
 
-//    FunctionalInterface_Type = ClassHelper.makeCached(FunctionalInterface.class),
-
-    // uncached constants.
-    CLASS_Type = makeWithoutCaching(Class.class), COMPARABLE_TYPE = makeWithoutCaching(Comparable.class),
-            GENERATED_CLOSURE_Type = makeWithoutCaching(GeneratedClosure.class),
-            GENERATED_LAMBDA_TYPE = makeWithoutCaching(GeneratedLambda.class),
-            GROOVY_OBJECT_SUPPORT_TYPE = makeWithoutCaching(GroovyObjectSupport.class),
+            // uncached constants
+            MAP_TYPE = makeWithoutCaching(Map.class),
+            LIST_TYPE = makeWithoutCaching(List.class),
+            Enum_Type = makeWithoutCaching(Enum.class),
+            CLASS_Type = makeWithoutCaching(Class.class),
+            TUPLE_TYPE = makeWithoutCaching(Tuple.class),
+            REFERENCE_TYPE = makeWithoutCaching(Reference.class),
+            COMPARABLE_TYPE = makeWithoutCaching(Comparable.class),
             GROOVY_OBJECT_TYPE = makeWithoutCaching(GroovyObject.class),
-            GROOVY_INTERCEPTABLE_TYPE = makeWithoutCaching(GroovyInterceptable.class);
+            GENERATED_LAMBDA_TYPE = makeWithoutCaching(GeneratedLambda.class),
+            GENERATED_CLOSURE_Type = makeWithoutCaching(GeneratedClosure.class),
+            GROOVY_INTERCEPTABLE_TYPE = makeWithoutCaching(GroovyInterceptable.class),
+            GROOVY_OBJECT_SUPPORT_TYPE = makeWithoutCaching(GroovyObjectSupport.class);
 
     private static final ClassNode[] types = new ClassNode[]{
             OBJECT_TYPE,
@@ -154,8 +164,7 @@ public class ClassHelper {
             GROOVY_OBJECT_TYPE, GROOVY_INTERCEPTABLE_TYPE, Enum_Type, Annotation_TYPE
     };
 
-    private static final int ABSTRACT_STATIC_PRIVATE =
-            Modifier.ABSTRACT | Modifier.PRIVATE | Modifier.STATIC;
+    private static final int ABSTRACT_STATIC_PRIVATE = Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE;
     private static final int VISIBILITY = 5; // public|protected
 
     protected static final ClassNode[] EMPTY_TYPE_ARRAY = {};
@@ -168,10 +177,8 @@ public class ClassHelper {
         if (classNodeSoftReference == null || (classNode = classNodeSoftReference.get()) == null) {
             classNode = new ClassNode(c);
             ClassHelperCache.classCache.put(c, new SoftReference<ClassNode>(classNode));
-
             VMPluginFactory.getPlugin().setAdditionalClassInformation(classNode);
         }
-
         return classNode;
     }
 
@@ -189,7 +196,6 @@ public class ClassHelper {
         for (int i = 0; i < cns.length; i++) {
             cns[i] = make(classes[i]);
         }
-
         return cns;
     }
 
@@ -236,7 +242,6 @@ public class ClassHelper {
         }
     }
 
-
     /**
      * Creates a ClassNode using a given class.
      * Unlike make(String) this method will not use the cache
@@ -332,7 +337,6 @@ public class ClassHelper {
         return cn;
     }
 
-
     /**
      * Test to determine if a ClassNode is a primitive type.
      * Note: this only works for ClassNodes created using a
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java b/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
index 58323b5..6dea156 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
@@ -478,7 +478,7 @@ public class BytecodeHelper implements Opcodes {
      */
     @Deprecated
     public static boolean box(MethodVisitor mv, ClassNode type) {
-        if (ClassHelper.isPrimitiveType(type) && !"void".equalsIgnoreCase(type.getName())) {
+        if (ClassHelper.isPrimitiveType(type) && !ClassHelper.VOID_TYPE.equals(type)) {
             box(mv, BytecodeHelper.getTypeDescription(type));
             return true;
         }
@@ -505,7 +505,7 @@ public class BytecodeHelper implements Opcodes {
      * Generates the bytecode to unbox the current value on the stack.
      */
     public static void unbox(MethodVisitor mv, ClassNode type) {
-        if (ClassHelper.isPrimitiveType(type) && !"void".equalsIgnoreCase(type.getName())) {
+        if (ClassHelper.isPrimitiveType(type) && !ClassHelper.VOID_TYPE.equals(type)) {
             unbox(mv, type.getName(), BytecodeHelper.getTypeDescription(type));
         }
     }
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 2510ff0..871fe37 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -806,12 +806,9 @@ public class JavaStubGenerator {
     }
 
     private void printReturn(PrintWriter out, ClassNode retType) {
-        String retName = retType.getName();
-        if (!retName.equals("void")) {
+        if (!ClassHelper.VOID_TYPE.equals(retType)) {
             out.print("return ");
-
             printDefaultValue(out, retType);
-
             out.print(";");
         }
     }