当前位置: 首页>>代码示例>>Java>>正文


Java CatchClause.getBody方法代码示例

本文整理汇总了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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:StatementAnalyzer.java

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

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

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

示例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;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:35,代码来源:ASTVisitorAtomicChange.java

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

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


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