本文整理汇总了Java中org.apache.bcel.generic.MethodGen类的典型用法代码示例。如果您正苦于以下问题:Java MethodGen类的具体用法?Java MethodGen怎么用?Java MethodGen使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodGen类属于org.apache.bcel.generic包,在下文中一共展示了MethodGen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportMatch
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
public void reportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match) {
MethodGen methodGen = classContext.getMethodGen(method);
JavaClass javaClass = classContext.getJavaClass();
BindingSet bindingSet = match.getBindingSet();
// Note that the lookup of "h" cannot fail, and
// it is guaranteed to be bound to a FieldVariable.
Binding binding = bindingSet.lookup("h");
FieldVariable field = (FieldVariable) binding.getVariable();
// Ignore fields generated for accesses to Foo.class
if (field.getFieldName().startsWith("class$"))
return;
// Find start and end instructions (for reporting source lines)
InstructionHandle start = match.getLabeledInstruction("startDC");
InstructionHandle end = match.getLabeledInstruction("endDC");
String sourceFile = javaClass.getSourceFileName();
bugReporter.reportBug(new BugInstance(this, "BCPDC_DOUBLECHECK", NORMAL_PRIORITY)
.addClassAndMethod(methodGen, sourceFile)
.addField(field).describe("FIELD_ON")
.addSourceLine(methodGen, sourceFile, start, end));
}
示例2: analyzeMethod
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
public void analyzeMethod(ClassContext classContext, Method method,
ResourceTrackerType resourceTracker, ResourceCollection<Resource> resourceCollection)
throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
CFG cfg = classContext.getCFG(method);
DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);
if (DEBUG) System.out.println(SignatureConverter.convertMethodSignature(methodGen));
for (Iterator<Resource> i = resourceCollection.resourceIterator(); i.hasNext();) {
Resource resource = i.next();
ResourceValueAnalysis<Resource> analysis =
new ResourceValueAnalysis<Resource>(methodGen, cfg, dfs, resourceTracker, resource);
Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>> dataflow =
new Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>>(cfg, analysis);
dataflow.execute();
inspectResult(classContext.getJavaClass(), methodGen, cfg, dataflow, resource);
}
}
示例3: analyzeMethod
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(m);
ConstantPoolGen cpg = classContext.getConstantPoolGen();
CFG cfg = classContext.getCFG(m);
if (methodGen == null || methodGen.getInstructionList() == null) {
return; //No instruction .. nothing to do
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
Location location = i.next();
Instruction inst = location.getHandle().getInstruction();
if (inst instanceof InvokeInstruction) {
InvokeInstruction invoke = (InvokeInstruction) inst;
String methodName = invoke.getMethodName(cpg);
if ("enableDefaultTyping".equals(methodName)) {
JavaClass clz = classContext.getJavaClass();
bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
.addClass(clz)
.addMethod(clz, m)
.addCalledMethod(cpg, invoke)
.addSourceLine(classContext, m, location)
);
}
}
}
}
示例4: SpawnTableEntry
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
SpawnTableEntry(SpawnTableEntry orig, MethodGen mg, MethodGen origM) {
isLocalUsed = new boolean[origM.getMaxLocals()];
hasInlet = orig.hasInlet;
if (hasInlet) {
/* copy and rewite exception table */
CodeExceptionGen origE[] = origM.getExceptionHandlers();
CodeExceptionGen newE[] = mg.getExceptionHandlers();
catchBlocks = new ArrayList<CodeExceptionGen>();
for (int i = 0; i < orig.catchBlocks.size(); i++) {
CodeExceptionGen origCatch = orig.catchBlocks.get(i);
for (int j = 0; j < origE.length; j++) {
if (origCatch == origE[j]) {
catchBlocks.add(newE[j]);
break;
}
}
}
}
}
示例5: MethodTableEntry
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
MethodTableEntry(MethodTableEntry orig, MethodGen mg) {
this.mg = mg;
containsInlet = orig.containsInlet;
clone = null;
nrSpawns = orig.nrSpawns;
isClone = true;
typesOfParams = orig.typesOfParams;
typesOfParamsNoThis = orig.typesOfParamsNoThis;
startLocalAlloc = orig.startLocalAlloc;
spawnTable = new SpawnTableEntry[orig.spawnTable.length];
for (int i = 0; i < spawnTable.length; i++) {
spawnTable[i] = new SpawnTableEntry(orig.spawnTable[i], mg,
orig.mg);
}
}
示例6: calcNrSpawns
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
private int calcNrSpawns(MethodGen mg) {
InstructionList il = mg.getInstructionList();
if (il == null) {
return 0;
}
InstructionHandle[] ins = il.getInstructionHandles();
int count = 0;
for (int i = 0; i < ins.length; i++) {
if (ins[i].getInstruction() instanceof INVOKEVIRTUAL) {
Method target = self.findMethod((INVOKEVIRTUAL) (ins[i]
.getInstruction()));
JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[i]
.getInstruction()));
if (isSpawnable(target, cl)) {
count++;
}
}
}
return count;
}
示例7: getLocal
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
final LocalVariableGen getLocal(MethodGen m, LocalVariableInstruction curr,
int pos) {
int localNr = curr.getIndex();
LocalVariableGen[] lt = getLocalTable(m);
for (int i = 0; i < lt.length; i++) {
// Watch out. The first initialization seems not to be included in
// the range given in the local variable table!
if (localNr == lt[i].getIndex()) {
// System.err.println("Looking for local " + localNr
// + " on position " + pos);
// System.err.println("found one with range "
// + lt[i].getStart().getPrev().getPosition() + ", "
// + lt[i].getEnd().getPosition());
if (pos >= lt[i].getStart().getPrev().getPosition()
&& pos < (lt[i].getEnd().getPosition())) {
return lt[i];
}
}
}
return null;
}
示例8: containsSpawnedCall
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
boolean containsSpawnedCall(MethodGen m) {
InstructionList code = m.getInstructionList();
if (code == null) {
return false;
}
InstructionHandle ih[] = code.getInstructionHandles();
for (int i = 0; i < ih.length; i++) {
Instruction ins = ih[i].getInstruction();
if (ins instanceof INVOKEVIRTUAL) {
Method target = self.findMethod((INVOKEVIRTUAL) (ins));
JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins));
if (isSpawnable(target, cl)) {
return true;
}
}
}
return false;
}
示例9: getExceptionHandler
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
CodeExceptionGen getExceptionHandler(MethodGen m, InstructionHandle self) {
CodeExceptionGen exc[] = m.getExceptionHandlers();
for (int j = 0; j < exc.length; j++) {
InstructionHandle h = exc[j].getStartPC();
InstructionHandle h2 = exc[j].getEndPC();
do {
if (h == self) {
return exc[j];
}
h = h.getNext();
} while (h != h2);
if (h == self) {
return exc[j];
}
}
return null;
}
示例10: rewriteStore
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
InstructionHandle rewriteStore(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
if (type.equals(Type.LONG) || type.equals(Type.DOUBLE)) {
il.insert(i, new DUP_X2());
il.insert(i, new POP());
} else {
il.insert(i, new SWAP());
}
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.PUTFIELD));
return i;
}
示例11: rewriteLoad
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
InstructionHandle rewriteLoad(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.GETFIELD));
return i;
}
示例12: showClass
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
void showClass(PrintStream out, JavaClass javaClass) {
print(out, 0, "constantpool:\n");
out.println(javaClass.getConstantPool());
ConstantPoolGen cp = new ConstantPoolGen(javaClass.getConstantPool());
Method[] methods = javaClass.getMethods();
for (Method method : methods) {
MethodGen methodGen = new MethodGen(method, javaClass.getClassName(), cp);
print(out, 0, "%s (with stack consumption)\n", method);
showMethod(out, methodGen, javaClass.getConstantPool());
out.println();
print(out, 0, "%s\n", method);
if (method.getCode() != null) out.println((method.getCode()).toString(true));
out.println();
}
}
示例13: visitClassContext
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
public void visitClassContext(ClassContext cc) {
JavaClass jc = cc.getJavaClass();
Method[] methods = jc.getMethods();
for (Method m : methods) {
MethodGen mg = cc.getMethodGen(m);
if (mg == null) {
continue;
}
try {
analyzeMethod(cc, m);
} catch (Exception e) {
// There was a problem,
// report it. Probably
// isn't going to
// be a big deal.
e.printStackTrace();
}
}
}
示例14: createHelperMethodForDotClassCalls
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
/**
* Creates a method class$(String) which is used
* during SomeClass.class instruction
*
* @param generatedClassName the instance class name
*/
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
il.append(factory.createNew("java.lang.NoClassDefFoundError"));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}
示例15: generateEqualsMethod
import org.apache.bcel.generic.MethodGen; //导入依赖的package包/类
private void generateEqualsMethod(String generatedClassName) {
/* public boolean equals(Object o) {
* return stubHelper.isEquals(this,o);
* }
*/
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool);
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD));
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE));
il.append(InstructionFactory.createReturn(Type.INT));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}