org.eclipse.xtext.common.types.util
Class TypeConformanceComputer

java.lang.Object
  extended by org.eclipse.xtext.common.types.util.TypeConformanceComputer
Direct Known Subclasses:
JvmOnlyTypeConformanceComputer, XbaseTypeConformanceComputer

public class TypeConformanceComputer
extends java.lang.Object

Author:
Sven Efftinge - Initial contribution and API, Sebastian Zarnekow

Nested Class Summary
protected static class TypeConformanceComputer.ArgumentResolver
           
protected static class TypeConformanceComputer.MaxDistanceRawTypeAcceptor
          Populates a Multiset with the maximum number of necessary steps from a given type to its super types.
 
Field Summary
protected  TypesFactory factory
           
protected  Primitives primitives
           
protected  SuperTypeCollector superTypeCollector
           
protected  TypeArgumentContextProvider typeArgumentContextProvider
           
protected  TypeReferences typeReferences
           
 
Constructor Summary
TypeConformanceComputer()
           
 
Method Summary
protected  java.lang.Boolean _isConformant(JvmArrayType leftType, JvmArrayType rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmArrayType leftType, JvmType rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmDeclaredType leftType, JvmArrayType rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmDeclaredType leftType, JvmDeclaredType rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmDeclaredType leftType, JvmPrimitiveType rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmDeclaredType leftType, JvmType rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmDeclaredType leftType, JvmTypeParameter rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmGenericArrayTypeReference left, JvmWildcardTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmMultiTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmParameterizedTypeReference left, JvmWildcardTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmPrimitiveType leftType, JvmPrimitiveType rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmPrimitiveType leftType, JvmType rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmType leftType, JvmArrayType rightType, JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmTypeParameter leftType, JvmType rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmTypeParameter leftType, JvmTypeParameter rightType, JvmParameterizedTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmTypeReference left, JvmMultiTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmWildcardTypeReference left, JvmGenericArrayTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmWildcardTypeReference left, JvmParameterizedTypeReference right, boolean ignoreGenerics)
           
protected  java.lang.Boolean _isConformant(JvmWildcardTypeReference left, JvmWildcardTypeReference right, boolean ignoreGenerics)
           
protected  boolean areArgumentsAssignableFrom(JvmParameterizedTypeReference left, JvmParameterizedTypeReference right)
           
protected  java.lang.Boolean areConstraintsConformant(java.util.List<JvmTypeConstraint> leftConstraints, java.util.List<JvmTypeConstraint> rightConstraints)
           
protected  boolean conformsToAll(JvmTypeReference type, java.util.List<JvmTypeReference> types)
           
protected  boolean containsPrimitive(java.util.List<JvmTypeReference> types)
           
protected  void cumulateDistance(java.util.List<JvmTypeReference> references, com.google.common.collect.Multimap<JvmType,JvmTypeReference> all, com.google.common.collect.Multiset<JvmType> cumulatedDistance)
          Keeps the cumulated distance for all the common raw super types of the given references.
protected  JvmType findContext(JvmTypeReference firstType)
           
 JvmTypeReference getCommonParameterSuperType(java.util.List<JvmTypeReference> types, java.util.List<JvmTypeReference> initiallyRequested)
           
 JvmTypeReference getCommonSuperType(java.util.List<JvmTypeReference> types)
          Compute the common super type for the given types.
protected  JvmTypeReference getFirstForRawType(com.google.common.collect.Multimap<JvmType,JvmTypeReference> all, JvmType rawType)
           
protected  JvmTypeReference getLower(JvmTypeReference argumentA)
           
protected  JvmTypeReference getTypeParametersForSupertype(com.google.common.collect.Multimap<JvmType,JvmTypeReference> all, JvmType rawType, java.util.List<JvmTypeReference> initiallyRequested)
           
protected  JvmTypeReference getUpper(JvmTypeReference argument)
           
protected  void initializeDistance(JvmTypeReference firstType, com.google.common.collect.Multimap<JvmType,JvmTypeReference> all, com.google.common.collect.Multiset<JvmType> cumulatedDistance)
           
protected  void inplaceSortByDistanceAndName(java.util.List<com.google.common.collect.Multiset.Entry<JvmType>> candidates)
           
