- Simplified annotation handling.

- Added support to Class.forName() for assembly qualified Java type names.
This commit is contained in:
jfrijters 2008-02-29 08:03:09 +00:00
Родитель 3460403e1f
Коммит 68e4e912ab
4 изменённых файлов: 82 добавлений и 82 удалений

Просмотреть файл

@ -71,8 +71,6 @@ public final
private transient String signature;
// generic info repository; lazily initialized
private transient ConstructorRepository genericInfo;
private byte[] annotations;
private byte[] parameterAnnotations;
// For non-public members or members in package-private classes,
// it is necessary to perform somewhat expensive security checks.
@ -122,8 +120,8 @@ public final
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations)
byte[] unused1,
byte[] unused2)
{
this.clazz = declaringClass;
this.parameterTypes = parameterTypes;
@ -131,8 +129,6 @@ public final
this.modifiers = modifiers;
this.slot = slot;
this.signature = signature;
this.annotations = annotations;
this.parameterAnnotations = parameterAnnotations;
}
/**
@ -152,8 +148,8 @@ public final
parameterTypes,
exceptionTypes, modifiers, slot,
signature,
annotations,
parameterAnnotations);
null,
null);
res.root = this;
// Might as well eagerly propagate this if already present
res.constructorAccessor = constructorAccessor;
@ -609,11 +605,11 @@ public final
}
byte[] getRawAnnotations() {
return annotations;
return null;
}
byte[] getRawParameterAnnotations() {
return parameterAnnotations;
return null;
}
/**
@ -640,10 +636,7 @@ public final
private synchronized Map<Class, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) {
declaredAnnotations = AnnotationParser.parseAnnotations(
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
declaredAnnotations = Method.getDeclaredAnnotationsImpl(this);
}
return declaredAnnotations;
}
@ -666,14 +659,9 @@ public final
*/
public Annotation[][] getParameterAnnotations() {
int numParameters = parameterTypes.length;
if (parameterAnnotations == null)
Annotation[][] result = Method.getParameterAnnotationsImpl(this);
if (result == null)
return new Annotation[numParameters][0];
Annotation[][] result = AnnotationParser.parseParameterAnnotations(
parameterAnnotations,
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
if (result.length != numParameters) {
Class<?> declaringClass = getDeclaringClass();
if (declaringClass.isEnum() ||

Просмотреть файл

@ -69,7 +69,6 @@ class Field extends AccessibleObject implements Member {
private transient String signature;
// generic info repository; lazily initialized
private transient FieldRepository genericInfo;
private byte[] annotations;
// Cached field accessor created without override
private FieldAccessor fieldAccessor;
// Cached field accessor created with override
@ -118,7 +117,7 @@ class Field extends AccessibleObject implements Member {
int modifiers,
int slot,
String signature,
byte[] annotations)
byte[] unused)
{
this.clazz = declaringClass;
this.name = name;
@ -126,7 +125,6 @@ class Field extends AccessibleObject implements Member {
this.modifiers = modifiers;
this.slot = slot;
this.signature = signature;
this.annotations = annotations;
}
/**
@ -142,7 +140,7 @@ class Field extends AccessibleObject implements Member {
// which implicitly requires that new java.lang.reflect
// objects be fabricated for each reflective call on Class
// objects.)
Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
Field res = new Field(clazz, name, type, modifiers, slot, signature, null);
res.root = this;
// Might as well eagerly propagate this if already present
res.fieldAccessor = fieldAccessor;
@ -1031,11 +1029,10 @@ class Field extends AccessibleObject implements Member {
private synchronized Map<Class, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) {
declaredAnnotations = AnnotationParser.parseAnnotations(
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
declaredAnnotations = getDeclaredAnnotationsImpl();
}
return declaredAnnotations;
}
private native Map<Class, Annotation> getDeclaredAnnotationsImpl();
}

Просмотреть файл

@ -74,9 +74,6 @@ public final
private transient String signature;
// generic info repository; lazily initialized
private transient MethodRepository genericInfo;
//private byte[] annotations;
//private byte[] parameterAnnotations;
//private byte[] annotationDefault;
private volatile MethodAccessor methodAccessor;
// For sharing of MethodAccessors. This branching structure is
// currently only two levels deep (i.e., one root Method and
@ -128,9 +125,9 @@ public final
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations,
byte[] annotationDefault)
byte[] unused1,
byte[] unused2,
byte[] unused3)
{
this.clazz = declaringClass;
this.name = name;
@ -140,9 +137,6 @@ public final
this.modifiers = modifiers;
this.slot = slot;
this.signature = signature;
//this.annotations = annotations;
//this.parameterAnnotations = parameterAnnotations;
//this.annotationDefault = annotationDefault;
}
/**
@ -160,8 +154,7 @@ public final
// objects.)
Method res = new Method(clazz, name, parameterTypes, returnType,
exceptionTypes, modifiers, slot, signature,
null, null, null);
//annotations, parameterAnnotations, annotationDefault);
null, null, null);
res.root = this;
// Might as well eagerly propagate this if already present
res.methodAccessor = methodAccessor;
@ -720,14 +713,12 @@ public final
private synchronized Map<Class, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) {
byte[] annotations = getRawAnnotations();
declaredAnnotations = AnnotationParser.parseAnnotations(
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
declaredAnnotations = getDeclaredAnnotationsImpl(this);
}
return declaredAnnotations;
}
static native Map<Class, Annotation> getDeclaredAnnotationsImpl(Object methodOrConstructor);
/**
* Returns the default value for the annotation member represented by
@ -743,21 +734,7 @@ public final
* default class value.
* @since 1.5
*/
public Object getDefaultValue() {
byte[] annotationDefault = getRawAnnotationDefault();
if (annotationDefault == null)
return null;
Class memberType = AnnotationType.invocationHandlerReturnType(
getReturnType());
Object result = AnnotationParser.parseMemberValue(
memberType, ByteBuffer.wrap(annotationDefault),
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
if (result instanceof sun.reflect.annotation.ExceptionProxy)
throw new AnnotationFormatError("Invalid default: " + this);
return result;
}
public native Object getDefaultValue();
/**
* Returns an array of arrays that represent the annotations on the formal
@ -776,23 +753,16 @@ public final
* @since 1.5
*/
public Annotation[][] getParameterAnnotations() {
byte[] parameterAnnotations = getRawParameterAnnotations();
Annotation[][] result = getParameterAnnotationsImpl(this);
int numParameters = parameterTypes.length;
if (parameterAnnotations == null)
if (result == null)
return new Annotation[numParameters][0];
Annotation[][] result = AnnotationParser.parseParameterAnnotations(
parameterAnnotations,
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass());
if (result.length != numParameters)
throw new java.lang.annotation.AnnotationFormatError(
"Parameter annotations don't match number of parameters");
return result;
}
private native byte[] getRawAnnotations();
private native byte[] getRawParameterAnnotations();
private native byte[] getRawAnnotationDefault();
static native Annotation[][] getParameterAnnotationsImpl(Object methodOrConstructor);
}

Просмотреть файл

@ -1,5 +1,5 @@
/*
Copyright (C) 2007 Jeroen Frijters
Copyright (C) 2007, 2008 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -2635,7 +2635,7 @@ namespace IKVM.NativeCode.java
Type type = Type.GetType(name);
if (type != null)
{
tw = DotNetTypeWrapper.GetWrapperFromDotNetType(type);
tw = ClassLoaderWrapper.GetWrapperFromType(type);
}
if (tw == null)
{
@ -2909,14 +2909,11 @@ namespace IKVM.NativeCode.java
return sig.Replace('.', '/');
}
public static object getDeclaredAnnotationsImpl(object thisClass)
internal static object AnnotationsToMap(object[] objAnn)
{
#if FIRST_PASS
return null;
#else
TypeWrapper wrapper = TypeWrapper.FromClass(thisClass);
wrapper.Finish();
object[] objAnn = wrapper.GetDeclaredAnnotations();
global::java.util.HashMap map = new global::java.util.HashMap();
if (objAnn != null)
{
@ -2925,6 +2922,7 @@ namespace IKVM.NativeCode.java
Annotation a = obj as Annotation;
if (a != null)
{
global::ikvm.@internal.AnnotationAttributeBase.freeze(a);
map.put(a.annotationType(), a);
}
}
@ -2933,6 +2931,17 @@ namespace IKVM.NativeCode.java
#endif
}
public static object getDeclaredAnnotationsImpl(object thisClass)
{
#if FIRST_PASS
return null;
#else
TypeWrapper wrapper = TypeWrapper.FromClass(thisClass);
wrapper.Finish();
return AnnotationsToMap(wrapper.GetDeclaredAnnotations());
#endif
}
#if !FIRST_PASS
internal static IConstantPoolWriter GetConstantPoolWriter(TypeWrapper wrapper)
{
@ -4594,21 +4603,57 @@ namespace IKVM.NativeCode.java
}
}
static class Field
{
public static object getDeclaredAnnotationsImpl(object thisField)
{
FieldWrapper fw = FieldWrapper.FromField(thisField);
return Class.AnnotationsToMap(fw.DeclaringType.GetFieldAnnotations(fw));
}
}
static class Method
{
public static byte[] getRawAnnotations(object thisMethod)
public static object getDeclaredAnnotationsImpl(object methodOrConstructor)
{
return MethodWrapper.FromMethodOrConstructor(thisMethod).GetRawAnnotations();
MethodWrapper mw = MethodWrapper.FromMethodOrConstructor(methodOrConstructor);
return Class.AnnotationsToMap(mw.DeclaringType.GetMethodAnnotations(mw));
}
public static byte[] getRawParameterAnnotations(object thisMethod)
public static object[][] getParameterAnnotationsImpl(object methodOrConstructor)
{
return MethodWrapper.FromMethodOrConstructor(thisMethod).GetRawParameterAnnotations();
#if FIRST_PASS
return null;
#else
MethodWrapper mw = MethodWrapper.FromMethodOrConstructor(methodOrConstructor);
object[][] objAnn = mw.DeclaringType.GetParameterAnnotations(mw);
if (objAnn == null)
{
return null;
}
Annotation[][] ann = new Annotation[objAnn.Length][];
for (int i = 0; i < ann.Length; i++)
{
List<Annotation> list = new List<Annotation>();
foreach (object obj in objAnn[i])
{
Annotation a = obj as Annotation;
if (a != null)
{
global::ikvm.@internal.AnnotationAttributeBase.freeze(a);
list.Add(a);
}
}
ann[i] = list.ToArray();
}
return ann;
#endif
}
public static byte[] getRawAnnotationDefault(object thisMethod)
public static object getDefaultValue(object thisMethod)
{
return MethodWrapper.FromMethodOrConstructor(thisMethod).GetRawAnnotationDefault();
MethodWrapper mw = MethodWrapper.FromMethodOrConstructor(thisMethod);
return mw.DeclaringType.GetAnnotationDefault(mw);
}
}
}