|
From: <ls...@us...> - 2007-01-04 20:20:20
|
Revision: 2982
http://jnode.svn.sourceforge.net/jnode/?rev=2982&view=rev
Author: lsantha
Date: 2007-01-04 12:20:19 -0800 (Thu, 04 Jan 2007)
Log Message:
-----------
Various classpath updates.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-01-04 19:48:10 UTC (rev 2981)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-01-04 20:20:19 UTC (rev 2982)
@@ -22,6 +22,7 @@
package java.lang;
import gnu.java.lang.VMClassHelper;
+import gnu.java.lang.reflect.ClassSignatureParser;
import java.io.InputStream;
import java.io.Serializable;
@@ -41,6 +42,8 @@
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Arrays;
import org.jnode.security.JNodePermission;
import org.jnode.vm.SoftByteCodes;
@@ -224,7 +227,12 @@
* @return Class
*/
public final Class< ? super T> getSuperclass() {
- VmType< ? super T> superCls = getLinkedVmClass().getSuperClass();
+ VmType<T> vmType = getLinkedVmClass();
+
+ if(vmType.isPrimitive() || vmType.isInterface())
+ return null;
+
+ VmType< ? super T> superCls = vmType.getSuperClass();
if (superCls != null) {
return superCls.asClass();
} else {
@@ -490,6 +498,50 @@
return null;
}
+ private static final class MethodKey
+ {
+ private String name;
+ private Class[] params;
+ private Class returnType;
+ private int hash;
+
+ MethodKey(Method m)
+ {
+ name = m.getName();
+ params = m.getParameterTypes();
+ returnType = m.getReturnType();
+ hash = name.hashCode() ^ returnType.hashCode();
+ for(int i = 0; i < params.length; i++)
+ {
+ hash ^= params[i].hashCode();
+ }
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o instanceof MethodKey)
+ {
+ MethodKey m = (MethodKey) o;
+ if (m.name.equals(name) && m.params.length == params.length
+ && m.returnType == returnType)
+ {
+ for (int i = 0; i < params.length; i++)
+ {
+ if (m.params[i] != params[i])
+ return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return hash;
+ }
+ }
+
/**
* Gets the method with the given name and argument types declared in this
* class or any of its super-classes.
@@ -525,8 +577,21 @@
*
* @return Method[]
*/
+
public Method[] getMethods() {
if (methods == null) {
+ Method[] a = internalGetMethods();
+ ArrayList<Method> list = new ArrayList<Method>();
+ for(int i = 0; i < a.length; i++){
+ list.add(a[i]);
+ }
+ methods = list;
+ }
+ return methods.toArray(new Method[methods.size()]);
+ }
+ /*
+ public Method[] getMethods() {
+ if (methods == null) {
final ArrayList<Method> list = new ArrayList<Method>();
Class< ? > cls = this;
while (cls != null) {
@@ -539,9 +604,42 @@
methods = list;
}
return (Method[]) methods.toArray(new Method[methods.size()]);
- }
+ }*/
/**
+ * Like <code>getMethods()</code> but without the security checks.
+ */
+ private Method[] internalGetMethods()
+ {
+ HashMap map = new HashMap();
+ Method[] methods;
+ Class[] interfaces = getInterfaces();
+ for(int i = 0; i < interfaces.length; i++)
+ {
+ methods = interfaces[i].internalGetMethods();
+ for(int j = 0; j < methods.length; j++)
+ {
+ map.put(new MethodKey(methods[j]), methods[j]);
+ }
+ }
+ Class superClass = getSuperclass();
+ if(superClass != null)
+ {
+ methods = superClass.internalGetMethods();
+ for(int i = 0; i < methods.length; i++)
+ {
+ map.put(new MethodKey(methods[i]), methods[i]);
+ }
+ }
+ methods = getDeclaredMethods(true);
+ for(int i = 0; i < methods.length; i++)
+ {
+ map.put(new MethodKey(methods[i]), methods[i]);
+ }
+ return (Method[])map.values().toArray(new Method[map.size()]);
+ }
+
+ /**
* Gets the method with the given name and argument types declared in this
* class.
*
@@ -579,25 +677,37 @@
*/
public Method[] getDeclaredMethods() {
if (declaredMethods == null) {
- final VmType<T> vmClass = getLinkedVmClass();
- final int cnt = vmClass.getNoDeclaredMethods();
- int max = 0;
- for (int i = 0; i < cnt; i++) {
- if (!vmClass.getDeclaredMethod(i).isConstructor()) {
- max++;
- }
+ declaredMethods = getDeclaredMethods(false);
+ }
+ return declaredMethods;
+ }
+
+ /**
+ * Gets all methods declared in this class.
+ *
+ * @return Method[]
+ */
+ private Method[] getDeclaredMethods(boolean publicOnly) {
+ final VmType<T> vmClass = getLinkedVmClass();
+ final int cnt = vmClass.getNoDeclaredMethods();
+ int max = 0;
+ for (int i = 0; i < cnt; i++) {
+ VmMethod method = vmClass.getDeclaredMethod(i);
+ if (!method.isConstructor() &&
+ (!publicOnly || method.isPublic())) {
+ max++;
}
- final Method[] list = new Method[max];
- max = 0;
- for (int i = 0; i < cnt; i++) {
- VmMethod vmMethod = vmClass.getDeclaredMethod(i);
- if (!vmMethod.isConstructor()) {
- list[max++] = (Method) vmMethod.asMember();
- }
+ }
+ final Method[] list = new Method[max];
+ max = 0;
+ for (int i = 0; i < cnt; i++) {
+ VmMethod vmMethod = vmClass.getDeclaredMethod(i);
+ if (!vmMethod.isConstructor() &&
+ (!publicOnly || vmMethod.isPublic())) {
+ list[max++] = (Method) vmMethod.asMember();
}
- declaredMethods = list;
}
- return declaredMethods;
+ return list;
}
/**
@@ -952,7 +1062,12 @@
* @see java.lang.reflect.GenericDeclaration#getTypeParameters()
*/
public TypeVariable< ? >[] getTypeParameters() {
- return new TypeVariable[0];
+ String sig = vmClass.getSignature();
+ if (sig == null)
+ return new TypeVariable[0];
+
+ ClassSignatureParser p = new ClassSignatureParser(this, sig);
+ return p.getTypeParameters();
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-05-16 19:09:21
|
Revision: 3203
http://jnode.svn.sourceforge.net/jnode/?rev=3203&view=rev
Author: lsantha
Date: 2007-05-16 12:09:15 -0700 (Wed, 16 May 2007)
Log Message:
-----------
Fixed getFields() and getDeclaredFields().
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-05-13 17:16:52 UTC (rev 3202)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-05-16 19:09:15 UTC (rev 3203)
@@ -61,6 +61,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Arrays;
+import java.util.HashSet;
import org.jnode.security.JNodePermission;
import org.jnode.vm.SoftByteCodes;
@@ -455,28 +456,32 @@
throw new NoSuchFieldException(name);
}
}
-
/**
* Gets all fields declared in this class and all of its super-classes.
- *
+ *
* @return Field[]
*/
- public Field[] getFields() {
- if (fields == null) {
- ArrayList<Field> list = new ArrayList<Field>();
- Class< ? > cls = this;
- while (cls != null) {
- final Field[] dlist = cls.getDeclaredFields();
- for (int i = 0; i < dlist.length; i++) {
- list.add(dlist[i]);
- }
- cls = cls.getSuperclass();
- }
- fields = list;
- }
- return (Field[]) fields.toArray(new Field[fields.size()]);
- }
+ public Field[] getFields()
+ {
+ //todo enable this: memberAccessCheck(Member.PUBLIC);
+ return internalGetFields();
+ }
+ /**
+ * Like <code>getFields()</code> but without the security checks.
+ */
+ private Field[] internalGetFields()
+ {
+ HashSet<Field> set = new HashSet<Field>();
+ set.addAll(Arrays.asList(getDeclaredFields(true)));
+ Class[] interfaces = getInterfaces();
+ for (int i = 0; i < interfaces.length; i++)
+ set.addAll(Arrays.asList(interfaces[i].internalGetFields()));
+ Class superClass = getSuperclass();
+ if (superClass != null)
+ set.addAll(Arrays.asList(superClass.internalGetFields()));
+ return set.toArray(new Field[set.size()]);
+ }
/**
* Gets the field with the given name that is declared in this class.
*
@@ -494,24 +499,44 @@
throw new NoSuchFieldException(name);
}
}
-
/**
* Gets all fields declared in this class
- *
+ *
* @return Field[]
*/
- public Field[] getDeclaredFields() {
- if (declaredFields == null) {
- final VmType<T> vmClass = getLinkedVmClass();
- final int cnt = vmClass.getNoDeclaredFields();
- final Field[] list = new Field[cnt];
+ public Field[] getDeclaredFields()
+ {
+ //todo enable this memberAccessCheck(Member.DECLARED);
+ return getDeclaredFields(false);
+ }
+
+ Field[] getDeclaredFields (boolean publicOnly)
+ {
+ if (declaredFields == null) {
+ final VmType<T> vmClass = getLinkedVmClass();
+ final int cnt = vmClass.getNoDeclaredFields();
+ final ArrayList<Field> fields = new ArrayList<Field>();
for (int i = 0; i < cnt; i++) {
- list[i] = vmClass.getDeclaredField(i).asField();
+ Field field = vmClass.getDeclaredField(i).asField();
+ if(field.getDeclaringClass() == this) {//todo we need this check?
+ fields.add(field);
+ }
}
- declaredFields = list;
+ declaredFields = fields.toArray(new Field[fields.size()]);
+ }
+ if(publicOnly){
+ final ArrayList<Field> fields = new ArrayList<Field>();
+ for (Field field : declaredFields) {
+ if((field.getModifiers() & Modifier.PUBLIC) != 0) {
+ fields.add(field);
+ }
}
- return declaredFields;
- }
+ return fields.toArray(new Field[fields.size()]);
+ } else {
+ //todo fials! return Arrays.copyOf(declaredFields, declaredFields.length);
+ return declaredFields;
+ }
+ }
/**
* Is this class a primitive class?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-10 12:20:13
|
Revision: 3238
http://jnode.svn.sourceforge.net/jnode/?rev=3238&view=rev
Author: lsantha
Date: 2007-06-10 05:20:11 -0700 (Sun, 10 Jun 2007)
Log Message:
-----------
javac integration from openjdk in progress.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-10 12:19:09 UTC (rev 3237)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-10 12:20:11 UTC (rev 3238)
@@ -94,7 +94,7 @@
*
* @serialData Class objects serialize specially:
* <code>TC_CLASS ClassDescriptor</code>. For more serialization information,
- * see {@link ObjectStreamClass}.
+ * see {@link java.io.ObjectStreamClass}.
*
* @author John Keiser
* @author Eric Blake (eb...@em...)
@@ -618,7 +618,7 @@
* @throws NoSuchMethodException
* @throws SecurityException
*/
- public Method getMethod(String name, Class< ? >[] argTypes)
+ public Method getMethod(String name, Class<?>... argTypes)
throws NoSuchMethodException, SecurityException {
VmType< ? >[] vmArgTypes;
if (argTypes == null) {
@@ -1282,4 +1282,40 @@
return "";
return name.substring(0, lastInd);
}
+
+ /**
+ * Returns true if this class is an <code>Annotation</code>.
+ *
+ * @return true if this is an annotation class.
+ * @since 1.5
+ */
+ public boolean isAnnotation()
+ {
+ //todo implement it
+ throw new UnsupportedOperationException();
+ }
+
+ public String getCanonicalName() {
+ //todo implement it
+ throw new UnsupportedOperationException();
+ /*
+ if (vmClass.isArray())
+ {
+ String componentName = vmClass.getComponentType().getCanonicalName();
+ if (componentName != null)
+ return componentName + "[]";
+ }
+ if (vmClass.isMemberClass(klass))
+ {
+ String memberName = getDeclaringClass(klass).getCanonicalName();
+ if (memberName != null)
+ return memberName + "." + getSimpleName(klass);
+ }
+ if (isLocalClass(klass) || vmClass.isAnonymousClass(klass))
+ return null;
+ return getName(klass);
+ */
+ }
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-16 19:26:32
|
Revision: 3246
http://jnode.svn.sourceforge.net/jnode/?rev=3246&view=rev
Author: lsantha
Date: 2007-06-16 12:26:27 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Do not return the system classloader in getClassLoader().
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-12 20:00:46 UTC (rev 3245)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-16 19:26:27 UTC (rev 3246)
@@ -72,6 +72,7 @@
import org.jnode.vm.classmgr.VmField;
import org.jnode.vm.classmgr.VmMethod;
import org.jnode.vm.classmgr.VmType;
+import org.jnode.vm.classmgr.VmClassLoader;
/**
* A Class represents a Java type. There will never be multiple Class
@@ -401,7 +402,8 @@
* @return ClassLoader
*/
public final ClassLoader getClassLoader() {
- return vmClass.getLoader().asClassLoader();
+ VmClassLoader loader = vmClass.getLoader();
+ return loader.isSystemClassLoader() ? null : loader.asClassLoader();
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-17 10:06:24
|
Revision: 3272
http://jnode.svn.sourceforge.net/jnode/?rev=3272&view=rev
Author: lsantha
Date: 2007-06-17 03:06:23 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Improved Java 5 language support.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-17 09:07:11 UTC (rev 3271)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-17 10:06:23 UTC (rev 3272)
@@ -803,7 +803,7 @@
return null;
}
- public Constructor getDeclaredConstructor(Class[] argTypes)
+ public Constructor<T> getDeclaredConstructor(Class<?>... argTypes)
throws NoSuchMethodException {
String signature = Signature.toSignature(null, argTypes);
final VmMethod vmMethod = getLinkedVmClass().getDeclaredMethod(
@@ -925,7 +925,7 @@
* @return Constructor
* @throws NoSuchMethodException
*/
- public Constructor getConstructor(Class[] argTypes)
+ public Constructor<T> getConstructor(Class<?>... argTypes)
throws NoSuchMethodException {
// Check security
memberAccessCheck(Member.PUBLIC);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-25 19:50:28
|
Revision: 3323
http://jnode.svn.sourceforge.net/jnode/?rev=3323&view=rev
Author: lsantha
Date: 2007-06-25 12:50:11 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Openjdk integration.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-25 19:47:44 UTC (rev 3322)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2007-06-25 19:50:11 UTC (rev 3323)
@@ -717,7 +717,7 @@
* @throws NoSuchMethodException
* @throws SecurityException
*/
- public Method getDeclaredMethod(String name, Class< ? >[] argTypes)
+ public Method getDeclaredMethod(String name, Class< ? >... argTypes)
throws NoSuchMethodException, SecurityException {
VmType< ? >[] vmArgTypes;
if (argTypes == null) {
@@ -1319,5 +1319,97 @@
*/
}
+ /**
+ * <p>
+ * Returns a <code>Type</code> object representing the direct superclass,
+ * whether class, interface, primitive type or void, of this class.
+ * If this class is an array class, then a class instance representing
+ * the <code>Object</code> class is returned. If this class is primitive,
+ * an interface, or a representation of either the <code>Object</code>
+ * class or void, then <code>null</code> is returned.
+ * </p>
+ * <p>
+ * If the superclass is a parameterized type, then the
+ * object returned for this interface reflects the actual type
+ * parameters used in the source code. Type parameters are created
+ * using the semantics specified by the <code>ParameterizedType</code>
+ * interface, and only if an instance has not already been created.
+ * </p>
+ *
+ * @return the superclass of this class.
+ * @throws GenericSignatureFormatError if the generic signature of the
+ * class does not comply with that specified by the Java
+ * Virtual Machine specification, 3rd edition.
+ * @throws TypeNotPresentException if the superclass refers
+ * to a non-existant type.
+ * @throws MalformedParameterizedTypeException if the superclass
+ * refers to a parameterized type that can not be instantiated for
+ * some reason.
+ * @since 1.5
+ * @see java.lang.reflect.ParameterizedType
+ */
+ public Type getGenericSuperclass()
+ {
+ if (isArray())
+ return Object.class;
+ if (isPrimitive() || isInterface() || this == Object.class)
+ return null;
+
+ String sig = vmClass.getSignature();
+ if (sig == null)
+ return getSuperclass();
+
+ ClassSignatureParser p = new ClassSignatureParser(this, sig);
+ return p.getSuperclassType();
+ }
+
+ /**
+ * <p>
+ * Returns an array of <code>Type</code> objects which represent the
+ * interfaces directly implemented by this class or extended by this
+ * interface.
+ * </p>
+ * <p>
+ * If one of the superinterfaces is a parameterized type, then the
+ * object returned for this interface reflects the actual type
+ * parameters used in the source code. Type parameters are created
+ * using the semantics specified by the <code>ParameterizedType</code>
+ * interface, and only if an instance has not already been created.
+ * </p>
+ * <p>
+ * The order of the interfaces in the array matches the order in which
+ * the interfaces are declared. For classes which represent an array,
+ * an array of two interfaces, <code>Cloneable</code> and
+ * <code>Serializable</code>, is always returned, with the objects in
+ * that order. A class representing a primitive type or void always
+ * returns an array of zero size.
+ * </p>
+ *
+ * @return an array of interfaces implemented or extended by this class.
+ * @throws GenericSignatureFormatError if the generic signature of one
+ * of the interfaces does not comply with that specified by the Java
+ * Virtual Machine specification, 3rd edition.
+ * @throws TypeNotPresentException if any of the superinterfaces refers
+ * to a non-existant type.
+ * @throws MalformedParameterizedTypeException if any of the interfaces
+ * refer to a parameterized type that can not be instantiated for
+ * some reason.
+ * @since 1.5
+ * @see java.lang.reflect.ParameterizedType
+ */
+ public Type[] getGenericInterfaces()
+ {
+ if (isPrimitive())
+ return new Type[0];
+
+ String sig = vmClass.getSignature();
+ if (sig == null)
+ return getInterfaces();
+
+ ClassSignatureParser p = new ClassSignatureParser(this, sig);
+ return p.getInterfaceTypes();
+ }
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-04-19 07:20:45
|
Revision: 3977
http://jnode.svn.sourceforge.net/jnode/?rev=3977&view=rev
Author: crawley
Date: 2008-04-19 00:20:43 -0700 (Sat, 19 Apr 2008)
Log Message:
-----------
Fix bug which caused Class.simpleName() to throw a bogus security exception
when called from unprivileged code.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/Class.java
Modified: trunk/core/src/classpath/vm/java/lang/Class.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/Class.java 2008-04-19 03:27:10 UTC (rev 3976)
+++ trunk/core/src/classpath/vm/java/lang/Class.java 2008-04-19 07:20:43 UTC (rev 3977)
@@ -361,7 +361,9 @@
}
static String getSimpleName(Class klass) {
- if (klass.getVmClass().isArray()){
+// if (klass.getVmClass().isArray()){
+ // The above involves a security check that is not appropriate in this context.
+ if (klass.vmClass.isArray()){
return klass.getComponentType().getSimpleName() + "[]";
}
String fullName = klass.getName();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|