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


Java BinaryTree.getLeftOperand方法代码示例

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


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

示例1: checkBinaryOp

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
private static boolean checkBinaryOp(CompilationInfo ci, TreePath expr, Tree prev) {
    BinaryTree bt = (BinaryTree)expr.getLeaf();
    Tree other = prev == bt.getLeftOperand() ? bt.getRightOperand() : bt.getLeftOperand();
    Boolean b = checkTwoArguments(ci, expr, other, prev);
    if (Boolean.TRUE == b) {
        return true;
    }
    if (b == null) {
        return false;
    }
    TypeMirror tm  = ci.getTrees().getTypeMirror(new TreePath(expr, other));
    if (tm != null && tm.getKind() == TypeKind.DECLARED) {
        Element el = ((DeclaredType)tm).asElement();
        if (el != null && el.getKind() == ElementKind.CLASS) {
            return ((TypeElement)el).getQualifiedName().contentEquals("java.lang.String"); // NOI18N
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:UnnecessaryBoxing.java

示例2: matchBinary

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  Type leftType = ASTHelpers.getType(leftOperand);
  Type rightType = ASTHelpers.getType(rightOperand);
  if (leftType == null || rightType == null) {
    throw new RuntimeException();
  }
  if (leftType.isPrimitive() && !rightType.isPrimitive()) {
    return doUnboxingCheck(state, rightOperand);
  }
  if (rightType.isPrimitive() && !leftType.isPrimitive()) {
    return doUnboxingCheck(state, leftOperand);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java

示例3: matchBinary

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  if (!(tree.getLeftOperand() instanceof JCLiteral)) {
    return Description.NO_MATCH;
  }
  if (!(tree.getRightOperand() instanceof JCLiteral)) {
    return Description.NO_MATCH;
  }
  Boolean constValue = ASTHelpers.constValue(tree, Boolean.class);
  if (constValue == null) {
    return Description.NO_MATCH;
  }
  return buildDescription(tree)
      .addFix(SuggestedFix.replace(tree, constValue.toString()))
      .setMessage(
          String.format(
              "This expression always evalutes to `%s`, prefer a boolean literal for clarity.",
              constValue))
      .build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ComplexBooleanConstant.java

示例4: suggestFixForSameReference

import com.sun.source.tree.BinaryTree; //导入方法依赖的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

示例5: matches

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public boolean matches(BinaryTree tree, VisitorState state) {
  Type leftType = ((JCTree) tree.getLeftOperand()).type;
  Types types = state.getTypes();
  Symtab symtab = state.getSymtab();
  if (!(types.isSameType(leftType, symtab.intType))
      && !(types.isSameType(leftType, symtab.byteType))
      && !(types.isSameType(leftType, symtab.shortType))
      && !(types.isSameType(leftType, symtab.charType))) {
    return false;
  }

  ExpressionTree rightOperand = tree.getRightOperand();
  if (rightOperand instanceof LiteralTree) {
    Object rightValue = ((LiteralTree) rightOperand).getValue();
    if (rightValue instanceof Number) {
      int intValue = ((Number) rightValue).intValue();
      return intValue < 0 || intValue > 31;
    }
  }

  return false;
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:BadShiftAmount.java

示例6: matchBinary

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  if (tree.getKind() == Kind.REMAINDER
      && tree.getLeftOperand() instanceof MethodInvocationTree
      && RANDOM_NEXT_INT.matches(tree.getLeftOperand(), state)) {
    ExpressionTree randomExpr = ASTHelpers.getReceiver(tree.getLeftOperand());
    ExpressionTree modulus = tree.getRightOperand();
    return describeMatch(
        tree,
        SuggestedFix.replace(
            tree,
            String.format(
                "%s.nextInt(%s)",
                state.getSourceForNode(randomExpr), state.getSourceForNode(modulus))));
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:18,代码来源:RandomModInteger.java

示例7: getNullCheckedExpression

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
/**
 * Matches comparisons to null (e.g. {@code foo == null}) and returns the expression being tested.
 */
private static ExpressionTree getNullCheckedExpression(ExpressionTree condition) {
  condition = stripParentheses(condition);
  if (!(condition instanceof BinaryTree)) {
    return null;
  }
  BinaryTree bin = (BinaryTree) condition;
  ExpressionTree other;
  if (bin.getLeftOperand().getKind() == Kind.NULL_LITERAL) {
    other = bin.getRightOperand();
  } else if (bin.getRightOperand().getKind() == Kind.NULL_LITERAL) {
    other = bin.getLeftOperand();
  } else {
    return null;
  }
  return other;
}
 
开发者ID:google,项目名称:error-prone,代码行数:20,代码来源:DoubleCheckedLocking.java

示例8: matches

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public boolean matches(BinaryTree tree, VisitorState state) {
  Type stringType = state.getSymtab().stringType;
  ExpressionTree leftOperand = tree.getLeftOperand();
  Type leftType = ((JCTree.JCExpression) leftOperand).type;
  // The left operand is not a String (ex. null) so no match
  if (!state.getTypes().isSameType(leftType, stringType)) {
    return false;
  }
  ExpressionTree rightOperand = tree.getRightOperand();
  Type rightType = ((JCTree.JCExpression) rightOperand).type;
  // We know that both operands are String objects
  if (state.getTypes().isSameType(rightType, stringType)) {
    return true;
  }
  return false;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:18,代码来源:StringEquality.java

示例9: matches

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public boolean matches(BinaryTree tree, VisitorState state) {
  Type leftType = ((JCTree) tree.getLeftOperand()).type;
  Types types = state.getTypes();
  Symtab symtab = state.getSymtab();
  if (!(types.isSameType(leftType, symtab.intType)) &&
      !(types.isSameType(leftType, symtab.byteType)) &&
      !(types.isSameType(leftType, symtab.shortType)) &&
      !(types.isSameType(leftType, symtab.charType))) {
    return false;
  }

  ExpressionTree rightOperand = tree.getRightOperand();
  if (rightOperand instanceof LiteralTree) {
    Object rightValue = ((LiteralTree) rightOperand).getValue();
    if (rightValue instanceof Number) {
      int intValue = ((Number) rightValue).intValue();
      return intValue < 0 || intValue > 31;
    }
  }

  return false;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:24,代码来源:BadShiftAmount.java

示例10: negateBinaryOperator

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
private static ExpressionTree negateBinaryOperator(TreeMaker make, Tree original, Kind newKind, boolean negateOperands) {
    BinaryTree bt = (BinaryTree) original;
    ExpressionTree left = bt.getLeftOperand();
    ExpressionTree right = bt.getRightOperand();
    if (negateOperands) {
        left = negate(make, left, original);
        right = negate(make, right, original);
    }
    return make.Binary(newKind, left, right);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Utilities.java

示例11: matchBinaryTree

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
/**
 * Given a BinaryTree to match against and a list of two matchers, applies the matchers to the
 * operands in both orders. If both matchers match, returns a list with the operand that matched
 * each matcher in the corresponding position.
 *
 * @param tree a BinaryTree AST node
 * @param matchers a list of matchers
 * @param state the VisitorState
 * @return a list of matched operands, or null if at least one did not match
 */
public static List<ExpressionTree> matchBinaryTree(
    BinaryTree tree, List<Matcher<ExpressionTree>> matchers, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  if (matchers.get(0).matches(leftOperand, state)
      && matchers.get(1).matches(rightOperand, state)) {
    return Arrays.asList(leftOperand, rightOperand);
  } else if (matchers.get(0).matches(rightOperand, state)
      && matchers.get(1).matches(leftOperand, state)) {
    return Arrays.asList(rightOperand, leftOperand);
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:ASTHelpers.java

示例12: matchTypeCast

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public Description matchTypeCast(TypeCastTree tree, VisitorState state) {
  // Check for a narrowing match first as its simplest match to test.
  if (!matches(tree, state)) {
    return Description.NO_MATCH;
  }

  // Test that the match is in a Comparable.compareTo or Comparator.compare method.
  ClassTree declaringClass = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class);
  if (!COMPARABLE_CLASS_MATCHER.matches(declaringClass, state)
      && !COMPARATOR_CLASS_MATCHER.matches(declaringClass, state)) {
    return Description.NO_MATCH;
  }
  MethodTree method = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
  if (method == null) {
    return Description.NO_MATCH;
  }
  if (!COMPARABLE_METHOD_MATCHER.matches(method, state)
      && !COMPARATOR_METHOD_MATCHER.matches(method, state)) {
    return Description.NO_MATCH;
  }

  // Get the unparenthesized expression.
  BinaryTree subtract = (BinaryTree) ASTHelpers.stripParentheses(tree.getExpression());
  ExpressionTree lhs = subtract.getLeftOperand();
  ExpressionTree rhs = subtract.getRightOperand();
  Fix fix;
  if (ASTHelpers.getType(lhs).isPrimitive()) {
    fix = SuggestedFix.replace(tree, "Long.compare(" + lhs + ", " + rhs + ")");
  } else {
    fix = SuggestedFix.replace(tree, lhs + ".compareTo(" + rhs + ")");
  }
  return describeMatch(tree, fix);
}
 
开发者ID:google,项目名称:error-prone,代码行数:35,代码来源:BadComparable.java

示例13: checkForRedundantTests

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
/**
 * Reports an error if a comparison of a @NonNull expression with the null
 * literal is performed.
 */
protected void checkForRedundantTests(BinaryTree node) {

    final ExpressionTree leftOp = node.getLeftOperand();
    final ExpressionTree rightOp = node.getRightOperand();

    // respect command-line option
    if (!checker.getLintOption(
            AbstractNullnessChecker.LINT_REDUNDANTNULLCOMPARISON,
            AbstractNullnessChecker.LINT_DEFAULT_REDUNDANTNULLCOMPARISON)) {
        return;
    }

    // equality tests
    if ((node.getKind() == Tree.Kind.EQUAL_TO || node.getKind() == Tree.Kind.NOT_EQUAL_TO)) {
        AnnotatedTypeMirror left = atypeFactory.getAnnotatedType(leftOp);
        AnnotatedTypeMirror right = atypeFactory.getAnnotatedType(rightOp);
        if (leftOp.getKind() == Tree.Kind.NULL_LITERAL
                && right.hasEffectiveAnnotation(NONNULL))
            checker.report(
                    Result.warning(KNOWN_NONNULL, rightOp.toString()), node);
        else if (rightOp.getKind() == Tree.Kind.NULL_LITERAL
                && left.hasEffectiveAnnotation(NONNULL))
            checker.report(
                    Result.warning(KNOWN_NONNULL, leftOp.toString()), node);
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:31,代码来源:NullnessVisitor.java

示例14: matchBinary

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  // Easy stuff: needs to be a binary expression of the form foo >= 0 or 0 <= foo
  ExpressionType expressionType = isGreaterThanEqualToZero(tree);
  if (expressionType == ExpressionType.MISMATCH) {
    return Description.NO_MATCH;
  }

  ExpressionTree operand =
      expressionType == ExpressionType.GREATER_THAN_EQUAL
          ? tree.getLeftOperand()
          : tree.getRightOperand();
  if (operand instanceof MethodInvocationTree) {
    MethodInvocationTree callToSize = (MethodInvocationTree) operand;
    if (INSTANCE_METHOD_MATCHER.matches(callToSize, state)) {
      return provideReplacementForMethodInvocation(tree, callToSize, state, expressionType);
    } else if (STATIC_METHOD_MATCHER.matches(callToSize, state)) {
      return provideReplacementForStaticMethodInvocation(tree, callToSize, state, expressionType);
    }
  } else if (operand instanceof MemberSelectTree) {
    if (ARRAY_LENGTH_MATCHER.matches((MemberSelectTree) operand, state)) {
      return removeEqualsFromComparison(tree, state, expressionType);
    }
  }

  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:28,代码来源:SizeGreaterThanOrEqualsZero.java

示例15: visitBinary

import com.sun.source.tree.BinaryTree; //导入方法依赖的package包/类
/**
 * Case 6: Check for redundant nullness tests Case 7: unboxing case:
 * primitive operations
 */
@Override
public Void visitBinary(BinaryTree node, Void p) {
    final ExpressionTree leftOp = node.getLeftOperand();
    final ExpressionTree rightOp = node.getRightOperand();

    if (isUnboxingOperation(node)) {
        checkForNullability(leftOp, UNBOXING_OF_NULLABLE);
        checkForNullability(rightOp, UNBOXING_OF_NULLABLE);
    }

    checkForRedundantTests(node);

    return super.visitBinary(node, p);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:19,代码来源:NullnessVisitor.java


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