当前位置: 首页>>代码示例>>Java>>正文


Java TreeInfo.skipParens方法代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.TreeInfo.skipParens方法的典型用法代码示例。如果您正苦于以下问题:Java TreeInfo.skipParens方法的具体用法?Java TreeInfo.skipParens怎么用?Java TreeInfo.skipParens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.tree.TreeInfo的用法示例。


在下文中一共展示了TreeInfo.skipParens方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: suggestFixForSameReference

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/** Handles the case "expr1 == expr2" */
private static void suggestFixForSameReference(
    SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state, boolean isEqual) {

  BinaryTree equalityTree = (BinaryTree) TreeInfo.skipParens((JCTree) foundAssert.getCondition());
  ExpressionTree expr1 = equalityTree.getLeftOperand();
  ExpressionTree expr2 = equalityTree.getRightOperand();

  if (expr1.getKind() == NULL_LITERAL) {
    // case: "assert null [op] expr"
    addFix(fix, (JCExpression) expr2, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
  } else if (expr2.getKind() == NULL_LITERAL) {
    // case: "assert expr [op] null"
    addFix(fix, (JCExpression) expr1, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
  } else {
    // case: "assert expr1 [op] expr2"
    addFix(
        fix,
        (JCExpression) expr1,
        foundAssert,
        state,
        String.format(isEqual ? IS_SAME_AS : IS_NOT_SAME_AS, expr2));
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:UseCorrectAssertInTests.java

示例2: collect

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private List<JCTree> collect(JCTree tree, List<JCTree> res) {
    tree = TreeInfo.skipParens(tree);
    if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
        JCTree.JCBinary op = (JCTree.JCBinary) tree;
        if (op.operator.kind == MTH && op.operator.opcode == string_add) {
            return res
                    .appendList(collect(op.lhs, res))
                    .appendList(collect(op.rhs, res));
        }
    }
    return res.append(tree);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:StringConcat.java

示例3: collect

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private List<JCTree> collect(JCTree tree, List<JCTree> res) {
    tree = TreeInfo.skipParens(tree);
    if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
        JCTree.JCBinary op = (JCTree.JCBinary) tree;
        if (op.operator.kind == MTH &&
                ((Symbol.OperatorSymbol) op.operator).opcode == string_add) {
            return res
                    .appendList(collect(op.lhs, res))
                    .appendList(collect(op.rhs, res));
        }
    }
    return res.append(tree);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:14,代码来源:StringConcat.java

示例4: replaceAssert

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private static void replaceAssert(
    SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state) {

  ExpressionTree expr = foundAssert.getCondition();
  expr = (ExpressionTree) TreeInfo.skipParens((JCTree) expr);

  // case: "assert !expr"
  if (expr.getKind().equals(LOGICAL_COMPLEMENT)) {
    addFix(fix, ((JCUnary) expr).getExpression(), foundAssert, state, IS_FALSE);
    return;
  }

  // case: "assert expr1.equals(expr2)"
  if (instanceMethod().onClass(Any.INSTANCE).named("equals").matches(expr, state)) {
    JCMethodInvocation equalsCall = ((JCMethodInvocation) expr);
    JCExpression expr1 = ((JCFieldAccess) ((JCMethodInvocation) expr).meth).selected;
    JCExpression expr2 = equalsCall.getArguments().get(0);

    addFix(
        fix,
        expr1,
        foundAssert,
        state,
        String.format(IS_EQUAL_TO, normalizedSourceForExpression(expr2, state)));
    return;
  }

  // case: "assert expr1 == expr2" or "assert expr1 != expr2"
  if (expr.getKind().equals(Kind.EQUAL_TO) || expr.getKind().equals(Kind.NOT_EQUAL_TO)) {
    suggestFixForSameReference(fix, foundAssert, state, expr.getKind().equals(Kind.EQUAL_TO));
    return;
  }

  // case: "assert expr", which didn't match any of the previous cases.
  addFix(fix, (JCExpression) expr, foundAssert, state, IS_TRUE);
}
 
开发者ID:google,项目名称:error-prone,代码行数:37,代码来源:UseCorrectAssertInTests.java

示例5: checkInit

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/** Check that variable is initialized and evaluate the variable's
         *  initializer, if not yet done. Also check that variable is not
         *  referenced before it is defined.
         *  @param tree    The tree making up the variable reference.
         *  @param env     The current environment.
         *  @param v       The variable's symbol.
         */
        private void checkInit(JCTree tree,
                               Env<AttrContext> env,
                               VarSymbol v,
                               boolean onlyWarning) {
//          System.err.println(v + " " + ((v.flags() & STATIC) != 0) + " " +
//                             tree.pos + " " + v.pos + " " +
//                             Resolve.isStatic(env));//DEBUG

            // A forward reference is diagnosed if the declaration position
            // of the variable is greater than the current tree position
            // and the tree and variable definition occur in the same class
            // definition.  Note that writes don't count as references.
            // This check applies only to class and instance
            // variables.  Local variables follow different scope rules,
            // and are subject to definite assignment checking.
            if ((env.info.enclVar == v || v.pos > tree.pos) &&
                v.owner.kind == TYP &&
                canOwnInitializer(env.info.scope.owner) &&
                v.owner == env.info.scope.owner.enclClass() &&
                ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) &&
                (env.tree.getTag() != JCTree.ASSIGN ||
                 TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
                String suffix = (env.info.enclVar == v) ?
                                "self.ref" : "forward.ref";
                if (!onlyWarning || isStaticEnumField(v)) {
                    log.error(tree.pos(), "illegal." + suffix);
                } else if (useBeforeDeclarationWarning) {
                    log.warning(tree.pos(), suffix, v);
                }
            }

            v.getConstValue(); // ensure initializer is evaluated

            checkEnumInitializer(tree, env, v);
        }
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:43,代码来源:Attr.java

示例6: instantiatePolymorphicSignatureInstance

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
                                        Name name,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case JCTree.TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case JCTree.EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, implicitArgType);
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:49,代码来源:Infer.java

示例7: instantiatePolymorphicSignatureInstance

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:Infer.java

示例8: instantiatePolymorphicSignatureInstance

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
        // The return type of the polymorphic signature is polymorphic,
        // and is computed from the enclosing tree E, as follows:
        // if E is a cast, then use the target type of the cast expression
        // as a return type; if E is an expression statement, the return
        // type is 'void'; otherwise
        // the return type is simply 'Object'. A correctness check ensures
        // that env.next refers to the lexically enclosing environment in
        // which the polymorphic signature call environment is nested.

        switch (env.next.tree.getTag()) {
            case TYPECAST:
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                          castTree.clazz.type :
                          syms.objectType;
                break;
            case EXEC:
                JCTree.JCExpressionStatement execTree =
                        (JCTree.JCExpressionStatement)env.next.tree;
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                          syms.voidType :
                          syms.objectType;
                break;
            default:
                restype = syms.objectType;
        }
    } else {
        // The return type of the polymorphic signature is fixed
        // (not polymorphic)
        restype = spMethod.getReturnType();
    }

    List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:56,代码来源:Infer.java


注:本文中的com.sun.tools.javac.tree.TreeInfo.skipParens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。