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

项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffConditional(JCConditional oldT, JCConditional newT, int[] bounds) {
    int localPointer = bounds[0];
    // cond
    int[] condBounds = getBounds(oldT.cond);
    copyTo(localPointer, condBounds[0]);
    localPointer = diffTree(oldT.cond, newT.cond, condBounds);
    // true
    int[] trueBounds = getBounds(oldT.truepart);
    copyTo(localPointer, trueBounds[0]);
    localPointer = diffTree(oldT.truepart, newT.truepart, trueBounds);
    // false
    int[] falseBounds = getBounds(oldT.falsepart);
    copyTo(localPointer, falseBounds[0]);
    localPointer = diffTree(oldT.falsepart, newT.falsepart, falseBounds);
    copyTo(localPointer, bounds[1]);

    return bounds[1];
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitConditional(JCConditional tree) {
    print(tree.cond);
    print(" ? ");
    print(tree.truepart);
    print(" : ");
    print(tree.falsepart);
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitConditional(JCConditional that) {
    try {
        print("JCConditional:");
    } catch (Exception e) {
    }
    super.visitConditional(that);
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitConditional(JCConditional tree) {
    try {
        open(prec, TreeInfo.condPrec);
        printExpr(tree.cond, TreeInfo.condPrec);
        print(" ? ");
        printExpr(tree.truepart, TreeInfo.condPrec);
        print(" : ");
        printExpr(tree.falsepart, TreeInfo.condPrec);
        close(prec, TreeInfo.condPrec);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:refactor-faster    文件:UConditional.java   
@Override
public JCConditional inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().Conditional(
      getCondition().inline(inliner),
      getTrueExpression().inline(inliner), 
      getFalseExpression().inline(inliner));
}
项目:android-retrolambda-lombok    文件:JcTreePrinter.java   
@Override public void visitConditional(JCConditional tree) {
    printNode(tree);
    child("cond", tree.cond);
    child("truepart", tree.truepart);
    child("falsepart", tree.falsepart);
    indent--;
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitConditional(JCConditional node) {
    InlineIfExpression iie = new InlineIfExpression();
    iie.rawCondition(toTree(node.getCondition()));
    iie.rawIfTrue(toTree(node.getTrueExpression()));
    iie.rawIfFalse(toTree(node.getFalseExpression()));
    set(node, iie);
}
项目:error-prone    文件:UConditional.java   
@Override
public JCConditional inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner
      .maker()
      .Conditional(
          getCondition().inline(inliner),
          getTrueExpression().inline(inliner),
          getFalseExpression().inline(inliner));
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCConditional>> visitConditionalExpression(
    final ConditionalExpressionTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyExpression(node.getCondition(), s),
      s -> unifyExpression(node.getTrueExpression(), s),
      s -> unifyExpression(node.getFalseExpression(), s),
      maker()::Conditional);
}
项目:s4j    文件:Pretty.java   
public void visitConditional(JCConditional tree) {
    try {
        open(prec, TreeInfo.condPrec);
        printExpr(tree.cond, TreeInfo.condPrec);
        print(" ? ");
        printExpr(tree.truepart, TreeInfo.condPrec);
        print(" : ");
        printExpr(tree.falsepart, TreeInfo.condPrec);
        close(prec, TreeInfo.condPrec);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:s4j    文件:Attr.java   
public void visitConditional(JCConditional tree) {
    attribExpr(tree.cond, env, syms.booleanType);
    attribExpr(tree.truepart, env);
    attribExpr(tree.falsepart, env);
    result = check(tree,
                   capture(condType(tree.pos(), tree.cond.type,
                                    tree.truepart.type, tree.falsepart.type)),
                   VAL, pkind, pt);
}
项目:Refaster    文件:UConditional.java   
@Override
public JCConditional inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().Conditional(
      getCondition().inline(inliner),
      getTrueExpression().inline(inliner), 
      getFalseExpression().inline(inliner));
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitConditional(JCConditional tree) {
    try {
        open(prec, TreeInfo.condPrec);
        printExpr(tree.cond, TreeInfo.condPrec);
        print(" ? ");
        printExpr(tree.truepart, TreeInfo.condPrec);
        print(" : ");
        printExpr(tree.falsepart, TreeInfo.condPrec);
        close(prec, TreeInfo.condPrec);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:HandleGetter.java   
private List<JCStatement> createSimpleGetterBody(TreeMaker treeMaker, JavacNode field) {
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);

    JCStatement returnExpression = null;

    String varTypeString = fieldDecl.vartype.toString();
    boolean isMutable = false;
    boolean isTypeCastNeeded = false;
    if (Timestamp.class.getSimpleName().equals(varTypeString) || Timestamp.class.getName().equals(varTypeString)) {
        isMutable = true;
        isTypeCastNeeded = true;
    } else if (varTypeString.endsWith("[]")) {
        isMutable = true;
    }

    if (isMutable) {
        JCExpression nullCheck = treeMaker.Binary(CTC_EQUAL, fieldRef, treeMaker.Literal(CTC_BOT, null));
        JCExpression callClone = treeMaker.Apply(List.<JCExpression>nil(), treeMaker.Select(fieldRef, field.toName("clone")), List.<JCExpression>nil());                    
        if (isTypeCastNeeded) {
            callClone = treeMaker.TypeCast(
                    fieldDecl.vartype,
                    callClone
            );
        }

        JCConditional conditional = treeMaker.Conditional(
                nullCheck, 
                treeMaker.Literal(CTC_BOT, null), 
                callClone
        );

        returnExpression = treeMaker.Return(conditional);
    } else {
        returnExpression = treeMaker.Return(fieldRef);
    }

    return List.<JCStatement>of(returnExpression);
}
项目:incubator-netbeans    文件:CasualDiff.java   
private boolean matchConditional(JCConditional t1, JCConditional t2) {
    return treesMatch(t1.cond, t2.cond) && treesMatch(t1.truepart, t2.truepart) &&
           treesMatch(t1.falsepart, t2.falsepart);
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
@Override
public void visitConditional(JCConditional that) {
    processArg(that, speculativeTree -> new ConditionalType(that, env, speculativeTree));
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
ConditionalType(JCExpression tree, Env<AttrContext> env, JCConditional speculativeCond) {
    this(tree, env, speculativeCond, new HashMap<>());
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
ConditionalType(JCExpression tree, Env<AttrContext> env, JCConditional speculativeCond, Map<ResultInfo, Type> speculativeTypes) {
   super(tree, env, speculativeCond, speculativeTypes);
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
@Override
ArgumentType<JCConditional> dup(JCConditional tree, Env<AttrContext> env) {
    return new ConditionalType(tree, env, speculativeTree, speculativeTypes);
}
项目:openjdk9    文件:ArgumentAttr.java   
@Override
public void visitConditional(JCConditional that) {
    processArg(that, speculativeTree -> new ConditionalType(that, env, speculativeTree));
}
项目:openjdk9    文件:ArgumentAttr.java   
ConditionalType(JCExpression tree, Env<AttrContext> env, JCConditional speculativeCond) {
    this(tree, env, speculativeCond, new HashMap<>());
}
项目:openjdk9    文件:ArgumentAttr.java   
ConditionalType(JCExpression tree, Env<AttrContext> env, JCConditional speculativeCond, Map<ResultInfo, Type> speculativeTypes) {
   super(tree, env, speculativeCond, speculativeTypes);
}
项目:openjdk9    文件:ArgumentAttr.java   
@Override
ArgumentType<JCConditional> dup(JCConditional tree, Env<AttrContext> env) {
    return new ConditionalType(tree, env, speculativeTree, speculativeTypes);
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCConditional Conditional(JCExpression cond, JCExpression thenpart, JCExpression elsepart) {
    return invoke(Conditional, cond, thenpart, elsepart);
}
项目:lombok-ianchiu    文件:HandleWither.java   
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam, boolean makeAbstract) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;

    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();

    List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);

    Name methodName = field.toName(witherName);

    JCExpression returnType = cloneSelfType(field);

    JCBlock methodBody = null;
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);

    JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);

    if (!makeAbstract) {
        ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();

        JCExpression selfType = cloneSelfType(field);
        if (selfType == null) return null;

        ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
        for (JavacNode child : field.up().down()) {
            if (child.getKind() != Kind.FIELD) continue;
            JCVariableDecl childDecl = (JCVariableDecl) child.get();
            // Skip fields that start with $
            if (childDecl.name.toString().startsWith("$")) continue;
            long fieldFlags = childDecl.mods.flags;
            // Skip static fields.
            if ((fieldFlags & Flags.STATIC) != 0) continue;
            // Skip initialized final fields.
            if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
            if (child.get() == field.get()) {
                args.append(maker.Ident(fieldDecl.name));
            } else {
                args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
            }
        }

        JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
        JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
        JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
        JCReturn returnStatement = maker.Return(conditional);

        if (nonNulls.isEmpty()) {
            statements.append(returnStatement);
        } else {
            JCStatement nullCheck = generateNullCheck(maker, field, source);
            if (nullCheck != null) statements.append(nullCheck);
            statements.append(returnStatement);
        }

        methodBody = maker.Block(0, statements.toList());
    }
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;

    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);

    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    if (makeAbstract) access = access | Flags.ABSTRACT;
    JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
    copyJavadoc(field, decl, CopyJavadoc.WITHER);
    return decl;
}
项目:javaparser2jctree    文件:AJCConditional.java   
public AJCConditional(JCConditional ltree) {
    super(ltree.cond, ltree.truepart, ltree.falsepart);
}
项目:javaparser2jctree    文件:AJCConditional.java   
public AJCConditional(JCConditional ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCConditional Conditional(JCExpression cond, JCExpression thenpart, JCExpression elsepart) {
    return invoke(Conditional, cond, thenpart, elsepart);
}
项目:EasyMPermission    文件:HandleWither.java   
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;

    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();

    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);

    Name methodName = field.toName(witherName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);

    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);

    JCExpression selfType = cloneSelfType(field);
    if (selfType == null) return null;

    ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
    for (JavacNode child : field.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        JCVariableDecl childDecl = (JCVariableDecl) child.get();
        // Skip fields that start with $
        if (childDecl.name.toString().startsWith("$")) continue;
        long fieldFlags = childDecl.mods.flags;
        // Skip static fields.
        if ((fieldFlags & Flags.STATIC) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
        if (child.get() == field.get()) {
            args.append(maker.Ident(fieldDecl.name));
        } else {
            args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
        }
    }

    JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
    JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
    JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
    JCReturn returnStatement = maker.Return(conditional);

    if (nonNulls.isEmpty()) {
        statements.append(returnStatement);
    } else {
        JCStatement nullCheck = generateNullCheck(maker, field, source);
        if (nullCheck != null) statements.append(nullCheck);
        statements.append(returnStatement);
    }

    JCExpression returnType = cloneSelfType(field);

    JCBlock methodBody = maker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;

    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);

    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
    copyJavadoc(field, decl, CopyJavadoc.WITHER);
    return decl;
}
项目:refactor-faster    文件:ExpressionTemplate.java   
/**
 * Returns the precedence level appropriate for unambiguously printing
 * leaf as a subexpression of its parent.
 */
private static int getPrecedence(JCTree leaf, Context context) {
  JCCompilationUnit comp = context.get(JCCompilationUnit.class);
  JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);

  // In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
  //
  // TODO(mdempsky): There are probably cases where we could omit parentheses
  // by tweaking the returned precedence, but they need careful review.
  // For example, consider a template to replace "add(a, b)" with "a + b",
  // which applied to "x + add(y, z)" would result in "x + (y + z)".
  // In most cases, we'd likely prefer "x + y + z" instead, but those aren't
  // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
  // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
  // to integer promotion rules.

  if (parent instanceof JCConditional) {
    // This intentionally differs from Pretty, because Pretty appears buggy:
    // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
    JCConditional conditional = (JCConditional) parent;
    return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssign) {
    JCAssign assign = (JCAssign) parent;
    return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssignOp) {
    JCAssignOp assignOp = (JCAssignOp) parent;
    return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCUnary) {
    return TreeInfo.opPrec(parent.getTag());
  } else if (parent instanceof JCBinary) {
    JCBinary binary = (JCBinary) parent;
    return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCTypeCast) {
    JCTypeCast typeCast = (JCTypeCast) parent;
    return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCInstanceOf) {
    JCInstanceOf instanceOf = (JCInstanceOf) parent;
    return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
  } else if (parent instanceof JCArrayAccess) {
    JCArrayAccess arrayAccess = (JCArrayAccess) parent;
    return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCFieldAccess) {
    JCFieldAccess fieldAccess = (JCFieldAccess) parent;
    return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else {
    return TreeInfo.noPrec;
  }
}
项目:error-prone    文件:ExpressionTemplate.java   
/**
 * Returns the precedence level appropriate for unambiguously printing leaf as a subexpression of
 * its parent.
 */
private static int getPrecedence(JCTree leaf, Context context) {
  JCCompilationUnit comp = context.get(JCCompilationUnit.class);
  JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);

  // In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
  //
  // TODO(mdempsky): There are probably cases where we could omit parentheses
  // by tweaking the returned precedence, but they need careful review.
  // For example, consider a template to replace "add(a, b)" with "a + b",
  // which applied to "x + add(y, z)" would result in "x + (y + z)".
  // In most cases, we'd likely prefer "x + y + z" instead, but those aren't
  // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
  // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
  // to integer promotion rules.

  if (parent instanceof JCConditional) {
    // This intentionally differs from Pretty, because Pretty appears buggy:
    // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
    JCConditional conditional = (JCConditional) parent;
    return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssign) {
    JCAssign assign = (JCAssign) parent;
    return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssignOp) {
    JCAssignOp assignOp = (JCAssignOp) parent;
    return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCUnary) {
    return TreeInfo.opPrec(parent.getTag());
  } else if (parent instanceof JCBinary) {
    JCBinary binary = (JCBinary) parent;
    return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCTypeCast) {
    JCTypeCast typeCast = (JCTypeCast) parent;
    return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCInstanceOf) {
    JCInstanceOf instanceOf = (JCInstanceOf) parent;
    return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
  } else if (parent instanceof JCArrayAccess) {
    JCArrayAccess arrayAccess = (JCArrayAccess) parent;
    return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCFieldAccess) {
    JCFieldAccess fieldAccess = (JCFieldAccess) parent;
    return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else {
    return TreeInfo.noPrec;
  }
}
项目:Refaster    文件:ExpressionTemplate.java   
/**
 * Returns the precedence level appropriate for unambiguously printing
 * leaf as a subexpression of its parent.
 */
private static int getPrecedence(JCTree leaf, Context context) {
  JCCompilationUnit comp = context.get(JCCompilationUnit.class);
  JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);

  // In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
  //
  // TODO(mdempsky): There are probably cases where we could omit parentheses
  // by tweaking the returned precedence, but they need careful review.
  // For example, consider a template to replace "add(a, b)" with "a + b",
  // which applied to "x + add(y, z)" would result in "x + (y + z)".
  // In most cases, we'd likely prefer "x + y + z" instead, but those aren't
  // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
  // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
  // to integer promotion rules.

  if (parent instanceof JCConditional) {
    // This intentionally differs from Pretty, because Pretty appears buggy:
    // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
    JCConditional conditional = (JCConditional) parent;
    return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssign) {
    JCAssign assign = (JCAssign) parent;
    return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssignOp) {
    JCAssignOp assignOp = (JCAssignOp) parent;
    return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCUnary) {
    return TreeInfo.opPrec(parent.getTag());
  } else if (parent instanceof JCBinary) {
    JCBinary binary = (JCBinary) parent;
    return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCTypeCast) {
    JCTypeCast typeCast = (JCTypeCast) parent;
    return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCInstanceOf) {
    JCInstanceOf instanceOf = (JCInstanceOf) parent;
    return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
  } else if (parent instanceof JCArrayAccess) {
    JCArrayAccess arrayAccess = (JCArrayAccess) parent;
    return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCFieldAccess) {
    JCFieldAccess fieldAccess = (JCFieldAccess) parent;
    return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else {
    return TreeInfo.noPrec;
  }
}
项目:lombok    文件:HandleWither.java   
private JCMethodDecl createWither(long access, JavacNode field, TreeMaker treeMaker, JCTree source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;

    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();

    ListBuffer<JCStatement> statements = ListBuffer.lb();
    List<JCAnnotation> nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN);

    Name methodName = field.toName(witherName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);

    JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);

    JCExpression selfType = cloneSelfType(field);
    if (selfType == null) return null;

    TreeMaker maker = field.getTreeMaker();

    ListBuffer<JCExpression> args = ListBuffer.lb();
    for (JavacNode child : field.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        JCVariableDecl childDecl = (JCVariableDecl) child.get();
        // Skip fields that start with $
        if (childDecl.name.toString().startsWith("$")) continue;
        long fieldFlags = childDecl.mods.flags;
        // Skip static fields.
        if ((fieldFlags & Flags.STATIC) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
        if (child.get() == field.get()) {
            args.append(maker.Ident(fieldDecl.name));
        } else {
            args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
        }
    }

    JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
    JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
    JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
    JCReturn returnStatement = maker.Return(conditional);

    if (nonNulls.isEmpty()) {
        statements.append(returnStatement);
    } else {
        JCStatement nullCheck = generateNullCheck(treeMaker, field);
        if (nullCheck != null) statements.append(nullCheck);
        statements.append(returnStatement);
    }

    JCExpression returnType = cloneSelfType(field);

    JCBlock methodBody = treeMaker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;

    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);

    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil()));
    }
    return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
}