From 2c65ecb9933d810fd553d84ce938e921e907b6e2 Mon Sep 17 00:00:00 2001 From: Jeroen Frijters Date: Sun, 23 Apr 2006 10:13:17 +0000 Subject: 2006-04-23 Jeroen Frijters * java/lang/Class.java (getEnumConstants): Implemented without delegating to VMClass. * vm/reference/java/lang/VMClass.java (getEnumConstants): Removed. --- ChangeLog | 6 ++++++ java/lang/Class.java | 26 +++++++++++++++++++++- vm/reference/java/lang/VMClass.java | 43 +------------------------------------ 3 files changed, 32 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 69ef416cf..c5da83e67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-04-23 Jeroen Frijters + + * java/lang/Class.java (getEnumConstants): Implemented without + delegating to VMClass. + * vm/reference/java/lang/VMClass.java (getEnumConstants): Removed. + 2006-04-23 Jeroen Frijters * java/lang/ClassLoader.java (definePackage): Added argument to diff --git a/java/lang/Class.java b/java/lang/Class.java index 2152accf3..c5ec1536d 100644 --- a/java/lang/Class.java +++ b/java/lang/Class.java @@ -1374,7 +1374,31 @@ public final class Class */ public T[] getEnumConstants() { - return (T[])VMClass.getEnumConstants(this); + if (isEnum()) + { + try + { + return (T[]) getMethod("values").invoke(null); + } + catch (NoSuchMethodException exception) + { + throw new Error("Enum lacks values() method"); + } + catch (IllegalAccessException exception) + { + throw new Error("Unable to access Enum class"); + } + catch (InvocationTargetException exception) + { + throw new + RuntimeException("The values method threw an exception", + exception); + } + } + else + { + return null; + } } /** diff --git a/vm/reference/java/lang/VMClass.java b/vm/reference/java/lang/VMClass.java index b68a4818e..47a91da8c 100644 --- a/vm/reference/java/lang/VMClass.java +++ b/vm/reference/java/lang/VMClass.java @@ -1,5 +1,5 @@ /* VMClass.java -- VM Specific Class methods - Copyright (C) 2003, 2004, 2005 Free Software Foundation + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation This file is part of GNU Classpath. @@ -41,7 +41,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; @@ -332,46 +331,6 @@ final class VMClass return fullName.substring(fullName.lastIndexOf(".") + 1); } - /** - * Returns the enumeration constants of this class, or - * null if this class is not an Enum. - * - * @param klass the class whose enumeration constants should be returned. - * @return an array of Enum constants - * associated with this class, or null if this - * class is not an enum. - * @since 1.5 - */ - static T[] getEnumConstants(Class klass) - { - if (isEnum(klass)) - { - try - { - return (T[]) - klass.getMethod("values").invoke(null); - } - catch (NoSuchMethodException exception) - { - throw new Error("Enum lacks values() method"); - } - catch (IllegalAccessException exception) - { - throw new Error("Unable to access Enum class"); - } - catch (InvocationTargetException exception) - { - throw new - RuntimeException("The values method threw an exception", - exception); - } - } - else - { - return null; - } - } - /** * Returns all annotations directly defined by the specified class. If * there are no annotations associated with this class, then a zero-length -- cgit v1.2.1