本文整理汇总了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);
}
示例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);
}
示例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));
}
示例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;
}
示例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)));
}
示例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)));
}