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

Java UnionType类代码示例

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

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



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

示例1: visitThrow

import javax.lang.model.type.UnionType; //导入依赖的package包/类
public Void visitThrow(ThrowTree node, Set<TypeMirror> p) {
    super.visitThrow(node, p);
    TypeMirror tm = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
    if (tm != null) {
        if (tm.getKind() == TypeKind.DECLARED)
            p.add(tm);
        else if (tm.getKind() == TypeKind.UNION)
            p.addAll(((UnionType)tm).getAlternatives());
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeUtilities.java


示例2: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public Void visitUnion(UnionType t, Collection<DeclaredType> p) {
    for (TypeMirror tm : t.getAlternatives()) {
        visit(tm, p);
    }
    return DEFAULT_VALUE;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DeclaredTypeCollector.java


示例3: performRewrite

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath tp = ctx.getPath();
    List<Tree> disjointTypes = new LinkedList<Tree>();
    TryTree tt = (TryTree) tp.getLeaf();
    int first = duplicates.get(0);
    List<Integer> remainingDuplicates = duplicates.subList(1, duplicates.size());
    
    addDisjointType(disjointTypes, tt.getCatches().get(first).getParameter().getType());

    for (Integer d : remainingDuplicates) {
        addDisjointType(disjointTypes, tt.getCatches().get((int) d).getParameter().getType());
    }

    List<CatchTree> newCatches = new LinkedList<CatchTree>();
    int c = 0;

    for (CatchTree ct : tt.getCatches()) {
        if (c == first) {
            wc.rewrite(ct.getParameter().getType(), wc.getTreeMaker().UnionType(disjointTypes));
        }
        
        if (remainingDuplicates.contains(c++)) continue;

        newCatches.add(ct);
    }

    TryTree nue = wc.getTreeMaker().Try(tt.getResources(), tt.getBlock(), newCatches, tt.getFinallyBlock());

    wc.rewrite(tt, nue);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:JoinCatches.java


示例4: getCaughtExceptions

import javax.lang.model.type.UnionType; //导入依赖的package包/类
private static List<? extends TypeMirror> getCaughtExceptions(TypeMirror caught) {
    if (caught == null) {
        return Collections.emptyList();
    }
    switch (caught.getKind()) {
        case UNION: {
            boolean cloned = false;
            List<? extends TypeMirror> types = ((UnionType) caught).getAlternatives();
            int i = types.size() - 1;
            for (; i >= 0; i--) {
                TypeMirror m = types.get(i);
                TypeKind mk = m.getKind();
                if (mk == null || mk != TypeKind.DECLARED) {
                    if (!cloned) {
                        types = new ArrayList<TypeMirror>(types);
                    }
                    types.remove(i);
                }
            }
            
            return types;
        }
        case DECLARED:
            return Collections.singletonList(caught);
        default:
            return Collections.emptyList();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:Utilities.java


示例5: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public Boolean visitUnion(UnionType tm, Void p) {
    for (TypeMirror t : tm.getAlternatives()) {
        if (stop) {
            return false;
        }
        
        if (t.accept(this, p)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ExportNonAccessibleElement.java


示例6: matches

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
  Type type = ((JCTree) tree).type;
  if (type.isUnion()) {
    for (TypeMirror alternative : ((UnionType) type).getAlternatives()) {
      if (!isKnownCheckedException(state, (Type) alternative)) {
        return false;
      }
    }
    return true;
  } else {
    return isKnownCheckedException(state, type);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ThrowIfUncheckedKnownChecked.java


示例7: getCopy

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public AnnotatedUnionType getCopy(boolean copyAnnotations) {
    AnnotatedUnionType type =
            new AnnotatedUnionType((UnionType) actualType, atypeFactory);
    if (copyAnnotations)
        type.addAnnotations(annotations);
    type.alternatives = this.alternatives;
    return type;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:10,代码来源:AnnotatedTypeMirror.java


示例8: getAlternatives

import javax.lang.model.type.UnionType; //导入依赖的package包/类
public List<AnnotatedDeclaredType> getAlternatives() {
    if (alternatives == null) {
        List<? extends TypeMirror> ualts = ((UnionType)actualType).getAlternatives();
        List<AnnotatedDeclaredType> res = new ArrayList<AnnotatedDeclaredType>(ualts.size());
        for (TypeMirror alt : ualts) {
            res.add((AnnotatedDeclaredType) createType(alt, atypeFactory));
        }
        alternatives = Collections.unmodifiableList(res);
    }
    return alternatives;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:12,代码来源:AnnotatedTypeMirror.java


示例9: accept

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  switch (kind) {
    case BOOLEAN:
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case CHAR:
    case FLOAT:
    case DOUBLE:
      return v.visitPrimitive((PrimitiveType) this, p);
    case PACKAGE:
    case VOID:
    case NONE:
      return v.visitNoType((NoType) this, p);
    case NULL:
      return v.visitNull((NullType) this, p);
    case ARRAY:
      return v.visitArray((ArrayType) this, p);
    case DECLARED:
      return v.visitDeclared((DeclaredType) this, p);
    case ERROR:
      return v.visitError((ErrorType) this, p);
    case TYPEVAR:
      return v.visitTypeVariable((TypeVariable) this, p);
    case WILDCARD:
      return v.visitWildcard((WildcardType) this, p);
    case EXECUTABLE:
      return v.visitExecutable((ExecutableType) this, p);
    case OTHER:
      return v.visit(this, p);
    case UNION:
      return v.visitUnion((UnionType) this, p);
    case INTERSECTION:
      return v.visitIntersection((IntersectionType) this, p);
    default:
      throw new AssertionError(String.format("Unknown TypeKind: %s", kind));
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:41,代码来源:StandaloneTypeMirror.java


示例10: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public Type visitUnion(UnionType t, Type.Parameters p) {
  throw new UnsupportedOperationException("UnionType type not supported");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:TypeExtractor.java


示例11: findUncaughtExceptions

import javax.lang.model.type.UnionType; //导入依赖的package包/类
private List<? extends TypeMirror> findUncaughtExceptions(CompilationInfo info, TreePath path, List<? extends TypeMirror> exceptions) {
    List<TypeMirror> result = new ArrayList<TypeMirror>();
    
    result.addAll(exceptions);
    
    Tree lastTree = null;
    
    while (path != null) {
        Tree currentTree = path.getLeaf();

        if (currentTree.getKind() == Tree.Kind.METHOD) {
            TypeMirror tm = info.getTrees().getTypeMirror(path);
            if (tm != null && tm.getKind() == TypeKind.EXECUTABLE) {
                for (TypeMirror mirr : ((ExecutableType) tm).getThrownTypes()) {
                    for (Iterator<TypeMirror> it = result.iterator(); it.hasNext();)
                        if (info.getTypes().isSameType(it.next(), mirr))
                            it.remove();
                }
                break;
            }
        }            
        
        if (currentTree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
            // no checked exceptions can be thrown out of Lambda, #243106
            break;
        }
        
        if (currentTree.getKind() == Kind.TRY) {
            TryTree tt = (TryTree) currentTree;
            
            if (tt.getBlock() == lastTree) {
                for (CatchTree c : tt.getCatches()) {
                    TreePath catchPath = new TreePath(new TreePath(path, c), c.getParameter());
                    VariableElement variable = (VariableElement) info.getTrees().getElement(catchPath);
                    if (variable == null) {
                        continue;
                    }
                    TypeMirror variableType = variable.asType();
                    if (variableType.getKind() == TypeKind.UNION) {
                        result.removeAll(((UnionType)variableType).getAlternatives());
                    } else {
                        result.remove(variableType);
                    }
                }
            }
        }
        
        lastTree = path.getLeaf();
        path = path.getParentPath();
    }
    
    List<TypeMirror> filtered = new ArrayList<>();
    
    OUTER: for (Iterator<TypeMirror> sourceIt = result.iterator(); sourceIt.hasNext(); ) {
        TypeMirror sourceType = sourceIt.next();
        
        for (Iterator<TypeMirror> filteredIt = filtered.iterator(); filteredIt.hasNext(); ) {
            TypeMirror filteredType = filteredIt.next();
            
            if (info.getTypes().isSubtype(sourceType, filteredType)) {
                sourceIt.remove();
                continue OUTER;
            }
            
            if (info.getTypes().isSubtype(filteredType, sourceType)) {
                filteredIt.remove();
                break;
            }
        }
        
        filtered.add(sourceType);
    }
    
    return filtered;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:UncaughtException.java


示例12: visitThrow

import javax.lang.model.type.UnionType; //导入依赖的package包/类
/**
 * Computes possible types for throw expression. Throw can safely throw an exception, which is
 * either declared by method as a thrown type, or catched within method, by an upper try-catch block.
 * Unchecked exceptions are permitted (derivatives of RuntimeException or Error).
 */
@Override
public List<? extends TypeMirror> visitThrow(ThrowTree node, Object p) {
    List<TypeMirror> result = new ArrayList<TypeMirror>();
    TreePath parents = getCurrentPath();
    Tree prev = null;
    while (parents != null && parents.getLeaf().getKind() != Tree.Kind.METHOD) {
        Tree l = parents.getLeaf();
        if (l.getKind() == Tree.Kind.TRY) {
            TryTree tt = (TryTree) l;
            if (prev == tt.getBlock()) {
                for (CatchTree ct : tt.getCatches()) {
                    TypeMirror ex = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), ct.getParameter().getType()));
                    if (ex != null) {
                        switch (ex.getKind()) {
                            case DECLARED:
                                if (!result.contains(ex)) {
                                    result.add(ex);
                                }
                                break;
                            case UNION:
                                for (TypeMirror t : ((UnionType) ex).getAlternatives()) {
                                    if (!result.contains(t)) {
                                        result.add(t);
                                    }
                                }
                                break;
                        }
                    }
                }
            }
        }
        prev = l;
        parents = parents.getParentPath();
    }
    if (parents != null) {
        MethodTree mt = (MethodTree) parents.getLeaf();
        for (ExpressionTree etree : mt.getThrows()) {
            TypeMirror m = info.getTrees().getTypeMirror(new TreePath(parents, etree));
            if (m != null && !result.contains(m)) {
                result.add(m);
            }
        }
    }
    TypeMirror jlre = info.getElements().getTypeElement("java.lang.RuntimeException").asType(); // NOI18N
    TypeMirror jler = info.getElements().getTypeElement("java.lang.Error").asType(); // NOI18N
    for (TypeMirror em : result) {
        if (jlre != null && info.getTypes().isAssignable(jlre, em)) {
            jlre = null;
        }
        if (jler != null && info.getTypes().isAssignable(jler, em)) {
            jler = null;
        }
        if (jlre == null && jler == null) {
            break;
        }
    }
    if (jlre != null) {
        result.add(jlre);
    }
    if (jler != null) {
        result.add(jler);
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:ExpectedTypeResolver.java


示例13: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public Boolean visitUnion(UnionType arg0, Boolean arg1) {
	return false;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:5,代码来源:ParamModel.java


示例14: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public String visitUnion(UnionType t, Void p) {
	return null;
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:5,代码来源:TypeResolver.java


示例15: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public final R visitUnion(UnionType type, TypeMirror otherType) {
    return otherType instanceof UnionType ? visitUnion(type, (UnionType) otherType) :
        unmatchedAction(type, otherType);
}
 
开发者ID:revapi,项目名称:revapi,代码行数:6,代码来源:TypeMirrorPairVisitor.java


示例16: createType

import javax.lang.model.type.UnionType; //导入依赖的package包/类
/**
 * Creates the appropriate AnnotatedTypeMirror specific wrapper for the
 * provided type
 *
 * @param type
 * @param atypeFactory
 * @return [to document]
 */
public static AnnotatedTypeMirror createType(TypeMirror type,
    AnnotatedTypeFactory atypeFactory) {
    if (type == null) {
        ErrorReporter.errorAbort("AnnotatedTypeMirror.createType: input type must not be null!");
        return null;
    }

    com.sun.tools.javac.code.Type jctype = ((com.sun.tools.javac.code.Type)type);
    type = jctype.unannotatedType();

    AnnotatedTypeMirror result;
    switch (type.getKind()) {
        case ARRAY:
            result = new AnnotatedArrayType((ArrayType) type, atypeFactory);
            break;
        case DECLARED:
            result = new AnnotatedDeclaredType((DeclaredType) type, atypeFactory);
            break;
        case ERROR:
            ErrorReporter.errorAbort("AnnotatedTypeMirror.createType: input should type-check already! Found error type: " + type);
            return null; // dead code
        case EXECUTABLE:
            result = new AnnotatedExecutableType((ExecutableType) type, atypeFactory);
            break;
        case VOID:
        case PACKAGE:
        case NONE:
            result = new AnnotatedNoType((NoType) type, atypeFactory);
            break;
        case NULL:
            result = new AnnotatedNullType((NullType) type, atypeFactory);
            break;
        case TYPEVAR:
            result = new AnnotatedTypeVariable((TypeVariable) type, atypeFactory);
            break;
        case WILDCARD:
            result = new AnnotatedWildcardType((WildcardType) type, atypeFactory);
            break;
        case INTERSECTION:
            result = new AnnotatedIntersectionType((IntersectionType) type, atypeFactory);
            break;
        case UNION:
            result = new AnnotatedUnionType((UnionType) type, atypeFactory);
            break;
        default:
            if (type.getKind().isPrimitive()) {
                result = new AnnotatedPrimitiveType((PrimitiveType) type, atypeFactory);
                break;
            }
            ErrorReporter.errorAbort("AnnotatedTypeMirror.createType: unidentified type " +
                    type + " (" + type.getKind() + ")");
            return null; // dead code
    }
    /*if (jctype.isAnnotated()) {
        result.addAnnotations(jctype.getAnnotationMirrors());
    }*/
    return result;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:67,代码来源:AnnotatedTypeMirror.java


示例17: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
@Nullable
public R visitUnion(UnionType t, P p) {
  throw new UnsupportedOperationException("NYI");
}
 
开发者ID:facebook,项目名称:buck,代码行数:6,代码来源:TypeScanner8.java


示例18: visitUnion

import javax.lang.model.type.UnionType; //导入依赖的package包/类
@Override
public Void visitUnion(UnionType t, Void aVoid) {
  scans.add(t.toString());
  return super.visitUnion(t, aVoid);
}
 
开发者ID:facebook,项目名称:buck,代码行数:6,代码来源:TypeScanner8Test.java


示例19: AnnotatedUnionType

import javax.lang.model.type.UnionType; //导入依赖的package包/类
/**
 * Constructor for this type
 *
 * @param type  underlying kind of this type
 * @param atypeFactory TODO
 */
private AnnotatedUnionType(UnionType type,
        AnnotatedTypeFactory atypeFactory) {
    super(type, atypeFactory);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:11,代码来源:AnnotatedTypeMirror.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java EncryptionConstants类代码示例发布时间:2022-05-21
下一篇:
Java InvalidPropertyException类代码示例发布时间: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