use of spoon.compiler.ModelBuildingException in project spoon by INRIA.
the class ExceptionTest method testExceptionIfNotCompilable.
@Test
public void testExceptionIfNotCompilable() throws Exception {
try {
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/resources/spoon/test/exceptions/ClassWithError.java")).build();
fail();
} catch (ModelBuildingException e) {
// perfect
}
}
use of spoon.compiler.ModelBuildingException in project spoon by INRIA.
the class ExceptionTest method testExceptionInSnippet.
@Test
public void testExceptionInSnippet() {
try {
Factory factory = createFactory();
factory.Code().createCodeSnippetStatement("" + "class X {" + "public void foo() {" + // does not compile here
" int x=Foo;" + "}};").compile();
fail();
} catch (ModelBuildingException e) {
// perfect
}
}
use of spoon.compiler.ModelBuildingException in project spoon by INRIA.
the class JDTBasedSpoonCompiler method report.
protected void report(Environment environment, CategorizedProblem problem) {
if (problem == null) {
throw new IllegalArgumentException("problem cannot be null");
}
File file = new File(new String(problem.getOriginatingFileName()));
String filename = file.getAbsolutePath();
String message = problem.getMessage() + " at " + filename + ":" + problem.getSourceLineNumber();
if (problem.isError()) {
if (!environment.getNoClasspath()) {
// by default, compilation errors are notified as exception
throw new ModelBuildingException(message);
} else {
// in noclasspath mode, errors are only reported
// but undefined import, type, and name errors are irrelevant
int problemId = problem.getID();
if (problemId != IProblem.UndefinedType && problemId != IProblem.UndefinedName && problemId != IProblem.ImportNotFound) {
environment.report(null, Level.WARN, message);
}
}
}
}
Aggregations