Class OffsetEquation
- java.lang.Object
-
- org.checkerframework.checker.index.upperbound.OffsetEquation
-
public class OffsetEquation extends java.lang.ObjectAn offset equation is 2 sets of Java expression strings, one set of added terms and one set of subtracted terms, and a single integer constant. The Java expression strings have been standardized and viewpoint-adapted.An OffsetEquation is mutable.
-
-
Field Summary
Fields Modifier and Type Field Description static OffsetEquationNEG_1The equation for -1.static OffsetEquationONEThe equation for 1.static OffsetEquationZEROThe equation for 0 (zero).
-
Constructor Summary
Constructors Modifier Constructor Description protectedOffsetEquation(OffsetEquation other)Create a new OffsetEquation that is a copy of the given one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OffsetEquationcopyAdd(char op, OffsetEquation other)Adds or subtracts the other equation to a copy of this one.static OffsetEquationcreateOffsetForInt(int value)Creates an offset equation that is only the int value specified.static OffsetEquationcreateOffsetFromJavaExpression(java.lang.String expressionEquation)Creates an offset equation from the expressionEquation.static OffsetEquationcreateOffsetFromNode(Node node, AnnotationProvider factory, char op)Creates an offset equation from the Node.static @Nullable OffsetEquationcreateOffsetFromNodesValue(Node node, ValueAnnotatedTypeFactory factory, char op)If node is an int value known at compile time, then the returned equation is just the int value or if op is '-', the return equation is the negation of the int value.booleanequals(@Nullable java.lang.Object o)@Nullable java.lang.StringgetError()intgetInt()Returns the int value associated with this equation.static @Nullable OffsetEquationgetIntOffsetEquation(java.util.Set<OffsetEquation> equationSet)Returns the offset equation that is an int value or null if there isn't one.booleanhasError()inthashCode()booleanisInt()Returns true if this equation is a single int value.booleanisNegativeOrZero()Returns true if this equation is negative or zero.booleanisNegOne()Returns true if this equation is exactly -1.booleanisNonNegative()Returns true if this equation non-negative.booleanlessThanOrEqual(OffsetEquation other)Returns whether or not this equation is known to be less than or equal to the other equation.@Nullable OffsetEquationremoveSequenceLengths(java.util.List<java.lang.String> sequences)Makes a copy of this offset and removes any added terms that are accesses to the length of the listed sequences.java.lang.StringtoString()
-
-
-
Field Detail
-
ZERO
public static final OffsetEquation ZERO
The equation for 0 (zero).
-
NEG_1
public static final OffsetEquation NEG_1
The equation for -1.
-
ONE
public static final OffsetEquation ONE
The equation for 1.
-
-
Constructor Detail
-
OffsetEquation
protected OffsetEquation(OffsetEquation other)
Create a new OffsetEquation that is a copy of the given one.- Parameters:
other- the OffsetEquation to copy
-
-
Method Detail
-
hasError
public boolean hasError()
-
getError
public @Nullable java.lang.String getError()
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
removeSequenceLengths
public @Nullable OffsetEquation removeSequenceLengths(java.util.List<java.lang.String> sequences)
Makes a copy of this offset and removes any added terms that are accesses to the length of the listed sequences. If any terms were removed, then the copy is returned. Otherwise, null is returned.- Parameters:
sequences- list of sequences (arrays or strings)- Returns:
- a copy of this equation with array.length and string.length() removed or null if no array.lengths or string.length() could be removed
-
copyAdd
public OffsetEquation copyAdd(char op, OffsetEquation other)
Adds or subtracts the other equation to a copy of this one.If subtraction is specified, then every term in other is subtracted.
- Parameters:
op- '-' for subtraction or '+' for additionother- equation to add or subtract- Returns:
- a copy of this equation +/- other
-
lessThanOrEqual
public boolean lessThanOrEqual(OffsetEquation other)
Returns whether or not this equation is known to be less than or equal to the other equation.- Parameters:
other- equation- Returns:
- whether or not this equation is known to be less than or equal to the other equation
-
isInt
public boolean isInt()
Returns true if this equation is a single int value.- Returns:
- true if this equation is a single int value
-
getInt
public int getInt()
Returns the int value associated with this equation.The equation may or may not have other terms. Use
isInt()to determine if the equation is only this int value.- Returns:
- the int value associated with this equation
-
isNegOne
public boolean isNegOne()
Returns true if this equation is exactly -1.- Returns:
- true if this equation is exactly -1
-
isNonNegative
public boolean isNonNegative()
Returns true if this equation non-negative.- Returns:
- true if this equation non-negative
-
isNegativeOrZero
public boolean isNegativeOrZero()
Returns true if this equation is negative or zero.- Returns:
- true if this equation is negative or zero
-
getIntOffsetEquation
public static @Nullable OffsetEquation getIntOffsetEquation(java.util.Set<OffsetEquation> equationSet)
Returns the offset equation that is an int value or null if there isn't one.- Parameters:
equationSet- a set of offset equations- Returns:
- the offset equation that is an int value or null if there isn't one
-
createOffsetForInt
public static OffsetEquation createOffsetForInt(int value)
Creates an offset equation that is only the int value specified.- Parameters:
value- int value of the equation- Returns:
- an offset equation that is only the int value specified
-
createOffsetFromJavaExpression
public static OffsetEquation createOffsetFromJavaExpression(java.lang.String expressionEquation)
Creates an offset equation from the expressionEquation. The expressionEquation may be several Java expressions added or subtracted from each other. The expressionEquation may also start with + or -. If the expressionEquation is the empty string, then the offset equation returned is zero.- Parameters:
expressionEquation- a Java expression made up of sums and differences- Returns:
- an offset equation created from expressionEquation
-
createOffsetFromNodesValue
public static @Nullable OffsetEquation createOffsetFromNodesValue(Node node, ValueAnnotatedTypeFactory factory, char op)
If node is an int value known at compile time, then the returned equation is just the int value or if op is '-', the return equation is the negation of the int value.Otherwise, null is returned.
- Parameters:
node- the Node from which to create an offset equationfactory- an AnnotationTypeFactoryop- '+' or '-'- Returns:
- an offset equation from value of known or null if the value isn't known
-
createOffsetFromNode
public static OffsetEquation createOffsetFromNode(Node node, AnnotationProvider factory, char op)
Creates an offset equation from the Node.If node is an addition or subtracted node, then this method is called recursively on the left and right hand nodes and the two equations are added/subtracted to each other depending on the value of op.
Otherwise the return equation is created by converting the node to a
JavaExpressionand then added as a term to the returned equation. If op is '-' then it is a subtracted term.- Parameters:
node- the Node from which to create an offset equationfactory- an AnnotationTypeFactoryop- '+' or '-'- Returns:
- an offset equation from the Node
-
-