use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class InnerClassesInfo method buildInnerClassesAttribute.
/*
* Make this class a member nested class of the given class or move it to top-level
*
* @param enclosingClass the new outer class of this class, or null to make it a toplevel class.
* @param innerName the simple name of this member class.
*/
/*
public void setEnclosingClass(ClassInfo enclosingClass, String innerName) throws AppInfoException {
// implement setOuterClass(), if needed. But this is not a simple task.
// need to
// - remove references to old outerClass from InnerClasses of this and all old outer classes
// - create InnerClasses attribute if none exists
// - add new entries to InnerClasses of this and all new outer classes.
// - update class hierarchy infos and fullyKnown flags
// - handle setEnclosingClass(null)
}
*/
/*
* Make this class a local nested class of the given method.
* @param methodInfo the enclosing method of this class.
*/
/*
public void setEnclosingMethod(MethodInfo methodInfo) {
}
*/
/*
* Add or replace InnerClass entries of this class with the info of the given classes.
* If no InnerClasses attribute exists, it is created. Enclosing classes are added if needed.
*
* @param nestedClasses a list of nested classes to add to the InnerClasses attribute.
*/
/*
public void addInnerClassRefs(Collection<ClassRef> nestedClasses) {
if ( nestedClasses == null || nestedClasses.isEmpty() ) {
return;
}
Map<String, InnerClass> classes = buildInnerClasses(nestedClasses);
// create an InnerClasses attribute if it does not exist
// add all InnerClasses to the existing InnerClasses (replace entries if existing)
}
*/
/**
* Build a new InnerClasses Attribute containing entries for all inner classes referenced by the current
* constantpool, using the current ClassInfos or the old InnerClasses attribute to build the table.
*
* @return a new InnerClasses attribute or null if this class does not reference any inner classes.
*/
public InnerClasses buildInnerClassesAttribute() {
ConstantPoolGen cpg = classGen.getConstantPool();
// check+update InnerClasses attribute (and add referenced nested classes)
List<ClassRef> referencedClasses = new LinkedList<ClassRef>();
for (String name : ConstantPoolReferenceFinder.findReferencedClasses(classInfo)) {
referencedClasses.add(classInfo.getAppInfo().getClassRef(name));
}
// find all referenced classes recursively, build InnerClass list from ClassInfo or old InnerClasses
Collection<InnerClass> classes = buildInnerClasses(referencedClasses);
if (classes.isEmpty()) {
return null;
}
InnerClass[] ics = null;
ics = classes.toArray(ics);
int length = ics.length * 8 + 2;
return new InnerClasses(cpg.addUtf8("InnerClasses"), length, ics, cpg.getConstantPool());
}
use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class MemberInfo method setSynthetic.
////////////////////////////////////////////////////////////////////////////
// Attribute access and helpers for custom attributes
////////////////////////////////////////////////////////////////////////////
public void setSynthetic(boolean flag) {
// from major version 49 on, ACC_SYNTHETIC is supported
Synthetic s = findSynthetic();
if (getClassInfo().getMajor() < 49) {
if (flag) {
if (s == null) {
ConstantPoolGen cpg = getClassInfo().getConstantPoolGen();
int index = cpg.addUtf8("Synthetic");
addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
}
} else {
if (s != null) {
removeAttribute(s);
}
}
} else {
accessFlags.isSynthetic(flag);
if (!flag && s != null) {
removeAttribute(s);
}
}
}
use of org.apache.bcel.generic.ConstantPoolGen 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 org.apache.bcel.generic.ConstantPoolGen 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 org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class FindUsedConstants method visitJavaClass.
public void visitJavaClass(JavaClass clazz) {
super.visitJavaClass(clazz);
cpool = new ConstantPoolGen(clazz.getConstantPool());
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
if (!(methods[i].isAbstract() || methods[i].isNative())) {
// methods[i] = find(methods[i]);
find(methods[i]);
}
}
// clazz.setConstantPool(cpoolNew.getConstantPool());
//System.out.println(clazz.getConstantPool());
}
Aggregations