This commit is contained in:
jfrijters 2013-02-22 07:21:22 +00:00
Родитель cdac05f4b4
Коммит ae51a94f51
2 изменённых файлов: 107 добавлений и 10 удалений

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

@ -629,13 +629,54 @@ namespace IKVM.StubGen
public override void Write(BigEndianStream bes)
{
base.Write(bes);
bes.WriteUInt32((uint)(mem.Length + 2));
bes.WriteUInt32(Length);
WriteImpl(bes);
}
internal void WriteImpl(BigEndianStream bes)
{
bes.WriteUInt16(count);
foreach (byte b in mem.ToArray())
{
bes.WriteByte(b);
}
}
internal uint Length
{
get { return (uint)mem.Length + 2; }
}
}
sealed class RuntimeVisibleParameterAnnotationsAttribute : ClassFileAttribute
{
private readonly List<RuntimeVisibleAnnotationsAttribute> parameters = new List<RuntimeVisibleAnnotationsAttribute>();
internal RuntimeVisibleParameterAnnotationsAttribute(ClassFileWriter classFile)
: base(classFile.AddUtf8("RuntimeVisibleParameterAnnotations"))
{
}
internal void Add(RuntimeVisibleAnnotationsAttribute parameter)
{
parameters.Add(parameter);
}
public override void Write(BigEndianStream bes)
{
base.Write(bes);
uint length = 1;
foreach (RuntimeVisibleAnnotationsAttribute attr in parameters)
{
length += attr.Length;
}
bes.WriteUInt32(length);
bes.WriteByte((byte)parameters.Count);
foreach (RuntimeVisibleAnnotationsAttribute attr in parameters)
{
attr.WriteImpl(bes);
}
}
}
sealed class AnnotationDefaultClassFileAttribute : ClassFileAttribute

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

@ -192,6 +192,7 @@ namespace IKVM.StubGen
m.AddAttribute(writer.MakeStringAttribute("Signature", sig));
}
AddAnnotations(writer, m, mw.GetMethod());
AddParameterAnnotations(writer, m, mw.GetMethod());
}
}
bool hasSerialVersionUID = false;
@ -241,28 +242,83 @@ namespace IKVM.StubGen
#if !FIRST_PASS && !STUB_GENERATOR
if (source != null)
{
RuntimeVisibleAnnotationsAttribute annot = null;
RuntimeVisibleAnnotationsAttribute attr = null;
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(source))
{
if (cad.ConstructorArguments.Count == 1 && cad.ConstructorArguments[0].ArgumentType == typeof(object[]) &&
(cad.Constructor.DeclaringType.IsSubclassOf(JVM.Import(typeof(ikvm.@internal.AnnotationAttributeBase)))
|| cad.Constructor.DeclaringType == JVM.Import(typeof(DynamicAnnotationAttribute))))
object[] ann = GetAnnotation(cad);
if (ann != null)
{
if (annot == null)
if (attr == null)
{
annot = new RuntimeVisibleAnnotationsAttribute(writer);
attr = new RuntimeVisibleAnnotationsAttribute(writer);
}
annot.Add(UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value));
attr.Add(UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value));
}
}
if (annot != null)
if (attr != null)
{
target.AddAttribute(annot);
target.AddAttribute(attr);
}
}
#endif
}
private static void AddParameterAnnotations(ClassFileWriter writer, FieldOrMethod target, MethodBase source)
{
#if !FIRST_PASS && !STUB_GENERATOR
if (source != null)
{
RuntimeVisibleParameterAnnotationsAttribute attr = null;
ParameterInfo[] parameters = source.GetParameters();
for (int i = 0; i < parameters.Length; i++)
{
RuntimeVisibleAnnotationsAttribute param = null;
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(parameters[i]))
{
object[] ann = GetAnnotation(cad);
if (ann != null)
{
if (param == null)
{
if (attr == null)
{
attr = new RuntimeVisibleParameterAnnotationsAttribute(writer);
for (int j = 0; j < i; j++)
{
attr.Add(new RuntimeVisibleAnnotationsAttribute(writer));
}
}
param = new RuntimeVisibleAnnotationsAttribute(writer);
}
param.Add(UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value));
}
}
if (attr != null)
{
attr.Add(param ?? new RuntimeVisibleAnnotationsAttribute(writer));
}
}
if (attr != null)
{
target.AddAttribute(attr);
}
}
#endif
}
#if !FIRST_PASS && !STUB_GENERATOR
private static object[] GetAnnotation(CustomAttributeData cad)
{
if (cad.ConstructorArguments.Count == 1 && cad.ConstructorArguments[0].ArgumentType == typeof(object[]) &&
(cad.Constructor.DeclaringType.IsSubclassOf(JVM.Import(typeof(ikvm.@internal.AnnotationAttributeBase)))
|| cad.Constructor.DeclaringType == JVM.Import(typeof(DynamicAnnotationAttribute))))
{
return UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value);
}
return null;
}
#endif
private static object[] UnpackArray(IList<CustomAttributeTypedArgument> list)
{
object[] arr = new object[list.Count];