Note that there are some explanatory texts on larger screens.

plurals
  1. PObindings not resolving with AST processing in eclipse
    primarykey
    data
    text
    <p>I'm using the eclipse JDT AST parser to process some Java code and am trying to extract the type bindings for fields and method declarations. The logic for doing that is inside my Visitor class (see below). Unfortunately, I'm not having any luck and none of the bindings are resolving (they are consistently null). The interesting thing is that the bindings do work on the same code with the eclipse ASTView plugin. What am I doing wrong?</p> <p>Here are some relevant code snippets which will hopefully help someone figure out what is going on!</p> <pre><code>ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(source); parser.setResolveBindings(true); CompilationUnit unit = (CompilationUnit) parser.createAST(null); GenericVisitor visitor = new GenericVisitor(outDir + "//" + file.getName() + ".xml"); visitor.process(unit); public class GenericVisitor extends ASTVisitor { public void endVisit(FieldDeclaration node) { String bindingInfo = ""; ITypeBinding binding = node.getType().resolveBinding(); if(binding == null) { System.out.println("field declaration binding = null"); } else { bindingInfo = binding.getQualifiedName(); } endVisitNode(node, bindingInfo); } public void endVisit(MethodInvocation node) { String bindingInfo = ""; IMethodBinding binding = node.resolveMethodBinding(); if(binding == null) { System.out.println("method binding = null"); } else { bindingInfo = binding.toString(); } endVisitNode(node, bindingInfo); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload