I am writing unit tests for my plugin that makes use of IType and IMethod interfaces from JDT. To write unit tests I would need to instantiate such interfaces. Answer to this question shows how to create AST model, but I don't know how to convert it into Java model?
My code looks like this:
String source =
"package com.test\n" +
"\n" +
"import com.test.something;" +
"\n" +
"public class Class{\n" +
"int sum(int a, int b)\n" +
"}\n";
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setSource(source.toCharArray());
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
So I have an instance of CompilationUnit
, but I need an instance of ICompilationUInit, so I can get access to IMethod
and IType
objects.