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/11/05 12:40:07 UTC
[groovy] branch master updated: refactor code
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 871f756 refactor code
871f756 is described below
commit 871f756094e8759d6142fe8fecfbb6ee72a04e26
Author: mattisonchao <ma...@gmail.com>
AuthorDate: Tue Nov 5 19:50:50 2019 +0800
refactor code
I refactor some code,the mainly about the new java version,
the other about some style or performance.
---Make progress every day!
---
src/test/groovy/bugs/Groovy2365Bug.java | 38 ++++++++++------------
.../groovy/classgen/ReflectorGeneratorTest.java | 4 +--
.../asm/sc/bugs/support/Groovy7538Support.java | 4 ++-
.../codehaus/groovy/tools/TestDgmConverter.java | 6 +---
4 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/test/groovy/bugs/Groovy2365Bug.java b/src/test/groovy/bugs/Groovy2365Bug.java
index b70aeec..f9350fc 100644
--- a/src/test/groovy/bugs/Groovy2365Bug.java
+++ b/src/test/groovy/bugs/Groovy2365Bug.java
@@ -46,30 +46,26 @@ public class Groovy2365Bug extends Groovy2365Base {
// thread one: newInstance script foo
final boolean completed [] = new boolean[2] ;
- Thread thread1 = new Thread() {
- public void run() {
- try {
- Script script = (Script) script1Class.getDeclaredConstructor().newInstance();
- script.run();
- completed [0] = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
+ Thread thread1 = new Thread(() -> {
+ try {
+ Script script = (Script) script1Class.getDeclaredConstructor().newInstance();
+ script.run();
+ completed [0] = true;
+ } catch (Exception e) {
+ e.printStackTrace();
}
- };
+ });
- Thread thread2 = new Thread() {
- public void run() {
- try {
- Class cls = groovyLoader.loadClass("Script2", true, true);
- Script script = (Script) cls.getDeclaredConstructor().newInstance();
- script.run();
- completed [1] = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
+ Thread thread2 = new Thread(() -> {
+ try {
+ Class cls = groovyLoader.loadClass("Script2", true, true);
+ Script script = (Script) cls.getDeclaredConstructor().newInstance();
+ script.run();
+ completed [1] = true;
+ } catch (Exception e) {
+ e.printStackTrace();
}
- };
+ });
// let's see if we get a deadlock
thread2.start();
diff --git a/src/test/org/codehaus/groovy/classgen/ReflectorGeneratorTest.java b/src/test/org/codehaus/groovy/classgen/ReflectorGeneratorTest.java
index 7bc8ee8..c0d16ac 100644
--- a/src/test/org/codehaus/groovy/classgen/ReflectorGeneratorTest.java
+++ b/src/test/org/codehaus/groovy/classgen/ReflectorGeneratorTest.java
@@ -31,9 +31,7 @@ class A_GroovyReflector {
CachedMethod m = CachedMethod.find(A.class.getDeclaredMethod("protectedMethod", new Class [0] ));
Object[] arguments = new Object[0];
m.setAccessible().invoke(new A(), arguments);
- } catch (NoSuchMethodException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
}
}
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7538Support.java b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7538Support.java
index 0ee598c..d1f42ff 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7538Support.java
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7538Support.java
@@ -18,6 +18,8 @@
*/
package org.codehaus.groovy.classgen.asm.sc.bugs.support;
+import java.util.Objects;
+
/*
* Test classes extracted and adapted from the AssertJ project.
*/
@@ -85,7 +87,7 @@ public class Groovy7538Support {
}
private static boolean equal(Object actual, Object other) {
- return (actual == other) || (actual != null && actual.equals(other));
+ return Objects.equals(actual, other);
}
}
diff --git a/src/test/org/codehaus/groovy/tools/TestDgmConverter.java b/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
index 393d7d6..26fadf3 100644
--- a/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
+++ b/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
@@ -52,11 +52,7 @@ public class TestDgmConverter extends TestCase {
final MetaMethod metaMethod = (MetaMethod) constructor.newInstance(null,null, null, null);
} catch (ClassNotFoundException e) {
fail("Failed to load " + className);
- } catch (IllegalAccessException e) {
- fail("Failed to instantiate " + className);
- } catch (InstantiationException e) {
- fail("Failed to instantiate " + className);
- } catch (InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) {
fail("Failed to instantiate " + className);
}
}