com.sun.source.tree.UnionTypeTree Java Examples

The following examples show how to use com.sun.source.tree.UnionTypeTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtraCatch.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example #2
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: TreeDuplicator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
    }
 
Example #4
Source File: DependencyCollector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: TreeNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: JoinCatches.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #7
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #8
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** 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,
      /* declarationAnnotationBreak= */ Optional.empty());
  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,
      /* modifiers= */ Optional.empty(),
      last,
      /* name= */ declaration.getName(),
      /* op= */ "",
      "=",
      Optional.ofNullable(declaration.getInitializer()),
      /* trailing= */ Optional.empty(),
      /* receiverExpression= */ Optional.empty(),
      /* typeWithDims= */ Optional.empty());
  builder.close();
}
 
Example #9
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitUnionType(UnionTypeTree node, Void unused) {
    throw new IllegalStateException("expected manual descent into union types");
}
 
Example #10
Source File: Flow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitUnionType(UnionTypeTree node, ConstructorData p) {
    super.visitUnionType(node, p);
    return null;
}
 
Example #11
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<? extends TypeMirror> visitUnionType(UnionTypeTree node, Object p) {
    return null;
}
 
Example #12
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Void visitUnionType(UnionTypeTree node, Void unused) {
    throw new IllegalStateException("expected manual descent into union types");
}
 
Example #13
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitUnionType(UnionTypeTree node, Void unused) {
  throw new IllegalStateException("expected manual descent into union types");
}