How to go from one of ibinding, ijavaelement, astnode to another? Tags: AST, mutual conversion between jdt
From an ibinding to its declaring astnode
Org. Eclipse. jdt. Core. Dom. compilationunit. finddeclaringnode (ibinding)
From an ibinding to an ijavaelement
Org. Eclipse. jdt. Core. Dom. ibinding. getjavaelement ()
From an astnode to an ibinding
Look for a 'resolvebinding () '(or similarly named method) method in a subtype of astnode. Note that not all subtypes of astnode have a corresponding binding, e.g. methoddeclaration, expression and variabledeclaration
Have one but ifstatement and forstatement do not.
From an ijavaelement to an ibinding
If you only need the binding key and not the binding object itself, look for a 'getkey () 'method in a subtype of ijavaelement. this method returns the binding key, which can be useful in many situations e.g. see next
Point. Note that not all subtypes of ijavaelement have a corresponding binding, e.g. itype and imethod have one but ipackagefragment and iimportiner iner do not.
If you really need the binding objects you can use 'org. eclipse. jdt. core. dom. astparser. createbindings (ijavaelement [], iprogressmonitor )'. note that this operation is slightly expensive, compared to just getting
Binding key, as the bindings have to be created.
From an ijavaelement to its declaring astnode
Org. Eclipse. jdt. Core. Dom. compilationunit. finddeclaringnode (string)-the string parameter is the binding key, see previous point.
Note: Some former colleagues asked about the conversion between jdt and AST. Today, I accidentally saw the above description in the jdt FAQ and posted it.
Delete other chat burning:
Ast --> jdt
Binding. getjavaelement ()
Jdt --> AST
Org. Eclipse. jdt. Core. Dom. compilationunit. finddeclaringnode (string)
Passengers 10:57:49
Public astnode finddeclaringnode (string key ){
Return this. Ast. getbindingresolver (). finddeclaringnode (key );
}
You can import the key parameter to ijavaelement. getkey ().
Passengers 10:59:30
Setresolvebindings (true) needs to be set)