forked from square/dagger
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more Gradle test coverage for issue #3136.
This CL adds tests to show how Dagger handles unrelated transitive annotations on the module and inject classes. RELNOTES=N/A PiperOrigin-RevId: 421078020
- Loading branch information
Showing
5 changed files
with
143 additions
and
12 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
97 changes: 97 additions & 0 deletions
97
...s/dagger/transitive-annotation-app/library1/src/main/java/library1/MyComponentModule.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,97 @@ | ||
/* | ||
* 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 library1; | ||
|
||
import static library2.MyTransitiveAnnotation.VALUE; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import javax.inject.Inject; | ||
import library2.MySimpleTransitiveAnnotation; | ||
import library2.MyTransitiveAnnotation; | ||
|
||
/** | ||
* A class used to test that Dagger won't fail when non-dagger related annotations cannot be | ||
* resolved. | ||
* | ||
* <p>During the compilation of {@code :app}, {@link MyTransitiveAnnotation} will no longer be on | ||
* the classpath. In most cases, Dagger shouldn't care that the annotation isn't on the classpath | ||
*/ | ||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
@Module(includes = { | ||
MyComponentModule.MyAbstractModule.class | ||
}) | ||
public final class MyComponentModule { | ||
public static final class Dep { | ||
@Inject Dep() {} | ||
} | ||
|
||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
@Module | ||
interface MyAbstractModule { | ||
@MySimpleTransitiveAnnotation | ||
// @MyTransitiveAnnotation(VALUE): Not yet supported | ||
@Binds | ||
Number bindNumber( | ||
@MySimpleTransitiveAnnotation | ||
// @MyTransitiveAnnotation(VALUE): Not yet supported | ||
int i); | ||
} | ||
|
||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
private final String nonDaggerField = ""; | ||
|
||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
MyComponentModule( | ||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
Dep dep) {} | ||
|
||
@MySimpleTransitiveAnnotation | ||
// @MyTransitiveAnnotation(VALUE): Not yet supported | ||
@Provides | ||
int provideInt( | ||
@MySimpleTransitiveAnnotation | ||
// @MyTransitiveAnnotation(VALUE): Not yet supported | ||
Dep dep) { | ||
return 1; | ||
} | ||
|
||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
String nonDaggerMethod( | ||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
String str) { | ||
return str; | ||
} | ||
|
||
|
||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
static String nonDaggerStaticMethod( | ||
@MySimpleTransitiveAnnotation | ||
@MyTransitiveAnnotation(VALUE) | ||
String str) { | ||
return str; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ansitive-annotation-app/library2/src/main/java/library2/MySimpleTransitiveAnnotation.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,20 @@ | ||
/* | ||
* Copyright (C) 2022 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 library2; | ||
|
||
/** A simple annotation that is a transitive dependency of the app. */ | ||
public @interface MySimpleTransitiveAnnotation {} |
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