List of usage examples for org.objectweb.asm.tree FieldNode visitAnnotation
@Override
public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible)
From source file:com.github.antag99.retinazer.weaver.SystemProcessor.java
License:Open Source License
private void processMethod(MethodNode methodNode) { InsnList insns = methodNode.instructions; // Filter out debugging nodes/labels int count = 0; int maxCount = insns.size(); AbstractInsnNode[] nodes = new AbstractInsnNode[maxCount]; for (AbstractInsnNode node = insns.getFirst(); node != null; node = node.getNext()) if (node.getOpcode() > 0) nodes[count++] = node;/*from ww w .j ava2s . com*/ // Find mapper get() calls and create an own flyweight instance for each for (int i = 0; i <= count - 4; i++) { if (!(nodes[i + 0] instanceof VarInsnNode)) continue; if (!(nodes[i + 1] instanceof FieldInsnNode)) continue; if (!(nodes[i + 2] instanceof VarInsnNode)) continue; if (!(nodes[i + 3] instanceof MethodInsnNode)) continue; VarInsnNode loadThis = (VarInsnNode) nodes[i + 0]; FieldInsnNode getField = (FieldInsnNode) nodes[i + 1]; VarInsnNode loadEntity = (VarInsnNode) nodes[i + 2]; MethodInsnNode getMethod = (MethodInsnNode) nodes[i + 3]; if (loadThis.var != 0 || loadThis.getOpcode() != ALOAD) continue; if (!getField.owner.equals(metadata.internalName) || !getField.desc.equals("L" + WeaverConstants.MAPPER_NAME + ";") || !metadata.mappersByName.containsKey(getField.name)) continue; if (loadEntity.getOpcode() != ILOAD) continue; if (!getMethod.owner.equals(WeaverConstants.MAPPER_NAME) || !getMethod.desc.equals("(I)L" + WeaverConstants.COMPONENT_NAME + ";") || !getMethod.name.equals("get")) continue; SystemMapper mapper = metadata.mappersByName.get(getField.name); // Add field to hold the flyweight String fieldName = "flyweight$" + flyweightFields.size(); String fieldDesc = mapper.componentType.getDescriptor(); FieldNode fieldNode = new FieldNode(ACC_PRIVATE, fieldName, fieldDesc, null, null); fieldNode.visitAnnotation("Lcom/github/antag99/retinazer/SkipWire;", true); FlyweightField flyweightField = new FlyweightField(); flyweightField.fieldNode = fieldNode; flyweightField.mapper = mapper; flyweightFields.add(flyweightField); // Rewrite access to use the flyweight getField.owner = metadata.internalName; getField.name = fieldName; getField.desc = fieldDesc; insns.insert(getField, new InsnNode(DUP)); insns.insert(loadEntity, new FieldInsnNode(PUTFIELD, mapper.componentType.getInternalName(), WeaverConstants.INDEX_FIELD_NAME, WeaverConstants.INDEX_FIELD_DESC)); insns.remove(getMethod); } }
From source file:net.enilink.composition.asm.ExtendedClassNode.java
License:Open Source License
@SuppressWarnings("unchecked") public void addInjectorField() { FieldNode injectorField = new FieldNode(Opcodes.ACC_PRIVATE, INJECTOR_FIELD, Type.getDescriptor(Injector.class), null, null); injectorField.visitAnnotation(Type.getDescriptor(Inject.class), true); fields.add(injectorField);// ww w . jav a 2s . co m }
From source file:net.enilink.composition.cache.behaviours.CacheBehaviourMethodProcessor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww.jav a 2s.c o m*/ public void initialize(BehaviourClassNode classNode) throws Exception { FieldNode cacheField = new FieldNode(Opcodes.ACC_PRIVATE, "cache", Type.getDescriptor(IPropertyCache.class), null, null); cacheField.visitAnnotation(Type.getDescriptor(Inject.class), true); classNode.fields.add(cacheField); }
From source file:org.anon.smart.base.stt.asm.ASMSTTReader.java
License:Open Source License
public void addFieldAnnotation(Class annot) throws CtxException { for (Object f : _clazz.fields) { FieldNode fn = (FieldNode) f; String annotcls = Type.getDescriptor(annot); fn.visitAnnotation(annotcls, true); }/*from w w w. j ava 2s . c o m*/ }
From source file:org.anon.smart.base.stt.asm.ASMSTTWriter.java
License:Open Source License
public Object createField(STTVisitor sttvisit, STTDescriptor stt, Object field) { ASMClazzContext cctx = (ASMClazzContext) sttvisit.clazzContext(); ClassVisitor visit = cctx.visitor(); FieldNode sfn = (FieldNode) field;// ww w . j a v a 2 s .c om FieldNode fn = new FieldNode(sfn.access, sfn.name, sfn.desc, sfn.signature, sfn.value); List<AnnotationNode> annons = sfn.visibleAnnotations; if (annons != null) { for (AnnotationNode annon : annons) fn.visitAnnotation(annon.desc, true); } sttvisit.addFieldAnnotations(this, stt, sfn, sfn.name); fn.accept(visit); return fn; }