Class Contract
- java.lang.Object
 - 
- org.checkerframework.framework.util.Contract
 
 
- 
- Direct Known Subclasses:
 Contract.ConditionalPostcondition,Contract.Postcondition,Contract.Precondition
public abstract class Contract extends java.lang.ObjectA contract represents an annotation on an expression. It is a precondition, postcondition, or conditional postcondition. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContract.ConditionalPostconditionRepresents a conditional postcondition that must be verified byBaseTypeVisitoror one of its subclasses.static classContract.KindEnumerates the kinds of contracts.static classContract.PostconditionA postcondition contract.static classContract.PreconditionA precondition contract. 
- 
Field Summary
Fields Modifier and Type Field Description javax.lang.model.element.AnnotationMirrorannotationThe annotation on the type of expression, according to this contract.javax.lang.model.element.AnnotationMirrorcontractAnnotationThe annotation that expressed this contract; used for diagnostic messages.java.lang.StringexpressionStringThe expression for which the condition must hold, such as"foo"in@RequiresNonNull("foo").Contract.KindkindThe kind of contract: precondition, postcondition, or conditional postcondition. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Contractcreate(Contract.Kind kind, java.lang.String expressionString, javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.AnnotationMirror contractAnnotation, java.lang.Boolean ensuresQualifierIf)Creates a new Contract.booleanequals(@Nullable java.lang.Object o)inthashCode()java.lang.StringtoString()javax.lang.model.element.AnnotationMirrorviewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?,?,?,?> factory, StringToJavaExpression stringToJavaExpr, @Nullable com.sun.source.tree.Tree errorTree)Viewpoint-adaptannotationusingstringToJavaExpr. 
 - 
 
- 
- 
Field Detail
- 
expressionString
public final java.lang.String 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
public final javax.lang.model.element.AnnotationMirror annotation
The annotation on the type of expression, according to this contract. 
- 
contractAnnotation
public final javax.lang.model.element.AnnotationMirror contractAnnotation
The annotation that expressed this contract; used for diagnostic messages. 
- 
kind
public final Contract.Kind kind
The kind of contract: precondition, postcondition, or conditional postcondition. 
 - 
 
- 
Method Detail
- 
create
public static Contract create(Contract.Kind kind, java.lang.String expressionString, javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.AnnotationMirror contractAnnotation, java.lang.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 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
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
 
- 
viewpointAdaptDependentTypeAnnotation
public javax.lang.model.element.AnnotationMirror viewpointAdaptDependentTypeAnnotation(GenericAnnotatedTypeFactory<?,?,?,?> factory, StringToJavaExpression stringToJavaExpr, @Nullable com.sun.source.tree.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 
 
 - 
 
 -