本文整理汇总了Java中org.apache.bcel.generic.BranchInstruction.setTarget方法的典型用法代码示例。如果您正苦于以下问题:Java BranchInstruction.setTarget方法的具体用法?Java BranchInstruction.setTarget怎么用?Java BranchInstruction.setTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.BranchInstruction
的用法示例。
在下文中一共展示了BranchInstruction.setTarget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerInstructionHandle
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
public void registerInstructionHandle(InstructionHandle ih) {
if (currentIds.size() == 0)
return;
for (Integer currentID : currentIds) {
mapID2InstructionHandle.put(currentID, ih);
List<BranchInstruction> l = mapID2BranchInstructions.get(currentID);
if (l != null) {
// We encountered some branch instructions earlier before we
// registered this instruction handle
for (BranchInstruction bi : l) {
bi.setTarget(ih);
}
mapID2BranchInstructions.remove(currentID);
}
}
currentIds.clear();
}
示例2: injectCommonExceptionCatchBlock
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
/**
* Inject common exception catch blocks
*/
public void injectCommonExceptionCatchBlock(InstructionList il, MethodGen method, int variableIndex) {
il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.RuntimeException"))));
BranchInstruction b1 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
il.append(b1);
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(factory.createCheckCast(new ObjectType("java.lang.RuntimeException")));
il.append(InstructionConstants.ATHROW);
InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.Error"))));
BranchInstruction b2 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
il.append(b2);
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(factory.createCheckCast(new ObjectType("java.lang.Error")));
il.append(InstructionConstants.ATHROW);
InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(factory.createInvoke("java.lang.Throwable", "printStackTrace", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createNew("org.codehaus.jremoting.client.InvocationException"));
il.append(InstructionConstants.DUP);
il.append(factory.createNew("java.lang.StringBuffer"));
il.append(InstructionConstants.DUP);
il.append(new PUSH(constantsPool, "Should never get here: "));
il.append(factory.createInvoke("java.lang.StringBuffer", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.StringBuffer", "toString", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("org.codehaus.jremoting.client.InvocationException", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
b1.setTarget(ih1);
b2.setTarget(ih2);
}
示例3: registerBranchInstruction
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
public void registerBranchInstruction(BranchInstruction g, int id) {
InstructionHandle ih = mapID2InstructionHandle.get(id);
if (ih != null) {
// Instruction handle was registered before
g.setTarget(ih);
return;
}
// We haven't seen the instruction handle yet. Remember this branch
// instruction
List<BranchInstruction> l = mapID2BranchInstructions.get(id);
if (l == null)
l = new ArrayList<BranchInstruction>();
l.add(g);
mapID2BranchInstructions.put(id, l);
}
示例4: createInterfaceMethodArgs
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
/**
* Create interface method's args.
*
* @param numberOfArguments the number of arguments.
* @param il an instruction list
* @param variableIndex a varible index.
* @param paramTypes parameter types
* @param generatedClassName the generated class name.
*/
private void createInterfaceMethodArgs(int numberOfArguments, InstructionList il, int variableIndex, Class[] paramTypes, String generatedClassName) {
Type previousType = null;
int loadIndex = 0;
for (int i = 0; i < numberOfArguments; i++) {
// assigning the obj ref's
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex - 1));
il.append(new PUSH(constantsPool, i));
String className = paramTypes[i].getName();
//adjust for any previous wider datatype (double/long)
if (previousType != null && (previousType == Type.DOUBLE || previousType == Type.LONG)) {
++loadIndex;
}
if (paramTypes[i].isPrimitive()) {
il.append(factory.createNew(getJavaWrapperClass(className)));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(getBCELPrimitiveType(className), ++loadIndex));
il.append(factory.createInvoke(getJavaWrapperClass(className), "<init>", Type.VOID, new Type[]{getBCELPrimitiveType(className)}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.AASTORE);
} else {
//create the static fields for enabling .class calls
String encodedFieldName;
if (paramTypes[i].isArray()) {
int index = className.lastIndexOf('[');
if (className.charAt(index + 1) == 'L') {
encodedFieldName = "array$" + className.substring(1 + index, className.length() - 1).replace('.', '$');
} else {
encodedFieldName = "array$" + className.substring(1 + index, className.length());
}
} else {
encodedFieldName = "class$" + className.replace('.', '$');
}
addField(encodedFieldName);
// ******** TODO assign the obj reference
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex - 1));
il.append(new PUSH(constantsPool, i));
il.append(InstructionFactory.createLoad(Type.OBJECT, ++loadIndex));
il.append(InstructionConstants.AASTORE);
// *********TODO assign the class ref's
il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
il.append(new PUSH(constantsPool, i));
il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.GETSTATIC));
BranchInstruction ifnull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
il.append(ifnull);
il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.GETSTATIC));
BranchInstruction goHeadToStoreRef = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
il.append(goHeadToStoreRef);
InstructionHandle ifnullStartHere = il.append(new PUSH(constantsPool, className));
ifnull.setTarget(ifnullStartHere);
il.append(factory.createInvoke(generatedClassName, "class$", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
il.append(InstructionConstants.DUP);
il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
InstructionHandle storeClassRef = il.append(InstructionConstants.AASTORE);
goHeadToStoreRef.setTarget(storeClassRef);
}
previousType = getBCELPrimitiveType(className);
}
}
示例5: genSet
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
@Override
public void genSet(Set s, GenScope scope) {
String javaClassName = description.getJavaClass(className);
SimpleSet setter = (SimpleSet) description.getSetter(className, s.getFeatureName());
assert(setter != null); // constructor setter should be rewritten in a pre-processing step
// ObjectType paramType = new ObjectType(setter.getSetter().getParameterTypes().get(0));
Type returnType = Type.VOID;
if ( setter.getSetter().getReturnType() != null ) {
returnType = computeParamType(setter.getSetter().getReturnType()); // new ObjectType(setter.getSetter().getReturnType());
}
InstructionList il = scope.getInstructionList();
InstructionFactory ifact = scope.getInstructionFactory();
Variable realReceptor = scope.getRealVariable(s.getReceptor());
Variable realValue = scope.getRealVariable(s.getValue());
BranchInstruction branchToEnd = InstructionFactory
.createBranchInstruction(Constants.GOTO, null);
BranchInstruction branchToMonovalued = InstructionFactory
.createBranchInstruction(Constants.IFEQ, null);
// push value
scope.loadVariable(realValue, il);
il.append(InstructionConstants.DUP);
// check if it is multivalued result
il.append(ifact.createInstanceOf(DefaultTypes.Iterable));
// If it is not an iterable goto -> monovalued set
il.append(branchToMonovalued);
// It is an iterable -> multivalued set
// the collection is in queue, get the iterator
il.append(ifact.createCheckCast(DefaultTypes.Iterable));
il.append(ifact.createInvoke("java.lang.Iterable", "iterator", new ObjectType("java.util.Iterator"), Type.NO_ARGS, Constants.INVOKEINTERFACE));
// got to check next
BranchHandle gotoHasNext = il.append(InstructionFactory.createBranchInstruction(Constants.GOTO, null));
// next object
InstructionHandle nextElement = il.append(InstructionConstants.DUP);
il.append(ifact.createInvoke("java.util.Iterator", "next", Type.OBJECT, Type.NO_ARGS, Constants.INVOKEINTERFACE));
genMonovaluedSet(scope, javaClassName, setter.getSetter(), il, ifact, realReceptor, returnType);
// check if hasNext, but before dup the iterator
gotoHasNext.setTarget( il.append(InstructionConstants.DUP) );
il.append(ifact.createInvoke("java.util.Iterator", "hasNext", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEINTERFACE));
il.append(InstructionFactory.createBranchInstruction(Constants.IFNE, nextElement));
// Pop the iterator, that it is no longer needed
il.append(InstructionConstants.POP);
// end of iteration
// Skip monovalued set
il.append(branchToEnd);
// target of monovalued
branchToMonovalued.setTarget(il.append(InstructionConstants.NOP));
genMonovaluedSet(scope, javaClassName, setter.getSetter(), il,
ifact, realReceptor, returnType);
branchToEnd.setTarget(il.append(InstructionConstants.NOP));
}
示例6: generate
import org.apache.bcel.generic.BranchInstruction; //导入方法依赖的package包/类
/**
* <<GET_IMODEL(THIS)>>
* ALOAD !!#receptor_variable!!
* LDC <<featureName>>
* INVOKEINTERFACE getFeature
*/
@Override
public void generate(GenScope scope) {
InstructionList il = scope.getInstructionList();
InstructionFactory ifact = scope.getInstructionFactory();
ConstantPoolGen cpg = scope.getConstantPool();
Variable realReceptor = scope.getRealVariable(this.receptor);
LocalVariableGen lvg = scope.newLocalVariable(this, Type.OBJECT);
// generate model access
scope.generateGetModel(realReceptor);
il.append(new DUP()); // for later calls of get/method calls (problem if I put the generateGetModel directly, not using the dup optimize, why?)
// push receptor
// push featureName
scope.loadVariable(realReceptor, il);
lvg.setStart(il.append(new LDC(cpg.addString(featureName))));
if ( kind == GetKind.PLAIN_GET ) {
appendGetFeature(il, ifact);
il.append(InstructionFactory.SWAP);
il.append(InstructionFactory.POP);
// I should swap, and then pop...
// il.append(new POP());
} else {
BranchInstruction branchToCall = InstructionFactory
.createBranchInstruction(Constants.IFEQ, null);
BranchInstruction branchToEnd = InstructionFactory
.createBranchInstruction(Constants.GOTO, null);
// hasFeature(f)
// ifeq (jump if value == 0)
appendHasFeature(il, ifact);
lvg.setStart(il.append(branchToCall));
// push receptor
// push featureName
// get & jump to the end
/*
scope.loadVariable(realReceptor, il);
lvg.setStart(il.append(new LDC(cpg.addString(featureName))));
*/
if ( isStreamingMode(scope) ) {
appendContinuableGetFeature(scope, realReceptor, il, ifact, cpg);
} else {
scope.loadVariable(realReceptor, il);
il.append(new LDC(cpg.addString(featureName)));
appendGetFeature(il, ifact);
// branchToEnd.setTarget(appendGetFeature(il, ifact));
}
il.append(branchToEnd);
// push receptor
// push featureName
// methodCall
branchToCall.setTarget( il.append(InstructionConstants.NOP) ); // label for this part
//scope.loadVariable(realReceptor, il);
// lvg.setStart(il.append(new LDC(cpg.addString(featureName))));
lvg.setStart(il.append(InstructionConstants.POP)); // remove IModel
appendMethodCall(scope, il, ifact);
// NOP-end
branchToEnd.setTarget( il.append(InstructionConstants.NOP) );
}
// store result
il.append(new ASTORE( lvg.getIndex() ));
}