private static void AddAnnotations(ClassFileWriter writer, IAttributeOwner target, MemberInfo source) { #if !FIRST_PASS && !STUB_GENERATOR if (source != 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 AddAnnotations(ClassFileWriter writer, IAttributeOwner target, MemberInfo source) { #if !FIRST_PASS && !STUB_GENERATOR #if !WINRT if (source != 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(ann); } } if (attr != null) { target.AddAttribute(attr); } } #else throw new NotImplementedException(); #endif #endif }
private static void AddMetaAnnotations(ClassFileWriter writer, TypeWrapper tw) { DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase attributeAnnotation = tw as DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase; if (attributeAnnotation != null) { // TODO write the annotation directly, instead of going thru the object[] encoding RuntimeVisibleAnnotationsAttribute annot = new RuntimeVisibleAnnotationsAttribute(writer); annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Retention;", "value", new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/RetentionPolicy;", "RUNTIME" } }); AttributeTargets validOn = attributeAnnotation.AttributeTargets; List <object> targets = new List <object>(); targets.Add(AnnotationDefaultAttribute.TAG_ARRAY); if ((validOn & (AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate | AttributeTargets.Assembly)) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "TYPE" }); } if ((validOn & AttributeTargets.Constructor) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "CONSTRUCTOR" }); } if ((validOn & AttributeTargets.Field) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "FIELD" }); } if ((validOn & (AttributeTargets.Method | AttributeTargets.ReturnValue)) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "METHOD" }); } if ((validOn & AttributeTargets.Parameter) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "PARAMETER" }); } annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Target;", "value", targets.ToArray() }); if (IsRepeatableAnnotation(tw)) { annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Repeatable;", "value", new object[] { AnnotationDefaultAttribute.TAG_CLASS, "L" + (tw.Name + DotNetTypeWrapper.AttributeAnnotationMultipleSuffix).Replace('.', '/') + ";" } }); } writer.AddAttribute(annot); } }
private static void AddParameterAnnotations(ClassFileWriter writer, FieldOrMethod target, MethodBase source) { #if !FIRST_PASS && !STUB_GENERATOR #if !WINRT 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(ann); } } if (attr != null) { attr.Add(param ?? new RuntimeVisibleAnnotationsAttribute(writer)); } } if (attr != null) { target.AddAttribute(attr); } } #else throw new NotImplementedException(); #endif #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 }
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(ann); } } if (attr != null) { attr.Add(param ?? new RuntimeVisibleAnnotationsAttribute(writer)); } } if (attr != null) { target.AddAttribute(attr); } } #endif }
private static void AddMetaAnnotations(ClassFileWriter writer, TypeWrapper tw) { DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase attributeAnnotation = tw as DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase; if (attributeAnnotation != null) { // TODO write the annotation directly, instead of going thru the object[] encoding RuntimeVisibleAnnotationsAttribute annot = new RuntimeVisibleAnnotationsAttribute(writer); annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Retention;", "value", new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/RetentionPolicy;", "RUNTIME" } }); AttributeTargets validOn = attributeAnnotation.AttributeTargets; List<object> targets = new List<object>(); targets.Add(AnnotationDefaultAttribute.TAG_ARRAY); if ((validOn & (AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate | AttributeTargets.Assembly)) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "TYPE" }); } if ((validOn & AttributeTargets.Constructor) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "CONSTRUCTOR" }); } if ((validOn & AttributeTargets.Field) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "FIELD" }); } if ((validOn & (AttributeTargets.Method | AttributeTargets.ReturnValue)) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "METHOD" }); } if ((validOn & AttributeTargets.Parameter) != 0) { targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "PARAMETER" }); } annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Target;", "value", targets.ToArray() }); if (Experimental.JDK_8 && IsRepeatableAnnotation(tw)) { annot.Add(new object[] { AnnotationDefaultAttribute.TAG_ANNOTATION, "Ljava/lang/annotation/Repeatable;", "value", new object[] { AnnotationDefaultAttribute.TAG_CLASS, "L" + (tw.Name + DotNetTypeWrapper.AttributeAnnotationMultipleSuffix).Replace('.', '/') + ";" } }); } writer.AddAttribute(annot); } }
private static void AddAnnotations(ClassFileWriter writer, IAttributeOwner target, MemberInfo source) { #if !FIRST_PASS && !STUB_GENERATOR if (source != 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(ann); } } if (attr != null) { target.AddAttribute(attr); } } #endif }
internal void Add(RuntimeVisibleAnnotationsAttribute parameter) { parameters.Add(parameter); }
private static void AddAnnotations(ClassFileWriter writer, IAttributeOwner target, MemberInfo source) { #if !FIRST_PASS && !STUB_GENERATOR if (source != 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 }