org.checkerframework.dataflow.busyexpr.BusyExprValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
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.
package org.checkerframework.dataflow.busyexpr;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.cfg.node.BinaryOperationNode;
/**
* BusyExprValue class contains a BinaryOperationNode. So we only consider expressions that are in
* form of BinaryOperationNode: lefOperandNode operator rightOperandNode.
* We override {@code .equals} in this class to compare nodes by value equality rather than
* reference equality. We want two different nodes with the same value (that is, two nodes refer to
* the same busy expression in the program) to be regarded as the same.
*/
public class BusyExprValue {
/**
* A busy expression is represented by a node, which can be a {@link
* org.checkerframework.dataflow.cfg.node.BinaryOperationNode}
*/
protected final BinaryOperationNode busyExpression;
/**
* Create a new busy expression.
*
* @param n a node
*/
public BusyExprValue(BinaryOperationNode n) {
this.busyExpression = n;
}
@Override
public String toString() {
return this.busyExpression.toString();
}
@Override
public int hashCode() {
return this.busyExpression.hashCode();
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof BusyExprValue)) {
return false;
}
BusyExprValue other = (BusyExprValue) obj;
// Use `equals` to check equality rather than using `==`.
return this.busyExpression.equals(other.busyExpression);
}
}