use of org.apache.bcel.classfile.ClassFormatException in project jop by jop-devel.
the class AppInfo method getMethodRef.
/**
* Get a reference to a method using the given memberID.
* If the method is defined only in a (known) superclass and is inherited by this class,
* get a methodRef which contains a ClassRef to the given class but a MethodInfo from the superclass.
* <p>
* If you already have a classRef, use {@link #getMethodRef(ClassRef, MemberID)}
* instead.
* </p>
* @param memberID the memberID of the method
* @param isInterfaceMethod true if the class is an interface.
* @return a method reference with or without MethodInfo or ClassInfo.
*/
public MethodRef getMethodRef(MemberID memberID, boolean isInterfaceMethod) {
ClassInfo cls = classes.get(memberID.getClassName());
ClassRef clsRef;
if (cls != null) {
if (cls.isInterface() != isInterfaceMethod) {
throw new ClassFormatException("Class '" + cls.getClassName() + "' interface flag does not match.");
}
clsRef = cls.getClassRef();
} else {
clsRef = new ClassRef(memberID.getClassName(), isInterfaceMethod);
}
return getMethodRef(clsRef, memberID);
}
use of org.apache.bcel.classfile.ClassFormatException in project OpenGrok by OpenGrok.
the class JavaClassAnalyzer method constantToString.
public String constantToString(Constant c, ConstantPool cp, int[] v) throws ClassFormatException {
String str;
int i, j, k;
byte tag = c.getTag();
switch(tag) {
case org.apache.bcel.Const.CONSTANT_Class:
i = ((ConstantClass) c).getNameIndex();
v[i] = 1;
Constant con = cp.getConstant(i, org.apache.bcel.Const.CONSTANT_Utf8);
str = Utility.compactClassName(((ConstantUtf8) con).getBytes(), false);
break;
case org.apache.bcel.Const.CONSTANT_String:
i = ((ConstantString) c).getStringIndex();
v[i] = 1;
Constant con2 = cp.getConstant(i, org.apache.bcel.Const.CONSTANT_Utf8);
str = ((ConstantUtf8) con2).getBytes();
break;
case org.apache.bcel.Const.CONSTANT_Utf8:
str = ((ConstantUtf8) c).toString();
break;
case org.apache.bcel.Const.CONSTANT_Double:
str = ((ConstantDouble) c).toString();
break;
case org.apache.bcel.Const.CONSTANT_Float:
str = ((ConstantFloat) c).toString();
break;
case org.apache.bcel.Const.CONSTANT_Long:
str = ((ConstantLong) c).toString();
break;
case org.apache.bcel.Const.CONSTANT_Integer:
str = ((ConstantInteger) c).toString();
break;
case org.apache.bcel.Const.CONSTANT_NameAndType:
i = ((ConstantNameAndType) c).getNameIndex();
v[i] = 1;
j = ((ConstantNameAndType) c).getSignatureIndex();
v[j] = 1;
String sig = constantToString(cp.getConstant(j), cp, v);
if (sig.charAt(0) == '(') {
str = Utility.methodSignatureToString(sig, constantToString(cp.getConstant(i), cp, v), " ");
} else {
str = Utility.signatureToString(sig) + ' ' + constantToString(cp.getConstant(i), cp, v);
}
break;
case org.apache.bcel.Const.CONSTANT_InterfaceMethodref:
case org.apache.bcel.Const.CONSTANT_Methodref:
case org.apache.bcel.Const.CONSTANT_Fieldref:
i = ((ConstantCP) c).getClassIndex();
v[i] = 1;
j = ((ConstantCP) c).getNameAndTypeIndex();
v[j] = 1;
str = (constantToString(cp.getConstant(i), cp, v) + ' ' + constantToString(cp.getConstant(j), cp, v));
break;
case org.apache.bcel.Const.CONSTANT_MethodType:
i = ((ConstantMethodType) c).getDescriptorIndex();
v[i] = 1;
str = constantToString(cp.getConstant(i), cp, v);
break;
// }
case org.apache.bcel.Const.CONSTANT_MethodHandle:
// TODO fix implementation as per below to have proper lookup table/constants
// i = ((ConstantMethodHandle) c).getReferenceKind();
// v[i] = 1;
// j = ((ConstantMethodHandle) c).getReferenceIndex();
// v[j] = 1;
// str = (constantToString(cp.getConstant(i), cp, v) + ' ' +
// constantToString(cp.getConstant(j), cp, v));
str = "";
break;
// }
case org.apache.bcel.Const.CONSTANT_InvokeDynamic:
// TODO fix implementation as per below and add bootstrap method tables first
// i = ((ConstantInvokeDynamic) c).getClassIndex();
// v[i] = 1;
// j = ((ConstantInvokeDynamic) c).getNameAndTypeIndex();
// v[j] = 1;
// k = ((ConstantInvokeDynamic) c).getBootstrapMethodAttrIndex();
// v[k] = 1;
// str = (constantToString(cp.getConstant(i), cp, v) + ' ' +
// constantToString(cp.getConstant(j), cp, v) + ' ' +
// constantToString(cp.getConstant(k), cp, v));
str = "";
break;
case org.apache.bcel.Const.CONSTANT_Package:
i = ((ConstantPackage) c).getNameIndex();
v[i] = 1;
str = constantToString(cp.getConstant(i), cp, v);
break;
case org.apache.bcel.Const.CONSTANT_Module:
i = ((ConstantModule) c).getNameIndex();
v[i] = 1;
str = constantToString(cp.getConstant(i), cp, v);
break;
default:
// Never reached
throw new ClassFormatException("Unknown constant type " + tag);
}
return str;
}
Aggregations