Search in sources :

Example 1 with AnnotationAttribute

use of com.jopdesign.common.bcel.AnnotationAttribute in project jop by jop-devel.

the class MemberInfo method getAnnotation.

/**
     * Get the annotation attribute of this member
     * @param visible whether to the the visible or invisible annotation attribute (see {@link AnnotationAttribute#isVisible()}
     * @param create if true, create the attribute if it does not exist
     * @return the annotation attribute or null if it does not exist and {@code create} is false
     */
public AnnotationAttribute getAnnotation(boolean visible, boolean create) {
    for (Attribute a : getAttributes()) {
        if (a instanceof AnnotationAttribute) {
            if (((AnnotationAttribute) a).isVisible() == visible) {
                return (AnnotationAttribute) a;
            }
        }
    }
    if (create) {
        ConstantPoolGen cpg = getClassInfo().getConstantPoolGen();
        String name = visible ? AnnotationReader.VISIBLE_ANNOTATION_NAME : AnnotationReader.INVISIBLE_ANNOTATION_NAME;
        AnnotationAttribute a = new AnnotationAttribute(cpg.addUtf8(name), 0, cpg.getConstantPool(), visible, 0);
        a.updateLength();
        addAttribute(a);
        return a;
    }
    return null;
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute) Attribute(org.apache.bcel.classfile.Attribute) CallString(com.jopdesign.common.code.CallString) AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute)

Example 2 with AnnotationAttribute

use of com.jopdesign.common.bcel.AnnotationAttribute in project jop by jop-devel.

the class MemberInfo method setUnusedAnnotation.

public void setUnusedAnnotation() {
    AnnotationAttribute a = getAnnotation(false, true);
    if (a.findAnnotation(AnnotationAttribute.UNUSED_TAG_NAME) != null)
        return;
    ConstantPoolGen cpg = getConstantPoolGen();
    int nameIdx = cpg.addUtf8(AnnotationAttribute.UNUSED_TAG_NAME);
    Annotation an = new Annotation(nameIdx, cpg.getConstantPool(), 0);
    a.addAnnotation(an);
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute) Annotation(com.jopdesign.common.bcel.Annotation)

Example 3 with AnnotationAttribute

use of com.jopdesign.common.bcel.AnnotationAttribute in project jop by jop-devel.

the class MemberInfo method removeUnusedAnnotation.

public void removeUnusedAnnotation() {
    AnnotationAttribute a = getAnnotation(false, false);
    if (a == null)
        return;
    Annotation an = a.findAnnotation(AnnotationAttribute.UNUSED_TAG_NAME);
    if (an != null) {
        a.removeAnnotation(an);
    }
}
Also used : AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute) Annotation(com.jopdesign.common.bcel.Annotation)

Example 4 with AnnotationAttribute

use of com.jopdesign.common.bcel.AnnotationAttribute in project jop by jop-devel.

the class ReplaceAtomicAnnotation method visitJavaClass.

public void visitJavaClass(JavaClass clazz) {
    super.visitJavaClass(clazz);
    Method[] methods = clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        for (Attribute a : methods[i].getAttributes()) {
            if (a instanceof AnnotationAttribute) {
                if (((AnnotationAttribute) a).hasAtomicAnnotation()) {
                    ConstantPoolGen cpoolgen = new ConstantPoolGen(clazz.getConstantPool());
                    Method nm = transform(methods[i], clazz, cpoolgen);
                    OldMethodInfo mi = getCli().getMethodInfo(nm.getName() + nm.getSignature());
                    // set new method also in MethodInfo
                    mi.setMethod(nm);
                    methods[i] = nm;
                    clazz.setConstantPool(cpoolgen.getFinalConstantPool());
                    System.out.println("RTTM: transformed atomic method " + clazz.getClassName() + "." + nm.getName() + nm.getSignature());
                }
            }
        }
    }
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) Attribute(org.apache.bcel.classfile.Attribute) AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute) Method(org.apache.bcel.classfile.Method) AnnotationAttribute(com.jopdesign.common.bcel.AnnotationAttribute)

Aggregations

AnnotationAttribute (com.jopdesign.common.bcel.AnnotationAttribute)4 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)3 Annotation (com.jopdesign.common.bcel.Annotation)2 Attribute (org.apache.bcel.classfile.Attribute)2 CallString (com.jopdesign.common.code.CallString)1 Method (org.apache.bcel.classfile.Method)1