Conversion between ibinding, ijavaelement, and astnode classes

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.