Variable reference and variable inizializer

Antonio Tancredi nazareno.tancredi at
Fri Sep 7 09:17:11 PDT 2012

Good morning,
I'm trying to create a simple AST visualizer using the OpenJDK compiler and
I have one problem.
I hope is allowed to ask this kind of question in the mailing list. If not,
please excuse me.

I'm trying to visit the JCCompilationUnit tree right after the Attr phase.
When I see a variable reference (a JCIdent where "sym.kind == Kinds.VAR",
if I'm correct), I want to retrieve the initializer (if exists) for that
For initializer, I mean the JCExpression used for the "init" field of the
related JCVariableDecl tree.

For instance, for this snippet

[1] int x = 0;
[2] int y = x+1;

in the second line, when I find the JCIdent for "x", I also want to find
the JCLiteral (the initializer with value zero) from the first line.

Is this possible using the compiler tools?

Thank you,

Antonio Tancredi
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the compiler-dev mailing list