protected  boolean is(JvmType typeA, java.lang.Class<?>... classes)
           
protected  boolean isAnyTypeReference(JvmTypeReference reference)
           
protected  boolean isArgumentAssignable(JvmTypeReference refA, JvmTypeReference refB)
           
protected  boolean isBoxing(JvmType typeA, JvmPrimitiveType typeB)
          see 5.1.7
 boolean isConformant(JvmTypeReference left, JvmTypeReference right)
           
 boolean isConformant(JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics)
           
protected  boolean isObject(JvmTypeReference reference)
           
protected  boolean isPrimitiveType(JvmTypeReference reference)
           
protected  boolean isPrimitiveVoid(JvmTypeReference reference)
           
protected  boolean isUnBoxing(JvmPrimitiveType typeA, JvmType typeB)
          see 5.1.8
protected  boolean isUnconstrainedWildcard(JvmTypeReference argumentA)
           
protected  boolean isUnresolvedType(JvmTypeReference reference)
           
protected  java.lang.Boolean isWideningConversion(JvmPrimitiveType leftType, JvmPrimitiveType rightType)
          See Java Language Specification {5.1.2} Widening Primitive Conversion
protected  Primitives.Primitive primitiveKind(JvmPrimitiveType primitiveType)
           
protected  java.util.List<JvmTypeReference> replacePrimitives(java.util.List<JvmTypeReference> types)
           
 void setFactory(TypesFactory factory)
           
 void setPrimitives(Primitives primitives)
           
 void setSuperTypeCollector(SuperTypeCollector superTypeCollector)
           
 void setTypeArgumentContextProvider(TypeArgumentContextProvider typeArgumentContextProvider)
           
 void setTypeReferences(TypeReferences typeReferences)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

superTypeCollector

@Inject
protected SuperTypeCollector superTypeCollector

factory

@Inject
protected TypesFactory factory

typeArgumentContextProvider

@Inject
protected TypeArgumentContextProvider typeArgumentContextProvider

primitives

@Inject
protected Primitives primitives

typeReferences

@Inject
protected TypeReferences typeReferences
Constructor Detail

TypeConformanceComputer

public TypeConformanceComputer()
Method Detail

setSuperTypeCollector

public void setSuperTypeCollector(SuperTypeCollector superTypeCollector)

setPrimitives

public void setPrimitives(Primitives primitives)

setFactory

public void setFactory(TypesFactory factory)

setTypeArgumentContextProvider

public void setTypeArgumentContextProvider(TypeArgumentContextProvider typeArgumentContextProvider)

setTypeReferences

public void setTypeReferences(TypeReferences typeReferences)

isConformant

public boolean isConformant(JvmTypeReference left,
                            JvmTypeReference right)

isConformant

public boolean isConformant(JvmTypeReference left,
                            JvmTypeReference right,
                            boolean ignoreGenerics)

isPrimitiveType

protected boolean isPrimitiveType(JvmTypeReference reference)

isAnyTypeReference

protected boolean isAnyTypeReference(JvmTypeReference reference)

isUnresolvedType

protected boolean isUnresolvedType(JvmTypeReference reference)

isPrimitiveVoid

protected boolean isPrimitiveVoid(JvmTypeReference reference)

isObject

protected boolean isObject(JvmTypeReference reference)

_isConformant

protected java.lang.Boolean _isConformant(JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmMultiTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmTypeReference left,
                                          JvmMultiTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmGenericArrayTypeReference left,
                                          JvmWildcardTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmWildcardTypeReference left,
                                          JvmGenericArrayTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmWildcardTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmParameterizedTypeReference left,
                                          JvmWildcardTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmWildcardTypeReference left,
                                          JvmWildcardTypeReference right,
                                          boolean ignoreGenerics)

areConstraintsConformant

protected java.lang.Boolean areConstraintsConformant(java.util.List<JvmTypeConstraint> leftConstraints,
                                                     java.util.List<JvmTypeConstraint> rightConstraints)

_isConformant

