Java 类com.sun.tools.javac.tree.JCTree.JCArrayTypeTree 实例源码

项目:annotation-tools    文件:TreeFinder.java   
@Override
public Pair<ASTRecord, Integer> visitArrayType(ArrayTypeTree node, Insertion ins) {
  dbug.debug("TypePositionFinder.visitArrayType(%s)%n", node);
  JCArrayTypeTree att = (JCArrayTypeTree) node;
  dbug.debug("TypePositionFinder.visitArrayType(%s) preferred = %s%n",
      node, att.getPreferredPosition());
  // If the code has a type like "String[][][]", then this gets called
  // three times:  for String[][][], String[][], and String[]
  // respectively.  For each of the three, call String[][][] "largest".
  ArrayTypeTree largest = largestContainingArray(node);
  int largestLevels = arrayLevels(largest);
  int levels = arrayLevels(node);
  int start = arrayContentType(att).getPreferredPosition() + 1;
  int end = att.getEndPosition(tree.endPositions);
  int pos = arrayInsertPos(start, end);

  dbug.debug("  levels=%d largestLevels=%d%n", levels, largestLevels);
  for (int i=levels; i<largestLevels; i++) {
    pos = getFirstInstanceAfter('[', pos+1);
    dbug.debug("  pos %d at i=%d%n", pos, i);
  }
  return Pair.of(astRecord(node), pos);
}
项目:incubator-netbeans    文件:CasualDiff.java   
private int dimension(JCTree t, int afterPos) {
    if (t.getKind() != Kind.ARRAY_TYPE) {
        return 0;
    }
    int add;
    if (afterPos >= 0) {
        final int[] bounds =  getBounds(t);
        add = afterPos < bounds[1] ? 1 : 0;
    } else {
        add = 1;
    }
    return add + dimension (((JCTree.JCArrayTypeTree)t).getType(), afterPos);
}
项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffTypeArray(JCArrayTypeTree oldT, JCArrayTypeTree newT, int[] bounds) {
    int localPointer = bounds[0];
    int[] elemtypeBounds = getBounds(oldT.elemtype);
    localPointer = diffTree(oldT.elemtype, newT.elemtype, elemtypeBounds);
    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
private int dims(JCExpression vartype) {
    if (vartype instanceof JCArrayTypeTree) {
        return 1 + dims(((JCArrayTypeTree) vartype).elemtype);
    }

    return 0;
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
private void printVarDef0(JCVariableDecl tree) {
    boolean varargs = (tree.mods.flags & VARARGS) != 0;
    if (varargs && tree.vartype instanceof JCArrayTypeTree) {
        print(((JCArrayTypeTree) tree.vartype).elemtype);
        print("...");
    } else {
        print(tree.vartype);
    }
    print(" ");
    print(tree.name);
    if (tree.init != null) {
        print(" = ");
        print(tree.init);
    }
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitNewArray(JCNewArray tree) {
    JCTree elem = tree.elemtype;
    int dims = 0;
    if (elem != null) {
        print("new ");

        while (elem instanceof JCArrayTypeTree) {
            dims++;
            elem = ((JCArrayTypeTree) elem).elemtype;
        }
        print(elem);

        for (JCExpression expr : tree.dims) {
            print("[");
            print(expr);
            print("]");
        }
    }

    for (int i = 0; i < dims; i++) print("[]");

    if (tree.elems != null) {
        if (elem != null) print("[] ");
        print("{");
        print(tree.elems, ", ");
        print("}");
    }
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitTypeArray(JCArrayTypeTree that) {
    try {
        print("JCArrayTypeTree:");
    } catch (Exception e) {
    }
    super.visitTypeArray(that);
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitVarDef(JCVariableDecl tree) {
    try {
        boolean suppressSemi = suppressFinalAndSemicolonsInTry;
        if (getJavadocFor(tree) != null) {
            println(); align();
        }
        printDocComment(tree);
        if ((tree.mods.flags & ENUM) != 0) {
            printEnumMember(tree);
        } else {
            printExpr(tree.mods);
            if ((tree.mods.flags & VARARGS) != 0) {
                printExpr(((JCArrayTypeTree) tree.vartype).elemtype);
                print("... " + tree.name);
            } else {
                printExpr(tree.vartype);
                print(" " + tree.name);
            }
            if (tree.init != null) {
                print(" = ");
                printExpr(tree.init);
            }
            if (prec == TreeInfo.notExpression && !suppressSemi) print(";");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitNewArray(JCNewArray tree) {
    try {
        if (tree.elemtype != null) {
            print("new ");
            JCTree elem = tree.elemtype;
            if (elem instanceof JCArrayTypeTree)
                printBaseElementType((JCArrayTypeTree) elem);
            else
                printExpr(elem);
            for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
                print("[");
                printExpr(l.head);
                print("]");
            }
            if (elem instanceof JCArrayTypeTree)
                printBrackets((JCArrayTypeTree) elem);
        }
        if (tree.elems != null) {
            if (tree.elemtype != null) print("[]");
            print("{");
            printExprs(tree.elems);
            print("}");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitTypeArray(JCArrayTypeTree tree) {
    try {
        printBaseElementType(tree);
        printBrackets(tree);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
private void printBaseElementType(JCArrayTypeTree tree) throws IOException {
    JCTree elem = tree.elemtype;
    while (elem instanceof JCWildcard)
        elem = ((JCWildcard) elem).inner;
    if (elem instanceof JCArrayTypeTree)
        printBaseElementType((JCArrayTypeTree) elem);
    else
        printExpr(elem);
}
项目:annotation-tools    文件:TreeFinder.java   
private JCTree arrayContentType(JCArrayTypeTree att) {
  JCTree node = att;
  do {
    node = ((JCArrayTypeTree) node).getType();
  } while (node.getKind() == Tree.Kind.ARRAY_TYPE);
  return node;
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
private static int countDims(JCExpression type) {
    int dims = 0;
    while (type instanceof JCArrayTypeTree) {
        type = ((JCArrayTypeTree) type).elemtype;
        dims++;
    }
    return dims;
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitTypeArray(JCArrayTypeTree node) {
    TypeReference ref = (TypeReference) toTree(node.getType(), FlagKey.TYPE_REFERENCE);
    int currentDim = ref.astArrayDimensions();
    ref.astArrayDimensions(currentDim + 1);
    setConversionPositionInfo(ref, "[]" + currentDim, getPosition(node));
    set(node, ref);
}
项目:s4j    文件:Pretty.java   
public void visitNewArray(JCNewArray tree) {
    try {
        if (tree.elemtype != null) {
            print("new ");
            JCTree elem = tree.elemtype;
            if (elem.getTag() == JCTree.TYPEARRAY)
                printBaseElementType((JCArrayTypeTree) elem);
            else
                printExpr(elem);
            for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
                print("[");
                printExpr(l.head);
                print("]");
            }
            if (elem instanceof JCArrayTypeTree)
                printBrackets((JCArrayTypeTree) elem);
        }
        if (tree.elems != null) {
            if (tree.elemtype != null) print("[]");
            print("{");
            printExprs(tree.elems);
            print("}");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:s4j    文件:Pretty.java   
public void visitTypeArray(JCArrayTypeTree tree) {
    try {
        printBaseElementType(tree);
        printBrackets(tree);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:error-prone-aspirator    文件:Matchers.java   
public static Matcher<MethodTree> methodReturns(final Type returnType) {
  return new Matcher<MethodTree>() {
    @Override
    public boolean matches(MethodTree methodTree, VisitorState state) {
      Tree returnTree = methodTree.getReturnType();
      Type methodReturnType = null;
      if (returnTree == null) {
        // This is a constructor, it has no return type.
        return false;
      }
      switch (returnTree.getKind()) {
        case ARRAY_TYPE:
          methodReturnType = ((JCArrayTypeTree)returnTree).type;
          break;
        case PRIMITIVE_TYPE:
          methodReturnType = ((JCPrimitiveTypeTree)returnTree).type;
          break;
        case PARAMETERIZED_TYPE:
          methodReturnType = ((JCTypeApply)returnTree).type;
          break;
        default:
          return false;
      }
      return state.getTypes().isSameType(methodReturnType, returnType);
    }
  };
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitVarDef(JCVariableDecl tree) {
    try {
        if (docComments != null && docComments.get(tree) != null) {
            println(); align();
        }
        printDocComment(tree);
        if ((tree.mods.flags & ENUM) != 0) {
            printEnumMember(tree);
        } else {
            printExpr(tree.mods);
            if ((tree.mods.flags & VARARGS) != 0) {
                printExpr(((JCArrayTypeTree) tree.vartype).elemtype);
                print("... " + tree.name);
            } else {
                printExpr(tree.vartype);
                print(" " + tree.name);
            }
            if (tree.init != null) {
                print(" = ");
                printExpr(tree.init);
            }
            if (prec == TreeInfo.notExpression) print(";");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitNewArray(JCNewArray tree) {
    try {
        if (tree.elemtype != null) {
            print("new ");
            JCTree elem = tree.elemtype;
            if (elem instanceof JCArrayTypeTree)
                printBaseElementType((JCArrayTypeTree) elem);
            else
                printExpr(elem);
            for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
                print("[");
                printExpr(l.head);
                print("]");
            }
            if (elem instanceof JCArrayTypeTree)
                printBrackets((JCArrayTypeTree) elem);
        }
        if (tree.elems != null) {
            if (tree.elemtype != null) print("[]");
            print("{");
            printExprs(tree.elems);
            print("}");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitTypeArray(JCArrayTypeTree tree) {
    try {
        printBaseElementType(tree);
        printBrackets(tree);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:PrettyCommentsPrinter.java   
private void printBaseElementType(JCArrayTypeTree tree) throws IOException {
    JCTree elem = tree.elemtype;
    while (elem instanceof JCWildcard)
        elem = ((JCWildcard) elem).inner;
    if (elem instanceof JCArrayTypeTree)
        printBaseElementType((JCArrayTypeTree) elem);
    else
        printExpr(elem);
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCArrayTypeTree TypeArray(JCExpression elemtype) {
    return invoke(TypeArray, elemtype);
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitTypeArray(JCArrayTypeTree tree) {
    JCTree elem = tree.elemtype;
    while (elem instanceof JCWildcard) elem = ((JCWildcard) elem).inner;
    print(elem);
    print("[]");
}
项目:lombok-ianchiu    文件:HandleToString.java   
static JCMethodDecl createToString(JavacNode typeNode, Collection<JavacNode> fields, boolean includeFieldNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
    JavacTreeMaker maker = typeNode.getTreeMaker();

    JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil());
    JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
    JCExpression returnType = genJavaLangTypeRef(typeNode, "String");

    boolean first = true;

    String typeName = getTypeName(typeNode);
    String infix = ", ";
    String suffix = ")";
    String prefix;
    if (callSuper) {
        prefix = typeName + "(super=";
    } else if (fields.isEmpty()) {
        prefix = typeName + "()";
    } else if (includeFieldNames) {
        prefix = typeName + "(" + ((JCVariableDecl)fields.iterator().next().get()).name.toString() + "=";
    } else {
        prefix = typeName + "(";
    }

    JCExpression current = maker.Literal(prefix);

    if (callSuper) {
        JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
                maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
                List.<JCExpression>nil());
        current = maker.Binary(CTC_PLUS, current, callToSuper);
        first = false;
    }

    for (JavacNode fieldNode : fields) {
        JCExpression expr;

        JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);

        JCExpression fieldType = getFieldType(fieldNode, fieldAccess);

        // The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
        boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
        boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
        boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
        @SuppressWarnings("unused")
        boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;

        if (fieldIsPrimitiveArray || fieldIsObjectArray) {
            JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
            expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
        } else expr = fieldAccessor;

        if (first) {
            current = maker.Binary(CTC_PLUS, current, expr);
            first = false;
            continue;
        }

        if (includeFieldNames) {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
        } else {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
        }

        current = maker.Binary(CTC_PLUS, current, expr);
    }

    if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));

    JCStatement returnStatement = maker.Return(current);

    JCBlock body = maker.Block(0, List.of(returnStatement));

    return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("toString"), returnType,
            List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
项目:lombok-ianchiu    文件:JavacHandlerUtil.java   
private static JCExpression cloneType0(JavacTreeMaker 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 = new ListBuffer<JCExpression>();
        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;
}
项目:javaparser2jctree    文件:AJCArrayTypeTree.java   
public AJCArrayTypeTree(JCArrayTypeTree ltree) {
    super(ltree.elemtype);
}
项目:javaparser2jctree    文件:AJCArrayTypeTree.java   
public AJCArrayTypeTree(JCArrayTypeTree ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCArrayTypeTree TypeArray(JCExpression elemtype) {
    return invoke(TypeArray, elemtype);
}
项目:EasyMPermission    文件:HandleToString.java   
static JCMethodDecl createToString(JavacNode typeNode, Collection<JavacNode> fields, boolean includeFieldNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
    JavacTreeMaker maker = typeNode.getTreeMaker();

    JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil());
    JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
    JCExpression returnType = genJavaLangTypeRef(typeNode, "String");

    boolean first = true;

    String typeName = getTypeName(typeNode);
    String infix = ", ";
    String suffix = ")";
    String prefix;
    if (callSuper) {
        prefix = typeName + "(super=";
    } else if (fields.isEmpty()) {
        prefix = typeName + "()";
    } else if (includeFieldNames) {
        prefix = typeName + "(" + ((JCVariableDecl)fields.iterator().next().get()).name.toString() + "=";
    } else {
        prefix = typeName + "(";
    }

    JCExpression current = maker.Literal(prefix);

    if (callSuper) {
        JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
                maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
                List.<JCExpression>nil());
        current = maker.Binary(CTC_PLUS, current, callToSuper);
        first = false;
    }

    for (JavacNode fieldNode : fields) {
        JCExpression expr;

        JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);

        JCExpression fieldType = getFieldType(fieldNode, fieldAccess);

        // The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
        boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
        boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
        boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
        @SuppressWarnings("unused")
        boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;

        if (fieldIsPrimitiveArray || fieldIsObjectArray) {
            JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
            expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
        } else expr = fieldAccessor;

        if (first) {
            current = maker.Binary(CTC_PLUS, current, expr);
            first = false;
            continue;
        }

        if (includeFieldNames) {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
        } else {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
        }

        current = maker.Binary(CTC_PLUS, current, expr);
    }

    if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));

    JCStatement returnStatement = maker.Return(current);

    JCBlock body = maker.Block(0, List.of(returnStatement));

    return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("toString"), returnType,
            List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
项目:EasyMPermission    文件:JavacHandlerUtil.java   
private static JCExpression cloneType0(JavacTreeMaker 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 = new ListBuffer<JCExpression>();
        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;
}
项目:refactor-faster    文件:UArrayTypeTree.java   
@Override
public JCArrayTypeTree inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeArray(getType().inline(inliner));
}
项目:android-retrolambda-lombok    文件:JcTreePrinter.java   
@Override public void visitTypeArray(JCArrayTypeTree tree) {
    printNode(tree);
    child("elemtype", tree.elemtype);
    indent--;
}
项目:error-prone    文件:UArrayTypeTree.java   
@Override
public JCArrayTypeTree inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeArray(getType().inline(inliner));
}
项目:s4j    文件:JavacParser.java   
private JCArrayTypeTree bracketsOptCont(JCExpression t, int pos) {
    accept(RBRACKET);
    t = bracketsOpt(t);
    return toP(F.at(pos).TypeArray(t));
}
项目:s4j    文件:Attr.java   
public void visitTypeArray(JCArrayTypeTree tree) {
    Type etype = attribType(tree.elemtype, env);
    Type type = new ArrayType(etype, syms.arrayClass);
    result = check(tree, type, TYP, pkind, pt);
}
项目:Refaster    文件:UArrayTypeTree.java   
@Override
public JCArrayTypeTree inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeArray(getType().inline(inliner));
}
项目:lombok    文件:HandleToString.java   
private JCMethodDecl createToString(JavacNode typeNode, List<JavacNode> fields, boolean includeFieldNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
    TreeMaker maker = typeNode.getTreeMaker();

    JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
    JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
    JCExpression returnType = chainDots(typeNode, "java", "lang", "String");

    boolean first = true;

    String typeName = getTypeName(typeNode);
    String infix = ", ";
    String suffix = ")";
    String prefix;
    if (callSuper) {
        prefix = typeName + "(super=";
    } else if (fields.isEmpty()) {
        prefix = typeName + "()";
    } else if (includeFieldNames) {
        prefix = typeName + "(" + ((JCVariableDecl)fields.iterator().next().get()).name.toString() + "=";
    } else {
        prefix = typeName + "(";
    }

    JCExpression current = maker.Literal(prefix);

    if (callSuper) {
        JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
                maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
                List.<JCExpression>nil());
        current = maker.Binary(CTC_PLUS, current, callToSuper);
        first = false;
    }

    for (JavacNode fieldNode : fields) {
        JCExpression expr;

        JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);

        JCExpression fieldType = getFieldType(fieldNode, fieldAccess);

        // The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
        boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
        boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
        boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
        @SuppressWarnings("unused")
        boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;

        if (fieldIsPrimitiveArray || fieldIsObjectArray) {
            JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
            expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
        } else expr = fieldAccessor;

        if (first) {
            current = maker.Binary(CTC_PLUS, current, expr);
            first = false;
            continue;
        }

        if (includeFieldNames) {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
        } else {
            current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
        }

        current = maker.Binary(CTC_PLUS, current, expr);
    }

    if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));

    JCStatement returnStatement = maker.Return(current);

    JCBlock body = maker.Block(0, List.of(returnStatement));

    return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("toString"), returnType,
            List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source);
}
项目:lombok    文件:JavacHandlerUtil.java   
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;
}