From 85fec988d5bc8bbd5aa4bacf17f6b6c6a1ef5292 Mon Sep 17 00:00:00 2001 From: Ilya Mizus Date: Thu, 9 Oct 2014 02:32:56 +0400 Subject: [PATCH] Added Class.getGenericSuperclass() and improved Member subclasses. Fixed Makefile on OS X --- classpath/java/lang/Class.java | 44 +++++++++++++++---- .../java/lang/reflect/AccessibleObject.java | 4 ++ classpath/java/lang/reflect/Field.java | 6 ++- classpath/java/lang/reflect/Member.java | 4 +- classpath/java/lang/reflect/Method.java | 4 +- makefile | 4 +- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/classpath/java/lang/Class.java b/classpath/java/lang/Class.java index db41d78edd..96c880ef72 100644 --- a/classpath/java/lang/Class.java +++ b/classpath/java/lang/Class.java @@ -712,10 +712,10 @@ public final class Class throw new UnsupportedOperationException("not yet implemented"); } - public Type[] getGenericInterfaces() { - if (vmClass.addendum == null || vmClass.addendum.signature == null) { - return getInterfaces(); - } + /** + * The first one is the superclass, the others are interfaces + **/ + private String[] getGenericTypeSignatures() { String signature = Classes.toString((byte[]) vmClass.addendum.signature); final char[] signChars = signature.toCharArray(); @@ -753,13 +753,39 @@ public final class Class } if (curTypeSign.length() > 0) typeSigns.add(curTypeSign.toString()); - // Parsing types, ignoring the first item in the array - // cause it's the base type - Type[] res = new Type[typeSigns.size() - 1]; - for (i = 0; i < typeSigns.size() - 1; i++) { - res[i] = SignatureParser.parse(vmClass.loader, typeSigns.get(i + 1), this); + String[] res = new String[typeSigns.size()]; + return typeSigns.toArray(res); + } + + public Type[] getGenericInterfaces() { + if (vmClass.addendum == null || vmClass.addendum.signature == null) { + return getInterfaces(); + } + + String[] typeSigns = getGenericTypeSignatures(); + if (typeSigns.length < 1) { + throw new RuntimeException("Class signature doesn't contain any type"); + } + + // Parsing types + Type[] res = new Type[typeSigns.length - 1]; + for (int i = 0; i < typeSigns.length - 1; i++) { + res[i] = SignatureParser.parse(vmClass.loader, typeSigns[i + 1], this); } return res; } + + public Type getGenericSuperclass() { + if (vmClass.addendum == null || vmClass.addendum.signature == null) { + return getSuperclass(); + } + String[] typeSigns = getGenericTypeSignatures(); + if (typeSigns.length < 1) { + throw new RuntimeException("Class signature doesn't contain any type"); + } + + return SignatureParser.parse(vmClass.loader, typeSigns[0], this); + } + } diff --git a/classpath/java/lang/reflect/AccessibleObject.java b/classpath/java/lang/reflect/AccessibleObject.java index 33a357de1e..bb4a1fe1db 100644 --- a/classpath/java/lang/reflect/AccessibleObject.java +++ b/classpath/java/lang/reflect/AccessibleObject.java @@ -15,6 +15,10 @@ import java.lang.annotation.Annotation; public abstract class AccessibleObject implements AnnotatedElement { protected static final int Accessible = 1 << 0; + // Access and property flags for Member descendants + protected static final int ACC_VARARGS = 0x0080; + protected static final int ACC_SYNTHETIC = 0x1000; + public boolean isAnnotationPresent (Class class_) { diff --git a/classpath/java/lang/reflect/Field.java b/classpath/java/lang/reflect/Field.java index ae169884bc..c9db3dbeb1 100644 --- a/classpath/java/lang/reflect/Field.java +++ b/classpath/java/lang/reflect/Field.java @@ -17,7 +17,7 @@ import avian.Classes; import java.lang.annotation.Annotation; -public class Field extends AccessibleObject { +public class Field extends AccessibleObject implements Member { private static final int VoidField = 0; private static final int ByteField = 1; private static final int CharField = 2; @@ -51,6 +51,10 @@ public class Field extends AccessibleObject { public int getModifiers() { return vmField.flags; } + + public boolean isSynthetic() { + return (vmField.flags & ACC_SYNTHETIC) != 0; + } public String getName() { return getName(vmField); diff --git a/classpath/java/lang/reflect/Member.java b/classpath/java/lang/reflect/Member.java index a21d231ff0..e6384279a9 100644 --- a/classpath/java/lang/reflect/Member.java +++ b/classpath/java/lang/reflect/Member.java @@ -13,8 +13,8 @@ package java.lang.reflect; public interface Member { public static final int PUBLIC = 0; public static final int DECLARED = 1; - - public Class getDeclaringClass(); + + public Class getDeclaringClass(); public int getModifiers(); diff --git a/classpath/java/lang/reflect/Method.java b/classpath/java/lang/reflect/Method.java index 4c6443e488..10f8e52c17 100644 --- a/classpath/java/lang/reflect/Method.java +++ b/classpath/java/lang/reflect/Method.java @@ -146,11 +146,11 @@ public class Method extends AccessibleObject implements Member { } public boolean isVarArgs() { - return (getModifiers() & 0x80) != 0; + return (getModifiers() & ACC_VARARGS) != 0; } public boolean isSynthetic() { - return (getModifiers() & 0x1000) != 0; + return (getModifiers() & ACC_SYNTHETIC) != 0; } public Object getDefaultValue() { diff --git a/makefile b/makefile index 1bcfb3726b..59fc6eb100 100755 --- a/makefile +++ b/makefile @@ -240,9 +240,7 @@ ifneq ($(android),) -g3 \ -Werror \ -Wno-shift-count-overflow - ifeq ($(platform),macosx) - android-cflags += -Doff64_t=off_t -Dlseek64=lseek - endif + # on Windows (in MinGW-based build) there are neither __BEGIN_DECLS nor __END_DECLS # defines; we don't want to patch every file that uses them, so we stub them in # using CFLAGS mechanism