本文整理汇总了Java中scouter.javassist.bytecode.Opcode.NEWARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java Opcode.NEWARRAY属性的具体用法?Java Opcode.NEWARRAY怎么用?Java Opcode.NEWARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scouter.javassist.bytecode.Opcode
的用法示例。
在下文中一共展示了Opcode.NEWARRAY属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getComponentType
/**
* Returns the type of array components. If the created array is
* a two-dimensional array of <tt>int</tt>,
* the type returned by this method is
* not <tt>int[]</tt> but <tt>int</tt>.
*/
public CtClass getComponentType() throws NotFoundException {
if (opcode == Opcode.NEWARRAY) {
int atype = iterator.byteAt(currentPos + 1);
return getPrimitiveType(atype);
}
else if (opcode == Opcode.ANEWARRAY
|| opcode == Opcode.MULTIANEWARRAY) {
int index = iterator.u16bitAt(currentPos + 1);
String desc = getConstPool().getClassInfo(index);
int dim = Descriptor.arrayDimension(desc);
desc = Descriptor.toArrayComponent(desc, dim);
return Descriptor.toCtClass(desc, thisClass.getClassPool());
}
else
throw new RuntimeException("bad opcode: " + opcode);
}
示例2: doit
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
int num = gen.getMethodArgsLength(args);
if (num != dimension)
throw new CompileError(Javac.proceedName
+ "() with a wrong number of parameters");
gen.atMethodArgs(args, new int[num],
new int[num], new String[num]);
bytecode.addOpcode(opcode);
if (opcode == Opcode.ANEWARRAY)
bytecode.addIndex(index);
else if (opcode == Opcode.NEWARRAY)
bytecode.add(index);
else /* if (opcode == Opcode.MULTIANEWARRAY) */ {
bytecode.addIndex(index);
bytecode.add(dimension);
bytecode.growStack(1 - dimension);
}
gen.setType(arrayType);
}
示例3: getDimension
/**
* Returns the dimension of the created array.
*/
public int getDimension() {
if (opcode == Opcode.NEWARRAY)
return 1;
else if (opcode == Opcode.ANEWARRAY
|| opcode == Opcode.MULTIANEWARRAY) {
int index = iterator.u16bitAt(currentPos + 1);
String desc = getConstPool().getClassInfo(index);
return Descriptor.arrayDimension(desc)
+ (opcode == Opcode.ANEWARRAY ? 1 : 0);
}
else
throw new RuntimeException("bad opcode: " + opcode);
}
示例4: loopBody
final boolean loopBody(CodeIterator iterator, CtClass clazz,
MethodInfo minfo, LoopContext context)
throws CannotCompileException
{
try {
Expr expr = null;
int pos = iterator.next();
int c = iterator.byteAt(pos);
if (c < Opcode.GETSTATIC) // c < 178
/* skip */;
else if (c < Opcode.NEWARRAY) { // c < 188
if (c == Opcode.INVOKESTATIC
|| c == Opcode.INVOKEINTERFACE
|| c == Opcode.INVOKEVIRTUAL) {
expr = new MethodCall(pos, iterator, clazz, minfo);
edit((MethodCall)expr);
}
else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC
|| c == Opcode.PUTFIELD
|| c == Opcode.PUTSTATIC) {
expr = new FieldAccess(pos, iterator, clazz, minfo, c);
edit((FieldAccess)expr);
}
else if (c == Opcode.NEW) {
int index = iterator.u16bitAt(pos + 1);
context.newList = new NewOp(context.newList, pos,
minfo.getConstPool().getClassInfo(index));
}
else if (c == Opcode.INVOKESPECIAL) {
NewOp newList = context.newList;
if (newList != null
&& minfo.getConstPool().isConstructor(newList.type,
iterator.u16bitAt(pos + 1)) > 0) {
expr = new NewExpr(pos, iterator, clazz, minfo,
newList.type, newList.pos);
edit((NewExpr)expr);
context.newList = newList.next;
}
else {
MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo);
if (mcall.getMethodName().equals(MethodInfo.nameInit)) {
ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo);
expr = ccall;
edit(ccall);
}
else {
expr = mcall;
edit(mcall);
}
}
}
}
else { // c >= 188
if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY
|| c == Opcode.MULTIANEWARRAY) {
expr = new NewArray(pos, iterator, clazz, minfo, c);
edit((NewArray)expr);
}
else if (c == Opcode.INSTANCEOF) {
expr = new Instanceof(pos, iterator, clazz, minfo);
edit((Instanceof)expr);
}
else if (c == Opcode.CHECKCAST) {
expr = new Cast(pos, iterator, clazz, minfo);
edit((Cast)expr);
}
}
if (expr != null && expr.edited()) {
context.updateMax(expr.locals(), expr.stack());
return true;
}
else
return false;
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
示例5: replace2
private void replace2(String statement)
throws CompileError, NotFoundException, BadBytecode,
CannotCompileException
{
thisClass.getClassFile(); // to call checkModify().
ConstPool constPool = getConstPool();
int pos = currentPos;
CtClass retType;
int codeLength;
int index = 0;
int dim = 1;
String desc;
if (opcode == Opcode.NEWARRAY) {
index = iterator.byteAt(currentPos + 1); // atype
CtPrimitiveType cpt = (CtPrimitiveType)getPrimitiveType(index);
desc = "[" + cpt.getDescriptor();
codeLength = 2;
}
else if (opcode == Opcode.ANEWARRAY) {
index = iterator.u16bitAt(pos + 1);
desc = constPool.getClassInfo(index);
if (desc.startsWith("["))
desc = "[" + desc;
else
desc = "[L" + desc + ";";
codeLength = 3;
}
else if (opcode == Opcode.MULTIANEWARRAY) {
index = iterator.u16bitAt(currentPos + 1);
desc = constPool.getClassInfo(index);
dim = iterator.byteAt(currentPos + 3);
codeLength = 4;
}
else
throw new RuntimeException("bad opcode: " + opcode);
retType = Descriptor.toCtClass(desc, thisClass.getClassPool());
Javac jc = new Javac(thisClass);
CodeAttribute ca = iterator.get();
CtClass[] params = new CtClass[dim];
for (int i = 0; i < dim; ++i)
params[i] = CtClass.intType;
int paramVar = ca.getMaxLocals();
jc.recordParams(javaLangObject, params,
true, paramVar, withinStatic());
/* Is $_ included in the source code?
*/
checkResultValue(retType, statement);
int retVar = jc.recordReturnType(retType, true);
jc.recordProceed(new ProceedForArray(retType, opcode, index, dim));
Bytecode bytecode = jc.getBytecode();
storeStack(params, true, paramVar, bytecode);
jc.recordLocalVariables(ca, pos);
bytecode.addOpcode(Opcode.ACONST_NULL); // initialize $_
bytecode.addAstore(retVar);
jc.compileStmnt(statement);
bytecode.addAload(retVar);
replace0(pos, bytecode, codeLength);
}