зеркало из https://github.com/mono/ikvm-fork.git
Add parameter annotations.
This commit is contained in:
Родитель
cdac05f4b4
Коммит
ae51a94f51
|
@ -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,27 +242,82 @@ namespace IKVM.StubGen
|
|||
#if !FIRST_PASS && !STUB_GENERATOR
|
||||
if (source != null)
|
||||
{
|
||||
RuntimeVisibleAnnotationsAttribute annot = null;
|
||||
RuntimeVisibleAnnotationsAttribute attr = null;
|
||||
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(source))
|
||||
{
|
||||
object[] ann = GetAnnotation(cad);
|
||||
if (ann != null)
|
||||
{
|
||||
if (attr == null)
|
||||
{
|
||||
attr = new RuntimeVisibleAnnotationsAttribute(writer);
|
||||
}
|
||||
attr.Add(UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value));
|
||||
}
|
||||
}
|
||||
if (attr != null)
|
||||
{
|
||||
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))))
|
||||
{
|
||||
if (annot == null)
|
||||
{
|
||||
annot = new RuntimeVisibleAnnotationsAttribute(writer);
|
||||
}
|
||||
annot.Add(UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value));
|
||||
}
|
||||
}
|
||||
if (annot != null)
|
||||
{
|
||||
target.AddAttribute(annot);
|
||||
return UnpackArray((IList<CustomAttributeTypedArgument>)cad.ConstructorArguments[0].Value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static object[] UnpackArray(IList<CustomAttributeTypedArgument> list)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче