use of spoon.reflect.code.CtCatchVariable in project spoon by INRIA.
the class JDTTreeBuilderHelper method createCatchVariable.
/**
* Creates a catch variable from a type reference.
*
* @param typeReference
* Correspond to the exception type declared in the catch.
* @return a catch variable.
*/
CtCatchVariable<Throwable> createCatchVariable(TypeReference typeReference) {
final Argument jdtCatch = (Argument) jdtTreeBuilder.getContextBuilder().stack.peekFirst().node;
final Set<CtExtendedModifier> modifiers = getModifiers(jdtCatch.modifiers, false, false);
CtCatchVariable<Throwable> result = jdtTreeBuilder.getFactory().Core().createCatchVariable();
result.<CtCatchVariable>setSimpleName(CharOperation.charToString(jdtCatch.name)).setExtendedModifiers(modifiers);
if (typeReference instanceof UnionTypeReference) {
// do not set type of variable yet. It will be initialized later by visit of multiple types. Each call then ADDs one type
return result;
} else {
CtTypeReference ctTypeReference = jdtTreeBuilder.getReferencesBuilder().<Throwable>getTypeReference(typeReference.resolvedType);
return result.<CtCatchVariable>setType(ctTypeReference);
}
}
use of spoon.reflect.code.CtCatchVariable 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