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

项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffTypeApply(JCTypeApply oldT, JCTypeApply newT, int[] bounds) {
    int localPointer = bounds[0];
    int[] clazzBounds = getBounds(oldT.clazz);
    copyTo(localPointer, clazzBounds[0]);
    localPointer = diffTree(oldT.clazz, newT.clazz, clazzBounds);
    if (!listsMatch(oldT.arguments, newT.arguments)) {
        int pos = oldT.arguments.nonEmpty() ? getOldPos(oldT.arguments.head) : endPos(oldT.clazz);
        copyTo(localPointer, pos);
        boolean printBrace = false;
        localPointer = diffParameterList(
                oldT.arguments,
                newT.arguments,
                printBrace ? new JavaTokenId[] { JavaTokenId.LT, JavaTokenId.GT } : null,
                pos,
                Measure.ARGUMENT
        );
    }
    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private static void unpack(StringBuilder sb, JCExpression expr) {
    if (expr instanceof JCIdent) {
        sb.append(((JCIdent) expr).name.toString());
        return;
    }

    if (expr instanceof JCFieldAccess) {
        JCFieldAccess jcfa = (JCFieldAccess) expr;
        unpack(sb, jcfa.selected);
        sb.append(".").append(jcfa.name.toString());
        return;
    }

    if (expr instanceof JCTypeApply) {
        sb.setLength(0);
        sb.append("ERR:");
        sb.append("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate.");
        sb.append("__ERR__");
        return;
    }

    sb.setLength(0);
    sb.append("ERR:");
    sb.append("Expected a type of some sort, not a " + expr.getClass().getName());
    sb.append("__ERR__");
}
项目:annotation-tools    文件:TreeFinder.java   
@Override
public Pair<ASTRecord, Integer> visitVariable(VariableTree node, Insertion ins) {
  Name name = node.getName();
  JCVariableDecl jn = (JCVariableDecl) node;
  JCTree jt = jn.getType();
  Criteria criteria = ins.getCriteria();
  dbug.debug("TypePositionFinder.visitVariable: %s %s%n", jt, jt.getClass());
  if (name != null && criteria.isOnFieldDeclaration()) {
    return Pair.of(astRecord(node), jn.getStartPosition());
  }
  if (jt instanceof JCTypeApply) {
    JCExpression type = ((JCTypeApply) jt).clazz;
    return pathAndPos(type);
  }
  return Pair.of(astRecord(node), jn.pos);
}
项目:annotation-tools    文件:TreeFinder.java   
@Override
public Pair<ASTRecord, Integer> visitNewClass(NewClassTree node, Insertion ins) {
  JCNewClass na = (JCNewClass) node;
  JCExpression className = na.clazz;
  // System.out.printf("classname %s (%s)%n", className, className.getClass());
  while (! (className.getKind() == Tree.Kind.IDENTIFIER)) { // IdentifierTree
    if (className instanceof JCAnnotatedType) {
      className = ((JCAnnotatedType) className).underlyingType;
    } else if (className instanceof JCTypeApply) {
      className = ((JCTypeApply) className).clazz;
    } else if (className instanceof JCFieldAccess) {
      // This occurs for fully qualified names, e.g. "new java.lang.Object()".
      // I'm not quite sure why the field "selected" is taken, but "name" would
      // be a type mismatch. It seems to work, see NewPackage test case.
      className = ((JCFieldAccess) className).selected;
    } else {
      throw new Error(String.format("unrecognized JCNewClass.clazz (%s): %s%n" +
              "   surrounding new class tree: %s%n", className.getClass(), className, node));
    }
    // System.out.printf("classname %s (%s)%n", className, className.getClass());
  }

  return visitIdentifier((IdentifierTree) className, ins);
}
项目:callsuper-annotation    文件:CodeAnalyzerTreeScanner.java   
@Override
public Object visitClass (ClassTree classTree, Trees trees) {
    Tree extendTree = classTree.getExtendsClause();

    if (extendTree instanceof JCTypeApply) { //generic classes case
        JCTypeApply generic = (JCTypeApply) extendTree;
        extendTree = generic.clazz;
    }

    if (extendTree instanceof JCIdent) {
        JCIdent tree = (JCIdent) extendTree;
        Scope members = tree.sym.members();

        if (checkScope(members))
            return super.visitClass(classTree, trees);

        if (checkSuperTypes((ClassType) tree.type))
            return super.visitClass(classTree, trees);

    }
    callSuperUsed = false;

    return super.visitClass(classTree, trees);
}
项目:android-retrolambda-lombok    文件:JcTreeBuilder.java   
@Override
public boolean visitTypeReferencePart(TypeReferencePart node) {
    JCIdent ident = (JCIdent) toTree(node.astIdentifier());

    List<JCExpression> typeArguments = toList(JCExpression.class, node.astTypeArguments());
    if (typeArguments.isEmpty()) {
        return set(node, ident);
    } else {
        JCTypeApply typeApply = treeMaker.TypeApply(ident, typeArguments);
        Position jcOpenBracketPos = getConversionPositionInfo(node, "<");
        if (jcOpenBracketPos == null) {
            setPos(posOfStructure(node, "<", true), node.getPosition().getEnd(), typeApply);
        } else {
            setPos(jcOpenBracketPos.getStart(), node.getPosition().getEnd(), typeApply);
        }
        return set(node, typeApply);
    }
}
项目:openjdk-jdk10    文件:Analyzer.java   
@Override
JCNewClass map(JCNewClass oldTree, JCNewClass newTree) {
    if (newTree.clazz.hasTag(TYPEAPPLY)) {
        ((JCTypeApply)newTree.clazz).arguments = List.nil();
    }
    return newTree;
}
项目:openjdk9    文件:Analyzer.java   
@Override
JCNewClass map(JCNewClass oldTree, JCNewClass newTree) {
    if (newTree.clazz.hasTag(TYPEAPPLY)) {
        ((JCTypeApply)newTree.clazz).arguments = List.nil();
    }
    return newTree;
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitTypeApply(JCTypeApply that) {
    try {
        print("JCTypeApply:");
    } catch (Exception e) {
    }
    super.visitTypeApply(that);
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitTypeApply(JCTypeApply tree) {
    try {
        printExpr(tree.clazz);
        print("<");
        printExprs(tree.arguments);
        print(">");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:annotation-tools    文件:TreeFinder.java   
@Override
public Pair<ASTRecord, Integer> visitParameterizedType(ParameterizedTypeTree node, Insertion ins) {
  Tree parent = parent(node);
  dbug.debug("TypePositionFinder.visitParameterizedType %s parent=%s%n",
      node, parent);
  Integer pos = getBaseTypePosition(((JCTypeApply) node).getType()).b;
  return Pair.of(astRecord(node), pos);
}
项目:android-retrolambda-lombok    文件:JcTreeBuilder.java   
private JCExpression plainTypeReference(TypeReference node) {
    if (node.isPrimitive() || node.isVoid() || node.astParts().size() == 1) {
        int end = node.getPosition().getEnd();
        if (node.astArrayDimensions() > 0) {
            end = node.astParts().last().getPosition().getEnd();
        }
        if (end == node.getPosition().getStart()) end = node.getPosition().getEnd();

        Identifier identifier = node.astParts().first().astIdentifier();
        int typeTag = primitiveTypeTag(identifier.astValue());
        if (typeTag > 0) return setPos(node.getPosition().getStart(), end, treeMaker.TypeIdent(typeTag));
    }

    JCExpression current = null;
    for (TypeReferencePart part : node.astParts()) {
        JCExpression expr = (JCExpression) toTree(part);
        if (current == null) {
            current = expr;
            continue;
        }
        if (expr instanceof JCIdent) {
            current = treeMaker.Select(current, ((JCIdent)expr).name);
            setPos(posOfStructure(part, ".", true), part.getPosition().getEnd(), current);
        } else if (expr instanceof JCTypeApply) {
            JCTypeApply apply = (JCTypeApply)expr;
            apply.clazz = treeMaker.Select(current, ((JCIdent)apply.clazz).name);
            setPos(posOfStructure(part, ".", true), part.astIdentifier().getPosition().getEnd(), apply.clazz);
            current = apply;
        } else {
            throw new IllegalStateException("Didn't expect a " + expr.getClass().getName() + " in " + node);
        }
    }

    //TODO add a lot more tests involving 'void', apparently we're missing a bunch.

    return current;
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitTypeApply(JCTypeApply node) {
    TypeReference ref = (TypeReference) toTree(node.clazz, FlagKey.TYPE_REFERENCE);
    TypeReferencePart last = ref.astParts().last();
    fillList(node.arguments, last.rawTypeArguments(), FlagKey.TYPE_REFERENCE);
    setPos(node, ref);
    setConversionPositionInfo(last, "<", getPosition(node));
    set(node, ref);
}
项目:s4j    文件:Pretty.java   
public void visitTypeApply(JCTypeApply tree) {
    try {
        printExpr(tree.clazz);
        print("<");
        printExprs(tree.arguments);
        print(">");
    } 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 visitTypeApply(JCTypeApply tree) {
    try {
        printExpr(tree.clazz);
        print("<");
        printExprs(tree.arguments);
        print(">");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:incubator-netbeans    文件:CasualDiff.java   
private boolean matchTypeApply(JCTypeApply t1, JCTypeApply t2) {
    return treesMatch(t1.clazz, t2.clazz) &&
           listsMatch(t1.arguments, t2.arguments);
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) {
    return invoke(TypeApply, clazz, arguments);
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitTypeApply(JCTypeApply tree) {
    print(tree.clazz);
    print("<");
    print(tree.arguments, ", ");
    print(">");
}
项目: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    文件:AJCTypeApply.java   
public AJCTypeApply(JCTypeApply ltree) {
    super(ltree.clazz, ltree.arguments);
}
项目:javaparser2jctree    文件:AJCTypeApply.java   
public AJCTypeApply(JCTypeApply ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) {
    return invoke(TypeApply, clazz, arguments);
}
项目: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    文件:UTypeApply.java   
@Override
public JCTypeApply inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeApply(
      getType().inline(inliner),
      inliner.<JCExpression, UExpression>inlineList(getTypeArguments()));
}
项目:android-retrolambda-lombok    文件:JcTreePrinter.java   
@Override public void visitTypeApply(JCTypeApply tree) {
    printNode(tree);
    child("clazz", tree.clazz);
    children("arguments", tree.arguments);
    indent--;
}
项目:error-prone    文件:UTypeApply.java   
@Override
public JCTypeApply inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner
      .maker()
      .TypeApply(getType().inline(inliner), inliner.<JCExpression>inlineList(getTypeArguments()));
}
项目:s4j    文件:JavacParser.java   
JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) {
    int pos = S.pos();
    List<JCExpression> args = typeArguments(diamondAllowed);
    return toP(F.at(pos).TypeApply(t, args));
}
项目:Refaster    文件:UTypeApply.java   
@Override
public JCTypeApply inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeApply(
      getType().inline(inliner),
      inliner.<JCExpression, UExpression>inlineList(getTypeArguments()));
}
项目: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;
}
项目:lombok    文件:HandleRelations.java   
private static JCVariableDecl createField(Object anno, JavacNode fieldNode) {
    TreeMaker maker = fieldNode.getTreeMaker();
    JCVariableDecl field = (JCVariableDecl) fieldNode.get();

    String relatedFieldName = null;
    boolean isOneToOne = false;
    boolean isUnique = false;

    Name baseTypeName = ((JCClassDecl) fieldNode.up().get()).name;
    JCIdent baseType = maker.Ident(baseTypeName);       
    JCExpression referenceType = getFieldType(fieldNode, FieldAccess.ALWAYS_FIELD);

    if (anno instanceof OneToOne) {
        isOneToOne = true;
        relatedFieldName = ((OneToOne) anno).field();
    } else {
        relatedFieldName = ((OneToMany) anno).field();
        isUnique = ((OneToMany) anno).unique();

        if (referenceType instanceof JCTypeApply) {
            referenceType = ((JCTypeApply) referenceType).arguments.get(0);
        }
    }

    JCClassDecl anonClass = maker.AnonymousClassDef(
            maker.Modifiers(0),
            List.<JCTree>of(
                    createGetReferencedKeyMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType),
                    createSetReferencedObjectMethod(fieldNode, maker, field, baseType, isUnique),
                    createSetRelatedIdMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType)
            )
    );

    JCVariableDecl var = maker.VarDef(
            maker.Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL),
            fieldNode.toName(toUpperCase(field.name.toString())),
            maker.TypeApply(
                    (isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
                    List.<JCExpression>of(baseType, referenceType)
            ),
            maker.NewClass(
                    null,
                    List.<JCExpression>nil(),
                    maker.TypeApply(
                            (isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
                            List.<JCExpression>of(baseType, referenceType)
                    ),
                    List.<JCExpression>nil(),
                    anonClass
            )
    );

    return var;
}