[Soot-list] Soot and Java Annotations

Eric Bodden eric.bodden at ec-spride.de
Thu Feb 2 03:25:13 EST 2012


Hi.

> You are right. I do not know why, but there are no annotations at local
> variables in the Java bytecode.

This has a reason: There are no local variables in bytecode. :-)

> But I have the Java sourcecode. Is it
> possible to write an additional (user-defined) soot phase, which retains the
> information about these annotations? I guess, the new step must be in the
> very beginning, before the source code is transformed in one of the
> intermediate languages.

It should be possible yes, best by modifying our JastAdd-based
frontend. Currently, this is implemented in the file
JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag which you
can find here:
http://svn.cs.lth.se/svn/jastadd-oxford/projects/trunk/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag

> It is hard to add user-defined attributes (about Java annotations) to
> locals, because the type "Local" does not implement the interface "Host",
> isn't it? But maybe we can introduce a new tag and add these information to
> the method, where the local variable is declared.
> Example:
> sootMethod.getTag("NewTag").localVarHasAnnotations(localVar);
> and / or
> sootMethod.getTag("NewTag").getAnnotation(localVar);

That sounds like a reasonable approach. I would rather attach it to
the method body though instead of the method, so that the tag will be
moved if the body is moved (some transformations do such fancy
things).

Eric


More information about the Soot-list mailing list