Top Description Inners Constructors Methods
com.google.auto.common

pack-priv abstract Class Overrides

extends Object
Class Inheritance
Known Direct Subclasses
com.google.auto.common.Overrides.NativeOverrides, com.google.auto.common.Overrides.ExplicitOverrides
Static Imports
java.util.stream.Collectors.toList

Determines if one method overrides another. This class defines two ways of doing that: NativeOverrides uses the method Elements#overrides(ExecutableElement, ExecutableElement, TypeElement) while ExplicitOverrides reimplements that method in a way that is more consistent between compilers, in particular between javac and ecj (the Eclipse compiler).
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Overridesback to summary
pack-priv Overrides()

Method Detail

overridesback to summary
pack-priv abstract boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement in)
com.google.auto.common back to summary

pack-priv Class Overrides.ExplicitOverrides

extends Overrides
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
Overrides.ExplicitOverrides.TypeSubstVisitor

Visitor that replaces type variables with their values in the types it sees.

Field Summary

Modifier and TypeField and Description
private final Types

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private TypeElement
pack-priv @Nullable ImmutableList<TypeMirror>
erasedParameterTypes(ExecutableElement method, TypeElement in)

Returns the list of erased parameter types of the given method as they appear in the given type.

private boolean
pack-priv @Nullable ExecutableElement
methodFromSuperclasses(TypeElement in, ExecutableElement method)

Returns the given method as it appears in the given type.

pack-priv @Nullable ExecutableElement
methodFromSuperinterfaces(TypeElement in, ExecutableElement method)

Returns the given interface method as it appears in the given type.

private @Nullable ExecutableElement
methodInType(TypeElement type, ExecutableElement method)

Returns the method from within the given type that has the same erased signature as the given method, or null if there is no such method.

public boolean
private @Nullable TypeElement
private ImmutableList<TypeElement>

Field Detail

typeUtilsback to summary
private final Types typeUtils

Constructor Detail

ExplicitOverridesback to summary
pack-priv ExplicitOverrides(Types typeUtils)

Method Detail

asTypeElementback to summary
private TypeElement asTypeElement(TypeMirror typeMirror)
erasedParameterTypesback to summary
pack-priv @Nullable ImmutableList<TypeMirror> erasedParameterTypes(ExecutableElement method, TypeElement in)

Returns the list of erased parameter types of the given method as they appear in the given type. For example, if the method is add(E) from List<E> and we ask how it appears in class NumberList implements List<Number>, the answer will be Number. That will also be the answer for class NumberList<E extends Number> implements List<E>. The parameter types are erased since the purpose of this method is to determine whether two methods are candidates for one to override the other.

isSubsignatureback to summary
private boolean isSubsignature(ExecutableElement overrider, ExecutableElement overridden, TypeElement in)
methodFromSuperclassesback to summary
pack-priv @Nullable ExecutableElement methodFromSuperclasses(TypeElement in, ExecutableElement method)

Returns the given method as it appears in the given type. This is the method itself, or the nearest override in a superclass of the given type, or null if the method is not found in the given type or any of its superclasses.

methodFromSuperinterfacesback to summary
pack-priv @Nullable ExecutableElement methodFromSuperinterfaces(TypeElement in, ExecutableElement method)

Returns the given interface method as it appears in the given type. This is the method itself, or the nearest override in a superinterface of the given type, or null if the method is not found in the given type or any of its transitive superinterfaces.

methodInTypeback to summary
private @Nullable ExecutableElement methodInType(TypeElement type, ExecutableElement method)

Returns the method from within the given type that has the same erased signature as the given method, or null if there is no such method.

overridesback to summary
public boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement in)

Implements abstract com.google.auto.common.Overrides.overrides.

Annotations
@Override
superclassback to summary
private @Nullable TypeElement superclass(TypeElement type)
superinterfacesback to summary
private ImmutableList<TypeElement> superinterfaces(TypeElement type)
com.google.auto.common back to summary

private Class Overrides.ExplicitOverrides.TypeSubstVisitor

extends SimpleTypeVisitor8<TypeMirror, Void>
Class Inheritance

Visitor that replaces type variables with their values in the types it sees. If we know that E is String, then we can return String for E, List<String> for List<E>, String[] for E[], etc. We don't have to cover all types here because (1) the type is going to end up being erased, and (2) wildcards can't appear in direct supertypes. So for example it is illegal to write class MyList implements List<? extends Number>. It's legal to write class MyList implements List<Set<? extends Number>> but that doesn't matter because the E of the List is going to be erased to raw Set.

