Question

How do I in BCEL check for this..

Say the bytecode in java is

newarray 10 (int)

I got this already done for visitor

instruction instanceof NEWARRAY

public boolean visit(Instruction instr) {
    return instr instanceof NEWARRAY;
}

But I also have to check if the newarray is int[]

how do I check this in BCEL?

I tried this

 && ((NEWARRAY) instr).getType() == Type.INT;

to well

return instr instanceof NEWARRAY && ((NEWARRAY) instr).getType() == Type.INT;

But you can see the above ^ will not work as it will never be int.. but int[]

But Type.INT is just int.. and not int[]..

How I represent Type int[]?

I was reading the BCEL source code and NEWARRAY.getType() returns this..

     /**
      * @return type of constructed array
      */
     public final Type getType() {
         return new ArrayType(BasicType.getType(type), 1);
     }

As you can see it returns a Type class so.. looking at http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/Type.html

http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/ArrayType.html

there isn't any Type's for ARRAY int[].

Was it helpful?

Solution

I don't think I understand your question well, but what about this:

if(instr.getClass().isArray()) return instr instanceof NEWARRAY[];
else return instr instanceof NEWARRAY;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top