本文整理汇总了Java中org.eclipse.jdt.core.dom.TryStatement.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java TryStatement.getBody方法的具体用法?Java TryStatement.getBody怎么用?Java TryStatement.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.TryStatement
的用法示例。
在下文中一共展示了TryStatement.getBody方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: endVisit
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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.TryStatement; //导入方法依赖的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.TryStatement; //导入方法依赖的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: getAddFinallyProposals
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
TryStatement tryStatement= ASTResolving.findParentTryStatement(node);
if (tryStatement == null || tryStatement.getFinally() != null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(node);
if (tryStatement != statement && tryStatement.getBody() != statement) {
return false; // an node inside a catch or finally block
}
if (resultingCollections == null) {
return true;
}
AST ast= tryStatement.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Block finallyBody= ast.newBlock();
rewrite.set(tryStatement, TryStatement.FINALLY_PROPERTY, finallyBody, null);
String label= CorrectionMessages.QuickAssistProcessor_addfinallyblock_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.ADD_FINALLY_BLOCK, image);
resultingCollections.add(proposal);
return true;
}
示例5: getAddFinallyProposals
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
TryStatement tryStatement= ASTResolving.findParentTryStatement(node);
if (tryStatement == null || tryStatement.getFinally() != null) {
return false;
}
Statement statement= ASTResolving.findParentStatement(node);
if (tryStatement != statement && tryStatement.getBody() != statement) {
return false; // an node inside a catch or finally block
}
if (resultingCollections == null) {
return true;
}
AST ast= tryStatement.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Block finallyBody= ast.newBlock();
rewrite.set(tryStatement, TryStatement.FINALLY_PROPERTY, finallyBody, null);
String label= CorrectionMessages.QuickAssistProcessor_addfinallyblock_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image);
resultingCollections.add(proposal);
return true;
}
示例6: visit
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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;
}
示例7: visit
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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;
}
示例8: handleResourceDeclarations
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private void handleResourceDeclarations(TryStatement tryStatement) {
List<VariableDeclarationExpression> resources= tryStatement.resources();
for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
iterator.next().accept(this);
}
//check if the exception is thrown as a result of resource#close()
boolean exitMarked= false;
for (VariableDeclarationExpression variable : resources) {
Type type= variable.getType();
IMethodBinding methodBinding= Bindings.findMethodInHierarchy(type.resolveBinding(), "close", new ITypeBinding[0]); //$NON-NLS-1$
if (methodBinding != null) {
ITypeBinding[] exceptionTypes= methodBinding.getExceptionTypes();
for (int j= 0; j < exceptionTypes.length; j++) {
if (matches(exceptionTypes[j])) { // a close() throws the caught exception
// mark name of resource
for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variable.fragments()) {
SimpleName name= fragment.getName();
fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
}
if (!exitMarked) {
// mark exit position
exitMarked= true;
Block body= tryStatement.getBody();
int offset= body.getStartPosition() + body.getLength() - 1; // closing bracket of try block
fResult.add(new OccurrenceLocation(offset, 1, 0, Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_implicit_close_description,
BasicElementLabels.getJavaElementName(fException.getName()))));
}
}
}
}
}
}
示例9: initialize
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
public String initialize(CompilationUnit root, ASTNode node) {
fASTRoot= root;
if (!(node instanceof Name)) {
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
}
fSelectedName= ASTNodes.getTopMostName((Name)node);
ASTNode parent= fSelectedName.getParent();
MethodDeclaration decl= resolveMethodDeclaration(parent);
if (decl != null && methodThrowsException(decl, fSelectedName)) {
fException= fSelectedName.resolveTypeBinding();
fStart= decl.getBody();
} else if (parent instanceof Type) {
parent= parent.getParent();
if (parent instanceof UnionType) {
parent= parent.getParent();
}
if (parent instanceof SingleVariableDeclaration && parent.getParent() instanceof CatchClause) {
CatchClause catchClause= (CatchClause)parent.getParent();
fTryStatement= (TryStatement)catchClause.getParent();
if (fTryStatement != null) {
fException= fSelectedName.resolveTypeBinding();
fStart= fTryStatement.getBody();
}
}
}
if (fException == null || fStart == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
fDescription= Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fException.getName()));
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:31,代码来源:ExceptionOccurrencesFinder.java
示例10: handleResourceDeclarations
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private void handleResourceDeclarations(TryStatement tryStatement) {
if (tryStatement.getAST().apiLevel() >= AST.JLS4) {
List<VariableDeclarationExpression> resources= tryStatement.resources();
for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
iterator.next().accept(this);
}
//check if the exception is thrown as a result of resource#close()
boolean exitMarked= false;
for (VariableDeclarationExpression variable : resources) {
Type type= variable.getType();
IMethodBinding methodBinding= Bindings.findMethodInHierarchy(type.resolveBinding(), "close", new ITypeBinding[0]); //$NON-NLS-1$
if (methodBinding != null) {
ITypeBinding[] exceptionTypes= methodBinding.getExceptionTypes();
for (int j= 0; j < exceptionTypes.length; j++) {
if (matches(exceptionTypes[j])) { // a close() throws the caught exception
// mark name of resource
for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variable.fragments()) {
SimpleName name= fragment.getName();
fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
}
if (!exitMarked) {
// mark exit position
exitMarked= true;
Block body= tryStatement.getBody();
int offset= body.getStartPosition() + body.getLength() - 1; // closing bracket of try block
fResult.add(new OccurrenceLocation(offset, 1, 0, Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_implicit_close_description,
BasicElementLabels.getJavaElementName(fException.getName()))));
}
}
}
}
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:36,代码来源:ExceptionOccurrencesFinder.java
示例11: initialize
import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
public String initialize(CompilationUnit root, ASTNode node) {
fASTRoot= root;
if (node == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
MethodDeclaration method= ASTResolving.findParentMethodDeclaration(node);
if (method == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
// The ExceptionOccurrencesFinder selects the whole type, no matter what part of it was selected. MethodExitsFinder behaves similar.
if (node instanceof Name) {
node= ASTNodes.getTopMostName((Name) node);
}
ASTNode parent= node.getParent();
if (node.getLocationInParent() == TagElement.FRAGMENTS_PROPERTY) {
// in Javadoc tag:
TagElement tagElement= (TagElement) parent;
String tagName= tagElement.getTagName();
if (node instanceof Name
&& node == tagElement.fragments().get(0)
&& (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName))) {
fSelectedNode= node;
fException= ((Name) node).resolveTypeBinding();
fStart= method;
}
} else {
Type type= ASTNodes.getTopMostType(node);
if (type == null) {
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
}
// in method's "throws" list:
if (type.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
fSelectedNode= type;
fException= type.resolveBinding();
fStart= method;
}
// in catch clause:
Type topType= type;
if (type.getLocationInParent() == UnionType.TYPES_PROPERTY) {
topType= (Type) type.getParent();
}
if (topType.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY
&& topType.getParent().getLocationInParent() == CatchClause.EXCEPTION_PROPERTY) {
fSelectedNode= type;
fException= type.resolveBinding();
fTryStatement= (TryStatement) topType.getParent().getParent().getParent();
fStart= fTryStatement.getBody();
}
}
if (fException == null || fStart == null)
return SearchMessages.ExceptionOccurrencesFinder_no_exception;
fDescription= Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fException.getName()));
return null;
}