Field Summary

Modifier and TypeField and Description
private final Map<TypeParameterElement, TypeMirror>
typeBindings

The bindings of type variables.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected TypeMirror
defaultAction(TypeMirror
the type to process
e
,
Void
a visitor-specified parameter
p
)

Overrides javax.lang.model.util.SimpleTypeVisitor6.defaultAction.

The default action for visit methods.
pack-priv @Nullable ImmutableList<TypeMirror>
public TypeMirror
visitArray(ArrayType
the type to visit
t
,
Void
a visitor-specified parameter
p
)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitArray.

Implements javax.lang.model.type.TypeVisitor.visitArray.

Visits an array type.
public TypeMirror
visitDeclared(DeclaredType
the type to visit
t
,
Void
a visitor-specified parameter
p
)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitDeclared.

Implements javax.lang.model.type.TypeVisitor.visitDeclared.

Visits a declared type.
public TypeMirror
visitTypeVariable(TypeVariable
the type to visit
t
,
Void
a visitor-specified parameter
p
)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitTypeVariable.

Implements javax.lang.model.type.TypeVisitor.visitTypeVariable.

Visits a type variable.
Inherited from javax.lang.model.util.SimpleTypeVisitor8:
visitIntersection

Field Detail

typeBindingsback to summary
private final Map<TypeParameterElement, TypeMirror> typeBindings

The bindings of type variables. We can put them all in one map because E in List<E> is not the same as E in Collection<E>. As we ascend the type hierarchy we'll add mappings for all the variables we see. We could equivalently create a new map for each type we visit, but this is slightly simpler and probably about as performant.

Constructor Detail

TypeSubstVisitorback to summary
private TypeSubstVisitor()

Method Detail

defaultActionback to summary
protected TypeMirror defaultAction(TypeMirror e, Void p)

Overrides javax.lang.model.util.SimpleTypeVisitor6.defaultAction.

Doc from javax.lang.model.util.SimpleTypeVisitor6.defaultAction.

The default action for visit methods.

Parameters
e:TypeMirror

the type to process

p:Void

a visitor-specified parameter

Returns:TypeMirror

DEFAULT_VALUE unless overridden

Annotations
@Override
erasedParameterTypesback to summary
pack-priv @Nullable ImmutableList<TypeMirror> erasedParameterTypes(ExecutableElement method, TypeElement in)
visitArrayback to summary
public TypeMirror visitArray(ArrayType t, Void p)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitArray.

Implements javax.lang.model.type.TypeVisitor.visitArray.

Doc from javax.lang.model.util.SimpleTypeVisitor6.visitArray.

Visits an array type.

Parameters
t:ArrayType

the type to visit

p:Void

a visitor-specified parameter

Returns:TypeMirror

the result of defaultAction

Annotations
@Override
visitDeclaredback to summary
public TypeMirror visitDeclared(DeclaredType t, Void p)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitDeclared.

Implements javax.lang.model.type.TypeVisitor.visitDeclared.

Doc from javax.lang.model.util.SimpleTypeVisitor6.visitDeclared.

Visits a declared type.

Parameters
t:DeclaredType

the type to visit

p:Void

a visitor-specified parameter

Returns:TypeMirror

the result of defaultAction

Annotations
@Override
visitTypeVariableback to summary
public TypeMirror visitTypeVariable(TypeVariable t, Void p)

Overrides javax.lang.model.util.SimpleTypeVisitor6.visitTypeVariable.

Implements javax.lang.model.type.TypeVisitor.visitTypeVariable.

Doc from javax.lang.model.util.SimpleTypeVisitor6.visitTypeVariable.

Visits a type variable.

Parameters
t:TypeVariable

the type to visit

p:Void

a visitor-specified parameter

Returns:TypeMirror

the result of defaultAction

Annotations
@Override
com.google.auto.common back to summary

pack-priv Class Overrides.NativeOverrides

extends Overrides
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Elements

Constructor Summary

AccessConstructor and Description
pack-priv
NativeOverrides(Elements elementUtils)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean

Field Detail

elementUtilsback to summary
private final Elements elementUtils

Constructor Detail

NativeOverridesback to summary
pack-priv NativeOverrides(Elements elementUtils)

Method Detail

overridesback to summary
pack-priv boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement in)

Implements abstract com.google.auto.common.Overrides.overrides.

Annotations
@Override