Question

I am using JDT as a library to annotate source code in UIMA framework. In UIMA framework, I obtain the source code in char[] form. Right now I want to figure out those variables binding in source code. Although I did setResolveBinding(true), I always get null by invoking resolveBinding(). JavaDoc said that I need to setProject() and setUnitName() to have non-null results if I feed setSource() by char[].

However, these two things, IJavaProject and UnitName, can only get by importing source file into eclispe project, which is not doable in my situation.

Has anyone solved this problem?

Was it helpful?

Solution 2

To get bindings across multiple files you will have to create temporary files of those char[] and work with (from the ASTParser docs):

public void setEnvironment(String[] classpathEntries,
                       String[] sourcepathEntries,
                       String[] encodings,
                       boolean includeRunningVMBootclasspath)

Sets the environment to be used when no IJavaProject is available. [...]

and

public void createASTs(String[] sourceFilePaths,
                   String[] encodings,
                   String[] bindingKeys,
                   FileASTRequestor requestor,
                   IProgressMonitor monitor)

Creates ASTs for a batch of compilation units. When bindings are being resolved, processing a batch of compilation units is more efficient because much of the work involved in resolving bindings can be shared.

When bindings are being resolved, all compilation units are resolved using the same environment, which must be set beforehand with setEnvironment. [...]

OTHER TIPS

Can you get the jar file of the UIMA framework? If so, We can traverse jar file. Parsing source code is a good option for getting information from AST. However, since a jar file is produced only after successfully compiling, it is also a good option to get useful information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top