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 Summary
Nested 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 Summary
FieldsModifier and TypeFieldDescriptionfinal AnnotationMirrorThe annotation on the type of expression, according to this contract.final AnnotationMirrorThe annotation that expressed this contract; used for diagnostic messages, but not for the location of the diagnostic message.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 Summary
Modifier and TypeMethodDescriptionstatic Contractcreate(Contract.Kind kind, String expressionString, AnnotationMirror annotation, AnnotationMirror contractAnnotation, Boolean ensuresQualifierIf) Creates a newContract.booleaninthashCode()toString()viewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?, ?, ?, ?> factory, StringToJavaExpression stringToJavaExpr, @Nullable Tree errorTree) Viewpoint-adaptannotationusingstringToJavaExpr. 
- 
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, but not for the location of the diagnostic message. - 
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 newContract.- Parameters:
 kind- precondition, postcondition, or conditional postconditionexpressionString- the Java expression that should have a type qualifierannotation- the type qualifier thatexpressionStringshould 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-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 getDependentTypesHelperstringToJavaExpr- function used to convert strings toJavaExpressionserrorTree- 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 
 
 -