• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TryStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jdt.core.dom.TryStatement的典型用法代码示例。如果您正苦于以下问题:Java TryStatement类的具体用法?Java TryStatement怎么用?Java TryStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TryStatement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了TryStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:28,代码来源:WeightMethodsPerClassVisitor.java


示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:FlowAnalyzer.java


示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:FlowAnalyzer.java


示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:StatementAnalyzer.java


示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:AbstractExceptionAnalyzer.java


示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:StatementAnalyzer.java


示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:InlineTempRefactoring.java


示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:FlowAnalyzer.java


示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ExtractTempRefactoring.java


示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:StatementAnalyzer.java


示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:QuickAssistProcessor.java


示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:27,代码来源:QuickAssistProcessor.java


示例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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:19,代码来源:HTTPClientResolution.java


示例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;
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:9,代码来源:WrapperDecorator.java


示例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);
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:14,代码来源:TryStatementWrapper.java


示例16: 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;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:31,代码来源:ASTVisitorAtomicChange.java


示例17: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
/**
 * @see ASTVisitor#visit(TryStatement)
 */
@Override
public boolean visit(TryStatement node) {
	cyclomaticComplexityIndex++;
	sumCyclomaticComplexity++;
	return true;
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:10,代码来源:CyclomaticComplexityVisitor.java


示例18: pushExcptions

import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
void pushExcptions(TryStatement node) {
	List<CatchClause> catchClauses= node.catchClauses();
	if (catchClauses == null) {
		catchClauses= EMPTY_CATCH_CLAUSE;
	}
	fExceptionStack.add(catchClauses);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:FlowContext.java


示例19: endVisit

import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@Override
public void endVisit(VariableDeclarationExpression node) {
	if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) {
		if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
			invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_resource_in_try_with_resources, JavaStatusContext.create(fCUnit, getSelection()));
		}
	}
	checkTypeInDeclaration(node.getType());
	super.endVisit(node);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:ExtractMethodAnalyzer.java


示例20: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	fCurrentExceptions = new ArrayList<>(1);
	fTryStack.push(fCurrentExceptions);

	// visit try block
	node.getBody().accept(this);

	List<VariableDeclarationExpression> resources = node.resources();
	for (Iterator<VariableDeclarationExpression> iterator = resources.iterator(); iterator.hasNext();) {
		iterator.next().accept(this);
	}

	// Remove those exceptions that get catch by following catch blocks
	List<CatchClause> catchClauses = node.catchClauses();
	if (!catchClauses.isEmpty()) {
		handleCatchArguments(catchClauses);
	}
	List<ITypeBinding> current = fTryStack.pop();
	fCurrentExceptions = fTryStack.peek();
	for (Iterator<ITypeBinding> iter = current.iterator(); iter.hasNext();) {
		addException(iter.next(), node.getAST());
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null) {
		node.getFinally().accept(this);
	}

	// return false. We have visited the body by ourselves.
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:AbstractExceptionAnalyzer.java



注:本文中的org.eclipse.jdt.core.dom.TryStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Activity类代码示例发布时间:2022-05-21
下一篇:
Java Embedded类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap