I am using the Rascal library for accessing syntax trees that are produced by the Eclipse Java compiler (JDT.rsc).
I am trying to get a fix on how the abstract syntax tree works. One thing that eludes me is the "variableBinding". Imagine a very simple class MyClass
with one method doNothing()
containing one statement, a variable declaration myVar
. The declaration of the string variable myVar
is represented in the AST-snipped below.
Inside the @bindings
annotation, under the variableBinding
key, there is a list that represents the consecutive components of a path to the variable myVar
. The last item represents the actual variable itself, which is represented by the Id constructor variable(str name, int id)
.
Question: What is the meaning of the id?
It certainly isn't unique, because when I duplicate the method doNothing()
and name it doNothing2()
, I find variable("doNothing",0)
and variable("doNothing2",0)
in the AST. What exactly does it identify?
...
variableDeclarationFragment(
"myVar",
none())[
@bindings=(
"typeBinding":entity([
package("java"),
package("lang"),
class("String")
]),
"variableBinding":entity([
class("MyClass"),
method(
"doNothing",
[],
entity([primitive(void())])),
variable("myVar",0) // Here it's 0, but
])
),
@javaType=entity([
package("java"),
package("lang"),
class("String")
]),
@location=|project://my-project/src/MyClass.java|(60,5,<4,15>,<4,19>)
]
...