use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class MethodCode method getFieldRef.
public FieldRef getFieldRef(FieldInstruction instr) {
ConstantPoolGen cpg = getConstantPoolGen();
String classname = getReferencedClassName(instr);
return getAppInfo().getFieldRef(classname, instr.getFieldName(cpg));
}
use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class InvokeSite method getReferencedMethod.
////////////////////////////////////////////////////////////////////////////////
// Private methods
////////////////////////////////////////////////////////////////////////////////
/**
* Get a MethodRef for the referenced method in a given invoke instruction in the invoker method.
* This does not resolve any super methods or devirtualize the call.
* <p>
* If you call {@link MethodRef#getMethodInfo()}, the method found in the referenced class
* or in its superclasses will be returned. For InvokeSpecial, this might not be correct,
* so use {@link #getInvokeeRef()} or {@link AppInfo#findImplementations(InvokeSite)} instead.</p>
* <p>
* Note: Since this could easily be used incorrectly, this method has been moved here from MethodInfo and
* made private in favor of getInvokeeRef()
* </p>
*
* @param invoker the method containing the instruction, used to resolve constantpool references.
* @param instr the instruction to resolve
* @return a method reference representing the invoke reference.
*/
private static MethodRef getReferencedMethod(MethodInfo invoker, InvokeInstruction instr) {
ConstantPoolGen cpg = invoker.getConstantPoolGen();
String methodname = instr.getMethodName(cpg);
String classname = invoker.getCode().getReferencedClassName(instr);
MemberID memberID = new MemberID(classname, methodname, instr.getSignature(cpg));
if ("<clinit>".equals(methodname)) {
// can have <clinit> methods which are invoked by invokestatic
return AppInfo.getSingleton().getMethodRef(memberID);
}
boolean isInterface = (instr instanceof INVOKEINTERFACE);
return AppInfo.getSingleton().getMethodRef(memberID, isInterface);
}
use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class MethodCode method getReferencedClassName.
/**
* Get the classname or array-type name referenced by an invoke- or field instruction in this code.
*
* @param instr the instruction to check, using this methods constantpool.
* @return the referenced classname or array-typename, to be used for a ClassRef or AppInfo getter.
*/
public String getReferencedClassName(FieldOrMethod instr) {
ConstantPoolGen cpg = getConstantPoolGen();
ReferenceType refType = instr.getReferenceType(cpg);
String classname;
if (refType instanceof ObjectType) {
classname = ((ObjectType) refType).getClassName();
} else if (refType instanceof ArrayType) {
// need to call array.<method>, which class should we use? Let's decide later..
String msg = "Calling a method of an array: " + refType.getSignature() + "#" + instr.getName(cpg) + " in " + methodInfo;
logger.debug(msg);
classname = refType.getSignature();
} else {
// Hu??
throw new JavaClassFormatError("Unknown reference type " + refType);
}
return classname;
}
use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class InnerClassesInfo method buildInnerClasses.
/**
* Build a map of InnerClasses containing all entries for all inner classes in the 'classes'
* parameter and all their enclosing inner classes.
*
* @param classes a collection of classes the result should contain.
* @return the map of className->InnerClass containing all inner classes in the 'classes' parameter.
*/
private Collection<InnerClass> buildInnerClasses(Collection<ClassRef> classes) {
List<ClassRef> queue = new LinkedList<ClassRef>(classes);
Set<String> visited = new HashSet<String>();
List<InnerClass> inner = new LinkedList<InnerClass>();
ConstantPoolGen cpg = classGen.getConstantPool();
InnerClasses ic = getInnerClassesAttribute();
while (!queue.isEmpty()) {
ClassRef ref = queue.remove(0);
ClassInfo cls = ref.getClassInfo();
int innerClassIdx;
int outerClassIdx = 0;
int innerNameIdx = 0;
int flags = 0;
String enclosingClass = null;
if (cls != null) {
InnerClassesInfo info = cls.getInnerClassesInfo();
// only nested classes have an entry
if (!info.isNestedClass()) {
continue;
}
enclosingClass = info.getEnclosingClassName();
innerClassIdx = cpg.addClass(ref.getClassName());
if (!info.isLocalInnerClass()) {
// class is a member, add outer class reference
outerClassIdx = cpg.addClass(enclosingClass);
}
if (!info.isAnonymousInnerClass()) {
// class has a simple name
innerNameIdx = cpg.addUtf8(info.getInnerName());
}
flags = cls.getAccessFlags();
} else {
// unknown class, need to check the existing InnerClass array, if it exists
InnerClass i = findInnerClass(ic, ref.getClassName());
if (i == null) {
// class is not an innerclass according to our old InnerClasses table
continue;
}
innerClassIdx = i.getInnerClassIndex();
outerClassIdx = i.getOuterClassIndex();
innerNameIdx = i.getInnerNameIndex();
flags = i.getInnerAccessFlags();
}
// will add a reference to the enclosing class anyway
if (enclosingClass != null && !visited.contains(enclosingClass)) {
queue.add(classInfo.getAppInfo().getClassRef(enclosingClass));
}
visited.add(ref.getClassName());
inner.add(new InnerClass(innerClassIdx, outerClassIdx, innerNameIdx, flags));
}
return inner;
}
use of org.apache.bcel.generic.ConstantPoolGen in project jop by jop-devel.
the class MemberInfo method setDeprecated.
public void setDeprecated(boolean flag) {
if (flag) {
if (findDeprecated() == null) {
ConstantPoolGen cpg = getClassInfo().getConstantPoolGen();
int index = cpg.addUtf8("Deprecated");
addAttribute(new org.apache.bcel.classfile.Deprecated(index, 0, new byte[0], cpg.getConstantPool()));
}
} else {
org.apache.bcel.classfile.Deprecated d = findDeprecated();
if (d != null) {
removeAttribute(d);
}
}
}
Aggregations