All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.checkerframework.dataflow.cfg.node.AssignmentNode Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.44.0
Show newest version
package org.checkerframework.dataflow.cfg.node;

import com.sun.source.tree.AssignmentTree;
import com.sun.source.tree.CompoundAssignmentTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.UnaryTree;
import com.sun.source.tree.VariableTree;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.javacutil.TreeUtils;

/**
 * A node for an assignment:
 *
 * 
 *   variable = expression
 *   expression . field = expression
 *   expression [ index ] = expression
 * 
* * We allow assignments without corresponding AST {@link Tree}s. */ public class AssignmentNode extends Node { protected final Tree tree; protected final Node lhs; protected final Node rhs; public AssignmentNode(Tree tree, Node target, Node expression) { super(TreeUtils.typeOf(tree)); assert tree instanceof AssignmentTree || tree instanceof VariableTree || tree instanceof CompoundAssignmentTree || tree instanceof UnaryTree; assert target instanceof FieldAccessNode || target instanceof LocalVariableNode || target instanceof ArrayAccessNode; this.tree = tree; this.lhs = target; this.rhs = expression; } /** * Returns the left-hand-side of the assignment. * * @return the left-hand-side of the assignment */ public Node getTarget() { return lhs; } public Node getExpression() { return rhs; } @Override public Tree getTree() { return tree; } @Override public R accept(NodeVisitor visitor, P p) { return visitor.visitAssignment(this, p); } @Override public String toString() { return getTarget() + " = " + getExpression(); } @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof AssignmentNode)) { return false; } AssignmentNode other = (AssignmentNode) obj; return getTarget().equals(other.getTarget()) && getExpression().equals(other.getExpression()); } @Override public int hashCode() { return Objects.hash(getTarget(), getExpression()); } @Override public Collection getOperands() { return Arrays.asList(getTarget(), getExpression()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy