I'm using Eclipse ast/jdt as is explained in this post - How can I use the java Eclipse Abstract Syntax Tree in a project outside Eclipse? (ie not an eclipse plugin)
The problem is that I always get null when I tried to use resolveBinding()
, and it's because of not using setProject(IJavaProject) or setEnvironment(String[], String[], String[], boolean)
, as is written in this post - VariableDeclarationFragment node resolveBindind() returns null in eclipse/jdt/ast
Solving the returning null issue, I tried to use the code but ended up getting an error saying Workspace is closed
.
What might be wrong?
I have .project file in the my workspace
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AstRewrite4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
You're not in a Plug-In/Bundle Runtime, so the org.eclipse.core.resources plug-in wasn't "started". Initialization of the Workspace and associated objects only happens then. You'll have to call the start() method on ResourcesPlugin yourself--not that I'm promising that'll solve everything, or that that's not going to cause you other problems.