@Override public String visitCompoundAssignment( CompoundAssignmentTree node, Object v ) { StringBuilder out = new StringBuilder(); appendComment( node, out ); ExpressionTree variable = node.getVariable(); ExpressionTree expression = node.getExpression(); JCTree.Tag operator = ((JCTree.JCAssignOp)node).getTag(); out.append( variable.accept( this, v ) ); out.append( " " ).append( operatorName( operator ) ).append( " " ); out.append( expression.accept( this, v ) ); return out.toString(); }
SuggestedFix.replace( tree.getStartPosition(), ((JCAssignOp) tree).getExpression().getStartPosition(), ""); fix.merge(replacement);
JCTree.JCExpression lhs = assignOp.getVariable(); JCTree.JCExpression rhs = assignOp.getExpression(); Source source = context.source; Optional<BlockScope> cb = source.getCurrentBlock();
SuggestedFix.replace( tree.getStartPosition(), ((JCAssignOp) tree).getExpression().getStartPosition(), ""); fix.merge(replacement);
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); bufferToString(tree.pos()); } else { if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) && l instanceof LocalItem && tree.lhs.type.getTag().isSubRangeOf(INT) && tree.rhs.type.constValue() != null) { int ival = ((Number) tree.rhs.type.constValue()).intValue(); if (tree.hasTag(MINUS_ASG)) ival = -ival; ((LocalItem)l).incr(ival); result = l;
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); bufferToString(tree.pos()); } else { if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) && l instanceof LocalItem && tree.lhs.type.getTag().isSubRangeOf(INT) && tree.rhs.type.constValue() != null) { int ival = ((Number) tree.rhs.type.constValue()).intValue(); if (tree.hasTag(MINUS_ASG)) ival = -ival; ((LocalItem)l).incr(ival); result = l;
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); bufferToString(tree.pos()); } else { if ((tree.getTag() == JCTree.PLUS_ASG || tree.getTag() == JCTree.MINUS_ASG) && l instanceof LocalItem && tree.lhs.type.tag <= INT && tree.rhs.type.constValue() != null) { int ival = ((Number) tree.rhs.type.constValue()).intValue(); if (tree.getTag() == JCTree.MINUS_ASG) ival = -ival; ((LocalItem)l).incr(ival); result = l;
public void visitAssignop(JCAssignOp tree) { // Attribute arguments. Type owntype = attribTree(tree.lhs, env, VAR, Type.noType); Type operand = attribExpr(tree.rhs, env); // Find operator. Symbol operator = tree.operator = rs.resolveBinaryOperator( tree.pos(), tree.tag - JCTree.ASGOffset, env, owntype, operand); if (operator.kind == MTH) { chk.checkOperator(tree.pos(), (OperatorSymbol)operator, tree.tag - JCTree.ASGOffset, owntype, operand); if (types.isSameType(operator.type.getReturnType(), syms.stringType)) { // String assignment; make sure the lhs is a string chk.checkType(tree.lhs.pos(), owntype, syms.stringType); } else { chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkCastable(tree.rhs.pos(), operator.type.getReturnType(), owntype); } } result = check(tree, owntype, VAL, pkind, pt); }
public void visitAssignop(JCAssignOp tree) { // Attribute arguments. Type owntype = attribTree(tree.lhs, env, VAR, Type.noType); Type operand = attribExpr(tree.rhs, env); // Find operator. Symbol operator = tree.operator = rs.resolveBinaryOperator( tree.pos(), tree.getTag() - JCTree.ASGOffset, env, owntype, operand); if (operator.kind == MTH) { chk.checkOperator(tree.pos(), (OperatorSymbol)operator, tree.getTag() - JCTree.ASGOffset, owntype, operand); if (types.isSameType(operator.type.getReturnType(), syms.stringType)) { // String assignment; make sure the lhs is a string chk.checkType(tree.lhs.pos(), owntype, syms.stringType); } else { chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkCastable(tree.rhs.pos(), operator.type.getReturnType(), owntype); } } result = check(tree, owntype, VAL, pkind, pt); }
@Override public void visitAssignop(JCAssignOp tree) { int col = out.col; printExpr(tree.lhs, TreeInfo.assignopPrec + 1); if (cs.spaceAroundAssignOps()) print(' '); print(operators.operatorName(tree.getTag().noAssignOp())); print('='); int rm = cs.getRightMargin(); switch(cs.wrapAssignOps()) { case WRAP_IF_LONG: if (widthEstimator.estimateWidth(tree.rhs, rm - out.col) + out.col <= cs.getRightMargin()) { if(cs.spaceAroundAssignOps()) print(' '); break; } case WRAP_ALWAYS: newline(); toColExactly(cs.alignMultilineAssignment() ? col : out.leftMargin + cs.getContinuationIndentSize()); break; case WRAP_NEVER: if(cs.spaceAroundAssignOps()) print(' '); break; } printExpr(tree.rhs, TreeInfo.assignopPrec); }
public void visitAssignop(JCAssignOp tree) { // Attribute arguments. Type owntype = attribTree(tree.lhs, env, varInfo); Type operand = attribExpr(tree.rhs, env); // Find operator. Symbol operator = tree.operator = rs.resolveBinaryOperator( tree.pos(), tree.getTag().noAssignOp(), env, owntype, operand); if (operator.kind == MTH && !owntype.isErroneous() && !operand.isErroneous()) { chk.checkOperator(tree.pos(), (OperatorSymbol)operator, tree.getTag().noAssignOp(), owntype, operand); chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkCastable(tree.rhs.pos(), operator.type.getReturnType(), owntype); } result = check(tree, owntype, VAL, resultInfo); }
public void visitAssignop(JCAssignOp tree) { // Attribute arguments. Type owntype = attribTree(tree.lhs, env, varInfo); Type operand = attribExpr(tree.rhs, env); // Find operator. Symbol operator = tree.operator = rs.resolveBinaryOperator( tree.pos(), tree.getTag().noAssignOp(), env, owntype, operand); if (operator.kind == MTH && !owntype.isErroneous() && !operand.isErroneous()) { chk.checkOperator(tree.pos(), (OperatorSymbol)operator, tree.getTag().noAssignOp(), owntype, operand); chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkCastable(tree.rhs.pos(), operator.type.getReturnType(), owntype); } result = check(tree, owntype, VAL, resultInfo); }
public JCTree build(final JCTree lhs) { JCTree.Tag newTag = tree.getTag().noAssignOp(); // Erasure (TransTypes) can change the type of // tree.lhs. However, we can still get the // unerased type of tree.lhs as it is stored // in tree.type in Attr. Symbol newOperator = rs.resolveBinaryOperator(tree.pos(), newTag, attrEnv, tree.type, tree.rhs.type); JCExpression expr = (JCExpression)lhs; if (expr.type != tree.type) expr = make.TypeCast(tree.type, expr); JCBinary opResult = make.Binary(newTag, expr, tree.rhs); opResult.operator = newOperator; opResult.type = newOperator.type.getReturnType(); JCExpression newRhs = boxingReq ? make.TypeCast(types.unboxedType(tree.type), opResult) : opResult; return make.Assign((JCExpression)lhs, newRhs).setType(tree.type); } });
public JCTree build(final JCTree lhs) { JCTree.Tag newTag = tree.getTag().noAssignOp(); // Erasure (TransTypes) can change the type of // tree.lhs. However, we can still get the // unerased type of tree.lhs as it is stored // in tree.type in Attr. Symbol newOperator = rs.resolveBinaryOperator(tree.pos(), newTag, attrEnv, tree.type, tree.rhs.type); JCExpression expr = (JCExpression)lhs; if (expr.type != tree.type) expr = make.TypeCast(tree.type, expr); JCBinary opResult = make.Binary(newTag, expr, tree.rhs); opResult.operator = newOperator; opResult.type = newOperator.type.getReturnType(); JCExpression newRhs = boxingReq ? make.TypeCast(types.unboxedType(tree.type), opResult) : opResult; return make.Assign((JCExpression)lhs, newRhs).setType(tree.type); } });
public JCTree build(final JCTree lhs) { int newTag = tree.tag - JCTree.ASGOffset; // Erasure (TransTypes) can change the type of // tree.lhs. However, we can still get the // unerased type of tree.lhs as it is stored // in tree.type in Attr. Symbol newOperator = rs.resolveBinaryOperator(tree.pos(), newTag, attrEnv, tree.type, tree.rhs.type); JCExpression expr = (JCExpression)lhs; if (expr.type != tree.type) expr = make.TypeCast(tree.type, expr); JCBinary opResult = make.Binary(newTag, expr, tree.rhs); opResult.operator = newOperator; opResult.type = newOperator.type.getReturnType(); JCTypeCast newRhs = make.TypeCast(types.unboxedType(tree.type), opResult); return make.Assign((JCExpression)lhs, newRhs).setType(tree.type); } });
public JCTree build(final JCTree lhs) { int newTag = tree.getTag() - JCTree.ASGOffset; // Erasure (TransTypes) can change the type of // tree.lhs. However, we can still get the // unerased type of tree.lhs as it is stored // in tree.type in Attr. Symbol newOperator = rs.resolveBinaryOperator(tree.pos(), newTag, attrEnv, tree.type, tree.rhs.type); JCExpression expr = (JCExpression)lhs; if (expr.type != tree.type) expr = make.TypeCast(tree.type, expr); JCBinary opResult = make.Binary(newTag, expr, tree.rhs); opResult.operator = newOperator; opResult.type = newOperator.type.getReturnType(); JCTypeCast newRhs = make.TypeCast(types.unboxedType(tree.type), opResult); return make.Assign((JCExpression)lhs, newRhs).setType(tree.type); } });
protected int diffAssignop(JCAssignOp oldT, JCAssignOp newT, int[] bounds) { int localPointer = bounds[0]; // lhs int[] lhsBounds = getBounds(oldT.lhs); copyTo(localPointer, lhsBounds[0]); localPointer = diffTree(oldT.lhs, newT.lhs, lhsBounds); if (oldT.getTag() != newT.getTag()) { // todo (#pf): operatorName() does not work copyTo(localPointer, oldT.pos); printer.print(getAssignementOperator(newT)); localPointer = oldT.pos + getAssignementOperator(oldT).length(); } // rhs int[] rhsBounds = getBounds(oldT.rhs); copyTo(localPointer, rhsBounds[0]); localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds); copyTo(localPointer, bounds[1]); return bounds[1]; }
public Kind getKind() { return TreeInfo.tagToKind(getTag()); } public JCExpression getVariable() { return lhs; }
public Kind getKind() { return TreeInfo.tagToKind(getTag()); } public JCExpression getVariable() { return lhs; }