本文整理汇总了Java中org.eclipse.jdt.core.dom.CatchClause.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java CatchClause.getBody方法的具体用法?Java CatchClause.getBody怎么用?Java CatchClause.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.CatchClause
的用法示例。
在下文中一共展示了CatchClause.getBody方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
@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);
}
示例2: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
@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);
}
示例3: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
@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);
}
示例4: visit
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
public boolean visit(TryStatement node) {
if (mtbStack.isEmpty()) // not part of a method
return true;
String bodyStr = node.getBody() != null ? node.getBody().toString()
: "";
bodyStr = edit_str(bodyStr);
StringBuilder catchClauses = new StringBuilder();
for (Object o : node.catchClauses()) {
if (catchClauses.length() > 0)
catchClauses.append(",");
CatchClause c = (CatchClause) o;
catchClauses.append(getQualifiedName(c.getException().getType()
.resolveBinding()));
catchClauses.append(":");
if (c.getBody() != null)
catchClauses.append(edit_str(c.getBody().toString()));
}
String finallyStr = node.getFinally() != null ? node.getFinally()
.toString() : "";
finallyStr = edit_str(finallyStr);
IMethodBinding mtb = mtbStack.peek();
String methodStr = getQualifiedName(mtb);
facts.add(Fact.makeTryCatchFact(bodyStr, catchClauses.toString(),
finallyStr, methodStr));
return true;
}
示例5: visit
import org.eclipse.jdt.core.dom.CatchClause; //导入方法依赖的package包/类
public boolean visit(TryStatement node)
{
if (this.mtbStack.isEmpty()) {
return true;
}
String bodyStr = node.getBody() != null ? node.getBody().toString() :
"";
bodyStr = edit_str(bodyStr);
StringBuilder catchClauses = new StringBuilder();
for (Object o : node.catchClauses())
{
if (catchClauses.length() > 0) {
catchClauses.append(",");
}
CatchClause c = (CatchClause)o;
catchClauses.append(getQualifiedName(c.getException().getType()
.resolveBinding()));
catchClauses.append(":");
if (c.getBody() != null) {
catchClauses.append(edit_str(c.getBody().toString()));
}
}
String finallyStr = node.getFinally() != null ? node.getFinally()
.toString() : "";
finallyStr = edit_str(finallyStr);
IMethodBinding mtb = (IMethodBinding)this.mtbStack.peek();
String methodStr = getQualifiedName(mtb);
this.facts.add(Fact.makeTryCatchFact(bodyStr, catchClauses.toString(),
finallyStr, methodStr));
return true;
}
示例6: 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;
}
示例7: 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;
}