use of spoon.reflect.code.CtCatch in project spoon by INRIA.
the class TryCatchTest method testMultiTryCatchWithCustomExceptions.
@Test
public void testMultiTryCatchWithCustomExceptions() throws Exception {
final Launcher launcher = new Launcher();
final SpoonModelBuilder compiler = launcher.createCompiler();
compiler.addInputSource(new File("./src/test/java/spoon/test/trycatch/testclasses/"));
compiler.build();
Factory factory = compiler.getFactory();
final CtClass<?> foo = (CtClass<?>) factory.Type().get(Foo.class);
final CtCatch ctCatch = foo.getElements(new AbstractFilter<CtCatch>(CtCatch.class) {
@Override
public boolean matches(CtCatch element) {
return true;
}
}).get(0);
final String expected = "catch (spoon.test.trycatch.testclasses.internal.MyException | spoon.test.trycatch.testclasses.internal.MyException2 ignore) {" + System.lineSeparator() + "}";
assertEquals(expected, ctCatch.toString());
}
use of spoon.reflect.code.CtCatch in project Ex2Amplifier by STAMP-project.
the class MainGenerator method addCatchGivenExceptionToTry.
private static void addCatchGivenExceptionToTry(CtTypeReference exceptionType, Factory factory, CtTry aTry, String suffixNameException) {
final CtCatch aCatch = factory.createCatch();
final CtCatchVariable catchVariable = factory.createCatchVariable();
catchVariable.setSimpleName("__exceptionEx2Amplifier" + suffixNameException);
catchVariable.setType(exceptionType);
aCatch.setParameter(catchVariable);
final CtThrow aThrow = factory.createThrow();
aThrow.setThrownExpression(factory.createConstructorCall(factory.Type().createReference("java.lang.RuntimeException"), factory.createVariableRead(factory.createCatchVariableReference(catchVariable), false)));
aCatch.setBody(aThrow);
aTry.addCatcher(aCatch);
}
Aggregations