Class Contract
java.lang.Object
org.checkerframework.framework.util.Contract
- Direct Known Subclasses:
Contract.ConditionalPostcondition
,Contract.Postcondition
,Contract.Precondition
A contract represents an annotation on an expression. It is a precondition, postcondition, or
conditional postcondition.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents a conditional postcondition that must be verified byBaseTypeVisitor
or one of its subclasses.static enum
Enumerates the kinds of contracts.static class
A postcondition contract.static class
A precondition contract. -
Field Summary
Modifier and TypeFieldDescriptionfinal AnnotationMirror
The annotation on the type of expression, according to this contract.final AnnotationMirror
The annotation that expressed this contract; used for diagnostic messages.final String
The expression for which the condition must hold, such as"foo"
in@RequiresNonNull("foo")
.final Contract.Kind
The kind of contract: precondition, postcondition, or conditional postcondition. -
Method Summary
Modifier and TypeMethodDescriptionstatic Contract
create
(Contract.Kind kind, String expressionString, AnnotationMirror annotation, AnnotationMirror contractAnnotation, Boolean ensuresQualifierIf) Creates a new Contract.boolean
int
hashCode()
toString()
viewpointAdaptDependentTypeAnnotation
(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, StringToJavaExpression stringToJavaExpr, @Nullable Tree errorTree) Viewpoint-adaptannotation
usingstringToJavaExpr
.
-
Field Details
-
expressionString
The expression for which the condition must hold, such as"foo"
in@RequiresNonNull("foo")
.An annotation like
@RequiresNonNull({"a", "b", "c"})
would be represented by multiple Contracts. -
annotation
The annotation on the type of expression, according to this contract. -
contractAnnotation
The annotation that expressed this contract; used for diagnostic messages. -
kind
The kind of contract: precondition, postcondition, or conditional postcondition.
-
-
Method Details
-
create
public static Contract create(Contract.Kind kind, String expressionString, AnnotationMirror annotation, AnnotationMirror contractAnnotation, Boolean ensuresQualifierIf) Creates a new Contract.- Parameters:
kind
- precondition, postcondition, or conditional postconditionexpressionString
- the Java expression that should have a type qualifierannotation
- the type qualifier thatexpressionString
should havecontractAnnotation
- the pre- or post-condition annotation that the programmer wrote; used for diagnostic messagesensuresQualifierIf
- the ensuresQualifierIf field, for a conditional postcondition- Returns:
- a new contract
-
equals
-
hashCode
public int hashCode() -
toString
-
viewpointAdaptDependentTypeAnnotation
public AnnotationMirror viewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, StringToJavaExpression stringToJavaExpr, @Nullable Tree errorTree) Viewpoint-adaptannotation
usingstringToJavaExpr
.For example, if the contract is
@EnsuresKeyFor(value = "this.field", map = "map")
,annotation
is@KeyFor("map")
. This method appliesstringToJava
to "map" and returns a newKeyFor
annotation with the result.- Parameters:
factory
- used to getDependentTypesHelper
stringToJavaExpr
- function used to convert strings toJavaExpression
serrorTree
- if non-null, where to report any errors that occur when parsing the dependent type annotation; if null, report no errors- Returns:
- the viewpoint-adapted annotation, or
annotation
if it is not a dependent type annotation
-