forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#444 from google/moe_writing_branch_from_f53…
…c3f9f3b293085727489fa39fb1134a4d36aaf Moe sync 08/23
- Loading branch information
Showing
13 changed files
with
251 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
compiler/src/main/java/dagger/internal/codegen/BindingTypeMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (C) 2014 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dagger.internal.codegen; | ||
|
||
import static com.google.common.collect.Iterables.getOnlyElement; | ||
import static dagger.internal.codegen.BindingType.CONTRIBUTION_TYPES; | ||
import static dagger.internal.codegen.BindingType.MEMBERS_INJECTION; | ||
import static dagger.internal.codegen.BindingType.PRODUCTION; | ||
import static dagger.internal.codegen.BindingType.PROVISION; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.FluentIterable; | ||
import com.google.common.collect.ImmutableSet; | ||
import dagger.producers.Producer; | ||
import javax.inject.Provider; | ||
|
||
/** | ||
* A mapper for associating a {@link DependencyRequest.Kind} to a {@link BindingType}, dependent on | ||
* the type of code to be generated (e.g., for {@link Provider} or {@link Producer}). | ||
*/ | ||
enum BindingTypeMapper { | ||
FOR_PROVIDER() { | ||
@Override public BindingType getBindingType(DependencyRequest.Kind requestKind) { | ||
switch (requestKind) { | ||
case INSTANCE: | ||
case PROVIDER: | ||
case PROVIDER_OF_LAZY: | ||
case LAZY: | ||
return PROVISION; | ||
case MEMBERS_INJECTOR: | ||
return MEMBERS_INJECTION; | ||
case PRODUCED: | ||
case PRODUCER: | ||
throw new IllegalArgumentException(requestKind.toString()); | ||
default: | ||
throw new AssertionError(requestKind); | ||
} | ||
} | ||
}, | ||
FOR_PRODUCER() { | ||
@Override public BindingType getBindingType(DependencyRequest.Kind requestKind) { | ||
switch (requestKind) { | ||
case INSTANCE: | ||
case PRODUCED: | ||
case PRODUCER: | ||
return PRODUCTION; | ||
case PROVIDER: | ||
case PROVIDER_OF_LAZY: | ||
case LAZY: | ||
return PROVISION; | ||
case MEMBERS_INJECTOR: | ||
return MEMBERS_INJECTION; | ||
default: | ||
throw new AssertionError(requestKind); | ||
} | ||
} | ||
}; | ||
|
||
static BindingTypeMapper forBindingType(BindingType bindingType) { | ||
return bindingType.equals(PRODUCTION) ? FOR_PRODUCER : FOR_PROVIDER; | ||
} | ||
|
||
abstract BindingType getBindingType(DependencyRequest.Kind requestKind); | ||
|
||
/** | ||
* Returns the {@link BindingType} to use for a collection of requests of the same | ||
* {@link BindingKey}. This allows factories to only take a single argument for multiple requests | ||
* of the same key. | ||
*/ | ||
BindingType getBindingType(Iterable<DependencyRequest> requests) { | ||
ImmutableSet<BindingType> classes = FluentIterable.from(requests) | ||
.transform(new Function<DependencyRequest, BindingType>() { | ||
@Override public BindingType apply(DependencyRequest request) { | ||
return getBindingType(request.kind()); | ||
} | ||
}) | ||
.toSet(); | ||
if (classes.size() == 1) { | ||
return getOnlyElement(classes); | ||
} else if (classes.equals(CONTRIBUTION_TYPES)) { | ||
return PROVISION; | ||
} else { | ||
throw new IllegalArgumentException("Bad set of framework classes: " + classes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
compiler/src/main/java/dagger/internal/codegen/DependencyRequestMapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.