Skip to content

Commit

Permalink
Merge pull request #320 from google/moe_writing_branch_from_6475f4779…
Browse files Browse the repository at this point in the history
…9f55eb2d22af72b7c8bddf3f7b1d01c

Merge out new changes from google's internal repository
  • Loading branch information
cgruber committed Feb 22, 2016
2 parents eebf6ee + ea019be commit d851a22
Show file tree
Hide file tree
Showing 89 changed files with 2,470 additions and 616 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test;

import dagger.Component;
import dagger.Module;

// https://github.com/google/dagger/issues/279
public class ComponentsWithNestedModules {
@Component(modules = RegularComponent.SharedModule.class)
public interface RegularComponent {
@Module class SharedModule {}
}

@Component(modules = ExtendsRegularComponent.SharedModule.class)
public interface ExtendsRegularComponent extends RegularComponent {
@Module(includes = RegularComponent.SharedModule.class)
class SharedModule {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import dagger.Module;
import dagger.Provides;

import static dagger.Provides.Type.SET;

@Module
final class BlueModule {
@Provides(type = SET)
@BlueScope
static Object blue() {
return new Object();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Scope;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Retention(RUNTIME)
@Scope
@interface BlueScope {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import dagger.Module;
import dagger.Provides;

import static dagger.Provides.Type.SET;

@Module
final class GreenModule {
@Provides(type = SET)
@GreenScope
static Object green() {
return new Object();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Scope;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Retention(RUNTIME)
@Scope
@interface GreenScope {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import dagger.Component;
import java.util.Set;

@BlueScope
@GreenScope
@Component(modules = {BlueModule.class, GreenModule.class, TurquoiseModule.class})
interface ScopedComponent {
Set<Object> set();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.scope;

import dagger.Module;
import dagger.Provides;

import static dagger.Provides.Type.SET;

@Module
final class TurquoiseModule {
@Provides(type = SET)
@BlueScope
static Object blue() {
return new Object();
}

@Provides(type = SET)
@GreenScope
static Object green() {
return new Object();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import dagger.Component;
import javax.inject.Singleton;

@Component(modules = ParentModule.class)
@Component(modules = {ParentModule.class, UnresolvableChildComponentModule.class})
@Singleton
interface ParentComponent extends ParentGetters {
ChildComponent newChildComponent();
Expand All @@ -28,4 +28,10 @@ interface ParentComponent extends ParentGetters {
ChildComponentRequiringModules newChildComponentRequiringModules(
ChildModuleWithParameters cmwp,
ChildModuleWithState childModuleWithState);

/**
* Requests a qualified version of this subcomponent builder, which does not install it as a
* subcomponent, but instead, uses the explicit binding of this qualified builder.
*/
@SomeQualifier UnresolvableChildComponent.Builder unresolvableChildComponentBuilder();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.subcomponent;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Qualifier;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Retention(RUNTIME)
@Qualifier
@interface SomeQualifier {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.subcomponent;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Qualifier;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* A qualifier representing an unbound type, to verify that the compiler does not attempt to
* generate code depending on it.
*/
@Documented
@Retention(RUNTIME)
@Qualifier
@interface Unbound {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.subcomponent;

import dagger.Subcomponent;

/**
* A subcomponent that's not resolvable in any parent component, for testing that qualified methods
* on components that return subcomponents do not trigger actual subcomponents.
*/
@Subcomponent
interface UnresolvableChildComponent {
/**
* Requests a type that is never bound in any component that this subcomponent might be installed
* in. If this subcomponent is ever attempted to be installed in a component, then it will produce
* a compiler error.
*/
@Unbound
String unboundString();

@Subcomponent.Builder
interface Builder {
UnresolvableChildComponent build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 Google, Inc.
*
* 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 test.subcomponent;

import dagger.Module;
import dagger.Provides;

@Module
final class UnresolvableChildComponentModule {
/**
* Provides a qualified version of the {@link UnresolvableChildComponent}'s builder. If the
* subcomponent were actually installed in a component, this would be a duplicate binding; but
* since that doesn't happen, this binding is OK.
*/
@Provides
@SomeQualifier
static UnresolvableChildComponent.Builder unresolvableChildComponentBuilder() {
return new UnresolvableChildComponent.Builder() {
@Override
public UnresolvableChildComponent build() {
return new UnresolvableChildComponent() {
@Override
public String unboundString() {
return "unbound";
}
};
}
};
}
}
Loading

0 comments on commit d851a22

Please sign in to comment.