JDT Users

Other FAQ collections

How to disable the navigation bar or the mini package explorer located above the Java editor?

The navigation bar is called the Breadcrumb. To disable the breadcrumb, click Toggle Java Editor Breadcrumb in the main toolbar. Since 3.7, you can also choose Hide Breadcrumb from the context menu of a breadcrumb item. More details on the Java editor breadcrumb can be found in Eclipse help.

Can I use JDT outside Eclipse to compile Java code?

Yes, the batch compiler can be invoked from command line or via the ant javac adapter. More details can be found in Java development user guide.

JDT Extenders

Other FAQ collection

Can I use JDT outside Eclipse to manipulate Java code?

JDT Core has no dependency on UI side, however it requires a runtime-workbench. Hence you can use it in an Eclipse headless application or include all the dependent jar files in the class path of your application. (You will have to use ASTParser.setSource() and ASTParser.setEnvironment() to be able to parse non Eclipse Java projects.)

How to go from one of IBinding, IJavaElement, ASTNode to another?

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 IImportContainer 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 the 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.

If your question is not answered above

Consider browsing through the frequently asked questions on Stackoverflow