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/02 20:29:12 UTC
[groovy] branch master updated (eff9a23 -> 2042f6c)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from eff9a23 Add one more test for `with` under STC mode
new b84e9af Fix the hardcoded caller class
new 6bc0645 Fix unchecked warning
new 5694a11 Fix illegal access warning `java.util.Observable.changed`
new bd5b786 Minor refactoring: pull the implementation up to super class
new 727bfb0 Java 8 refactor
new a754cee Minor refactor: remove legacy code
new 2042f6c Java 8 refactor
The 7 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:
src/main/java/groovy/lang/MetaClassImpl.java | 52 +++++++---------------
.../groovy/reflection/ReflectionUtils.java | 27 +++--------
.../org/codehaus/groovy/vmplugin/VMPlugin.java | 10 +++++
.../org/codehaus/groovy/vmplugin/v5/Java5.java | 5 +++
.../org/codehaus/groovy/vmplugin/v7/Selector.java | 2 +-
.../org/codehaus/groovy/vmplugin/v9/Java9.java | 5 +++
src/test/groovy/GroovyMethodsTest.groovy | 9 +++-
7 files changed, 52 insertions(+), 58 deletions(-)
[groovy] 01/07: Fix the hardcoded caller class
Posted by su...@apache.org.
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
commit b84e9af0eb488dba41501c21c42fcf9fdc28c78a
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 00:42:32 2019 +0800
Fix the hardcoded caller class
---
src/main/java/groovy/lang/MetaClassImpl.java | 7 +++----
src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java | 10 ++++++++++
src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java | 5 +++++
src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java | 2 +-
src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 5 +++++
5 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 1443797..e1b00eb 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -80,7 +80,6 @@ import org.codehaus.groovy.util.SingleKeyHashMap;
import org.codehaus.groovy.vmplugin.VMPluginFactory;
import javax.annotation.Nullable;
-
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
@@ -1263,7 +1262,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
}
if (method != null) {
- MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+ MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments));
return transformedMetaMethod.doMethodInvoke(object, arguments);
} else {
return invokePropertyOrMissing(object, methodName, originalArguments, fromInsideClass, isCallToSuper);
@@ -1924,7 +1923,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
//----------------------------------------------------------------------
// executing the getter method
//----------------------------------------------------------------------
- MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+ MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments));
return transformedMetaMethod.doMethodInvoke(object, arguments);
}
@@ -2824,7 +2823,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
arguments[1] = newValue;
}
- MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+ MetaMethod transformedMetaMethod = VMPluginFactory.getPlugin().transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments));
transformedMetaMethod.doMethodInvoke(object, arguments);
return;
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index c0cd3bd..b5118d3 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -103,4 +103,14 @@ public interface VMPlugin {
* @return the transformed meta method
*/
MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller);
+
+ /**
+ * transform meta method.
+ *
+ * @param metaClass meta class
+ * @param metaMethod the original meta method
+ * @param params parameter types
+ * @return the transformed meta method
+ */
+ MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params);
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 1ab516b..ff52fb8 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -591,6 +591,11 @@ public class Java5 implements VMPlugin {
return metaMethod;
}
+ @Override
+ public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params) {
+ return metaMethod;
+ }
+
private static final Permission ACCESS_PERMISSION = new ReflectPermission("suppressAccessChecks");
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
index c686a78..7872c67 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
@@ -634,7 +634,7 @@ public abstract class Selector {
if (metaMethod instanceof CachedMethod) {
if (LOG_ENABLED) LOG.info("meta method is CachedMethod instance");
CachedMethod cm = (CachedMethod) metaMethod;
- cm = (CachedMethod) VMPluginFactory.getPlugin().transformMetaMethod(getMetaClass(), cm, cm.getPT(), Selector.class);
+ cm = (CachedMethod) VMPluginFactory.getPlugin().transformMetaMethod(getMetaClass(), cm, cm.getPT());
isVargs = cm.isVargsMethod();
try {
Method m = cm.getCachedMethod();
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index a1970c9..ab6d335 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -168,6 +168,11 @@ public class Java9 extends Java8 {
}
@Override
+ public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params) {
+ return transformMetaMethod(metaClass, metaMethod, params, ReflectionUtils.getCallingClass());
+ }
+
+ @Override
public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller) {
if (!(metaMethod instanceof CachedMethod)) {
return metaMethod;
[groovy] 04/07: Minor refactoring: pull the implementation up to
super class
Posted by su...@apache.org.
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
commit bd5b786a57bef89b94cab9569ea234ee2099b902
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 01:25:49 2019 +0800
Minor refactoring: pull the implementation up to super class
---
src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java | 2 +-
src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index ff52fb8..08bee6e 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -593,7 +593,7 @@ public class Java5 implements VMPlugin {
@Override
public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params) {
- return metaMethod;
+ return transformMetaMethod(metaClass, metaMethod, params, null);
}
private static final Permission ACCESS_PERMISSION = new ReflectPermission("suppressAccessChecks");
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index ab6d335..b067add 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -50,6 +50,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -168,11 +169,6 @@ public class Java9 extends Java8 {
}
@Override
- public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params) {
- return transformMetaMethod(metaClass, metaMethod, params, ReflectionUtils.getCallingClass());
- }
-
- @Override
public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller) {
if (!(metaMethod instanceof CachedMethod)) {
return metaMethod;
@@ -190,6 +186,10 @@ public class Java9 extends Java8 {
int methodModifiers = cachedMethod.getModifiers();
+ if (null == caller) {
+ caller = Objects.requireNonNull(ReflectionUtils.getCallingClass(), "Failed to get caller class");
+ }
+
// if caller can access the method,
// no need to transform the meta method
if (checkAccessible(caller, declaringClass, methodModifiers, false)) {
[groovy] 06/07: Minor refactor: remove legacy code
Posted by su...@apache.org.
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
commit a754ceea44b02d6844cb88d9f863db350c7f4a9a
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 04:15:55 2019 +0800
Minor refactor: remove legacy code
---
.../codehaus/groovy/reflection/ReflectionUtils.java | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index 64ec613..4a5fd6c 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -56,7 +56,11 @@ public class ReflectionUtils {
IGNORED_PACKAGES.add("sun.reflect");
IGNORED_PACKAGES.add("java.security");
IGNORED_PACKAGES.add("java.lang.invoke");
+ IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v5");
+ IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v6");
IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v7");
+ IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v8");
+ IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v9");
}
private static final ClassContextHelper HELPER = new ClassContextHelper();
@@ -113,19 +117,10 @@ public class ReflectionUtils {
int depth = 0;
try {
Class c;
- // this super class stuff is for Java 1.4 support only
- // it isn't needed on a 5.0 VM
- Class sc;
do {
do {
c = classContext[depth++];
- if (c != null) {
- sc = c.getSuperclass();
- } else {
- sc = null;
- }
- } while (classShouldBeIgnored(c, extraIgnoredPackages)
- || superClassShouldBeIgnored(sc));
+ } while (classShouldBeIgnored(c, extraIgnoredPackages));
} while (c != null && matchLevel-- > 0 && depth<classContext.length);
return c;
} catch (Throwable t) {
@@ -213,10 +208,6 @@ public class ReflectionUtils {
}
}
- private static boolean superClassShouldBeIgnored(Class sc) {
- return ((sc != null) && (sc.getPackage() != null) && "org.codehaus.groovy.runtime.callsite".equals(sc.getPackage().getName()));
- }
-
private static boolean classShouldBeIgnored(Class c, Collection<String> extraIgnoredPackages) {
return ((c != null)
&& (c.isSynthetic()
[groovy] 07/07: 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2042f6c2cc38114acf7e27d7dfda3b34389d5903
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 04:28:53 2019 +0800
Java 8 refactor
---
src/main/java/groovy/lang/MetaClassImpl.java | 45 +++++++++-------------------
1 file changed, 14 insertions(+), 31 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index e1b00eb..8cee0f2 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -82,7 +82,6 @@ import org.codehaus.groovy.vmplugin.VMPluginFactory;
import javax.annotation.Nullable;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
-import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
@@ -1626,14 +1625,12 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
CachedConstructor constructor = createCachedConstructor(arguments);
List l = new ArrayList(constructors.toList());
- Comparator comp = new Comparator() {
- public int compare(Object arg0, Object arg1) {
- CachedConstructor c0 = (CachedConstructor) arg0;
- CachedConstructor c1 = (CachedConstructor) arg1;
- String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes());
- String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes());
- return descriptor0.compareTo(descriptor1);
- }
+ Comparator comp = (arg0, arg1) -> {
+ CachedConstructor c0 = (CachedConstructor) arg0;
+ CachedConstructor c1 = (CachedConstructor) arg1;
+ String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes());
+ String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes());
+ return descriptor0.compareTo(descriptor1);
};
Collections.sort(l, comp);
int found = -1;
@@ -3404,17 +3401,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
// introspect
try {
if (isBeanDerivative(theClass)) {
- info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws IntrospectionException {
- return Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO);
- }
- });
+ info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO));
} else {
- info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws IntrospectionException {
- return Introspector.getBeanInfo(theClass);
- }
- });
+ info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass));
}
} catch (PrivilegedActionException pae) {
throw new GroovyRuntimeException("exception during bean introspection", pae.getException());
@@ -3914,21 +3903,15 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
metaMethodIndex.clearCaches();
}
- private static final SingleKeyHashMap.Copier NAME_INDEX_COPIER = new SingleKeyHashMap.Copier() {
- public Object copy(Object value) {
- if (value instanceof FastArray) {
- return ((FastArray) value).copy();
- } else {
- return value;
- }
+ private static final SingleKeyHashMap.Copier NAME_INDEX_COPIER = value -> {
+ if (value instanceof FastArray) {
+ return ((FastArray) value).copy();
+ } else {
+ return value;
}
};
- private static final SingleKeyHashMap.Copier METHOD_INDEX_COPIER = new SingleKeyHashMap.Copier() {
- public Object copy(Object value) {
- return SingleKeyHashMap.copy(new SingleKeyHashMap(false), (SingleKeyHashMap) value, NAME_INDEX_COPIER);
- }
- };
+ private static final SingleKeyHashMap.Copier METHOD_INDEX_COPIER = value -> SingleKeyHashMap.copy(new SingleKeyHashMap(false), (SingleKeyHashMap) value, NAME_INDEX_COPIER);
static class MethodIndex extends Index {
public MethodIndex(boolean b) {
[groovy] 03/07: Fix illegal access warning
`java.util.Observable.changed`
Posted by su...@apache.org.
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
commit 5694a1187252dfb91379b1ed634c191abbc6a4f4
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Nov 1 23:49:45 2019 +0800
Fix illegal access warning `java.util.Observable.changed`
---
src/test/groovy/GroovyMethodsTest.groovy | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/test/groovy/GroovyMethodsTest.groovy b/src/test/groovy/GroovyMethodsTest.groovy
index fcbf3dd..0c9d5d3 100644
--- a/src/test/groovy/GroovyMethodsTest.groovy
+++ b/src/test/groovy/GroovyMethodsTest.groovy
@@ -99,9 +99,14 @@ class GroovyMethodsTest extends GroovyTestCase {
void testAsCoercionInterface() {
def letters = ['a', 'b', 'c']
def ol = new ObserverLike()
- def o = new Observable()
+ def o = new Observable() {
+ @Override
+ synchronized void setChanged() {
+ super.setChanged()
+ }
+ }
o.addObserver(ol as Observer) // addObserver takes Observer as param
- letters.each{ o.changed = true; o.notifyObservers(it) }
+ letters.each{ o.setChanged(); o.notifyObservers(it) }
assert ol.observed == letters
}
[groovy] 02/07: Fix unchecked warning
Posted by su...@apache.org.
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
commit 6bc06451208f72abed26ef1d2d17ee8b83a061d6
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 00:50:28 2019 +0800
Fix unchecked warning
---
src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index f530129..0b8200f 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -93,7 +93,7 @@ public class ReflectionUtils {
* enough stackframes to satisfy matchLevel
*/
public static Class getCallingClass(int matchLevel) {
- return getCallingClass(matchLevel, Collections.EMPTY_SET);
+ return getCallingClass(matchLevel, Collections.emptySet());
}
/**
[groovy] 05/07: 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 727bfb0d913efee4233c439ce8de0eea3913fea4
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 01:42:19 2019 +0800
Java 8 refactor
---
src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index 0b8200f..64ec613 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -184,11 +184,7 @@ public class ReflectionUtils {
}
public static Optional<AccessibleObject> makeAccessibleInPrivilegedAction(final AccessibleObject ao) {
- return AccessController.doPrivileged(new PrivilegedAction<Optional<AccessibleObject>>() {
- public Optional<AccessibleObject> run() {
- return makeAccessible(ao);
- }
- });
+ return AccessController.doPrivileged((PrivilegedAction<Optional<AccessibleObject>>) () -> makeAccessible(ao));
}
// to be run in PrivilegedAction!