Class StructuralEqualityComparer
- java.lang.Object
-
- org.checkerframework.framework.type.visitor.AbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
- org.checkerframework.framework.type.StructuralEqualityComparer
-
- All Implemented Interfaces:
AtmComboVisitor<java.lang.Boolean,java.lang.Void>
public class StructuralEqualityComparer extends AbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
A visitor used to compare two type mirrors for "structural" equality. Structural equality implies that, for two objects, all fields are also structurally equal and for primitives their values are equal.See also DefaultTypeHierarchy, and SubtypeVisitHistory
-
-
Field Summary
Fields Modifier and Type Field Description protected StructuralEqualityVisitHistory
visitHistory
History saving the result of previous comparisons.
-
Constructor Summary
Constructors Constructor Description StructuralEqualityComparer(StructuralEqualityVisitHistory typeargVisitHistory)
Create a StructuralEqualityComparer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
areAllEqual(java.util.Collection<? extends AnnotatedTypeMirror> types1, java.util.Collection<? extends AnnotatedTypeMirror> types2)
Compare each type in types1 and types2 pairwise and return true if they are all equal.boolean
areEqualInHierarchy(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, javax.lang.model.element.AnnotationMirror top)
protected boolean
arePrimeAnnosEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
Return true if type1 and type2 have the same set of annotations.protected boolean
checkOrAreEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
First check visitHistory to see if type1 and type2 have been compared once already.java.lang.Boolean
defaultAction(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, java.lang.Void p)
Called by the default implementation of every AbstractAtmComboVisitor visit method.java.lang.String
defaultErrorMessage(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, java.lang.Void p)
Called for every combination that isn't specifically handled.java.lang.Boolean
visitArray_Array(AnnotatedTypeMirror.AnnotatedArrayType type1, AnnotatedTypeMirror.AnnotatedArrayType type2, java.lang.Void p)
Two arrays are equal if: Their sets of primary annotations are equal, and Their component types are equaljava.lang.Boolean
visitDeclared_Declared(AnnotatedTypeMirror.AnnotatedDeclaredType type1, AnnotatedTypeMirror.AnnotatedDeclaredType type2, java.lang.Void p)
Two declared types are equal if: The types are of the same class/interfaces Their sets of primary annotations are equal Their sets of type arguments are equal or one type is rawjava.lang.Boolean
visitDeclared_Primitive(AnnotatedTypeMirror.AnnotatedDeclaredType type1, AnnotatedTypeMirror.AnnotatedPrimitiveType type2, java.lang.Void p)
java.lang.Boolean
visitIntersection_Intersection(AnnotatedTypeMirror.AnnotatedIntersectionType type1, AnnotatedTypeMirror.AnnotatedIntersectionType type2, java.lang.Void p)
Two intersection types are equal if: Their sets of primary annotations are equal Their sets of bounds (the types being intersected) are equaljava.lang.Boolean
visitPrimitive_Declared(AnnotatedTypeMirror.AnnotatedPrimitiveType type1, AnnotatedTypeMirror.AnnotatedDeclaredType type2, java.lang.Void p)
java.lang.Boolean
visitPrimitive_Primitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type1, AnnotatedTypeMirror.AnnotatedPrimitiveType type2, java.lang.Void p)
Two primitive types are equal if: Their sets of primary annotations are equaljava.lang.Boolean
visitTypevar_Typevar(AnnotatedTypeMirror.AnnotatedTypeVariable type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2, java.lang.Void p)
Two type variables are equal if: Their bounds are equal Note: Primary annotations will be taken into account when the bounds are retrievedjava.lang.Boolean
visitWildcard_Typevar(AnnotatedTypeMirror.AnnotatedWildcardType type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2, java.lang.Void p)
java.lang.Boolean
visitWildcard_Wildcard(AnnotatedTypeMirror.AnnotatedWildcardType type1, AnnotatedTypeMirror.AnnotatedWildcardType type2, java.lang.Void p)
Two wildcards are equal if: Their bounds are equal Note: Primary annotations will be taken into account when the bounds are retrieved-
Methods inherited from class org.checkerframework.framework.type.visitor.AbstractAtmComboVisitor
visit, visitArray_Declared, visitArray_Executable, visitArray_Intersection, visitArray_None, visitArray_Null, visitArray_Primitive, visitArray_Typevar, visitArray_Union, visitArray_Wildcard, visitDeclared_Array, visitDeclared_Executable, visitDeclared_Intersection, visitDeclared_None, visitDeclared_Null, visitDeclared_Typevar, visitDeclared_Union, visitDeclared_Wildcard, visitExecutable_Array, visitExecutable_Declared, visitExecutable_Executable, visitExecutable_Intersection, visitExecutable_None, visitExecutable_Null, visitExecutable_Primitive, visitExecutable_Typevar, visitExecutable_Union, visitExecutable_Wildcard, visitIntersection_Array, visitIntersection_Declared, visitIntersection_Executable, visitIntersection_None, visitIntersection_Null, visitIntersection_Primitive, visitIntersection_Typevar, visitIntersection_Union, visitIntersection_Wildcard, visitNone_Array, visitNone_Declared, visitNone_Executable, visitNone_Intersection, visitNone_None, visitNone_Null, visitNone_Primitive, visitNone_Union, visitNone_Wildcard, visitNull_Array, visitNull_Declared, visitNull_Executable, visitNull_Intersection, visitNull_None, visitNull_Null, visitNull_Primitive, visitNull_Typevar, visitNull_Union, visitNull_Wildcard, visitPrimitive_Array, visitPrimitive_Executable, visitPrimitive_Intersection, visitPrimitive_None, visitPrimitive_Null, visitPrimitive_Typevar, visitPrimitive_Union, visitPrimitive_Wildcard, visitTypevar_Array, visitTypevar_Declared, visitTypevar_Executable, visitTypevar_Intersection, visitTypevar_None, visitTypevar_Null, visitTypevar_Primitive, visitTypevar_Union, visitTypevar_Wildcard, visitUnion_Array, visitUnion_Declared, visitUnion_Executable, visitUnion_Intersection, visitUnion_None, visitUnion_Null, visitUnion_Primitive, visitUnion_Typevar, visitUnion_Union, visitUnion_Wildcard, visitWildcard_Array, visitWildcard_Declared, visitWildcard_Executable, visitWildcard_Intersection, visitWildcard_None, visitWildcard_Null, visitWildcard_Primitive, visitWildcard_Union
-
-
-
-
Field Detail
-
visitHistory
protected final StructuralEqualityVisitHistory visitHistory
History saving the result of previous comparisons.
-
-
Constructor Detail
-
StructuralEqualityComparer
public StructuralEqualityComparer(StructuralEqualityVisitHistory typeargVisitHistory)
Create a StructuralEqualityComparer.- Parameters:
typeargVisitHistory
- history saving the result of previous comparisons
-
-
Method Detail
-
defaultAction
public java.lang.Boolean defaultAction(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, java.lang.Void p)
Description copied from interface:AtmComboVisitor
Called by the default implementation of every AbstractAtmComboVisitor visit method. This methodnS issues a runtime exception by default. In general, it should handle the case where a visit method has been called with a pair of type mirrors that should never be passed to this particular visitor.- Parameters:
type1
- the first AnnotatedTypeMirror parameter to the visit method calledtype2
- the second AnnotatedTypeMirror parameter to the visit method calledp
- subtype specific parameter passed to every visit method- Returns:
- a value of type RETURN_TYPE, if no exception is thrown
-
defaultErrorMessage
public java.lang.String defaultErrorMessage(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, java.lang.Void p)
Called for every combination that isn't specifically handled.- Parameters:
type1
- the first AnnotatedTypeMirror parameter to the visit method calledtype2
- the second AnnotatedTypeMirror parameter to the visit method calledp
- subtype specific parameter passed to every visit method- Returns:
- error message explaining the two types' classes are not the same
-
areEqualInHierarchy
public boolean areEqualInHierarchy(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, javax.lang.model.element.AnnotationMirror top)
-
arePrimeAnnosEqual
protected boolean arePrimeAnnosEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
Return true if type1 and type2 have the same set of annotations.- Parameters:
type1
- a typetype2
- a type- Returns:
- true if type1 and type2 have the same set of annotations
-
areAllEqual
protected boolean areAllEqual(java.util.Collection<? extends AnnotatedTypeMirror> types1, java.util.Collection<? extends AnnotatedTypeMirror> types2)
Compare each type in types1 and types2 pairwise and return true if they are all equal. This method throws an exceptions if types1.size() != types2.size()- Returns:
- true if for each pair (t1 = types1.get(i); t2 = types2.get(i)), areEqual(t1,t2)
-
checkOrAreEqual
protected boolean checkOrAreEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
First check visitHistory to see if type1 and type2 have been compared once already. If so return true; otherwise compare them and put them in visitHistory.- Parameters:
type1
- the first typetype2
- the second type- Returns:
- whether the two types are equal
-
visitArray_Array
public java.lang.Boolean visitArray_Array(AnnotatedTypeMirror.AnnotatedArrayType type1, AnnotatedTypeMirror.AnnotatedArrayType type2, java.lang.Void p)
Two arrays are equal if:- Their sets of primary annotations are equal, and
- Their component types are equal
- Specified by:
visitArray_Array
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitArray_Array
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitDeclared_Declared
public java.lang.Boolean visitDeclared_Declared(AnnotatedTypeMirror.AnnotatedDeclaredType type1, AnnotatedTypeMirror.AnnotatedDeclaredType type2, java.lang.Void p)
Two declared types are equal if:- The types are of the same class/interfaces
- Their sets of primary annotations are equal
- Their sets of type arguments are equal or one type is raw
- Specified by:
visitDeclared_Declared
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitDeclared_Declared
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitIntersection_Intersection
public java.lang.Boolean visitIntersection_Intersection(AnnotatedTypeMirror.AnnotatedIntersectionType type1, AnnotatedTypeMirror.AnnotatedIntersectionType type2, java.lang.Void p)
Two intersection types are equal if:- Their sets of primary annotations are equal
- Their sets of bounds (the types being intersected) are equal
- Specified by:
visitIntersection_Intersection
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitIntersection_Intersection
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitPrimitive_Primitive
public java.lang.Boolean visitPrimitive_Primitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type1, AnnotatedTypeMirror.AnnotatedPrimitiveType type2, java.lang.Void p)
Two primitive types are equal if:- Their sets of primary annotations are equal
- Specified by:
visitPrimitive_Primitive
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitPrimitive_Primitive
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitTypevar_Typevar
public java.lang.Boolean visitTypevar_Typevar(AnnotatedTypeMirror.AnnotatedTypeVariable type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2, java.lang.Void p)
Two type variables are equal if:- Their bounds are equal
- Specified by:
visitTypevar_Typevar
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitTypevar_Typevar
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitWildcard_Wildcard
public java.lang.Boolean visitWildcard_Wildcard(AnnotatedTypeMirror.AnnotatedWildcardType type1, AnnotatedTypeMirror.AnnotatedWildcardType type2, java.lang.Void p)
Two wildcards are equal if:- Their bounds are equal
- Specified by:
visitWildcard_Wildcard
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitWildcard_Wildcard
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitWildcard_Typevar
public java.lang.Boolean visitWildcard_Typevar(AnnotatedTypeMirror.AnnotatedWildcardType type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2, java.lang.Void p)
- Specified by:
visitWildcard_Typevar
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitWildcard_Typevar
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitDeclared_Primitive
public java.lang.Boolean visitDeclared_Primitive(AnnotatedTypeMirror.AnnotatedDeclaredType type1, AnnotatedTypeMirror.AnnotatedPrimitiveType type2, java.lang.Void p)
- Specified by:
visitDeclared_Primitive
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitDeclared_Primitive
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
visitPrimitive_Declared
public java.lang.Boolean visitPrimitive_Declared(AnnotatedTypeMirror.AnnotatedPrimitiveType type1, AnnotatedTypeMirror.AnnotatedDeclaredType type2, java.lang.Void p)
- Specified by:
visitPrimitive_Declared
in interfaceAtmComboVisitor<java.lang.Boolean,java.lang.Void>
- Overrides:
visitPrimitive_Declared
in classAbstractAtmComboVisitor<java.lang.Boolean,java.lang.Void>
-
-