Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the isPresent Option state to functional style #1849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions core/src/com/google/inject/internal/InjectorBindingData.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,10 @@ public void addInterceptorBinding(InterceptorBinding interceptorBinding) {
}

public ImmutableList<InterceptorBinding> getInterceptorBindings() {
if (parent.isPresent()) {
return new ImmutableList.Builder<InterceptorBinding>()
.addAll(parent.get().getInterceptorBindings())
.addAll(interceptorBindings)
.build();
}
return ImmutableList.copyOf(interceptorBindings);
return parent.map(injectorBindingData -> new ImmutableList.Builder<InterceptorBinding>()
.addAll(injectorBindingData.getInterceptorBindings())
.addAll(interceptorBindings)
.build()).orElseGet(() -> ImmutableList.copyOf(interceptorBindings));
}

public ImmutableList<InterceptorBinding> getInterceptorBindingsThisLevel() {
Expand All @@ -196,13 +193,10 @@ public void addTypeListener(TypeListenerBinding listenerBinding) {
}

public ImmutableList<TypeListenerBinding> getTypeListenerBindings() {
if (parent.isPresent()) {
return new ImmutableList.Builder<TypeListenerBinding>()
.addAll(parent.get().getTypeListenerBindings())
.addAll(typeListenerBindings)
.build();
}
return ImmutableList.copyOf(typeListenerBindings);
return parent.map(injectorBindingData -> new ImmutableList.Builder<TypeListenerBinding>()
.addAll(injectorBindingData.getTypeListenerBindings())
.addAll(typeListenerBindings)
.build()).orElseGet(() -> ImmutableList.copyOf(typeListenerBindings));
}

public ImmutableList<TypeListenerBinding> getTypeListenerBindingsThisLevel() {
Expand All @@ -214,13 +208,10 @@ public void addProvisionListener(ProvisionListenerBinding listenerBinding) {
}

public ImmutableList<ProvisionListenerBinding> getProvisionListenerBindings() {
if (parent.isPresent()) {
return new ImmutableList.Builder<ProvisionListenerBinding>()
.addAll(parent.get().getProvisionListenerBindings())
.addAll(provisionListenerBindings)
.build();
}
return ImmutableList.copyOf(provisionListenerBindings);
return parent.map(injectorBindingData -> new ImmutableList.Builder<ProvisionListenerBinding>()
.addAll(injectorBindingData.getProvisionListenerBindings())
.addAll(provisionListenerBindings)
.build()).orElseGet(() -> ImmutableList.copyOf(provisionListenerBindings));
}

public ImmutableList<ProvisionListenerBinding> getProvisionListenerBindingsThisLevel() {
Expand All @@ -232,13 +223,10 @@ public void addScanner(ModuleAnnotatedMethodScannerBinding scanner) {
}

public ImmutableList<ModuleAnnotatedMethodScannerBinding> getScannerBindings() {
if (parent.isPresent()) {
return new ImmutableList.Builder<ModuleAnnotatedMethodScannerBinding>()
.addAll(parent.get().getScannerBindings())
.addAll(scannerBindings)
.build();
}
return ImmutableList.copyOf(scannerBindings);
return parent.map(injectorBindingData -> new ImmutableList.Builder<ModuleAnnotatedMethodScannerBinding>()
.addAll(injectorBindingData.getScannerBindings())
.addAll(scannerBindings)
.build()).orElseGet(() -> ImmutableList.copyOf(scannerBindings));
}

public ImmutableList<ModuleAnnotatedMethodScannerBinding> getScannerBindingsThisLevel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ void banKey(Key<?> key, InjectorBindingData injectorBindingData, Object source)
* overriding explicit bindings declared in a child injector.
*/
void banKeyInParent(Key<?> key, InjectorBindingData injectorBindingData, Object source) {
if (parent.isPresent()) {
parent.get().banKey(key, injectorBindingData, source);
}
parent.ifPresent(injectorJitBindingData -> injectorJitBindingData.banKey(key, injectorBindingData, source));
}

/**
Expand Down