lang tools : how to get "TypeElement" for a local variable

Jonathan Gibbons Jonathan.Gibbons at Sun.COM
Sun Nov 9 21:25:41 PST 2008

I would guess the most likely cause is that you are asking for the info
before it has been evaluated.  The TypeElements for the members
and methods are determined fairly early; the TypeElements for the
local variables is determined much later, when the containing
method is being analyzed prior to being code generated.

-- Jon

On Nov 9, 2008, at 9:29 AM, Mayuresh wrote:

> Hi
> I was exploring the syntax tree exposed by Compiler API using  
> TreePathScanner
> based visitor.
> I am trying to get the "TypeElement" for a variable declaration to  
> extract
> qualified type of the variable etc.
> I am using Trees.getElement() to get the TypeElement to which I pass  
> current
> path at a VariableTree node.
> I can get the Element for member or method parameter declaration  
> though for
> local variables Element returned is null.
> Is this a bug? Is there some other way to get TypeElement?
> Mayuresh.

More information about the compiler-dev mailing list