private void removeAlternativeFromMultiCatch(TransformationContext ctx) throws Exception { TreePath unionPath = ctx.getPath().getParentPath(); UnionTypeTree union = (UnionTypeTree)unionPath.getLeaf(); TreeMaker mk = ctx.getWorkingCopy().getTreeMaker(); GeneratorUtilities gen = GeneratorUtilities.get(ctx.getWorkingCopy()); union = gen.importComments(union, ctx.getWorkingCopy().getCompilationUnit()); List<? extends Tree> alts = new ArrayList<>(union.getTypeAlternatives()); alts.remove(ctx.getPath().getLeaf()); if (alts.size() > 1) { // still remains a multi-catch Tree newUnion = mk.UnionType(alts); ctx.getWorkingCopy().rewrite(union, newUnion); } else { // replace union type with just ordinary type ctx.getWorkingCopy().rewrite(union, alts.get(0)); } }
@Override public Tree visitUnionType(UnionTypeTree tree, Void p) { UnionTypeTree n = make.UnionType(tree.getTypeAlternatives()); // model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Void visitUnionType(UnionTypeTree node, EnumSet<UseTypes> p) { for (Tree tree : node.getTypeAlternatives()) { handlePossibleIdentifier(new TreePath(getCurrentPath(), tree), EnumSet.of(UseTypes.CLASS_USE)); } return super.visitUnionType(node, p); }
@Override public Object visitUnionType(UnionTypeTree node, Object p) { for (Tree t : node.getTypeAlternatives()) { addDependency(info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), t))); } return super.visitUnionType(node, p); }
@Override public Void visitUnionType(UnionTypeTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitUnionType(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
private void addDisjointType(List<Tree> to, Tree type) { if (type == null) return; if (type.getKind() == Kind.UNION_TYPE) { to.addAll(((UnionTypeTree) type).getTypeAlternatives()); } else { to.add(type); } }
@Override public Mirror visitUnionType(UnionTypeTree node, EvaluationContext p) { // union type expression in a multicatch var declaration // unsupported, since catch is unsupported Assert.error(node, "unsupported"); return null; }
/** * Formats a union type declaration in a catch clause. */ private void visitUnionType(VariableTree declaration) { UnionTypeTree type = (UnionTypeTree) declaration.getType(); builder.open(ZERO); sync(declaration); visitAndBreakModifiers( declaration.getModifiers(), Direction.HORIZONTAL, Optional.<BreakTag>absent()); List<? extends Tree> union = type.getTypeAlternatives(); boolean first = true; for (int i = 0; i < union.size() - 1; i++) { if (!first) { builder.breakOp(" "); token("|"); builder.space(); } else { first = false; } scan(union.get(i), null); } builder.breakOp(" "); token("|"); builder.space(); Tree last = union.get(union.size() - 1); declareOne( DeclarationKind.NONE, Direction.HORIZONTAL, Optional.<ModifiersTree>absent(), last, VarArgsOrNot.NO, // VarArgsOrNot.valueOf(declaration.isVarargs()), ImmutableList.<AnnotationTree>of(), // declaration.varargsAnnotations(), declaration.getName(), "", // declaration.extraDimensions(), "=", Optional.fromNullable(declaration.getInitializer()), Optional.<String>absent(), Optional.<ExpressionTree>absent(), Optional.<TypeWithDims>absent()); builder.close(); }
@Override public Void visitUnionType(UnionTypeTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (UnionTypeTreeMatcher matcher : unionTypeMatchers) { if (!isSuppressed(matcher, state)) { try { reportMatch(matcher.matchUnionType(tree, state), tree, state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitUnionType(tree, state); }
@Override public AnnotatedTypeMirror visitUnionType(UnionTypeTree node, AnnotatedTypeFactory f) { AnnotatedTypeMirror type = f.type(node); if (type.getKind() == TypeKind.TYPEVAR) return forTypeVariable(type, f); return type; }
public Boolean visitUnionType(UnionTypeTree node, ConstructorData p) { super.visitUnionType(node, p); return null; }
@Override public List<? extends TypeMirror> visitUnionType(UnionTypeTree node, Object p) { return null; }
@Override public Void visitUnionType(UnionTypeTree node, Void unused) { throw new IllegalStateException("expected manual descent into union types"); }
@Override public R visitUnionType(UnionTypeTree utt, P p) { return null; }
@Override public List<T> visitUnionType(UnionTypeTree node, T p) { return checkForCriteria(node); }
@Override public UUnionType visitUnionType(UnionTypeTree tree, Void v) { return UUnionType.create(templateTypeExpressions(tree.getTypeAlternatives())); }
@Override public Choice<Unifier> visitUnionType(UnionTypeTree node, Unifier unifier) { return unifyList(unifier, getTypeAlternatives(), node.getTypeAlternatives()); }
@Override public Node visitUnionType(UnionTypeTree tree, Void p) { assert false : "UnionTypeTree is unexpected in AST to CFG translation"; return null; }
@Override public PurityResult visitUnionType(UnionTypeTree node, PurityResult p) { assert false : "this type of tree is unexpected here"; return null; }
Description matchUnionType(UnionTypeTree tree, VisitorState state);