use of org.eclipse.jdt.core.dom.CatchClause in project eclipse.jdt.ls by eclipse.
the class FlowAnalyzer method endVisit.
@Override
public void endVisit(TryStatement node) {
if (skipNode(node)) {
return;
}
TryFlowInfo info = createTry();
setFlowInfo(node, info);
for (Iterator<VariableDeclarationExpression> iterator = node.resources().iterator(); iterator.hasNext(); ) {
info.mergeResources(getFlowInfo(iterator.next()), fFlowContext);
}
info.mergeTry(getFlowInfo(node.getBody()), fFlowContext);
for (Iterator<CatchClause> iter = node.catchClauses().iterator(); iter.hasNext(); ) {
CatchClause element = iter.next();
info.mergeCatch(getFlowInfo(element), fFlowContext);
}
info.mergeFinally(getFlowInfo(node.getFinally()), fFlowContext);
}
use of org.eclipse.jdt.core.dom.CatchClause in project evosuite by EvoSuite.
the class JUnitCodeGenerator method createTryStmtWithEmptyCatch.
/*
* Needed to preserve program flow:
*
* try
* {
* var0.doSth();
* }
* catch(Throwable t) {}
*/
@SuppressWarnings("unchecked")
private TryStatement createTryStmtWithEmptyCatch(final AST ast, Statement stmt) {
final TryStatement tryStmt = ast.newTryStatement();
tryStmt.getBody().statements().add(stmt);
final CatchClause cc = ast.newCatchClause();
SingleVariableDeclaration excDecl = ast.newSingleVariableDeclaration();
excDecl.setType(ast.newSimpleType(ast.newSimpleName("Throwable")));
excDecl.setName(ast.newSimpleName("t"));
cc.setException(excDecl);
tryStmt.catchClauses().add(cc);
return tryStmt;
}
use of org.eclipse.jdt.core.dom.CatchClause in project evosuite by EvoSuite.
the class JUnitCodeGenerator method createTryStatementForPostProcessing.
/*
* try
* {
* var0.doSth();
* }
* catch(Throwable t)
* {
* org.uni.saarland.sw.prototype.capture.PostProcessor.captureException(<logRecNo>);
* }
*/
@SuppressWarnings("unchecked")
private TryStatement createTryStatementForPostProcessing(final AST ast, final Statement stmt, final int logRecNo) {
final TryStatement tryStmt = this.createTryStmtWithEmptyCatch(ast, stmt);
final CatchClause cc = (CatchClause) tryStmt.catchClauses().get(0);
final MethodInvocation m = ast.newMethodInvocation();
m.setExpression(ast.newName(new String[] { "org", "evosuite", "testcarver", "codegen", "PostProcessor" }));
m.setName(ast.newSimpleName("captureException"));
m.arguments().add(ast.newNumberLiteral(String.valueOf(logRecNo)));
cc.getBody().statements().add(ast.newExpressionStatement(m));
MethodInvocation m2 = ast.newMethodInvocation();
m2.setExpression(ast.newSimpleName("t"));
m2.setName(ast.newSimpleName("printStackTrace"));
cc.getBody().statements().add(ast.newExpressionStatement(m2));
return tryStmt;
}
use of org.eclipse.jdt.core.dom.CatchClause in project flux by eclipse.
the class StatementAnalyzer method endVisit.
/* (non-Javadoc)
* Method declared in ASTVisitor
*/
@Override
public void endVisit(TryStatement node) {
ASTNode firstSelectedNode = getFirstSelectedNode();
if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) {
if (firstSelectedNode == node.getBody() || firstSelectedNode == node.getFinally()) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else {
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iterator = catchClauses.iterator(); iterator.hasNext(); ) {
CatchClause element = iterator.next();
if (element == firstSelectedNode || element.getBody() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else if (element.getException() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_catch_argument);
}
}
}
}
super.endVisit(node);
}
use of org.eclipse.jdt.core.dom.CatchClause in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final SingleVariableDeclaration it) {
if ((((it.getParent() instanceof MethodDeclaration) || (it.getParent() instanceof CatchClause)) || (it.getParent() instanceof EnhancedForStatement))) {
final Function1<IExtendedModifier, Boolean> _function = (IExtendedModifier it_1) -> {
return Boolean.valueOf(it_1.isAnnotation());
};
this.appendModifiers(it, IterableExtensions.<IExtendedModifier>filter(Iterables.<IExtendedModifier>filter(it.modifiers(), IExtendedModifier.class), _function));
} else {
this.appendModifiers(it, it.modifiers());
}
it.getType().accept(this);
this.appendExtraDimensions(it.getExtraDimensions());
boolean _isVarargs = it.isVarargs();
if (_isVarargs) {
this.appendToBuffer("...");
}
this.appendSpaceToBuffer();
it.getName().accept(this);
Expression _initializer = it.getInitializer();
boolean _tripleNotEquals = (_initializer != null);
if (_tripleNotEquals) {
this.appendToBuffer("=");
it.getInitializer().accept(this);
}
return false;
}
Aggregations