@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); } }
@Override public Boolean visitUnion(UnionType t, Void p) { return any(t.getAlternatives(), this); } }
@Override public Void visitUnion(UnionType t, Void aVoid) { t.getAlternatives().forEach(Descriptor::verifyResolved); return null; }
@Override public Void visitUnion(UnionType t, Void aVoid) { t.getAlternatives().forEach(Descriptor::verifyResolved); return null; }
@Override public T visitUnion(UnionType t, Void aVoid) { //just resolve to the first alternative return t.getAlternatives().get(0).accept(this, aVoid); }
private String toJava(UnionType unionType) { return unionType.getAlternatives().stream() .map(alt -> toJava(alt)) .collect(Collectors.joining(" | ")); }
@Override public T visitUnion(UnionType t, Void aVoid) { //just resolve to the first alternative return t.getAlternatives().get(0).accept(this, aVoid); }
@Override public Boolean visitUnion(UnionType t, Void p) { return any(t.getAlternatives(), this); } }
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; }
@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); } }
if (t != null) { if (t.getKind() == TypeKind.UNION) { for (TypeMirror tm : ((UnionType)t).getAlternatives()) { if (tm != null && tm.getKind() != TypeKind.ERROR) c.add(tm);
: "caught type must be a union or a declared type"; UnionType caughtUnion = (UnionType) caught; for (TypeMirror alternative : caughtUnion.getAlternatives()) { assert alternative instanceof DeclaredType : "alternatives of an caught union type must be declared types";
case UNION: typeMirrors = new ArrayList<TypeMirrorHandle<? extends TypeMirror>>(); for (TypeMirror alternative : ((UnionType) tm).getAlternatives()) { typeMirrors.add(create(alternative, map));
} else if (k == TypeKind.UNION) { UnionType ut = (UnionType) type; type = getUnionType(types, ut.getAlternatives()); if (type == null) { ErrorManager.getDefault().notify(new IllegalStateException("No union type found from "+ut+", alternatives = "+ut.getAlternatives())); return null;