You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/10/12 13:03:05 UTC

[groovy] branch GROOVY_3_0_X updated (1556475 -> 9541f46)

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

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


    from 1556475  Merge changes from groovy.console.ui.ScriptToTreeNodeAdapter
     new 9b2fb21  Java 8 refactor
     new 50cce73  minor refactor
     new c716595  fix for NPE
     new 9541f46  GROOVY-9274: Add DGM `minus` to `LocalDate`

The 4 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/groovy/lang/MissingMethodException.java   |  28 ++--
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  11 +-
 .../java/org/codehaus/groovy/ast/ClassNode.java    | 173 +++++++++++----------
 .../datetime/extensions/DateTimeExtensions.java    |  12 ++
 .../test/gdk/WorkingWithDateTimeTypesTest.groovy   |  14 ++
 5 files changed, 133 insertions(+), 105 deletions(-)


[groovy] 02/04: minor refactor

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

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

commit 50cce73a7ffb802e290138acb0c4209536c8f205
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Oct 11 13:06:13 2019 -0500

    minor refactor
    
    (cherry picked from commit 1da2081e399a58dadf9dd3b610c23623e11e2bb2)
---
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  11 +-
 .../java/org/codehaus/groovy/ast/ClassNode.java    | 168 +++++++++++----------
 2 files changed, 92 insertions(+), 87 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
