本文整理汇总了Java中org.eclipse.jdt.core.dom.TryStatement类的典型用法代码示例。如果您正苦于以下问题:Java TryStatement类的具体用法?Java TryStatement怎么用?Java TryStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TryStatement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了TryStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStatementType
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
/**
* Method that check statement type.
* @author Mariana Azevedo
* @since 13/07/2014
* @param itStatement
*/
private void getStatementType(Object itStatement) {
if (itStatement instanceof CatchClause){
this.visitor.visit((CatchClause)itStatement);
}else if (itStatement instanceof ForStatement){
this.visitor.visit((ForStatement)itStatement);
}else if (itStatement instanceof IfStatement){
this.visitor.visit((IfStatement)itStatement);
}else if (itStatement instanceof WhileStatement){
this.visitor.visit((WhileStatement)itStatement);
}else if (itStatement instanceof TryStatement){
this.visitor.visit((TryStatement)itStatement);
}else if (itStatement instanceof ConditionalExpression){
this.visitor.visit((ConditionalExpression)itStatement);
}else if (itStatement instanceof SwitchCase){
this.visitor.visit((SwitchCase)itStatement);
}else if (itStatement instanceof DoStatement){
this.visitor.visit((DoStatement)itStatement);
}else if (itStatement instanceof ExpressionStatement){
this.visitor.visit((ExpressionStatement)itStatement);
}
}
示例2: visit
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
if (traverseNode(node)) {
fFlowContext.pushExcptions(node);
for (Iterator<VariableDeclarationExpression> iterator = node.resources().iterator(); iterator.hasNext();) {
iterator.next().accept(this);
}
node.getBody().accept(this);
fFlowContext.popExceptions();
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
iter.next().accept(this);
}
Block finallyBlock = node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
}
return false;
}
示例3: endVisit
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@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);
}
示例4: 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);
}
示例5: visit
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@Override
public boolean visit(VariableDeclarationExpression node) {
if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
Type type = node.getType();
ITypeBinding resourceTypeBinding = type.resolveBinding();
if (resourceTypeBinding != null) {
IMethodBinding methodBinding =
Bindings.findMethodInHierarchy(
resourceTypeBinding, "close", new ITypeBinding[0]); // $NON-NLS-1$
if (methodBinding != null) {
addExceptions(methodBinding.getExceptionTypes(), node.getAST());
}
}
}
return super.visit(node);
}
示例6: 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);
}
示例7: checkSelection
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
private RefactoringStatus checkSelection(VariableDeclaration decl) {
ASTNode parent= decl.getParent();
if (parent instanceof MethodDeclaration) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_method_parameter);
}
if (parent instanceof CatchClause) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_exceptions_declared);
}
if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == ForStatement.INITIALIZERS_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_for_initializers);
}
if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_resource_in_try_with_resources);
}
if (decl.getInitializer() == null) {
String message= Messages.format(RefactoringCoreMessages.InlineTempRefactoring_not_initialized, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
return RefactoringStatus.createFatalErrorStatus(message);
}
return checkAssignments(decl);
}
示例8: visit
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
if (traverseNode(node)) {
fFlowContext.pushExcptions(node);
node.getBody().accept(this);
fFlowContext.popExceptions();
List<CatchClause> catchClauses= node.catchClauses();
for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
iter.next().accept(this);
}
Block finallyBlock= node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
}
return false;
}
示例9: checkExpression
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent= selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
else
return null;
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
示例10: 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);
}
示例11: 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;
}
示例12: 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;
}
示例13: findLastTryStatementUsingVariable
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static TryStatement findLastTryStatementUsingVariable(SimpleName variable) {
// looks for the last try statement that has a reference to the variable referred to
// by the included simpleName.
// If we can't find such a try block, we give up trying to fix
Block parentBlock = TraversalUtil.findClosestAncestor(variable, Block.class);
List<Statement> statements = parentBlock.statements();
for (int i = statements.size() - 1; i >= 0; i--) {
Statement s = statements.get(i);
if (s instanceof TryStatement) {
TryStatement tryStatement = (TryStatement) s;
if (tryRefersToVariable(tryStatement, variable)) {
return tryStatement;
}
}
}
return null;
}
示例14: wrap
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
public static Object wrap(Object statement, int indentation, Applicable applicable) {
if (statement instanceof IfStatement) {
return new IfStatementWrapper((IfStatement) statement, indentation, applicable);
} else if (statement instanceof TryStatement) {
return new TryStatementWrapper((TryStatement) statement, indentation, applicable);
}
return statement;
}
示例15: TryStatementWrapper
import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
TryStatementWrapper(TryStatement statement, int indentationLevel, Applicable applicable) {
super(indentationLevel, applicable);
body.addAll(statement.resources());
ofNullable(statement.getBody()).ifPresent(block -> body.addAll(block.statements()));
this.catchClauses = (LinkedList<CatchClauseWrapper>) statement.catchClauses().stream()
.map(catchClause -> new CatchClauseWrapper((CatchClause) catchClause, indentationLevel, applicable))
.collect(toCollection(LinkedList::new));
finallyBody = ofNullable(statement.getFinally())
.map(Block::statements);
applicable.applyFeaturesToStatements(body);
finallyBody.ifPresent(applicable::applyFeaturesToStatements);
}