Java Code Examples for spoon.reflect.code.CtTry#setCatchers()

The following examples show how to use spoon.reflect.code.CtTry#setCatchers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpoonModelLibrary.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
public static CtTry newTryCatch(Factory factory, CtStatement tryBlock, List<CtCatch> catchers, CtElement parent) {
    CtTry tryCatch = factory.Core().createTry();
    tryCatch.setBody(asBlock(tryBlock, tryCatch));
    tryCatch.setCatchers(catchers);
    setParent(tryCatch, catchers);
    setParent(parent, tryCatch);
    return tryCatch;
}
 
Example 2
Source File: SingleTryOperator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean applyModification() {

	CtElement el = MetaGenerator.geOriginalElement(statementToWrap);
	if (!(el instanceof CtStatement)) {
		return false;
	}

	CtStatement original = (CtStatement) el;
	this.setParentBlock(original.getParent(CtBlock.class));

	CtTry tryNew = MutationSupporter.getFactory().createTry();
	List<CtCatch> catchers = new ArrayList<>();
	CtCatch catchEx1 = MutationSupporter.getFactory().createCtCatch("e", Exception.class, new CtBlockImpl());
	catchers.add(catchEx1);
	tryNew.setCatchers(catchers);
	CtBlock tryBoddy = new CtBlockImpl();
	tryNew.setBody(tryBoddy);

	CtStatement stmtC = statementToWrap.clone();

	MutationSupporter.clearPosition(stmtC);
	tryBoddy.addStatement(stmtC);

	//
	super.setOriginal(original);
	super.setModified(tryNew);
	//

	return super.applyModification();
}