3

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?

Community
  • 1
  • 1
Danny Lo
  • 1,553
  • 4
  • 26
  • 48
  • possible duplicate of [Eclipse create CompilationUnit from .java file](http://stackoverflow.com/questions/11166862/eclipse-create-compilationunit-from-java-file) – Valentin Montmirail Aug 19 '15 at 09:20

1 Answers1

0

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.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • This is unfortunately insufficient because my goal is get an object of type `org.eclipse.jdt.core.IType` and I cannot use `resolveBinding()` on resulting `ASTNode` if I use `setSource` without JDT – Danny Lo Aug 19 '15 at 09:17