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;
}
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);
}
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);
}
}
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());
}
}
}
}
}
Aggregations