Re: question
"Konstantin L. Metlov" <[email protected]> Thu, 7 Apr 2005 14:32:36 +0200 (CEST)
| Newsgroups | gmane.comp.java.jel.general |
|---|---|
| Message-ID | <[email protected]> |
Dear Damien,
> Is there a way to get the list of variables
> referenced/used in an expression?
>
> Using the resolver it could be possible:
> - create an empty list before compiling
> - compiling
> - in getTypeName calls, add the var to the list
>
> Is it right? Is there a better way?
Yes, this is the right way. I'm not sure if there can be anything really
better for this task. The method "getTypeName(String name)" of the
resolver is called for each of recognized identifiers as soon as they are
recognized by the parser. It is really the best place to collect variable
names.
One thing to note is that if the variable name contains dots (e.g. looks
like "name1.name2.name3") the getTypeName() will be called three times
(with arguments "name1", "name1.name2" and "name1.name2.name3"), which
reflects the hierarchical (tree-like) structure of DV namespace. In this
case, the longest sequence for which getTypeName() still returns a
non-null value is considered to be the DV name, but the variables on the
preceding level of the hierarchy (e.g. "name1" and "name1.name2" in the
above example) must also be defined (e.g. (getTypeName("name1") != null)
and (getTypeName("name1.name2")!=null)).
With the best regards,
Konstantin.