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


Java UnionType类代码示例

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


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

示例1: getTopMostType

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
 * <p>
 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
 *
 * @param node the starting node, can be <code>null</code>
 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
 * @see #getNormalizedNode(ASTNode)
 */
public static Type getTopMostType(ASTNode node) {
	ASTNode result= null;
	while (node instanceof Type && !(node instanceof UnionType)
			|| node instanceof Name
			|| node instanceof Annotation || node instanceof MemberValuePair
			|| node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
		result= node;
		node= node.getParent();
	}

	if (result instanceof Type) {
		return (Type) result;
	}

	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java

示例2: getTopMostType

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
 * <p>
 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
 * 
 * @param node the starting node, can be <code>null</code>
 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
 * @see #getNormalizedNode(ASTNode)
 */
public static Type getTopMostType(ASTNode node) {
	ASTNode result= null;
	while (node instanceof Type && !(node instanceof UnionType)
			|| node instanceof Name
			|| node instanceof Annotation || node instanceof MemberValuePair
			|| node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
		result= node;
		node= node.getParent();
	}
	
	if (result instanceof Type)
		return (Type) result;
	
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:ASTNodes.java

示例3: 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

示例4: handleCatchArguments

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
private void handleCatchArguments(List<CatchClause> catchClauses) {
	for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
		Type type = iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types = ((UnionType) type).types();
			for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
				removeCaughtExceptions(iterator.next().resolveBinding());
			}
		} else {
			removeCaughtExceptions(type.resolveBinding());
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:AbstractExceptionAnalyzer.java

示例5: handleCatchArguments

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
private void handleCatchArguments(List<CatchClause> catchClauses) {
  for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext(); ) {
    Type type = iter.next().getException().getType();
    if (type instanceof UnionType) {
      List<Type> types = ((UnionType) type).types();
      for (Iterator<Type> iterator = types.iterator(); iterator.hasNext(); ) {
        removeCaughtExceptions(iterator.next().resolveBinding());
      }
    } else {
      removeCaughtExceptions(type.resolveBinding());
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:AbstractExceptionAnalyzer.java

示例6: handleCatchArguments

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
private void handleCatchArguments(List<CatchClause> catchClauses) {
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) {
		Type type= iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types= ((UnionType) type).types();
			for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				removeCaughtExceptions(iterator.next().resolveBinding());
			}
		} else {
			removeCaughtExceptions(type.resolveBinding());
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:AbstractExceptionAnalyzer.java

示例7: visit

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	int currentSize= fCaughtExceptions.size();
	List<CatchClause> catchClauses= node.catchClauses();
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
		Type type= iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types= ((UnionType) type).types();
			for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				addCaughtException(iterator.next());
			}
		} else {
			addCaughtException(type);
		}
	}

	node.getBody().accept(this);

	handleResourceDeclarations(node);

	int toRemove= fCaughtExceptions.size() - currentSize;
	for (int i= toRemove; i > 0; i--) {
		fCaughtExceptions.remove(currentSize);
	}

	// 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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:ExceptionOccurrencesFinder.java

示例8: 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

示例9: visit

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(UnionType node) {
	for (Iterator<Type> it= node.types().iterator(); it.hasNext();) {
		Type t= it.next();
		t.accept(this);
		if (it.hasNext()) {
			this.fBuffer.append("|");//$NON-NLS-1$
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:12,代码来源:ASTFlattener.java

示例10: newType

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
/**
 * Returns the new type node corresponding to the type of the given declaration
 * including the extra dimensions. If the type is a {@link UnionType}, use the LUB type.
 * If the <code>importRewrite</code> is <code>null</code>, the type may be fully-qualified. 
 * 
 * @param ast The AST to create the resulting type with.
 * @param declaration The variable declaration to get the type from
 * @param importRewrite the import rewrite to use, or <code>null</code>
 * @param context the import rewrite context, or <code>null</code>
 * @return a new type node created with the given AST.
 * 
 * @since 3.7.1
 */
public static Type newType(AST ast, VariableDeclaration declaration, ImportRewrite importRewrite, ImportRewriteContext context) {
	Type type= ASTNodes.getType(declaration);

	if (declaration instanceof SingleVariableDeclaration) {
		Type type2= ((SingleVariableDeclaration) declaration).getType();
		if (type2 instanceof UnionType) {
			ITypeBinding typeBinding= type2.resolveBinding();
			if (typeBinding != null) {
				if (importRewrite != null) {
					type= importRewrite.addImport(typeBinding, ast, context);
					return type;
				} else {
					String qualifiedName= typeBinding.getQualifiedName();
					if (qualifiedName.length() > 0) {
						type= ast.newSimpleType(ast.newName(qualifiedName));
						return type;
					}
				}
			}
			// XXX: fallback for intersection types or unresolved types: take first type of union
			type= (Type) ((UnionType) type2).types().get(0);
			return type;
		}
	}
	int extraDim= declaration.getExtraDimensions();
	type= (Type) ASTNode.copySubtree(ast, type);
	for (int i= 0; i < extraDim; i++) {
		type= ast.newArrayType(type);
	}
	return type;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:45,代码来源:ASTNodeFactory.java

示例11: initialize

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

示例12: visit

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
public boolean visit(UnionType node) {
	for (Iterator it = node.types().iterator(); it.hasNext(); ) {
		Type t = (Type) it.next();
		t.accept(this);
		if (it.hasNext()) {
			this.buffer.append('|');
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:11,代码来源:NaiveASTFlattener.java

示例13: 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

示例14: visit

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(final UnionType node) {
	return false;
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:5,代码来源:NotRecursingAstVisitor.java

示例15: visit

import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(final UnionType node) {
	// not instrumentable, contains no instrumentable nodes
	return false;
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:6,代码来源:InstrumentableAstNodeLister.java


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