本文整理汇总了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;
}
示例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;
}
示例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);
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例14: visit
import org.eclipse.jdt.core.dom.UnionType; //导入依赖的package包/类
@Override
public boolean visit(final UnionType node) {
return false;
}
示例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;
}