1 /* 2 * Copyright 2021 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package tests; 17 18 import com.google.auto.factory.AutoFactory; 19 import com.google.auto.factory.Provided; 20 21 class Generics { 22 interface Bar {} 23 24 interface Foo<M extends Bar> {} 25 26 interface FooFactory<M extends Bar> { create()27 Foo<M> create(); 28 } 29 30 // The generated FooImplFactory should also have an <M extends Bar> type parameter, so we can 31 // have FooImplFactory<M extends Bar> implements FooFactory<M>. 32 @AutoFactory(implementing = FooFactory.class) 33 static final class FooImpl<M extends Bar> implements Foo<M> { FooImpl()34 FooImpl() {} 35 } 36 37 // The generated ExplicitFooImplFactory should have an <M extends Bar> type parameter, which 38 // serves both for FooFactory<M> and for Provider<M> in the constructor. 39 @AutoFactory(implementing = FooFactory.class) 40 static final class ExplicitFooImpl<M extends Bar> implements Foo<M> { ExplicitFooImpl(@rovided M unused)41 ExplicitFooImpl(@Provided M unused) {} 42 } 43 44 abstract static class FooFactoryClass<M extends Bar> { create()45 abstract Foo<M> create(); 46 } 47 48 @AutoFactory(extending = FooFactoryClass.class) 49 static final class FooImplWithClass<M extends Bar> implements Foo<M> {} 50 } 51