git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@206 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -56,12 +56,12 @@ class AnnotationImpl implements InvocationHandler { | |||
String name = method.getName(); | |||
MemberValue mv = annotation.getMemberValue(name); | |||
if (mv == null) | |||
return getDefault(name); | |||
return getDefault(name, method); | |||
else | |||
return mv.getValue(classLoader, pool); | |||
return mv.getValue(classLoader, pool, method); | |||
} | |||
private Object getDefault(String name) | |||
private Object getDefault(String name, Method method) | |||
throws ClassNotFoundException, RuntimeException | |||
{ | |||
String classname = annotation.getTypeName(); | |||
@@ -76,7 +76,7 @@ class AnnotationImpl implements InvocationHandler { | |||
minfo.getAttribute(AnnotationDefaultAttribute.tag); | |||
if (ainfo != null) { | |||
MemberValue mv = ainfo.getDefaultValue(); | |||
return mv.getValue(classLoader, pool); | |||
return mv.getValue(classLoader, pool, method); | |||
} | |||
} | |||
} |
@@ -17,6 +17,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Nested annotation. | |||
@@ -43,7 +44,7 @@ public class AnnotationMemberValue extends MemberValue { | |||
value = a; | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) | |||
throws ClassNotFoundException | |||
{ | |||
return AnnotationImpl.make(cl, getType(cl), cp, value); |
@@ -18,6 +18,7 @@ import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Array; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Array member. | |||
@@ -49,14 +50,27 @@ public class ArrayMemberValue extends MemberValue { | |||
values = null; | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) throws ClassNotFoundException { | |||
if (type == null || values == null) | |||
throw new ClassNotFoundException("no array elements specified"); | |||
Object getValue(ClassLoader cl, ClassPool cp, Method method) | |||
throws ClassNotFoundException | |||
{ | |||
if (values == null) | |||
throw new ClassNotFoundException( | |||
"no array elements found: " + method.getName()); | |||
int size = values.length; | |||
Object a = Array.newInstance(type.getType(cl), size); | |||
Class clazz; | |||
if (type == null) { | |||
clazz = method.getReturnType().getComponentType(); | |||
if (clazz == null || size > 0) | |||
throw new ClassNotFoundException("broken array type: " | |||
+ method.getName()); | |||
} | |||
else | |||
clazz = type.getType(cl); | |||
Object a = Array.newInstance(clazz, size); | |||
for (int i = 0; i < size; i++) | |||
Array.set(a, i, values[i].getValue(cl, cp)); | |||
Array.set(a, i, values[i].getValue(cl, cp, method)); | |||
return a; | |||
} |
@@ -17,6 +17,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Boolean constant value. | |||
@@ -56,7 +57,7 @@ public class BooleanMemberValue extends MemberValue { | |||
setValue(false); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Boolean(getValue()); | |||
} | |||
@@ -17,6 +17,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Byte constant value. | |||
@@ -56,7 +57,7 @@ public class ByteMemberValue extends MemberValue { | |||
setValue((byte)0); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Byte(getValue()); | |||
} | |||
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Char constant value. | |||
@@ -57,7 +58,7 @@ public class CharMemberValue extends MemberValue { | |||
setValue('\0'); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Character(getValue()); | |||
} | |||
@@ -19,6 +19,7 @@ import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import javassist.bytecode.Descriptor; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Class value. | |||
@@ -59,7 +60,7 @@ public class ClassMemberValue extends MemberValue { | |||
setValue("java.lang.Class"); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) | |||
throws ClassNotFoundException | |||
{ | |||
return loadClass(cl, getValue()); |
@@ -18,13 +18,14 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Double floating-point number constant value. | |||
* | |||
* @author <a href="mailto:bill@jboss.org">Bill Burke</a> | |||
* @author Shigeru Chiba | |||
* @version $Revision: 1.6 $ | |||
* @version $Revision: 1.7 $ | |||
*/ | |||
public class DoubleMemberValue extends MemberValue { | |||
int valueIndex; | |||
@@ -58,7 +59,7 @@ public class DoubleMemberValue extends MemberValue { | |||
setValue(0.0); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Double(getValue()); | |||
} | |||
@@ -16,6 +16,7 @@ | |||
package javassist.bytecode.annotation; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
@@ -54,7 +55,7 @@ public class EnumMemberValue extends MemberValue { | |||
typeIndex = valueIndex = 0; | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) | |||
throws ClassNotFoundException | |||
{ | |||
try { |
@@ -18,13 +18,14 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Floating-point number constant value. | |||
* | |||
* @author <a href="mailto:bill@jboss.org">Bill Burke</a> | |||
* @author Shigeru Chiba | |||
* @version $Revision: 1.6 $ | |||
* @version $Revision: 1.7 $ | |||
*/ | |||
public class FloatMemberValue extends MemberValue { | |||
int valueIndex; | |||
@@ -58,7 +59,7 @@ public class FloatMemberValue extends MemberValue { | |||
setValue(0.0F); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Float(getValue()); | |||
} | |||
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Integer constant value. | |||
@@ -63,7 +64,7 @@ public class IntegerMemberValue extends MemberValue { | |||
setValue(0); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Integer(getValue()); | |||
} | |||
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Long integer constant value. | |||
@@ -57,7 +58,7 @@ public class LongMemberValue extends MemberValue { | |||
setValue(0L); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Long(getValue()); | |||
} | |||
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* The value of a member declared in an annotation. | |||
@@ -39,7 +40,7 @@ public abstract class MemberValue { | |||
* Returns the value. If the value type is a primitive type, the | |||
* returned value is boxed. | |||
*/ | |||
abstract Object getValue(ClassLoader cl, ClassPool cp) | |||
abstract Object getValue(ClassLoader cl, ClassPool cp, Method m) | |||
throws ClassNotFoundException; | |||
abstract Class getType(ClassLoader cl) throws ClassNotFoundException; |
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* Short integer constant value. | |||
@@ -57,7 +58,7 @@ public class ShortMemberValue extends MemberValue { | |||
setValue((short)0); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return new Short(getValue()); | |||
} | |||
@@ -18,6 +18,7 @@ package javassist.bytecode.annotation; | |||
import javassist.ClassPool; | |||
import javassist.bytecode.ConstPool; | |||
import java.io.IOException; | |||
import java.lang.reflect.Method; | |||
/** | |||
* String constant value. | |||
@@ -57,7 +58,7 @@ public class StringMemberValue extends MemberValue { | |||
setValue(""); | |||
} | |||
Object getValue(ClassLoader cl, ClassPool cp) { | |||
Object getValue(ClassLoader cl, ClassPool cp, Method m) { | |||
return getValue(); | |||
} | |||