forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid clashes with nested type defined in super Interface/Class.
RELNOTES=n/a PiperOrigin-RevId: 418837115
- Loading branch information
1 parent
8bb1d1a
commit 8ff7d6b
Showing
3 changed files
with
88 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2021 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.functional; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Regression test for b/212604806. */ | ||
@RunWith(JUnit4.class) | ||
public final class ComponentNestedTypeTest { | ||
@Component(modules = TestModule.class) | ||
interface TestComponent { | ||
|
||
// Dagger generated component implementation that extends TestComponent will implement this | ||
// method, so the component implementation will keep a reference to the {@link | ||
// dagger.functional.sub.NestedType}. The reference to {@link dagger.functional.sub.NestedType} | ||
// may collide with the NestedType defined inside of TestComponent, because javapoet may strip | ||
// the package prefix of the type as it does not have enough information about the super | ||
// class/interfaces. | ||
dagger.functional.sub.NestedType nestedType(); | ||
|
||
interface NestedType {} | ||
} | ||
|
||
public static final class SomeType implements dagger.functional.sub.NestedType {} | ||
|
||
@Module | ||
static final class TestModule { | ||
@Provides | ||
static dagger.functional.sub.NestedType provideSomeType() { | ||
return new SomeType(); | ||
} | ||
} | ||
|
||
@Test | ||
public void typeNameWontClashWithNestedTypeName() { | ||
TestComponent component = | ||
DaggerComponentNestedTypeTest_TestComponent.builder().testModule(new TestModule()).build(); | ||
assertThat(component.nestedType()).isNotNull(); | ||
} | ||
} |
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,21 @@ | ||
/* | ||
* Copyright (C) 2021 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.functional.sub; | ||
|
||
// Move this back to dagger.functional package once the javapoet clash bug gets fixed. | ||
// https://github.com/square/javapoet/issues/860 | ||
public interface NestedType {} |