return false; List<TypeMirror> overriderParams = erasedParameterTypes(overrider, in); List<TypeMirror> overriddenParams = erasedParameterTypes(overridden, in); if (overriderParams == null || overriddenParams == null) {
if (!isSubsignature(overrider, overridden, in)) { return false; ExecutableElement inherited = methodFromSuperclasses(in, overridden); return !overridden.getEnclosingElement().equals(inherited.getEnclosingElement()); } else if (overriddenType.getKind().isInterface()) { ExecutableElement inherited = methodFromSuperinterfaces(in, overridden); return !overridden.getEnclosingElement().equals(inherited.getEnclosingElement()); } else {
TypeMirror candidateType = typeUtils.erasure(t.asType()); if (typeUtils.isAssignable(candidateType, methodContainerType)) { ExecutableElement tMethod = methodInType(t, method); if (tMethod != null) { return tMethod; newTypes.addAll(superinterfaces(t)); TypeElement sup = superclass(t); if (sup != null) { newTypes.add(sup);
/** * Returns the set of all non-private methods from {@code type}, including methods that it * inherits from its ancestors. Inherited methods that are overridden are not included in the * result. So if {@code type} defines {@code public String toString()}, the returned set will * contain that method, but not the {@code toString()} method defined by {@code Object}. * * <p>The returned set may contain more than one method with the same signature, if * {@code type} inherits those methods from different ancestors. For example, if it * inherits from unrelated interfaces {@code One} and {@code Two} which each define * {@code void foo();}, and if it does not itself override the {@code foo()} method, * then both {@code One.foo()} and {@code Two.foo()} will be in the returned set. * * @param type the type whose own and inherited methods are to be returned * @param typeUtils a {@link Types} object, typically returned by * {@link javax.annotation.processing.AbstractProcessor#processingEnv processingEnv}<!-- * -->.{@link javax.annotation.processing.ProcessingEnvironment#getTypeUtils * getTypeUtils()} * @param elementUtils an {@link Elements} object, typically returned by * {@link javax.annotation.processing.AbstractProcessor#processingEnv processingEnv}<!-- * -->.{@link javax.annotation.processing.ProcessingEnvironment#getElementUtils * getElementUtils()} */ public static ImmutableSet<ExecutableElement> getLocalAndInheritedMethods( TypeElement type, Types typeUtils, Elements elementUtils) { // TODO(emcmanus): detect if the Types and Elements are the javac ones, and use // NativeOverrides if so. We may need to adjust the logic further to avoid the bug // tested for by MoreElementsTest.getLocalAndInheritedMethods_DaggerBug. Overrides overrides = new Overrides.ExplicitOverrides(typeUtils); return getLocalAndInheritedMethods(type, overrides); }
/** * 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. */ private ExecutableElement methodInType(TypeElement type, ExecutableElement method) { int nParams = method.getParameters().size(); List<TypeMirror> params = erasedParameterTypes(method, type); if (params == null) { return null; } methods: for (ExecutableElement tMethod : ElementFilter.methodsIn(type.getEnclosedElements())) { if (tMethod.getSimpleName().equals(method.getSimpleName()) && tMethod.getParameters().size() == nParams) { for (int i = 0; i < nParams; i++) { TypeMirror tParamType = typeUtils.erasure(tMethod.getParameters().get(i).asType()); if (!typeUtils.isSameType(params.get(i), tParamType)) { continue methods; } } return tMethod; } } return null; }
/** * 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. */ ExecutableElement methodFromSuperclasses(TypeElement in, ExecutableElement method) { for (TypeElement t = in; t != null; t = superclass(t)) { ExecutableElement tMethod = methodInType(t, method); if (tMethod != null) { return tMethod; } } return null; }