Skip to content

Commit acb05f9

Browse files
Jamie5Andre Rocha
authored and
Andre Rocha
committed
Ignore base class annotation (bazel-contrib#991)
1 parent fae42a4 commit acb05f9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer/AstUsedJarFinder.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,20 @@ class AstUsedJarFinder(
103103

104104
if (shouldExamine) {
105105
if (tree.hasSymbolField) {
106-
tree.symbol.annotations.foreach(exploreAnnotationInfo)
106+
tree.symbol.annotations
107+
// We skip annotations without positions. The reason for
108+
// this is the case of
109+
// @SomeAnnotation class A
110+
// class B extends A
111+
// Now assuming A and B are in separate packages, while
112+
// examining B we will examine A as well, and hence
113+
// examine A's annotations. However we don't wish to examine
114+
// A's annotations as we don't care about those details of A.
115+
// Hence we only examine annotations with positions (hence,
116+
// they were defined in the same compilation unit and thus
117+
// matter).
118+
.filter(_.pos.isDefined)
119+
.foreach(exploreAnnotationInfo)
107120
}
108121
if (tree.tpe != null) {
109122
exploreType(tree.tpe, tree.pos)

third_party/dependency_analyzer/src/test/io/bazel/rulesscala/dependencyanalyzer/AstUsedJarFinderTest.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ class AstUsedJarFinderTest extends FunSuite {
293293
)
294294
}
295295

296+
test("static annotation of inherited class is indirect") {
297+
checkIndirectDependencyDetected(
298+
aCode = "class A extends scala.annotation.StaticAnnotation",
299+
bCode = "@A class B",
300+
cCode = "class C extends B"
301+
)
302+
}
303+
296304
test("class type parameter bound is direct") {
297305
checkDirectDependencyRecognized(
298306
aCode =

0 commit comments

Comments
 (0)