Question

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>)
]
...
Was it helpful?

Solution

This id field actually appears to be an identifier assigned internally by Eclipse. You can see the JavaDoc for the IVariableBinding interface here, which is the source of the id:

http://help.eclipse.org/indigo/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/IVariableBinding.html#getVariableId()

Just click on the link for getVariableId() if it doesn't take you there, and instead just takes you to the page for the interface. This is the method called to get the id. From what I can tell, it isn't very useful and can probably safely be ignored in most cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top