diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-04-14 06:50:23 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-04-14 06:50:23 +0000 |
commit | fe67a5ac72d12dd8faf471d1c612492fed829a4b (patch) | |
tree | e63047006842dfddf0388368324211987cc15509 /java/lang | |
parent | 71fa4db0b20e97806bd5b11d96370695112f21b4 (diff) | |
download | classpath-fe67a5ac72d12dd8faf471d1c612492fed829a4b.tar.gz |
2006-04-13 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics-branch from 2006/03/26 to 2006/04/13.
Diffstat (limited to 'java/lang')
-rw-r--r-- | java/lang/Class.java | 8 | ||||
-rw-r--r-- | java/lang/EnumConstantNotPresentException.java | 2 | ||||
-rw-r--r-- | java/lang/StackTraceElement.java | 4 | ||||
-rw-r--r-- | java/lang/Thread.java | 3 | ||||
-rw-r--r-- | java/lang/TypeNotPresentException.java | 3 | ||||
-rw-r--r-- | java/lang/annotation/AnnotationFormatError.java | 1 | ||||
-rw-r--r-- | java/lang/reflect/GenericDeclaration.java | 18 | ||||
-rw-r--r-- | java/lang/reflect/GenericSignatureFormatError.java | 1 | ||||
-rw-r--r-- | java/lang/reflect/MalformedParameterizedTypeException.java | 17 | ||||
-rw-r--r-- | java/lang/reflect/Modifier.java | 34 | ||||
-rw-r--r-- | java/lang/reflect/TypeVariable.java | 50 |
11 files changed, 100 insertions, 41 deletions
diff --git a/java/lang/Class.java b/java/lang/Class.java index af5f3c723..2152accf3 100644 --- a/java/lang/Class.java +++ b/java/lang/Class.java @@ -265,7 +265,7 @@ public final class Class<T> ClassLoader loader = VMClass.getClassLoader(this); // Check if we may get the classloader SecurityManager sm = SecurityManager.current; - if (sm != null) + if (loader != null && sm != null) { // Get the calling classloader ClassLoader cl = VMStackWalker.getCallingClassLoader(); @@ -1139,7 +1139,7 @@ public final class Class<T> } try { - return constructor.newInstance(); + return constructor.newInstance(null); } catch (InvocationTargetException e) { @@ -1302,7 +1302,9 @@ public final class Class<T> */ public T cast(Object obj) { - return (T)VMClass.cast(obj, this); + if (obj != null && ! isInstance(obj)) + throw new ClassCastException(); + return (T) obj; } /** diff --git a/java/lang/EnumConstantNotPresentException.java b/java/lang/EnumConstantNotPresentException.java index 50b0b45b9..4586c372c 100644 --- a/java/lang/EnumConstantNotPresentException.java +++ b/java/lang/EnumConstantNotPresentException.java @@ -48,6 +48,8 @@ package java.lang; */ public class EnumConstantNotPresentException extends RuntimeException { + private static final long serialVersionUID = -6046998521960521108L; + /** * The enum's type. Note that the name is fixed by the * serialization spec. diff --git a/java/lang/StackTraceElement.java b/java/lang/StackTraceElement.java index cf4d1c76f..746dd63db 100644 --- a/java/lang/StackTraceElement.java +++ b/java/lang/StackTraceElement.java @@ -1,5 +1,5 @@ /* StackTraceElement.java -- One function call or call stack element - Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -211,7 +211,7 @@ public final class StackTraceElement implements Serializable } if (methodName != null) sb.append(methodName); - sb.append(" ("); + sb.append("("); if (fileName != null) sb.append(fileName); else diff --git a/java/lang/Thread.java b/java/lang/Thread.java index b4ebd58e4..99c8381aa 100644 --- a/java/lang/Thread.java +++ b/java/lang/Thread.java @@ -1,5 +1,5 @@ /* Thread -- an independent thread of executable code - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation This file is part of GNU Classpath. @@ -1220,4 +1220,5 @@ public class Thread implements Runnable */ private static final long serialVersionUID = 605505746047245783L; } + } diff --git a/java/lang/TypeNotPresentException.java b/java/lang/TypeNotPresentException.java index 3010c968b..65d98457e 100644 --- a/java/lang/TypeNotPresentException.java +++ b/java/lang/TypeNotPresentException.java @@ -58,7 +58,8 @@ package java.lang; public class TypeNotPresentException extends RuntimeException { - + private static final long serialVersionUID = -5101214195716534496L; + /** * Constructs a <code>TypeNotPresentException</code> for * the supplied type. The specified cause <code>Throwable</code> diff --git a/java/lang/annotation/AnnotationFormatError.java b/java/lang/annotation/AnnotationFormatError.java index 40ce3ca10..36f600632 100644 --- a/java/lang/annotation/AnnotationFormatError.java +++ b/java/lang/annotation/AnnotationFormatError.java @@ -49,6 +49,7 @@ package java.lang.annotation; */ public class AnnotationFormatError extends Error { + private static final long serialVersionUID = -4256701562333669892L; /** * Constructs a new <code>AnnotationFormatError</code> diff --git a/java/lang/reflect/GenericDeclaration.java b/java/lang/reflect/GenericDeclaration.java index 0ee7cc4a1..244befd88 100644 --- a/java/lang/reflect/GenericDeclaration.java +++ b/java/lang/reflect/GenericDeclaration.java @@ -38,7 +38,25 @@ exception statement from your version. */ package java.lang.reflect; +/** + * Represents an entity that declares one or more type parameters. + * This includes classes and methods (including constructors). + * + * @author Tom Tromey (tromey@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ public interface GenericDeclaration { + /** + * Returns a <code>TypeVariable</code> object for each type variable + * declared by this entity, in order of declaration. An empty array + * is returned if no type variables are declared. + * + * @return an array of <code>TypeVariable</code> objects. + * @throws GenericSignatureFormatError if the signature format within the + * class file does not conform to that specified in the 3rd edition + * of the Java Virtual Machine Specification. + */ TypeVariable<?>[] getTypeParameters(); } diff --git a/java/lang/reflect/GenericSignatureFormatError.java b/java/lang/reflect/GenericSignatureFormatError.java index ab6928de6..0f09522bc 100644 --- a/java/lang/reflect/GenericSignatureFormatError.java +++ b/java/lang/reflect/GenericSignatureFormatError.java @@ -51,6 +51,7 @@ package java.lang.reflect; public class GenericSignatureFormatError extends ClassFormatError { + private static final long serialVersionUID = 6709919147137911034L; /** * Constructs a new <code>GenericSignatureFormatError</code>. diff --git a/java/lang/reflect/MalformedParameterizedTypeException.java b/java/lang/reflect/MalformedParameterizedTypeException.java index fe53290ec..50ae23000 100644 --- a/java/lang/reflect/MalformedParameterizedTypeException.java +++ b/java/lang/reflect/MalformedParameterizedTypeException.java @@ -38,9 +38,22 @@ exception statement from your version. */ package java.lang.reflect; -/** @since 1.5 */ -public class MalformedParameterizedTypeException extends RuntimeException +/** + * This exception class is thrown when one of the reflection + * methods encountered an invalid parameterized type within + * the metadata of a class. One possible reason for this + * exception being thrown is the specification of too few or + * too many type variables. + * + * @author Tom Tromey (tromey@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MalformedParameterizedTypeException + extends RuntimeException { + private static final long serialVersionUID = -5696557788586220964L; + public MalformedParameterizedTypeException() { } diff --git a/java/lang/reflect/Modifier.java b/java/lang/reflect/Modifier.java index 1799b0d39..45fc4e37e 100644 --- a/java/lang/reflect/Modifier.java +++ b/java/lang/reflect/Modifier.java @@ -173,7 +173,7 @@ public class Modifier static final int SYNTHETIC = 0x1000; /** - * Flag indicating an enum constant. + * Flag indicating an enum constant or an enum class. */ static final int ENUM = 0x4000; @@ -319,42 +319,12 @@ public class Modifier */ static StringBuilder toString(int mod, StringBuilder r) { - if (isPublic(mod)) - r.append("public "); - if (isProtected(mod)) - r.append("protected "); - if (isPrivate(mod)) - r.append("private "); - if (isAbstract(mod)) - r.append("abstract "); - if (isStatic(mod)) - r.append("static "); - if (isFinal(mod)) - r.append("final "); - if (isTransient(mod)) - r.append("transient "); - if (isVolatile(mod)) - r.append("volatile "); - if (isSynchronized(mod)) - r.append("synchronized "); - if (isNative(mod)) - r.append("native "); - if (isStrict(mod)) - r.append("strictfp "); - if (isInterface(mod)) - r.append("interface "); - - // Trim trailing space. - if ((mod & ALL_FLAGS) != 0) - r.setLength(r.length() - 1); + r.append(toString(mod, new StringBuffer())); return r; } /** * Package helper method that can take a StringBuffer. - * This is indeed a duplicate of the method that takes a StringBuilder - * since some runtimes override the given Method, Constructor and Field - * classes that and use a StringBuffer. * @param mod the modifier * @param r the StringBuffer to which the String representation is appended * @return r, with information appended diff --git a/java/lang/reflect/TypeVariable.java b/java/lang/reflect/TypeVariable.java index 5cbd81b80..ec6af69db 100644 --- a/java/lang/reflect/TypeVariable.java +++ b/java/lang/reflect/TypeVariable.java @@ -38,9 +38,59 @@ exception statement from your version. */ package java.lang.reflect; +/** + * <p> + * This is a common interface for all type variables provided by + * the Java language. Instances are created the first time a type + * variable is needed by one of the reflective methods declared in + * this package. + * </p> + * <p> + * Creating a type variable requires resolving the appropriate type. + * This may involve resolving other classes as a side effect (e.g. + * if the type is nested inside other classes). Creation should not + * involve resolving the bounds. Repeated creation has no effect; an + * equivalent instance is returned. Caching is not required, but all + * instances must be <code>equal()</code> to each other. + * </p> + * + * @author Tom Tromey (tromey@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ public interface TypeVariable<T extends GenericDeclaration> extends Type { + + /** + * Returns an array of <code>Type</code> objects which represent the upper + * bounds of this type variable. There is always a default bound of + * <code>Object</code>. Any <code>ParameterizedType</code>s will be + * created as necessary, and other types resolved. + * + * @return an array of <code>Type</code> objects representing the upper + * bounds. + * @throws TypeNotPresentException if any of the bounds refer to a + * non-existant type. + * @throws MalformedParameterizedTypeException if the creation of a + * <code>ParameterizedType</code> fails. + */ Type[] getBounds(); + + + /** + * Returns a representation of the declaration used to declare this + * type variable. + * + * @return the <code>GenericDeclaration</code> object for this type + * variable. + */ T getGenericDeclaration(); + + /** + * Returns the name of the type variable, as written in the source + * code. + * + * @return the name of the type variable. + */ String getName(); } |