javax.lang.model.type.UnknownTypeException#javax.lang.model.type.UnionType源码实例Demo

下面列出了javax.lang.model.type.UnknownTypeException#javax.lang.model.type.UnionType 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: TreeUtilities.java
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;
}
 
源代码2 项目: netbeans   文件: DeclaredTypeCollector.java
@Override
public Void visitUnion(UnionType t, Collection<DeclaredType> p) {
    for (TypeMirror tm : t.getAlternatives()) {
        visit(tm, p);
    }
    return DEFAULT_VALUE;
}
 
源代码3 项目: netbeans   文件: JoinCatches.java
@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);
}
 
源代码4 项目: netbeans   文件: Utilities.java
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();
    }
}
 
源代码5 项目: netbeans   文件: ExportNonAccessibleElement.java
@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;
}
 
源代码6 项目: j2objc   文件: TypeUtil.java
/**
 * Maps the given type to it's Objective-C equivalent. Array types are mapped to their equivalent
 * IOSArray type and common Java classes like String and Object are mapped to NSString and
 * NSObject.
 */
public TypeElement getObjcClass(TypeMirror t) {
  if (isArray(t)) {
    return getIosArray(((ArrayType) t).getComponentType());
  } else if (isDeclaredType(t)) {
    return getObjcClass((TypeElement) ((DeclaredType) t).asElement());
  } else if (t.getKind() == TypeKind.UNION) {
    TypeMirror lub = leastUpperBound(((UnionType)t).getAlternatives());
    return getObjcClass(asTypeElement(lub));
  }
  return null;
}
 
源代码7 项目: revapi   文件: Util.java
@Override
public final T visitUnion(UnionType t, StringBuilderAndState<S> st) {
    try {
        st.depth++;
        return doVisitUnion(t, st);
    } finally {
        st.depth--;
    }
}
 
源代码8 项目: buck   文件: StandaloneTypeMirror.java
@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));
  }
}
 
源代码9 项目: auto   文件: TypeVariables.java
@Override
public ImmutableSet<TypeVariable> visitUnion(
    UnionType t, Set<Element> visited) {
  ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
  for (TypeMirror unionType : t.getAlternatives()) {
    typeVariables.addAll(unionType.accept(this, visited));
  }
  return typeVariables.build();
}
 
源代码10 项目: netbeans   文件: UncaughtException.java
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;
}
 
源代码11 项目: netbeans   文件: ExpectedTypeResolver.java
/**
 * 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;
}
 
源代码12 项目: FreeBuilder   文件: IsInvalidTypeVisitor.java
@Override
public Boolean visitUnion(UnionType t, Void p) {
  return any(t.getAlternatives(), this);
}
 
源代码13 项目: revapi   文件: Util.java
protected T doVisitUnion(UnionType t, StringBuilderAndState<S> st) {
    return defaultAction(t, st);
}
 
源代码14 项目: revapi   文件: TypeMirrorPairVisitor.java
@Override
public final R visitUnion(UnionType type, TypeMirror otherType) {
    return otherType instanceof UnionType ? visitUnion(type, (UnionType) otherType) :
        unmatchedAction(type, otherType);
}
 
源代码15 项目: revapi   文件: TypeMirrorPairVisitor.java
protected R visitUnion(UnionType type, UnionType otherType) {
    return defaultMatchAction(type, otherType);
}
 
源代码16 项目: buck   文件: TypeScanner8.java
@Override
@Nullable
public R visitUnion(UnionType t, P p) {
  throw new UnsupportedOperationException("NYI");
}
 
源代码17 项目: buck   文件: StandaloneTypeMirror.java
@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 MODULE:
    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));
  }
}
 
源代码18 项目: buck   文件: TypeScanner8Test.java
@Override
public Void visitUnion(UnionType t, Void aVoid) {
  scans.add(t.toString());
  return super.visitUnion(t, aVoid);
}
 
源代码19 项目: immutables   文件: TypeExtractor.java
@Override
public Type visitUnion(UnionType t, Type.Parameters p) {
  throw new UnsupportedOperationException("UnionType type not supported");
}