use of org.objectweb.asm.AnnotationVisitor in project drill by apache.
the class CheckMethodVisitorFsm method visitParameterAnnotation.
@Override
public AnnotationVisitor visitParameterAnnotation(final int parameter, final String desc, final boolean visible) {
fsmCursor.transition("visitParameterAnnotation");
final AnnotationVisitor annotationVisitor = super.visitParameterAnnotation(parameter, desc, visible);
// TODO: add CheckAnnotationVisitorFsm
return annotationVisitor;
}
use of org.objectweb.asm.AnnotationVisitor in project groovy by apache.
the class AsmClassGenerator method visitAnnotationAttributes.
/**
* Generate the annotation attributes.
* @param an the node with an annotation
* @param av the visitor to use
*/
private void visitAnnotationAttributes(AnnotationNode an, AnnotationVisitor av) {
Map<String, Object> constantAttrs = new HashMap<String, Object>();
Map<String, PropertyExpression> enumAttrs = new HashMap<String, PropertyExpression>();
Map<String, Object> atAttrs = new HashMap<String, Object>();
Map<String, ListExpression> arrayAttrs = new HashMap<String, ListExpression>();
for (String name : an.getMembers().keySet()) {
Expression expr = an.getMember(name);
if (expr instanceof AnnotationConstantExpression) {
atAttrs.put(name, ((AnnotationConstantExpression) expr).getValue());
} else if (expr instanceof ConstantExpression) {
constantAttrs.put(name, ((ConstantExpression) expr).getValue());
} else if (expr instanceof ClassExpression) {
constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription((expr.getType()))));
} else if (expr instanceof PropertyExpression) {
enumAttrs.put(name, (PropertyExpression) expr);
} else if (expr instanceof ListExpression) {
arrayAttrs.put(name, (ListExpression) expr);
} else if (expr instanceof ClosureExpression) {
ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) expr, ACC_PUBLIC);
constantAttrs.put(name, Type.getType(BytecodeHelper.getTypeDescription(closureClass)));
}
}
for (Map.Entry entry : constantAttrs.entrySet()) {
av.visit((String) entry.getKey(), entry.getValue());
}
for (Map.Entry entry : enumAttrs.entrySet()) {
PropertyExpression propExp = (PropertyExpression) entry.getValue();
av.visitEnum((String) entry.getKey(), BytecodeHelper.getTypeDescription(propExp.getObjectExpression().getType()), String.valueOf(((ConstantExpression) propExp.getProperty()).getValue()));
}
for (Map.Entry entry : atAttrs.entrySet()) {
AnnotationNode atNode = (AnnotationNode) entry.getValue();
AnnotationVisitor av2 = av.visitAnnotation((String) entry.getKey(), BytecodeHelper.getTypeDescription(atNode.getClassNode()));
visitAnnotationAttributes(atNode, av2);
av2.visitEnd();
}
visitArrayAttributes(an, arrayAttrs, av);
}
use of org.objectweb.asm.AnnotationVisitor in project groovy by apache.
the class AsmClassGenerator method visitClass.
// GroovyClassVisitor interface
//-------------------------------------------------------------------------
public void visitClass(ClassNode classNode) {
referencedClasses.clear();
WriterControllerFactory factory = (WriterControllerFactory) classNode.getNodeMetaData(WriterControllerFactory.class);
WriterController normalController = new WriterController();
if (factory != null) {
this.controller = factory.makeController(normalController);
} else {
this.controller = normalController;
}
this.controller.init(this, context, cv, classNode);
if (controller.shouldOptimizeForInt() || factory != null) {
OptimizingStatementWriter.setNodeMeta(controller.getTypeChooser(), classNode);
}
try {
cv.visit(controller.getBytecodeVersion(), adjustedClassModifiersForClassWriting(classNode), controller.getInternalClassName(), BytecodeHelper.getGenericsSignature(classNode), controller.getInternalBaseClassName(), BytecodeHelper.getClassInternalNames(classNode.getInterfaces()));
cv.visitSource(sourceFile, null);
if (classNode instanceof InnerClassNode) {
InnerClassNode innerClass = (InnerClassNode) classNode;
MethodNode enclosingMethod = innerClass.getEnclosingMethod();
if (enclosingMethod != null) {
String outerClassName = BytecodeHelper.getClassInternalName(innerClass.getOuterClass().getName());
cv.visitOuterClass(outerClassName, enclosingMethod.getName(), BytecodeHelper.getMethodDescriptor(enclosingMethod));
}
}
if (classNode.getName().endsWith("package-info")) {
PackageNode packageNode = classNode.getPackage();
if (packageNode != null) {
// pull them out of package node but treat them like they were on class node
for (AnnotationNode an : packageNode.getAnnotations()) {
// skip built-in properties
if (an.isBuiltIn())
continue;
if (an.hasSourceRetention())
continue;
AnnotationVisitor av = getAnnotationVisitor(classNode, an, cv);
visitAnnotationAttributes(an, av);
av.visitEnd();
}
}
cv.visitEnd();
return;
} else {
visitAnnotations(classNode, cv);
}
if (classNode.isInterface()) {
ClassNode owner = classNode;
if (owner instanceof InnerClassNode) {
owner = owner.getOuterClass();
}
String outerClassName = classNode.getName();
String name = outerClassName + "$" + context.getNextInnerClassIdx();
controller.setInterfaceClassLoadingClass(new InterfaceHelperClassNode(owner, name, ACC_SUPER | ACC_SYNTHETIC | ACC_STATIC, ClassHelper.OBJECT_TYPE, controller.getCallSiteWriter().getCallSites()));
super.visitClass(classNode);
createInterfaceSyntheticStaticFields();
} else {
super.visitClass(classNode);
MopWriter.Factory mopWriterFactory = classNode.getNodeMetaData(MopWriter.Factory.class);
if (mopWriterFactory == null) {
mopWriterFactory = MopWriter.FACTORY;
}
MopWriter mopWriter = mopWriterFactory.create(controller);
mopWriter.createMopMethods();
controller.getCallSiteWriter().generateCallSiteArray();
createSyntheticStaticFields();
}
// GROOVY-6750 and GROOVY-6808
for (Iterator<InnerClassNode> iter = classNode.getInnerClasses(); iter.hasNext(); ) {
InnerClassNode innerClass = iter.next();
makeInnerClassEntry(innerClass);
}
makeInnerClassEntry(classNode);
cv.visitEnd();
} catch (GroovyRuntimeException e) {
e.setModule(classNode.getModule());
throw e;
} catch (NegativeArraySizeException nase) {
throw new GroovyRuntimeException("NegativeArraySizeException while processing " + sourceFile, nase);
} catch (NullPointerException npe) {
throw new GroovyRuntimeException("NPE while processing " + sourceFile, npe);
}
}
use of org.objectweb.asm.AnnotationVisitor in project groovy by apache.
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()) {
AnnotationVisitor avl = av.visitArray(null);
ClassNode componentType = type.getComponentType();
if (exp instanceof ListExpression) {
ListExpression list = (ListExpression) exp;
for (Expression lExp : list.getExpressions()) {
visitAnnotationDefaultExpression(avl, componentType, lExp);
}
} else {
visitAnnotationDefaultExpression(avl, componentType, exp);
}
} 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 groovy by apache.
the class AsmClassGenerator method visitAnnotations.
private void visitAnnotations(AnnotatedNode targetNode, Object visitor) {
for (AnnotationNode an : targetNode.getAnnotations()) {
// skip built-in properties
if (an.isBuiltIn())
continue;
if (an.hasSourceRetention())
continue;
AnnotationVisitor av = getAnnotationVisitor(targetNode, an, visitor);
visitAnnotationAttributes(an, av);
av.visitEnd();
}
}
Aggregations