Java Code Examples for com.sun.source.tree.Tree.Kind#XOR_ASSIGNMENT

The following examples show how to use com.sun.source.tree.Tree.Kind#XOR_ASSIGNMENT . 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: AssignmentIssues.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: AssignmentIssues.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.AssignmentIssues.nestedAssignment", description = "#DESC_org.netbeans.modules.java.hints.AssignmentIssues.nestedAssignment", category = "assignment_issues", enabled = false, suppressWarnings = "NestedAssignment", 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})
public static ErrorDescription nestedAssignment(HintContext context) {
    final TreePath path = context.getPath();
    final Kind parentKind = path.getParentPath().getLeaf().getKind();
    if (parentKind != Kind.EXPRESSION_STATEMENT && parentKind != Kind.ANNOTATION) {
        return ErrorDescriptionFactory.forTree(context, path, NbBundle.getMessage(AssignmentIssues.class, "MSG_NestedAssignment", path.getLeaf())); //NOI18N
    }
    return null;
}
 
Example 3
Source File: AssignmentIssues.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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);
}