Search in sources :

Example 6 with CtThrow

use of spoon.reflect.code.CtThrow 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);
}
Also used : CtThrow(spoon.reflect.code.CtThrow) CtCatch(spoon.reflect.code.CtCatch) CtCatchVariable(spoon.reflect.code.CtCatchVariable)

Aggregations

CtThrow (spoon.reflect.code.CtThrow)6 CtConstructorCall (spoon.reflect.code.CtConstructorCall)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.junit.Test)1 SpoonException (spoon.SpoonException)1 CtAssignment (spoon.reflect.code.CtAssignment)1 CtBlock (spoon.reflect.code.CtBlock)1 CtCatch (spoon.reflect.code.CtCatch)1 CtCatchVariable (spoon.reflect.code.CtCatchVariable)1 CtComment (spoon.reflect.code.CtComment)1 CtExpression (spoon.reflect.code.CtExpression)1 CtFieldAccess (spoon.reflect.code.CtFieldAccess)1 CtIf (spoon.reflect.code.CtIf)1 CtInvocation (spoon.reflect.code.CtInvocation)1 CtLocalVariable (spoon.reflect.code.CtLocalVariable)1 CtVariableAccess (spoon.reflect.code.CtVariableAccess)1 CtElement (spoon.reflect.declaration.CtElement)1