Eclipse create CompilationUnit handle from String

330 Views Asked by At

My question is similar to Eclipse create CompilationUnit from .java file however I don't have a file and I would like to create a handle for a CompilationUnit with given contents without actually creating underlying resources.

The actual goal is to get an object of type org.eclipse.jdt.core.IType, so using setSource(char[] source) doesn't solve the problem since there are no bindings in the resulting AST.

Do I necessary have to create a temporary file to fulfill my requirement?

1

There are 1 best solutions below

1
greg-449 On

You can use the

public void setSource(char[] source)

version of the ASTParser.setSource method to give it the source of the code you want to process in a character array rather than a file.