use of org.objectweb.asm.AnnotationVisitor in project groovy-core by groovy.
the class AsmClassGenerator method visitArrayAttributes.
private void visitArrayAttributes(AnnotationNode an, Map<String, ListExpression> arrayAttr, AnnotationVisitor av) {
if (arrayAttr.isEmpty())
return;
for (Map.Entry entry : arrayAttr.entrySet()) {
AnnotationVisitor av2 = av.visitArray((String) entry.getKey());
List<Expression> values = ((ListExpression) entry.getValue()).getExpressions();
if (!values.isEmpty()) {
int arrayElementType = determineCommonArrayType(values);
for (Expression exprChild : values) {
visitAnnotationArrayElement(exprChild, arrayElementType, av2);
}
}
av2.visitEnd();
}
}
use of org.objectweb.asm.AnnotationVisitor in project groovy-core by groovy.
the class AsmClassGenerator method visitAnnotationDefaultExpression.
void visitAnnotationDefaultExpression(AnnotationVisitor av, ClassNode type, Expression exp) {
if (exp instanceof ClosureExpression) {
ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) exp, ACC_PUBLIC);
Type t = Type.getType(BytecodeHelper.getTypeDescription(closureClass));
av.visit(null, t);
} else if (type.isArray()) {
ListExpression list = (ListExpression) exp;
AnnotationVisitor avl = av.visitArray(null);
ClassNode componentType = type.getComponentType();
for (Expression lExp : list.getExpressions()) {
visitAnnotationDefaultExpression(avl, componentType, lExp);
}
} else if (ClassHelper.isPrimitiveType(type) || type.equals(ClassHelper.STRING_TYPE)) {
ConstantExpression constExp = (ConstantExpression) exp;
av.visit(null, constExp.getValue());
} else if (ClassHelper.CLASS_Type.equals(type)) {
ClassNode clazz = exp.getType();
Type t = Type.getType(BytecodeHelper.getTypeDescription(clazz));
av.visit(null, t);
} else if (type.isDerivedFrom(ClassHelper.Enum_Type)) {
PropertyExpression pExp = (PropertyExpression) exp;
ClassExpression cExp = (ClassExpression) pExp.getObjectExpression();
String desc = BytecodeHelper.getTypeDescription(cExp.getType());
String name = pExp.getPropertyAsString();
av.visitEnum(null, desc, name);
} else if (type.implementsInterface(ClassHelper.Annotation_TYPE)) {
AnnotationConstantExpression avExp = (AnnotationConstantExpression) exp;
AnnotationNode value = (AnnotationNode) avExp.getValue();
AnnotationVisitor avc = av.visitAnnotation(null, BytecodeHelper.getTypeDescription(avExp.getType()));
visitAnnotationAttributes(value, avc);
} else {
throw new GroovyBugError("unexpected annotation type " + type.getName());
}
av.visitEnd();
}
use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.
the class ApiMemberSelector method visitAnnotationValue.
private void visitAnnotationValue(AnnotationVisitor annotationVisitor, AnnotationValue<?> value) {
String name = value.getName();
if (value instanceof EnumAnnotationValue) {
annotationVisitor.visitEnum(name, ((EnumAnnotationValue) value).getTypeDesc(), (String) value.getValue());
} else if (value instanceof SimpleAnnotationValue) {
annotationVisitor.visit(name, value.getValue());
} else if (value instanceof ArrayAnnotationValue) {
AnnotationVisitor arrayVisitor = annotationVisitor.visitArray(name);
AnnotationValue<?>[] values = ((ArrayAnnotationValue) value).getValue();
for (AnnotationValue<?> annotationValue : values) {
visitAnnotationValue(arrayVisitor, annotationValue);
}
arrayVisitor.visitEnd();
} else if (value instanceof AnnotationAnnotationValue) {
AnnotationMember annotation = ((AnnotationAnnotationValue) value).getValue();
AnnotationVisitor annVisitor = annotationVisitor.visitAnnotation(name, annotation.getName());
visitAnnotationValues(annotation, annVisitor);
}
}
use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.
the class ApiMemberSelector method visitAnnotationMembers.
private void visitAnnotationMembers(Set<AnnotationMember> annotationMembers) {
for (AnnotationMember annotation : annotationMembers) {
AnnotationVisitor annotationVisitor = apiMemberAdapter.visitAnnotation(annotation.getName(), annotation.isVisible());
visitAnnotationValues(annotation, annotationVisitor);
}
}
use of org.objectweb.asm.AnnotationVisitor in project gradle by gradle.
the class ApiMemberSelector method visitAnnotationMembers.
private void visitAnnotationMembers(MethodVisitor mv, Set<AnnotationMember> annotationMembers) {
for (AnnotationMember annotation : annotationMembers) {
AnnotationVisitor annotationVisitor;
if (annotation instanceof ParameterAnnotationMember) {
annotationVisitor = mv.visitParameterAnnotation(((ParameterAnnotationMember) annotation).getParameter(), annotation.getName(), annotation.isVisible());
} else {
annotationVisitor = mv.visitAnnotation(annotation.getName(), annotation.isVisible());
}
visitAnnotationValues(annotation, annotationVisitor);
}
}
Aggregations