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.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classRepresents a conditional postcondition that must be verified byBaseTypeVisitoror one of its subclasses.static enumEnumerates the kinds of contracts.static classA postcondition contract.static classA precondition contract.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionfinal AnnotationMirrorThe annotation on the type of expression, according to this contract.final AnnotationMirrorThe annotation that expressed this contract; used for diagnostic messages.final StringThe expression for which the condition must hold, such as"foo"in@RequiresNonNull("foo").final Contract.KindThe kind of contract: precondition, postcondition, or conditional postcondition.
- 
Method SummaryModifier and TypeMethodDescriptionstatic Contractcreate(Contract.Kind kind, String expressionString, AnnotationMirror annotation, AnnotationMirror contractAnnotation, Boolean ensuresQualifierIf) Creates a new Contract.booleaninthashCode()toString()viewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, StringToJavaExpression stringToJavaExpr, @Nullable Tree errorTree) Viewpoint-adaptannotationusingstringToJavaExpr.
- 
Field Details- 
expressionStringThe 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.
- 
annotationThe annotation on the type of expression, according to this contract.
- 
contractAnnotationThe annotation that expressed this contract; used for diagnostic messages.
- 
kindThe kind of contract: precondition, postcondition, or conditional postcondition.
 
- 
- 
Method Details- 
createpublic static Contract create(Contract.Kind kind, String expressionString, AnnotationMirror annotation, AnnotationMirror contractAnnotation, Boolean ensuresQualifierIf) Creates a new Contract.- Parameters:
- kind- precondition, postcondition, or conditional postcondition
- expressionString- the Java expression that should have a type qualifier
- annotation- the type qualifier that- expressionStringshould have
- contractAnnotation- the pre- or post-condition annotation that the programmer wrote; used for diagnostic messages
- ensuresQualifierIf- the ensuresQualifierIf field, for a conditional postcondition
- Returns:
- a new contract
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
viewpointAdaptDependentTypeAnnotationpublic AnnotationMirror viewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, StringToJavaExpression stringToJavaExpr, @Nullable Tree errorTree) Viewpoint-adaptannotationusingstringToJavaExpr.For example, if the contract is @EnsuresKeyFor(value = "this.field", map = "map"),annotationis@KeyFor("map"). This method appliesstringToJavato "map" and returns a newKeyForannotation with the result.- Parameters:
- factory- used to get- DependentTypesHelper
- stringToJavaExpr- function used to convert strings to- JavaExpressions
- errorTree- 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 annotationif it is not a dependent type annotation
 
 
-