[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: specialinvoke for <init> = super()



The SpecialInvokeExpr is an expression, not a statement. Before adding
it to the chain of units, you need to wrap it in an InvokeStmt:

myUnits.addLast(
    Jimple.v().newInvokeStmt(
        Jimple.v().newSpecialInvokeExpr(initLocal,myInitMethod)));

Ondrej

On Mon, Nov 24, 2003 at 01:16:39PM +0100, Emil Slusanschi wrote:
> Ok, I created the new method <init> in my class but how do I get a 
> statement like this?
> 
> specialinvoke r0.<java.lang.Object: void <init>()>();
> 
> I got the "java.lang.Object: void <init>()" SootMethod as you can see below:
> 
> Chain myUnits = myBody.getUnits();
> 
> SootClass mySuperClass = myClass.getSuperclass();
> 
> SootMethod myInitMethod = mySuperClass.getMethodByName("<init>");
> 
> 
> But when I try to add this to my chain/body:
> 	myUnits.addLast(Jimple.v().newSpecialInvokeExpr(initLocal,myInitMethod));
> 
> 
> I get the a "Exception in thread "main" java.lang.ClassCastException" 
> exception when I try to write it out with the Printer package to a class 
> file. Of course initLocal is exactly the r0 local referred above in my 
> target Jimple expression.
> 
> Cheers,
> 
> Emil
> 
> Feng Qian wrote:
> > I believe you have to create an <init> method, because a newly created 
> > object should be initialized before other uses. You can create a very 
> > simple <init> method which invokes super.<init> .
> > 
> > Cheers,
> > Feng
> 
> 
>