# HG changeset patch # User Doug Simon # Date 1370906230 -7200 # Node ID f3330a4487eb4d59b39206650638272848860503 # Parent 13384d19fec0af8e42d8d97a0dd231365831802a added ResolvedJava[Field|Method].isSynthetic() diff -r 13384d19fec0 -r f3330a4487eb graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java Tue Jun 11 00:00:40 2013 +0200 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java Tue Jun 11 01:17:10 2013 +0200 @@ -132,6 +132,18 @@ } @Test + public void isSyntheticTest() { + for (Map.Entry e : methods.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); + } + for (Map.Entry e : constructors.entrySet()) { + ResolvedJavaMethod m = e.getValue(); + assertEquals(e.getKey().isSynthetic(), m.isSynthetic()); + } + } + + @Test public void canBeStaticallyBoundTest() { for (Map.Entry e : methods.entrySet()) { ResolvedJavaMethod m = e.getValue(); diff -r 13384d19fec0 -r f3330a4487eb graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaField.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaField.java Tue Jun 11 00:00:40 2013 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaField.java Tue Jun 11 01:17:10 2013 +0200 @@ -45,6 +45,11 @@ boolean isInternal(); /** + * Determines if this field is a synthetic field as defined by the Java Language Specification. + */ + boolean isSynthetic(); + + /** * Gets the constant value of this field for a given object, if available. * * @param receiver object from which this field's value is to be read. This value is ignored if diff -r 13384d19fec0 -r f3330a4487eb graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Tue Jun 11 00:00:40 2013 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Tue Jun 11 01:17:10 2013 +0200 @@ -80,6 +80,12 @@ int getModifiers(); /** + * Determines if this method is a synthetic method as defined by the Java Language + * Specification. + */ + boolean isSynthetic(); + + /** * Checks whether this method is a class initializer. * * @return {@code true} if the method is a class initializer diff -r 13384d19fec0 -r f3330a4487eb graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java Tue Jun 11 00:00:40 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java Tue Jun 11 01:17:10 2013 +0200 @@ -160,6 +160,15 @@ } @Override + public boolean isSynthetic() { + Field javaField = toJava(); + if (javaField != null) { + return javaField.isSynthetic(); + } + return false; + } + + @Override public T getAnnotation(Class annotationClass) { Field javaField = toJava(); if (javaField != null) { diff -r 13384d19fec0 -r f3330a4487eb graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Tue Jun 11 00:00:40 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Tue Jun 11 01:17:10 2013 +0200 @@ -332,6 +332,29 @@ } @Override + public boolean isSynthetic() { + if (isConstructor()) { + Constructor javaConstructor = toJavaConstructor(); + return javaConstructor == null ? false : javaConstructor.isSynthetic(); + } + + // Cannot use toJava() as it ignores the return type + HotSpotSignature sig = getSignature(); + JavaType[] sigTypes = MetaUtil.signatureToTypes(sig, null); + HotSpotRuntime runtime = graalRuntime().getRuntime(); + for (Method method : holder.mirror().getDeclaredMethods()) { + if (method.getName().equals(name)) { + if (runtime.lookupJavaType(method.getReturnType()).equals(sig.getReturnType(holder))) { + if (matches(runtime, sigTypes, method.getParameterTypes())) { + return method.isSynthetic(); + } + } + } + } + return false; + } + + @Override public Type[] getGenericParameterTypes() { if (isConstructor()) { Constructor javaConstructor = toJavaConstructor(); @@ -351,6 +374,18 @@ return result; } + private static boolean matches(HotSpotRuntime runtime, JavaType[] sigTypes, Class[] parameterTypes) { + if (parameterTypes.length == sigTypes.length) { + for (int i = 0; i < parameterTypes.length; i++) { + if (!runtime.lookupJavaType(parameterTypes[i]).equals(sigTypes[i])) { + return false; + } + } + return true; + } + return false; + } + private Method toJava() { try { return holder.mirror().getDeclaredMethod(name, signatureToTypes());