com.sun.source.tree.CompoundAssignmentTree Java Examples
The following examples show how to use
com.sun.source.tree.CompoundAssignmentTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Trees.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { // JCTree.Tag tag = ((JCTree) expression).getTag(); // if (tag == JCTree.Tag.ASSIGN) { // return "="; // } // boolean assignOp = expression instanceof CompoundAssignmentTree; // if (assignOp) { // tag = tag.noAssignOp(); // } int tag = ((JCTree) expression).getTag(); if (tag == JCTree.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { // tag = tag.noAssignOp(); // TODO: 22-Jul-17 ????? } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #2
Source File: Trees.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { // JCTree.Tag tag = ((JCTree) expression).getTag(); // if (tag == JCTree.Tag.ASSIGN) { // return "="; // } // boolean assignOp = expression instanceof CompoundAssignmentTree; // if (assignOp) { // tag = tag.noAssignOp(); // } int tag = ((JCTree) expression).getTag(); if (tag == JCTree.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { // tag = tag.noAssignOp(); // TODO: 22-Jul-17 ????? } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #3
Source File: AssignmentIssues.java From netbeans with Apache License 2.0 | 5 votes |
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", description = "#DESC_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", category = "assignment_issues", enabled = false, suppressWarnings = "AssignmentToMethodParameter", options=Options.QUERY) //NOI18N @TriggerTreeKind({Kind.ASSIGNMENT, Kind.AND_ASSIGNMENT, Kind.DIVIDE_ASSIGNMENT, Kind.LEFT_SHIFT_ASSIGNMENT, Kind.MINUS_ASSIGNMENT, Kind.MULTIPLY_ASSIGNMENT, Kind.OR_ASSIGNMENT, Kind.PLUS_ASSIGNMENT, Kind.REMAINDER_ASSIGNMENT, Kind.RIGHT_SHIFT_ASSIGNMENT, Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT, Kind.XOR_ASSIGNMENT, Kind.PREFIX_INCREMENT, Kind.PREFIX_DECREMENT, Kind.POSTFIX_INCREMENT, Kind.POSTFIX_DECREMENT}) public static ErrorDescription assignmentToMethodParam(HintContext context) { final TreePath path = context.getPath(); Element element = null; switch (path.getLeaf().getKind()) { case ASSIGNMENT: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((AssignmentTree) path.getLeaf()).getVariable())); break; case PREFIX_INCREMENT: case PREFIX_DECREMENT: case POSTFIX_INCREMENT: case POSTFIX_DECREMENT: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((UnaryTree) path.getLeaf()).getExpression())); break; default: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((CompoundAssignmentTree) path.getLeaf()).getVariable())); } if (element != null && element.getKind() == ElementKind.PARAMETER) { return ErrorDescriptionFactory.forTree(context, path, NbBundle.getMessage(AssignmentIssues.class, "MSG_AssignmentToMethodParam", element.getSimpleName())); //NOI18N } return null; }
Example #4
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree expected, Tree actual) { Optional<CompoundAssignmentTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getVariable(), other.get().getVariable()); scan(expected.getExpression(), other.get().getExpression()); return null; }
Example #5
Source File: UAssignOp.java From Refaster with Apache License 2.0 | 5 votes |
@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); }
Example #6
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 5 votes |
private TreeNode convertAssignOp(CompoundAssignmentTree node, TreePath parent) { TreePath path = getTreePath(parent, node); Assignment newNode = new Assignment(); return newNode .setOperator(Assignment.Operator.from(node.getKind())) .setLeftHandSide((Expression) convert(node.getVariable(), path)) .setRightHandSide((Expression) convert(node.getExpression(), path)); }
Example #7
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree node, Void unused) { sync(node); builder.open(plusFour); scan(node.getVariable(), null); builder.space(); splitToken(operatorName(node)); builder.breakOp(" "); scan(node.getExpression(), null); builder.close(); return null; }
Example #8
Source File: Trees.java From google-java-format with Apache License 2.0 | 5 votes |
/** Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { JCTree.Tag tag = ((JCTree) expression).getTag(); if (tag == JCTree.Tag.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { tag = tag.noAssignOp(); } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #9
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree node, Void unused) { sync(node); builder.open(plusFour); scan(node.getVariable(), null); builder.space(); splitToken(operatorName(node)); builder.breakOp(" "); scan(node.getExpression(), null); builder.close(); return null; }
Example #10
Source File: NullAway.java From NullAway with MIT License | 5 votes |
@Override public Description matchCompoundAssignment(CompoundAssignmentTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } Type lhsType = ASTHelpers.getType(tree.getVariable()); Type stringType = state.getTypeFromString("java.lang.String"); if (lhsType != null && !state.getTypes().isSameType(lhsType, stringType)) { // both LHS and RHS could get unboxed return doUnboxingCheck(state, tree.getVariable(), tree.getExpression()); } return Description.NO_MATCH; }
Example #11
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 5 votes |
/** * Compound assignment expects the assigned-to variable's type. */ @Override public List<? extends TypeMirror> visitCompoundAssignment(CompoundAssignmentTree node, Object p) { if (theExpression == null) { initExpression(new TreePath(getCurrentPath(), node.getExpression())); } return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getVariable()))); }
Example #12
Source File: AssignmentIssues.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree node, List<TreePath> p) { if (param == trees.getElement(TreePath.getPath(getCurrentPath(), node.getVariable()))) { p.add(getCurrentPath()); return null; } return super.visitCompoundAssignment(node, p); }
Example #13
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree node, Void unused) { sync(node); builder.open(plusFour); scan(node.getVariable(), null); builder.space(); splitToken(operatorName(node)); builder.breakOp(" "); scan(node.getExpression(), null); builder.close(); return null; }
Example #14
Source File: TreeDuplicator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitCompoundAssignment(CompoundAssignmentTree tree, Void p) { CompoundAssignmentTree n = make.CompoundAssignment(tree.getKind(), tree.getVariable(), tree.getExpression()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
Example #15
Source File: ReplaceBufferByString.java From netbeans with Apache License 2.0 | 5 votes |
private ExpressionTree makeParenthesis(ExpressionTree arg) { Class c = arg.getKind().asInterface(); // if the original append argument was an expression, surround it in parenthesis, to get the same toString effect if (c == BinaryTree.class || c == UnaryTree.class || c == CompoundAssignmentTree.class || c == AssignmentTree.class || c == ConditionalExpressionTree.class) { return mk.Parenthesized(arg); } else { return arg; } }
Example #16
Source File: CopyFinder.java From netbeans with Apache License 2.0 | 5 votes |
public Boolean visitCompoundAssignment(CompoundAssignmentTree node, TreePath p) { if (p == null) { super.visitCompoundAssignment(node, p); return false; } CompoundAssignmentTree bt = (CompoundAssignmentTree) p.getLeaf(); boolean result = scan(node.getExpression(), bt.getExpression(), p); return result && scan(node.getVariable(), bt.getVariable(), p); }
Example #17
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitCompoundAssignment(CompoundAssignmentTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitCompoundAssignment(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
Example #18
Source File: ProspectiveOperation.java From netbeans with Apache License 2.0 | 5 votes |
private static ProspectiveOperation handleCompoundAssignementReducer(TreeMaker tm, ExpressionTree expr, OperationType operationType, PreconditionsChecker precond, WorkingCopy workingCopy, List<ProspectiveOperation> ls, ProspectiveOperation redOp) { //this variable will be removed at a later stage. VariableTree var = tm.Variable(tm.Modifiers(new HashSet<Modifier>()), "dummyVar18912", tm.Type("Object"), ((CompoundAssignmentTree) expr).getExpression()); ProspectiveOperation map = new ProspectiveOperation(var, operationType.MAP, precond.getInnerVariables(), workingCopy, precond.getVarToName()); map.getAvailableVariables().add(var.getName()); ls.add(map); redOp = new ProspectiveOperation(expr, operationType, precond.getInnerVariables(), workingCopy, precond.getVarToName()); redOp.neededVariables = new HashSet<Name>(); redOp.neededVariables.add(var.getName()); redOp.reducingVariable = ((CompoundAssignmentTree) expr).getVariable(); return redOp; }
Example #19
Source File: IteratorToFor.java From netbeans with Apache License 2.0 | 5 votes |
@TriggerPattern(value="for (int $index = 0; $index < $arr.length; $index++) $statement;", constraints=@ConstraintVariableType(variable="$arr", type="Object[]")) public static ErrorDescription forIndexedArray(final HintContext ctx) { AccessAndVarVisitor v = new AccessAndVarVisitor(ctx) { @Override public Void visitArrayAccess(ArrayAccessTree node, Void p) { TreePath path = getCurrentPath(); if (MatcherUtilities.matches(ctx, path, "$arr[$index]")) { // NOI18N if (path.getParentPath() != null) { if ( path.getParentPath().getLeaf().getKind() == Kind.ASSIGNMENT && ((AssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) { unsuitable(); } if (CompoundAssignmentTree.class.isAssignableFrom(path.getParentPath().getLeaf().getKind().asInterface()) && ((CompoundAssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) { unsuitable(); } } toReplace.add(path); return null; } return super.visitArrayAccess(node, p); } }; v.scan(ctx.getVariables().get("$statement"), null); // NOI18N if (v.unsuitable) return null; return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_IteratorToForArray(), new ReplaceIndexedForEachLoop(ctx.getInfo(), ctx.getPath(), ctx.getVariables().get("$arr"), v.toReplace, v.definedVariables).toEditorFix()); }
Example #20
Source File: PreconditionsChecker.java From netbeans with Apache License 2.0 | 4 votes |
private boolean isLeftHandSideOfCompoundAssignement(Tree parent, IdentifierTree that) { return TreeUtilities.isCompoundAssignementAssignement(parent.getKind()) && ((CompoundAssignmentTree) parent).getVariable().equals(that); }
Example #21
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UAssignOp visitCompoundAssignment(CompoundAssignmentTree tree, Void v) { return UAssignOp.create(template(tree.getVariable()), tree.getKind(), template(tree.getExpression())); }
Example #22
Source File: RemoveUnnecessary.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitCompoundAssignment(CompoundAssignmentTree node, Object p) { return addExpressionStatement(node, p); }
Example #23
Source File: Flow.java From netbeans with Apache License 2.0 | 4 votes |
@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; }
Example #24
Source File: ExpressionScanner.java From netbeans with Apache License 2.0 | 4 votes |
@Override public List<Tree> visitCompoundAssignment(CompoundAssignmentTree node, ExpressionScanner.ExpressionsInfo p) { return scan(node.getVariable(), node.getExpression(), p); }
Example #25
Source File: Unbalanced.java From netbeans with Apache License 2.0 | 4 votes |
@TriggerTreeKind({Kind.IDENTIFIER, Kind.MEMBER_SELECT}) @TriggerOptions(TriggerOptions.PROCESS_GUARDED) public static ErrorDescription before(HintContext ctx) { VariableElement var = testElement(ctx); if (var == null) return null; TreePath tp = ctx.getPath(); if (tp.getParentPath().getLeaf().getKind() == Kind.ARRAY_ACCESS) { State accessType = State.READ; State secondAccess = null; Tree access = tp.getParentPath().getLeaf(); Tree assign = tp.getParentPath().getParentPath().getLeaf(); switch (assign.getKind()) { case ASSIGNMENT: if (((AssignmentTree) assign).getVariable() == access) { accessType = State.WRITE; } break; case AND_ASSIGNMENT: case DIVIDE_ASSIGNMENT: case LEFT_SHIFT_ASSIGNMENT: case MINUS_ASSIGNMENT: case MULTIPLY_ASSIGNMENT: case OR_ASSIGNMENT: case PLUS_ASSIGNMENT: case REMAINDER_ASSIGNMENT: case RIGHT_SHIFT_ASSIGNMENT: case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT: case XOR_ASSIGNMENT: if (((CompoundAssignmentTree) assign).getVariable() == access) { secondAccess = State.WRITE; } break; case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: case PREFIX_DECREMENT: case PREFIX_INCREMENT: secondAccess = State.WRITE; break; } record(ctx.getInfo(), var, accessType); if (secondAccess != null) { record(ctx.getInfo(), var, secondAccess); } } else { record(ctx.getInfo(), var, State.WRITE, State.READ); } return null; }
Example #26
Source File: AssignmentIssues.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void performRewrite(TransformationContext ctx) { WorkingCopy wc = ctx.getWorkingCopy(); final AssignmentTree at = (AssignmentTree) ctx.getPath().getLeaf(); Kind kind = null; switch (at.getExpression().getKind()) { case AND: kind = Kind.AND_ASSIGNMENT; break; case DIVIDE: kind = Kind.DIVIDE_ASSIGNMENT; break; case LEFT_SHIFT: kind = Kind.LEFT_SHIFT_ASSIGNMENT; break; case MINUS: kind = Kind.MINUS_ASSIGNMENT; break; case MULTIPLY: kind = Kind.MULTIPLY_ASSIGNMENT; break; case OR: kind = Kind.OR_ASSIGNMENT; break; case PLUS: kind = Kind.PLUS_ASSIGNMENT; break; case REMAINDER: kind = Kind.REMAINDER_ASSIGNMENT; break; case RIGHT_SHIFT: kind = Kind.RIGHT_SHIFT_ASSIGNMENT; break; case UNSIGNED_RIGHT_SHIFT: kind = Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT; break; case XOR: kind = Kind.XOR_ASSIGNMENT; break; } if (kind == null) { return; } final CompoundAssignmentTree cat = wc.getTreeMaker().CompoundAssignment(kind, at.getVariable(), ((BinaryTree) at.getExpression()).getRightOperand()); wc.rewrite(at, cat); }
Example #27
Source File: DoubleCheck.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitCompoundAssignment(CompoundAssignmentTree node, Object p) { // TODO: it's not necessary for reference-type variables; might be eventually used // for primitives return super.visitCompoundAssignment(node, p); }
Example #28
Source File: SideEffectVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitCompoundAssignment(CompoundAssignmentTree node, Object p) { checkVariableAccess(node.getVariable(), node.getVariable()); return super.visitCompoundAssignment(node, p); }
Example #29
Source File: ASTPath.java From annotation-tools with MIT License | 2 votes |
/** * Determines if the given kind is a compound assignment. * * @param kind * the kind to test * @return true if the given kind is a compound assignment */ public static boolean isCompoundAssignment(Tree.Kind kind) { return kind.asInterface().equals(CompoundAssignmentTree.class); }