本文整理汇总了Java中org.eclipse.jdt.core.dom.CatchClause.setException方法的典型用法代码示例。如果您正苦于以下问题:Java CatchClause.setException方法的具体用法?Java CatchClause.setException怎么用?Java CatchClause.setException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.CatchClause
的用法示例。
在下文中一共展示了CatchClause.setException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTryStmtWithEmptyCatch
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
@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;
}
示例2: getPickoutTypeFromMulticatchProposals
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
private static boolean getPickoutTypeFromMulticatchProposals(IInvocationContext context, ASTNode node, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
CatchClause catchClause= (CatchClause) ASTResolving.findAncestor(node, ASTNode.CATCH_CLAUSE);
if (catchClause == null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(node);
if (statement != catchClause.getParent() && statement != catchClause.getBody()) {
return false; // selection is in a statement inside the body
}
Type type= catchClause.getException().getType();
if (!type.isUnionType()) {
return false;
}
Type selectedMultiCatchType= null;
if (type.isUnionType() && node instanceof Name) {
Name topMostName= ASTNodes.getTopMostName((Name) node);
ASTNode parent= topMostName.getParent();
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
selectedMultiCatchType= (Type) parent;
}
}
boolean multipleExceptions= coveredNodes.size() > 1;
if ((selectedMultiCatchType == null) && (!(node instanceof UnionType) || !multipleExceptions)) {
return false;
}
if (!multipleExceptions) {
coveredNodes.add(selectedMultiCatchType);
}
BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(catchClause);
if (!(bodyDeclaration instanceof MethodDeclaration) && !(bodyDeclaration instanceof Initializer)) {
return false;
}
if (resultingCollections == null) {
return true;
}
AST ast= bodyDeclaration.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
CatchClause newCatchClause= ast.newCatchClause();
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
UnionType newUnionType= ast.newUnionType();
List<Type> types= newUnionType.types();
for (int i= 0; i < coveredNodes.size(); i++) {
ASTNode typeNode= coveredNodes.get(i);
types.add((Type) rewrite.createCopyTarget(typeNode));
rewrite.remove(typeNode, null);
}
newSingleVariableDeclaration.setType(newUnionType);
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName()));
newCatchClause.setException(newSingleVariableDeclaration);
setCatchClauseBody(newCatchClause, rewrite, catchClause);
TryStatement tryStatement= (TryStatement)catchClause.getParent();
ListRewrite listRewrite= rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY);
listRewrite.insertAfter(newCatchClause, catchClause, null);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);
String label= !multipleExceptions
? CorrectionMessages.QuickAssistProcessor_move_exception_to_separate_catch_block
: CorrectionMessages.QuickAssistProcessor_move_exceptions_to_separate_catch_block;
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.MOVE_EXCEPTION_TO_SEPERATE_CATCH_BLOCK, image);
resultingCollections.add(proposal);
return true;
}
示例3: getUnrollMultiCatchProposals
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
private static boolean getUnrollMultiCatchProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
if (!JavaModelUtil.is17OrHigher(context.getCompilationUnit().getJavaProject()))
return false;
CatchClause catchClause= (CatchClause) ASTResolving.findAncestor(covering, ASTNode.CATCH_CLAUSE);
if (catchClause == null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(covering);
if (statement != catchClause.getParent() && statement != catchClause.getBody()) {
return false; // selection is in a statement inside the body
}
Type type1= catchClause.getException().getType();
Type selectedMultiCatchType= null;
if (type1.isUnionType() && covering instanceof Name) {
Name topMostName= ASTNodes.getTopMostName((Name) covering);
ASTNode parent= topMostName.getParent();
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
selectedMultiCatchType= (Type) parent;
}
}
if (selectedMultiCatchType != null)
return false;
SingleVariableDeclaration singleVariableDeclaration= catchClause.getException();
Type type= singleVariableDeclaration.getType();
if (!(type instanceof UnionType))
return false;
if (resultingCollections == null)
return true;
AST ast= covering.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
TryStatement tryStatement= (TryStatement) catchClause.getParent();
ListRewrite listRewrite= rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY);
UnionType unionType= (UnionType) type;
List<Type> types= unionType.types();
for (int i= types.size() - 1; i >= 0; i--) {
Type type2= types.get(i);
CatchClause newCatchClause= ast.newCatchClause();
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2));
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
newCatchClause.setException(newSingleVariableDeclaration);
setCatchClauseBody(newCatchClause, rewrite, catchClause);
listRewrite.insertAfter(newCatchClause, catchClause, null);
}
rewrite.remove(catchClause, null);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
String label= CorrectionMessages.QuickAssistProcessor_convert_to_multiple_singletype_catch_blocks;
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.USE_SEPARATE_CATCH_BLOCKS, image);
resultingCollections.add(proposal);
return true;
}