Class PurityUtils
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDeterminismOfVoidCall(EnumSet<PurityKind> kinds, TypeMirror returnType) AddsPurityKind.DETERMINISTICtokindsifkindscontainsPurityKind.SIDE_EFFECT_FREEandreturnTypeis void; seesideEffectFreeImpliesDeterministic(javax.lang.model.type.TypeMirror).static EnumSet<PurityKind> getPurityKinds(AnnotationProvider provider, MethodTree methodTree) Returns the purity annotations on the methodmethodTree.static EnumSet<PurityKind> getPurityKinds(AnnotationProvider provider, ExecutableElement methodElement) Returns the purity annotations on the methodmethodElement.static booleanhasPurityAnnotation(AnnotationProvider provider, MethodTree methodTree) Does the methodmethodTreehave any purity annotation?static booleanhasPurityAnnotation(AnnotationProvider provider, ExecutableElement methodElement) Does the methodmethodElementhave any purity annotation?static booleanisDeterministic(AnnotationProvider provider, MethodTree methodTree) Is the methodmethodTreedeterministic?static booleanisDeterministic(AnnotationProvider provider, ExecutableElement methodElement) Is the methodmethodElementdeterministic?static booleanisPure(AnnotationProvider provider, JavaExpression expression) Returns true if the given expression is pure: evaluating it has no side effect, and, in an unchanged environment, every evaluation yields the same location or value.static booleanisSideEffectFree(AnnotationProvider provider, ExecutableElement methodElement) Is the methodmethodElementside-effect-free?static booleansideEffectFreeImpliesDeterministic(TypeMirror returnType) Returns true if a side-effect-free call that returnsreturnTypeis also deterministic.
-
Method Details
-
hasPurityAnnotation
Does the methodmethodTreehave any purity annotation?- Parameters:
provider- how to get annotationsmethodTree- a method to test- Returns:
- true if the method has any purity annotations
-
hasPurityAnnotation
public static boolean hasPurityAnnotation(AnnotationProvider provider, ExecutableElement methodElement) Does the methodmethodElementhave any purity annotation?- Parameters:
provider- how to get annotationsmethodElement- a method to test- Returns:
- true if the method has any purity annotations
-
isDeterministic
Is the methodmethodTreedeterministic?- Parameters:
provider- how to get annotationsmethodTree- a method to test- Returns:
- true if the method is deterministic
-
isDeterministic
Is the methodmethodElementdeterministic?- Parameters:
provider- how to get annotationsmethodElement- a method to test- Returns:
- true if the method is deterministic
-
isSideEffectFree
public static boolean isSideEffectFree(AnnotationProvider provider, ExecutableElement methodElement) Is the methodmethodElementside-effect-free?This method does not use, and has different semantics than,
AnnotationProvider.isSideEffectFree(javax.lang.model.element.ExecutableElement). This method is concerned only with standard purity annotations.- Parameters:
provider- how to get annotationsmethodElement- a method to test- Returns:
- true if the method is side-effect-free
-
getPurityKinds
public static EnumSet<PurityKind> getPurityKinds(AnnotationProvider provider, MethodTree methodTree) Returns the purity annotations on the methodmethodTree.- Parameters:
provider- how to get annotations. ItsAnnotationProvider.isSideEffectFree(javax.lang.model.element.ExecutableElement)andAnnotationProvider.isDeterministic(javax.lang.model.element.ExecutableElement)methods are not used.methodTree- a method to test- Returns:
- the types of purity of the method
methodTree; a new set, which the caller may modify
-
getPurityKinds
public static EnumSet<PurityKind> getPurityKinds(AnnotationProvider provider, ExecutableElement methodElement) Returns the purity annotations on the methodmethodElement.@Pureis treated as an alias for@SideEffectFreeand@Deterministic.- Parameters:
provider- how to get annotations. ItsAnnotationProvider.isSideEffectFree(javax.lang.model.element.ExecutableElement)andAnnotationProvider.isDeterministic(javax.lang.model.element.ExecutableElement)methods are not used.methodElement- a method to test- Returns:
- the types of purity of the method
methodElement; a new set, which the caller may modify
-
sideEffectFreeImpliesDeterministic
Returns true if a side-effect-free call that returnsreturnTypeis also deterministic. That holds whenreturnTypeis void: two calls of a side-effect-free method that returns no value return the same (absent) value.- Parameters:
returnType- the type of the value that a call returns- Returns:
- true if a side-effect-free call that returns
returnTypeis deterministic
-
addDeterminismOfVoidCall
AddsPurityKind.DETERMINISTICtokindsifkindscontainsPurityKind.SIDE_EFFECT_FREEandreturnTypeis void; seesideEffectFreeImpliesDeterministic(javax.lang.model.type.TypeMirror).getPurityKinds(org.checkerframework.javacutil.AnnotationProvider, com.sun.source.tree.MethodTree)andisDeterministic(org.checkerframework.javacutil.AnnotationProvider, com.sun.source.tree.MethodTree)do not apply this rule, for two reasons. First, a constructor's return type is void, but anewexpression is not deterministic. Second, a caller may combine purity from several sources, such as the command-line assumptions, and this rule must be applied after all of them.- Parameters:
kinds- the purity of a call; modified by this methodreturnType- the type of the value that the call returns
-
isPure
Returns true if the given expression is pure: evaluating it has no side effect, and, in an unchanged environment, every evaluation yields the same location or value.In one way, this method is more conservative than
isDeterministic: it returns false for an expression such asa + b, which is pure but denotes no location that a method could modify.- Parameters:
provider- how to get annotationsexpression- an expression- Returns:
- true if the given expression is pure
-