protected java.lang.Boolean _isConformant(JvmPrimitiveType leftType,
                                          JvmPrimitiveType rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

isWideningConversion

protected java.lang.Boolean isWideningConversion(JvmPrimitiveType leftType,
                                                 JvmPrimitiveType rightType)
See Java Language Specification {5.1.2} Widening Primitive Conversion


primitiveKind

protected Primitives.Primitive primitiveKind(JvmPrimitiveType primitiveType)

_isConformant

protected java.lang.Boolean _isConformant(JvmPrimitiveType leftType,
                                          JvmType rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmDeclaredType leftType,
                                          JvmPrimitiveType rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmDeclaredType leftType,
                                          JvmDeclaredType rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmDeclaredType leftType,
                                          JvmType rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmDeclaredType leftType,
                                          JvmTypeParameter rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmTypeParameter leftType,
                                          JvmTypeParameter rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmTypeParameter leftType,
                                          JvmType rightType,
                                          JvmParameterizedTypeReference left,
                                          JvmParameterizedTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmArrayType leftType,
                                          JvmArrayType rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmArrayType leftType,
                                          JvmType rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmType leftType,
                                          JvmArrayType rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

_isConformant

protected java.lang.Boolean _isConformant(JvmDeclaredType leftType,
                                          JvmArrayType rightType,
                                          JvmTypeReference left,
                                          JvmTypeReference right,
                                          boolean ignoreGenerics)

areArgumentsAssignableFrom

protected boolean areArgumentsAssignableFrom(JvmParameterizedTypeReference left,
                                             JvmParameterizedTypeReference right)

isArgumentAssignable

protected boolean isArgumentAssignable(JvmTypeReference refA,
                                       JvmTypeReference refB)

isUnconstrainedWildcard

protected boolean isUnconstrainedWildcard(JvmTypeReference argumentA)

getLower

protected JvmTypeReference getLower(JvmTypeReference argumentA)

getUpper

protected JvmTypeReference getUpper(JvmTypeReference argument)

isBoxing

protected boolean isBoxing(JvmType typeA,
                           JvmPrimitiveType typeB)
see 5.1.7


isUnBoxing

protected boolean isUnBoxing(JvmPrimitiveType typeA,
                             JvmType typeB)
see 5.1.8


is

protected boolean is(JvmType typeA,
                     java.lang.Class<?>... classes)

getCommonSuperType

public JvmTypeReference getCommonSuperType(java.util.List<JvmTypeReference> types)
Compute the common super type for the given types. May return null in case one of the types is primitive void but not all of them are.


findContext

protected JvmType findContext(JvmTypeReference firstType)

replacePrimitives

protected java.util.List<JvmTypeReference> replacePrimitives(java.util.List<JvmTypeReference> types)

containsPrimitive

protected boolean containsPrimitive(java.util.List<JvmTypeReference> types)

getTypeParametersForSupertype

protected JvmTypeReference getTypeParametersForSupertype(com.google.common.collect.Multimap<JvmType,JvmTypeReference> all,
                                                         JvmType rawType,
                                                         java.util.List<JvmTypeReference> initiallyRequested)

getFirstForRawType

protected JvmTypeReference getFirstForRawType(com.google.common.collect.Multimap<JvmType,JvmTypeReference> all,
                                              JvmType rawType)

initializeDistance

protected void initializeDistance(JvmTypeReference firstType,
                                  com.google.common.collect.Multimap<JvmType,JvmTypeReference> all,
                                  com.google.common.collect.Multiset<JvmType> cumulatedDistance)

cumulateDistance

protected void cumulateDistance(java.util.List<JvmTypeReference> references,
                                com.google.common.collect.Multimap<JvmType,JvmTypeReference> all,
                                com.google.common.collect.Multiset<JvmType> cumulatedDistance)
Keeps the cumulated distance for all the common raw super types of the given references. Interfaces that are more directly implemented will get a lower total count than more general interfaces.


inplaceSortByDistanceAndName

protected void inplaceSortByDistanceAndName(java.util.List<com.google.common.collect.Multiset.Entry<JvmType>> candidates)

getCommonParameterSuperType

public JvmTypeReference getCommonParameterSuperType(java.util.List<JvmTypeReference> types,
                                                    java.util.List<JvmTypeReference> initiallyRequested)

conformsToAll

protected boolean conformsToAll(JvmTypeReference type,
                                java.util.List<JvmTypeReference> types)