Java Code Examples for spoon.reflect.code.CtCatch

The following examples show how to use spoon.reflect.code.CtCatch. These examples are extracted from open source projects. 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 Project: nopol   Source File: SpoonModelLibrary.java    License: 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 Project: astor   Source File: SingleTryOperator.java    License: 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();
}
 
Example 3
@Override
public void process(CtStatement element) {
	if (!(element instanceof CtBlock || element instanceof CtClass || element instanceof CtMethod
			|| element instanceof CtTry || element instanceof CtCatch) && 
			(element.getParent() instanceof CtBlock) && 
			(!(element.toString().startsWith("super"))
					|| ConfigurationProperties.getPropertyBool("manipulatesuper"))) {
		add(element);
	}
}
 
Example 4
Source Project: nopol   Source File: SpoonModelLibrary.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static <E extends Throwable> CtTry newTryCatch(Factory factory, CtStatement tryBlock, Class<E> exception, String catchName, CtStatement catchBlock, CtElement parent) {
    CtCatch newCatch = newCatch(factory, exception, catchName, catchBlock);
    return newTryCatch(factory, tryBlock, asList(newCatch), parent);
}
 
Example 5
Source Project: nopol   Source File: SpoonModelLibrary.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static <E extends Throwable> CtCatch newCatch(Factory factory, Class<E> throwableClass, String catchName, CtStatement catchBlock) {
    CtCatch aCatch = factory.Core().createCatch();
    aCatch.setParameter(factory.Code().createCatchVariable(newTypeReference(factory, throwableClass), catchName));
    aCatch.setBody(asBlock(catchBlock, aCatch));
    return aCatch;
}
 
Example 6
@Override
public boolean isToBeProcessed(CtCatch candidate) {
	return candidate.getBody().getStatements().isEmpty();
}
 
Example 7
@Override
public void process(CtCatch element) {
	getEnvironment().report(this, Level.WARN, element, "empty catch clause " + element.getPosition().toString());
	emptyCatchs.add(element);
}