use of org.apache.bcel.classfile.Method in project jop by jop-devel.
the class JopMethodInfo method setInfo.
/**
* Extract linking information for this method
* @param addr the bytecode start address
*/
public void setInfo(int addr) {
codeAddress = addr;
Method m = getMethod();
margs = 0;
Type[] at = m.getArgumentTypes();
for (int i = 0; i < at.length; ++i) {
margs += at[i].getSize();
}
// for now only handle inits
if (!m.isStatic()) {
margs++;
}
if (m.isAbstract()) {
mstack = mreallocals = len = exclen = 0;
exctab = null;
} else {
mstack = m.getCode().getMaxStack();
// the 'real' locals - means without arguments
mreallocals = m.getCode().getMaxLocals() - margs;
// System.err.println(" ++++++++++++ "+methodId+" --> mlocals
// ="+mlocals+" margs ="+margs);
len = (m.getCode().getCode().length + 3) / 4;
exctab = m.getCode().getExceptionTable();
exclen = exctab != null ? exctab.length : 0;
// TODO: couldn't len=JOP...MAX_SIZE/4 be ok?
if (len >= JOPizer.METHOD_MAX_SIZE / 4 || mreallocals > 31 || margs > 31) {
// we interprete clinit on JOP - no size restriction
if (!m.getName().equals("<clinit>")) {
System.err.println("len(max:" + (JOPizer.METHOD_MAX_SIZE / 4) + ")=" + len + "mreallocals(max:31)=" + mreallocals + " margs(max:31)=" + margs);
System.err.println("wrong size: " + getCli().clazz.getClassName() + "." + methodId);
throw new Error();
}
}
// System.out.println((mstack+m.getCode().getMaxLocals())+" "+
// m.getName()+" maxStack="+mstack+"
// locals="+m.getCode().getMaxLocals());
}
}
use of org.apache.bcel.classfile.Method in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findPoolReferences.
// //////////////////////////////////////////////////////////////
// Find/replace references, member names, Pool entries
// //////////////////////////////////////////////////////////////
public static Set<Integer> findPoolReferences(ClassInfo classInfo, boolean checkMembers) {
JavaClass javaClass = classInfo.compile();
Set<Integer> ids = findPoolReferences(classInfo, javaClass);
if (checkMembers) {
for (Field field : javaClass.getFields()) {
FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
ids.addAll(findPoolReferences(fieldInfo, field));
}
for (Method method : javaClass.getMethods()) {
MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
ids.addAll(findPoolReferences(methodInfo, method));
}
}
return ids;
}
use of org.apache.bcel.classfile.Method in project contribution by checkstyle.
the class UnusedMethodCheck method leaveSet.
/**
* @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor
*/
public void leaveSet(Set aJavaClasses) {
final Iterator it = aJavaClasses.iterator();
while (it.hasNext()) {
final JavaClass javaClass = (JavaClass) it.next();
final String className = javaClass.getClassName();
final JavaClassDefinition classDef = findJavaClassDef(javaClass);
final MethodDefinition[] methodDefs = classDef.getMethodDefs();
for (int i = 0; i < methodDefs.length; i++) {
if (!classDef.hasReference(methodDefs[i], getReferenceDAO())) {
final Method method = methodDefs[i].getMethod();
if (!ignore(className, method)) {
log(javaClass, 0, "unused.method", new Object[] { methodDefs[i] });
}
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class NonRecycleableTaglibs method getAttributes.
/**
* collect all possible attributes given the name of methods available.
*
* @param cls
* the class to look for setter methods to infer properties
* @return the map of possible attributes/types
*/
private static Map<QMethod, String> getAttributes(JavaClass cls) {
Map<QMethod, String> atts = new HashMap<>();
Method[] methods = cls.getMethods();
for (Method m : methods) {
String name = m.getName();
if (name.startsWith("set") && m.isPublic() && !m.isStatic()) {
String sig = m.getSignature();
List<String> args = SignatureUtils.getParameterSignatures(sig);
if ((args.size() == 1) && Values.SIG_VOID.equals(SignatureUtils.getReturnSignature(sig))) {
String parmSig = args.get(0);
if (validAttrTypes.contains(parmSig)) {
Code code = m.getCode();
if ((code != null) && (code.getCode().length < MAX_ATTRIBUTE_CODE_LENGTH)) {
atts.put(new QMethod(name, sig), parmSig);
}
}
}
}
}
return atts;
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class NonSymmetricEquals method visitCode.
/**
* implements the visitor to see if this method is equals(Object o)
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
Method m = getMethod();
String name = m.getName();
String signature = m.getSignature();
if ("equals".equals(name) && SignatureBuilder.SIG_OBJECT_TO_BOOLEAN.equals(signature) && prescreen(m)) {
stack.resetForMethodEntry(this);
super.visitCode(obj);
}
}
Aggregations