index e1399ec..349e469 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -49,11 +49,6 @@ import static org.codehaus.groovy.syntax.Types.RIGHT_SHIFT_UNSIGNED;
 
 public class ExpressionUtils {
     private static ArrayList<Integer> handledTypes = new ArrayList<Integer>();
-
-    private ExpressionUtils() {
-
-    }
-
     static {
         handledTypes.add(PLUS);
         handledTypes.add(MINUS);
@@ -68,6 +63,9 @@ public class ExpressionUtils {
         handledTypes.add(POWER);
     }
 
+    private ExpressionUtils() {
+    }
+
     /**
      * Turns expressions of the form ConstantExpression(40) + ConstantExpression(2)
      * into the simplified ConstantExpression(42) at compile time.
@@ -236,7 +234,7 @@ public class ExpressionUtils {
                         Field field = type.redirect().getTypeClass().getField(pe.getPropertyAsString());
                         if (field != null && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
                             ConstantExpression ce3 = new ConstantExpression(field.get(null), true);
-                            ce3.setSourcePosition(exp);
+                            configure(exp, ce3);
                             return ce3;
                         }
                     } catch(Exception e) {
@@ -346,5 +344,4 @@ public class ExpressionUtils {
         }
         return null;
     }
-
 }
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 747694d..15f6eb0 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -137,8 +137,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     private boolean syntheticPublic;
     private ClassNode[] interfaces;
     private MixinNode[] mixins;
-    private List<ConstructorNode> constructors;
     private List<Statement> objectInitializers;
+    private List<ConstructorNode> constructors;
     private MapOfLists methods;
     private List<MethodNode> methodsList;
     private LinkedList<FieldNode> fields;
@@ -195,13 +195,13 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     /**
      * Sets this instance as proxy for the given {@code ClassNode}.
      *
-     * @param cn the class to redirect to; if {@code null} the redirect is removed
+     * @param node the class to redirect to; if {@code null} the redirect is removed
      */
-    public void setRedirect(ClassNode cn) {
-        if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode (" + getName() + "->" + cn.getName() + ").");
-        if (cn != null && !isGenericsPlaceHolder()) cn = cn.redirect();
-        if (cn == this) return;
-        redirect = cn;
+    public void setRedirect(ClassNode node) {
+        if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode (" + getName() + "->" + node.getName() + ").");
+        if (node != null && !isGenericsPlaceHolder()) node = node.redirect();
+        if (node == this) return;
+        redirect = node;
     }
 
     /**
@@ -209,20 +209,18 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * by this.
      */
     public ClassNode makeArray() {
+        ClassNode node;
         if (redirect != null) {
-            ClassNode res = redirect().makeArray();
-            res.componentType = this;
-            return res;
-        }
-        ClassNode cn;
-        if (clazz != null) {
+            node = redirect.makeArray();
+            node.componentType = this;
+        } else if (clazz != null) {
             Class<?> type = Array.newInstance(clazz, 0).getClass();
             // don't use the ClassHelper here!
-            cn = new ClassNode(type, this);
+            node = new ClassNode(type, this);
         } else {
-            cn = new ClassNode(this);
+            node = new ClassNode(this);
         }
-        return cn;
+        return node;
     }
 
     /**
@@ -351,7 +349,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @return the fields associated with this {@code ClassNode}
      */
     public List<FieldNode> getFields() {
-        if (redirect != null) return redirect().getFields();
+        if (redirect != null)
+            return redirect.getFields();
         lazyClassInit();
         if (fields == null)
             fields = new LinkedList<>();
@@ -362,14 +361,15 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @return the interfaces implemented by this {@code ClassNode}
      */
     public ClassNode[] getInterfaces() {
-        if (redirect != null) return redirect().getInterfaces();
+        if (redirect != null)
+            return redirect.getInterfaces();
         lazyClassInit();
         return interfaces;
     }
 
     public void setInterfaces(ClassNode[] interfaces) {
         if (redirect != null) {
-            redirect().setInterfaces(interfaces);
+            redirect.setInterfaces(interfaces);
         } else {
             this.interfaces = interfaces;
         }
@@ -391,7 +391,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      */
     public List<MethodNode> getMethods() {
         if (redirect != null)
-            return redirect().getMethods();
+            return redirect.getMethods();
         lazyClassInit();
         return methodsList;
     }
@@ -416,11 +416,11 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
     private void getAllInterfaces(Set<ClassNode> set) {
         if (isInterface()) {
-          set.add(this);
+            set.add(this);
         }
-        for (ClassNode anInterface : getInterfaces()) {
-            set.add(anInterface);
-            anInterface.getAllInterfaces(set);
+        for (ClassNode face : getInterfaces()) {
+            set.add(face);
+            face.getAllInterfaces(set);
         }
     }
 
@@ -429,8 +429,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
         ClassNodeUtils.addDeclaredMethodsFromInterfaces(this, result);
         // add in the methods implemented in this class
         for (MethodNode method : getMethods()) {
-            String sig = method.getTypeDescriptor();
-            result.put(sig, method);
+            result.put(method.getTypeDescriptor(), method);
         }
         return result;
     }
@@ -457,7 +456,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
     public List<PropertyNode> getProperties() {
         if (redirect != null)
-            return redirect().getProperties();
+            return redirect.getProperties();
         if (properties == null)
             properties = new ArrayList<>();
         return properties;
@@ -465,7 +464,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
     public List<ConstructorNode> getDeclaredConstructors() {
         if (redirect != null)
-            return redirect().getDeclaredConstructors();
+            return redirect.getDeclaredConstructors();
         lazyClassInit();
         if (constructors == null)
             constructors = new ArrayList<>();
@@ -476,9 +475,9 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @return the constructor matching the given parameters or {@code null}
      */
     public ConstructorNode getDeclaredConstructor(Parameter[] parameters) {
-        for (ConstructorNode method : getDeclaredConstructors()) {
-            if (parametersEqual(method.getParameters(), parameters)) {
-                return method;
+        for (ConstructorNode constructor : getDeclaredConstructors()) {
+            if (parametersEqual(constructor.getParameters(), parameters)) {
+                return constructor;
             }
         }
         return null;
@@ -512,7 +511,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     private void addField(FieldNode node, boolean isFirst) {
-        final ClassNode r = redirect();
+        ClassNode r = redirect();
         node.setDeclaringClass(r);
         node.setOwner(r);
         if (r.fields == null)
@@ -574,7 +573,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
     public void addConstructor(ConstructorNode node) {
         node.setDeclaringClass(this);
-        final ClassNode r = redirect();
+        ClassNode r = redirect();
         if (r.constructors == null)
             r.constructors = new ArrayList<>();
         r.constructors.add(node);
@@ -588,20 +587,20 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
     public void addMethod(MethodNode node) {
         node.setDeclaringClass(this);
-        ClassNode base = redirect();
-        if (base.methodsList.isEmpty()) {
-            base.methodsList = new ArrayList<>();
+        ClassNode r = redirect();
+        if (r.methodsList.isEmpty()) {
+            r.methodsList = new ArrayList<>();
         }
-        base.methodsList.add(node);
-        base.methods.put(node.getName(), node);
+        r.methodsList.add(node);
+        r.methods.put(node.getName(), node);
     }
 
     public void removeMethod(MethodNode node) {
-        ClassNode base = redirect();
-        if (!base.methodsList.isEmpty()) {
-            base.methodsList.remove(node);
+        ClassNode r = redirect();
+        if (!r.methodsList.isEmpty()) {
+            r.methodsList.remove(node);
         }
-        base.methods.remove(node.getName(), node);
+        r.methods.remove(node.getName(), node);
     }
 
     /**
@@ -645,9 +644,9 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * Adds a synthetic method as part of the compilation process.
      */
     public MethodNode addSyntheticMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code) {
-        MethodNode answer = addMethod(name, modifiers | ACC_SYNTHETIC, returnType, parameters, exceptions, code);
-        answer.setSynthetic(true);
-        return answer;
+        MethodNode node = addMethod(name, modifiers | ACC_SYNTHETIC, returnType, parameters, exceptions, code);
+        node.setSynthetic(true);
+        return node;
     }
 
     public FieldNode addField(String name, int modifiers, ClassNode type, Expression initialValue) {
@@ -665,9 +664,9 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     public void addInterface(ClassNode type) {
         // let's check if it already implements an interface
         boolean skip = false;
-        ClassNode[] interfaces = redirect().interfaces;
-        for (ClassNode existing : interfaces) {
-            if (type.equals(existing)) {
+        ClassNode[] interfaces = getInterfaces();
+        for (ClassNode face : interfaces) {
+            if (type.equals(face)) {
                 skip = true;
                 break;
             }
@@ -683,18 +682,17 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     public boolean equals(Object that) {
         if (that == this) return true;
         if (!(that instanceof ClassNode)) return false;
-        if (redirect != null) return redirect().equals(that);
+        if (redirect != null) return redirect.equals(that);
         return (((ClassNode) that).getText().equals(getText()));
     }
 
     public int hashCode() {
-        if (redirect != null) return redirect().hashCode();
-        return getText().hashCode();
+        return (redirect != null ? redirect.hashCode() : getText().hashCode());
     }
 
     public void addMixin(MixinNode mixin) {
         // let's check if it already uses a mixin
-        MixinNode[] mixins = redirect().mixins;
+        MixinNode[] mixins = getMixins();
         boolean skip = false;
         for (MixinNode existing : mixins) {
             if (mixin.equals(existing)) {
@@ -717,8 +715,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @return the method matching the given name and parameters or null
      */
     public FieldNode getDeclaredField(String name) {
-        if (redirect != null) return redirect().getDeclaredField(name);
-
+        if (redirect != null)
+            return redirect.getDeclaredField(name);
         lazyClassInit();
         return fieldIndex == null ? null : fieldIndex.get(name);
     }
@@ -744,14 +742,14 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      */
     public FieldNode getOuterField(String name) {
         if (redirect != null) {
-            return redirect().getOuterField(name);
+            return redirect.getOuterField(name);
         }
         return null;
     }
 
     public ClassNode getOuterClass() {
         if (redirect != null) {
-            return redirect().getOuterClass();
+            return redirect.getOuterClass();
         }
         return null;
     }
@@ -824,8 +822,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) {
-        MethodNode method = getOrAddStaticConstructorNode();
-        Statement statement = method.getCode();
+        MethodNode constructor = getOrAddStaticConstructorNode();
+        Statement statement = constructor.getCode();
         if (statement instanceof BlockStatement) {
             BlockStatement block = (BlockStatement) statement;
             // add given statements for explicitly declared static fields just after enum-special fields
@@ -857,7 +855,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @see #getMethods(String)
      */
     public List<MethodNode> getDeclaredMethods(String name) {
-        if (redirect != null) return redirect().getDeclaredMethods(name);
+        if (redirect != null)
+            return redirect.getDeclaredMethods(name);
         lazyClassInit();
         return methods.get(name);
     }
@@ -869,13 +868,13 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      * @see #getDeclaredMethods(String)
      */
     public List<MethodNode> getMethods(String name) {
-        List<MethodNode> answer = new ArrayList<>();
+        List<MethodNode> result = new ArrayList<>();
         ClassNode node = this;
         while (node != null) {
-            answer.addAll(node.getDeclaredMethods(name));
+            result.addAll(node.getDeclaredMethods(name));
             node = node.getSuperClass();
         }
-        return answer;
+        return result;
     }
 
     /**
@@ -961,6 +960,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
             node = node.getSuperClass();
         }
         while (node != null);
+
         return false;
     }
 
@@ -991,13 +991,13 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
      */
     public boolean declaresInterface(ClassNode classNode) {
         ClassNode[] interfaces = redirect().getInterfaces();
-        for (ClassNode cn : interfaces) {
-            if (cn.equals(classNode)) {
+        for (ClassNode face : interfaces) {
+            if (face.equals(classNode)) {
                 return true;
             }
         }
-        for (ClassNode cn : interfaces) {
-            if (cn.declaresInterface(classNode)) {
+        for (ClassNode face : interfaces) {
+            if (face.declaresInterface(classNode)) {
                 return true;
             }
         }
@@ -1021,14 +1021,16 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     public ClassNode getUnresolvedSuperClass(boolean useRedirect) {
-        if (!useRedirect) return superClass;
-        if (redirect != null) return redirect().getUnresolvedSuperClass(true);
+        if (!useRedirect)
+            return superClass;
+        if (redirect != null)
+            return redirect.getUnresolvedSuperClass(true);
         lazyClassInit();
         return superClass;
     }
 
-    public void setUnresolvedSuperClass(ClassNode sn) {
-        superClass = sn;
+    public void setUnresolvedSuperClass(ClassNode superClass) {
+        this.superClass = superClass;
     }
 
     public ClassNode[] getUnresolvedInterfaces() {
@@ -1036,14 +1038,17 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     public ClassNode[] getUnresolvedInterfaces(boolean useRedirect) {
-        if (!useRedirect) return interfaces;
-        if (redirect != null) return redirect().getUnresolvedInterfaces(true);
+        if (!useRedirect)
+            return interfaces;
+        if (redirect != null)
+            return redirect.getUnresolvedInterfaces(true);
         lazyClassInit();
         return interfaces;
     }
 
     public CompileUnit getCompileUnit() {
-        if (redirect != null) return redirect().getCompileUnit();
+        if (redirect != null)
+            return redirect.getCompileUnit();
         if (compileUnit == null && module != null) {
             compileUnit = module.getUnit();
         }
@@ -1051,7 +1056,8 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     protected void setCompileUnit(CompileUnit cu) {
-        if (redirect != null) redirect().setCompileUnit(cu);
+        if (redirect != null)
+            redirect.setCompileUnit(cu);
         if (compileUnit != null) compileUnit = cu;
     }
 
@@ -1096,7 +1102,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     private void visitMethods(GroovyClassVisitor visitor) {
-        // create snapshot of the method list to avoid java.util.ConcurrentModificationException
+        // create snapshot of the method list to avoid ConcurrentModificationException
         List<MethodNode> methodList = new ArrayList<>(getMethods());
         for (MethodNode mn : methodList) {
             visitor.visitMethod(mn);
@@ -1211,7 +1217,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
             ret.append(stream(genericsTypes).map(this::genericTypeAsString).collect(joining(", ")));
             ret.append(">");
         }
-        if (isRedirectNode() && showRedirect) {
+        if (showRedirect && redirect != null) {
             ret.append(" -> ").append(redirect.toString());
         }
         return ret.toString();
@@ -1465,13 +1471,15 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     public List<AnnotationNode> getAnnotations() {
-        if (redirect != null) return redirect.getAnnotations();
+        if (redirect != null)
+            return redirect.getAnnotations();
         lazyClassInit();
         return super.getAnnotations();
     }
 
     public List<AnnotationNode> getAnnotations(ClassNode type) {
-        if (redirect != null) return redirect.getAnnotations(type);
+        if (redirect != null)
+            return redirect.getAnnotations(type);
         lazyClassInit();
         return super.getAnnotations(type);
     }
@@ -1493,7 +1501,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
         ClassNode r = redirect();
         if (r.fieldIndex == null)
             r.fieldIndex = new LinkedHashMap<>();
-        final Map<String, FieldNode> index = r.fieldIndex;
+        Map<String, FieldNode> index = r.fieldIndex;
         index.put(newName, index.remove(oldName));
     }
 
@@ -1501,7 +1509,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
         ClassNode r = redirect();
         if (r.fieldIndex == null)
             r.fieldIndex = new LinkedHashMap<>();
-        final Map<String, FieldNode> index = r.fieldIndex;
+        Map<String, FieldNode> index = r.fieldIndex;
         r.fields.remove(index.get(oldName));
         index.remove(oldName);
     }


[groovy] 04/04: GROOVY-9274: Add DGM `minus` to `LocalDate`

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

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

commit 9541f467e9a718c79200cfa72a2720e30c5897fa
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Wed Oct 9 18:05:19 2019 +0800

    GROOVY-9274: Add DGM `minus` to `LocalDate`
    
    (cherry picked from commit 37ec9a72b676a550582baa03e70126e2603c9fa0)
---
 .../groovy/datetime/extensions/DateTimeExtensions.java     | 12 ++++++++++++
 .../src/spec/test/gdk/WorkingWithDateTimeTypesTest.groovy  | 14 ++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java b/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java
index c46789a..85bf09f 100644
--- a/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java
+++ b/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java
@@ -579,6 +579,18 @@ public class DateTimeExtensions {
     }
 
     /**
+     * Calculates the number of days between two dates
+     *
+     * @param self a LocalDate
+     * @param other the other LocalDate
+     * @return the number of days
+     * @since 3.0.0
+     */
+    public static long minus(final LocalDate self, LocalDate other) {
+        return ChronoUnit.DAYS.between(other, self);
+    }
+
+    /**
      * Returns a {@link java.time.LocalDate} one day after this date.
      *
      * @param self a LocalDate
diff --git a/subprojects/groovy-datetime/src/spec/test/gdk/WorkingWithDateTimeTypesTest.groovy b/subprojects/groovy-datetime/src/spec/test/gdk/WorkingWithDateTimeTypesTest.groovy
index 14c0191..005c8df 100644
--- a/subprojects/groovy-datetime/src/spec/test/gdk/WorkingWithDateTimeTypesTest.groovy
+++ b/subprojects/groovy-datetime/src/spec/test/gdk/WorkingWithDateTimeTypesTest.groovy
@@ -252,4 +252,18 @@ class WorkingWithDateTimeTypesTest extends GroovyTestCase {
         // end::to_jsr310_types[]
     }
 
+    void testLocalDateMinusOtherLocalDate() {
+        def date1 = LocalDate.of(2019, Month.OCTOBER, 10)
+        def date2 = LocalDate.of(2019, Month.OCTOBER, 1)
+        assert 9 == date1 - date2
+        assert -9 == date2 - date1
+
+        def date3 = LocalDate.of(2019, Month.OCTOBER, 1)
+        def date4 = LocalDate.of(2019, Month.OCTOBER, 1)
+        assert 0 == date3 - date4
+
+        def date5 = LocalDate.of(2019, Month.OCTOBER, 1)
+        def date6 = LocalDate.of(2019, Month.SEPTEMBER, 30)
+        assert 1 == date5 - date6
+    }
 }


[groovy] 03/04: fix for NPE

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

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

commit c716595eb3a801b9a315003c04e38b06abc0ad0c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Oct 11 15:11:46 2019 -0500

    fix for NPE
    
    closes #810
    
    (cherry picked from commit 22a46a113e935745a699c7fac753c94e69ce053e)
---
 .../java/groovy/lang/MissingMethodException.java   | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/main/java/groovy/lang/MissingMethodException.java b/src/main/java/groovy/lang/MissingMethodException.java
index 3dbaf86..6a9a857 100644
--- a/src/main/java/groovy/lang/MissingMethodException.java
+++ b/src/main/java/groovy/lang/MissingMethodException.java
@@ -29,41 +29,41 @@ import org.codehaus.groovy.runtime.MethodRankHelper;
  */
 public class MissingMethodException extends GroovyRuntimeException {
 
-    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
     private static final long serialVersionUID = -6676430495683939401L;
+
     private final String method;
-    private final Class type;
+    private final Class<?> type;
     private final boolean isStatic;
+    private final Object[] arguments;
 
-    public Object[] getArguments() {
-        return arguments;
-    }
-
-    private final Object arguments[];
-
-    public MissingMethodException(String method, Class type, Object[] arguments) {
+    public MissingMethodException(String method, Class<?> type, Object[] arguments) {
         this(method, type, arguments, false);
     }
 
-    public MissingMethodException(String method, Class type, Object[] arguments, boolean isStatic) {
+    public MissingMethodException(String method, Class<?> type, Object[] arguments, boolean isStatic) {
         super();
         this.method = method;
         this.type = type;
         this.isStatic = isStatic;
-        this.arguments = arguments == null ? EMPTY_OBJECT_ARRAY : arguments;
+        this.arguments = arguments != null ? arguments : new Object[0];
+    }
+
+    public Object[] getArguments() {
+        return arguments;
     }
 
+    @Override
     public String getMessage() {
         return "No signature of method: "
                 + (isStatic ? "static " : "")
-                + type.getName()
+                + (type != null ? type.getName() : "<unknown>")
                 + "."
                 + method
                 + "() is applicable for argument types: ("
                 + InvokerHelper.toTypeString(arguments, 60)
                 + ") values: "
                 + InvokerHelper.toArrayString(arguments, 60, true)
-                + MethodRankHelper.getMethodSuggestionString(method, type, arguments);
+                + (type != null ? MethodRankHelper.getMethodSuggestionString(method, type, arguments) : "");
     }
 
     /**
@@ -76,7 +76,7 @@ public class MissingMethodException extends GroovyRuntimeException {
     /**
      * @return The type on which the method was attempted to be called
      */
-    public Class getType() {
+    public Class<?> getType() {
         return type;
     }
 


[groovy] 01/04: Java 8 refactor

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

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

commit 9b2fb212f30dbf84205410614e2f873480cab3e7
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Oct 11 12:49:27 2019 -0500

    Java 8 refactor
    
    (cherry picked from commit 5e6866dfea2ada5852c200e4caf725d4e8b79d9a)
---
 src/main/java/org/codehaus/groovy/ast/ClassNode.java | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 4e6ea90..747694d 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -334,10 +334,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
             usesGenerics = superClass.isUsingGenerics();
         }
         if (!usesGenerics && interfaces != null) {
-            for (ClassNode anInterface : interfaces) {
-                usesGenerics = usesGenerics || anInterface.isUsingGenerics();
-                if (usesGenerics) break;
-            }
+            usesGenerics = stream(interfaces).anyMatch(ClassNode::isUsingGenerics);
         }
         methods = new MapOfLists();
         methodsList = Collections.emptyList();