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


Java CompoundAssignmentTree.getKind方法代码示例

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


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

示例1: visitCompoundAssignment

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
    ExpressionTree var = node.getVariable();
    ExpressionTree expr = node.getExpression();
    AnnotatedTypeMirror varType = atypeFactory.getAnnotatedType(var);
    AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);

    Kind kind = node.getKind();

    if ( (kind == Kind.PLUS_ASSIGNMENT || kind == Kind.MINUS_ASSIGNMENT)) {
        if (!atypeFactory.getTypeHierarchy().isSubtype(exprType, varType)) {
            checker.report(Result.failure("compound.assignment.type.incompatible",
                    varType, exprType), node);
        }
    } else if (exprType.getAnnotation(UnknownUnits.class) == null) {
        // Only allow mul/div with unqualified units
        checker.report(Result.failure("compound.assignment.type.incompatible",
                varType, exprType), node);
    }

    return null; // super.visitCompoundAssignment(node, p);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:23,代码来源:UnitsVisitor.java

示例2: visitCompoundAssignment

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
@Override
@Nullable
public Unifier visitCompoundAssignment(
    CompoundAssignmentTree assignOp, @Nullable Unifier unifier) {
  unifier = (getKind() == assignOp.getKind()) ? unifier : null;
  unifier = getVariable().unify(assignOp.getVariable(), unifier);
  return getExpression().unify(assignOp.getExpression(), unifier);      
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:9,代码来源:UAssignOp.java

示例3: rewriteCompoundAssignment

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
/** Desugars a compound assignment, making the cast explicit. */
private static Optional<Fix> rewriteCompoundAssignment(
    CompoundAssignmentTree tree, VisitorState state) {
  CharSequence var = state.getSourceForNode(tree.getVariable());
  CharSequence expr = state.getSourceForNode(tree.getExpression());
  if (var == null || expr == null) {
    return Optional.absent();
  }
  switch (tree.getKind()) {
    case RIGHT_SHIFT_ASSIGNMENT:
      // narrowing the result of a signed right shift does not lose information
      return Optional.absent();
    default:
      break;
  }
  Kind regularAssignmentKind = regularAssignmentFromCompound(tree.getKind());
  String op = assignmentToString(regularAssignmentKind);

  // Add parens to the rhs if necessary to preserve the current precedence
  // e.g. 's -= 1 - 2' -> 's = s - (1 - 2)'
  if (tree.getExpression() instanceof JCBinary) {
    Kind rhsKind = tree.getExpression().getKind();
    if (!OperatorPrecedence.from(rhsKind)
        .isHigher(OperatorPrecedence.from(regularAssignmentKind))) {
      expr = String.format("(%s)", expr);
    }
  }

  // e.g. 's *= 42' -> 's = (short) (s * 42)'
  String castType = getType(tree.getVariable()).toString();
  String replacement = String.format("%s = (%s) (%s %s %s)", var, castType, var, op, expr);
  return Optional.of(SuggestedFix.replace(tree, replacement));
}
 
开发者ID:google,项目名称:error-prone,代码行数:34,代码来源:NarrowingCompoundAssignment.java

示例4: visitCompoundAssignment

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
@Override
public Boolean visitCompoundAssignment(CompoundAssignmentTree node, ConstructorData p) {
    TypeElement oldQName = this.referenceTarget;
    this.referenceTarget = null;

    lValueDereference = true;
    scan(node.getVariable(), null);
    lValueDereference = false;

    Boolean constVal = scan(node.getExpression(), p);

    Element e = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable()));

    if (e != null) {
        if (SUPPORTED_VARIABLES.contains(e.getKind())) {
            VariableElement ve = (VariableElement) e;
            State prevState = variable2State.get(ve);
            if (LOCAL_VARIABLES.contains(e.getKind())) {
                addUse2Values(node.getVariable(), prevState);
            } else if (e.getKind() == ElementKind.FIELD && prevState != null && prevState.hasUnassigned() && !finalCandidates.contains(ve)) {
                usedWhileUndefined.add(ve);
            }
            recordVariableState(ve, getCurrentPath());
        } else if (shouldProcessUndefined(e)) {
            Element cv = canonicalUndefined(e);
            recordVariableState(cv, getCurrentPath());
        }
    }

    this.referenceTarget = oldQName;
    boolean retain = false;
    switch (node.getKind()) {
        case OR_ASSIGNMENT:
            retain = constVal == Boolean.TRUE;
            break;
        case AND_ASSIGNMENT:
            retain = constVal == Boolean.FALSE;
            break;
    }
    return retain ? constVal : null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:Flow.java

示例5: isStringCompoundConcatenation

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
/**
 * Returns true if the compound assignment tree is a string concatenation
 */
public static final boolean isStringCompoundConcatenation(CompoundAssignmentTree tree) {
    return (tree.getKind() == Tree.Kind.PLUS_ASSIGNMENT
            && TypesUtils.isString(InternalUtils.typeOf(tree)));
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:8,代码来源:TreeUtils.java

示例6: isStringCompoundConcatenation

import com.sun.source.tree.CompoundAssignmentTree; //导入方法依赖的package包/类
/** Returns true if the compound assignment tree is a string concatenation */
public static final boolean isStringCompoundConcatenation(CompoundAssignmentTree tree) {
    return (tree.getKind() == Tree.Kind.PLUS_ASSIGNMENT
            && TypesUtils.isString(InternalUtils.typeOf(tree)));
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:6,代码来源:TreeUtils.java


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