• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Dagger Authors.
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 
17 package dagger.internal.codegen.binding;
18 
19 import static dagger.internal.codegen.binding.BindingType.PRODUCTION;
20 
21 import dagger.internal.codegen.model.RequestKind;
22 
23 /**
24  * A mapper for associating a {@link RequestKind} to a {@link FrameworkType}, dependent on the type
25  * of code to be generated (e.g., for {@code Provider} or {@code Producer}).
26  */
27 public enum FrameworkTypeMapper {
FOR_PROVIDER()28   FOR_PROVIDER() {
29     @Override
30     public FrameworkType getFrameworkType(RequestKind requestKind) {
31       switch (requestKind) {
32         case INSTANCE:
33         case PROVIDER:
34         case PROVIDER_OF_LAZY:
35         case LAZY:
36           return FrameworkType.PROVIDER;
37         case PRODUCED:
38         case PRODUCER:
39           throw new IllegalArgumentException(requestKind.toString());
40         default:
41           throw new AssertionError(requestKind);
42       }
43     }
44   },
FOR_PRODUCER()45   FOR_PRODUCER() {
46     @Override
47     public FrameworkType getFrameworkType(RequestKind requestKind) {
48       switch (requestKind) {
49         case INSTANCE:
50         case PRODUCED:
51         case PRODUCER:
52           return FrameworkType.PRODUCER_NODE;
53         case PROVIDER:
54         case PROVIDER_OF_LAZY:
55         case LAZY:
56           return FrameworkType.PROVIDER;
57         default:
58           throw new AssertionError(requestKind);
59       }
60     }
61   };
62 
forBindingType(BindingType bindingType)63   public static FrameworkTypeMapper forBindingType(BindingType bindingType) {
64     return bindingType.equals(PRODUCTION) ? FOR_PRODUCER : FOR_PROVIDER;
65   }
66 
getFrameworkType(RequestKind requestKind)67   public abstract FrameworkType getFrameworkType(RequestKind requestKind);
68 }
69