예제 #1
0
  private static JCExpression cloneType0(TreeMaker maker, JCTree in) {
    if (in == null) return null;

    if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;

    if (in instanceof JCIdent) {
      return maker.Ident(((JCIdent) in).name);
    }

    if (in instanceof JCFieldAccess) {
      JCFieldAccess fa = (JCFieldAccess) in;
      return maker.Select(cloneType0(maker, fa.selected), fa.name);
    }

    if (in instanceof JCArrayTypeTree) {
      JCArrayTypeTree att = (JCArrayTypeTree) in;
      return maker.TypeArray(cloneType0(maker, att.elemtype));
    }

    if (in instanceof JCTypeApply) {
      JCTypeApply ta = (JCTypeApply) in;
      ListBuffer<JCExpression> lb = ListBuffer.lb();
      for (JCExpression typeArg : ta.arguments) {
        lb.append(cloneType0(maker, typeArg));
      }
      return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
    }

    if (in instanceof JCWildcard) {
      JCWildcard w = (JCWildcard) in;
      JCExpression newInner = cloneType0(maker, w.inner);
      TypeBoundKind newKind;
      switch (w.getKind()) {
        case SUPER_WILDCARD:
          newKind = maker.TypeBoundKind(BoundKind.SUPER);
          break;
        case EXTENDS_WILDCARD:
          newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
          break;
        default:
        case UNBOUNDED_WILDCARD:
          newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
          break;
      }
      return maker.Wildcard(newKind, newInner);
    }

    // This is somewhat unsafe, but it's better than outright throwing an exception here. Returning
    // null will just cause an exception down the pipeline.
    return (JCExpression) in;
  }
예제 #2
0
  @Override
  public void visitWildcard(JCWildcard tree) {
    try {
      Object kind = tree.getClass().getField("kind").get(tree);
      print(kind);
      if (kind != null && kind.getClass().getSimpleName().equals("TypeBoundKind")) {
        kind = kind.getClass().getField("kind").get(kind);
      }

      if (tree.getKind() != Tree.Kind.UNBOUNDED_WILDCARD) printExpr(tree.inner);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
예제 #3
0
 @Override
 public void visitWildcard(JCWildcard tree) {
   switch (tree.getKind()) {
     default:
     case UNBOUNDED_WILDCARD:
       print("?");
       return;
     case EXTENDS_WILDCARD:
       print("? extends ");
       print(tree.inner);
       return;
     case SUPER_WILDCARD:
       print("? super ");
       print(tree.inner);
       return;
   }
 }