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


Java UnionType.types方法代码示例

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


在下文中一共展示了UnionType.types方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeException

import org.eclipse.jdt.core.dom.UnionType; //导入方法依赖的package包/类
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
	ListRewrite listRewrite = rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
	List<Type> types = unionType.types();
	for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
		Type type = iterator.next();
		if (type.equals(exception)) {
			listRewrite.remove(type, null);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:QuickAssistProcessor.java

示例2: removeException

import org.eclipse.jdt.core.dom.UnionType; //导入方法依赖的package包/类
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
	ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
	List<Type> types= unionType.types();
	for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
		Type type= iterator.next();
		if (type.equals(exception)) {
			listRewrite.remove(type, null);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:QuickAssistProcessor.java

示例3: visit

import org.eclipse.jdt.core.dom.UnionType; //导入方法依赖的package包/类
@Override
public boolean visit(CatchClause node) {
	//System.out.println("Found: " + node.getClass());
	ArrayList<Type> types = new ArrayList<>();
	// Handle union types in catch clauses
	if (node.getException().getType() instanceof UnionType) {
		//println("UNIONUNIONUNION");
		UnionType ut = (UnionType)node.getException().getType();
		for (Object o : ut.types()) {
			types.add((Type)o);
		}
	} else {
		types.add(node.getException().getType());
	}
	for (Type t : types) {
		print("catch (");
		t.accept(this);
		print(" ");
		node.getException().getName().accept(this);
		//node.getException().accept(this);
		println(") {");
		indent++;
		node.getBody().accept(this);
		indent--;
		print("} ");
	}
	return false;
}
 
开发者ID:mrmonday,项目名称:j2d,代码行数:29,代码来源:J2dVisitor.java

示例4: getPickoutTypeFromMulticatchProposals

import org.eclipse.jdt.core.dom.UnionType; //导入方法依赖的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

示例5: getUnrollMultiCatchProposals

import org.eclipse.jdt.core.dom.UnionType; //导入方法依赖的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.UnionType.types方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。