Skip to content

Commit 19f2608

Browse files
committed
Remove line numbers from annotationsInDependencies test
This change makes the test makes the expected output stable across changes. Previously, if lines were added or removed (even whitespace), the expected test output would be very sensitive to it. In the worst case, a single line addition or removal immediately after the test directives would result in a diff for the entire expected output since it shifts the line numbers by one.
1 parent 819befa commit 19f2608

2 files changed

Lines changed: 80 additions & 88 deletions

File tree

kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AnnotationsInDependenciesProcessor.kt

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,17 @@ class AnnotationsInDependenciesProcessor(override val enableNewFeatures: Boolean
7777

7878
private fun KSAnnotated.toSignature(): String {
7979
return when (this) {
80-
is KSClassDeclaration -> "class ${(qualifiedName ?: simpleName).asString()} ${this.location.lineNumber}"
81-
is KSPropertyDeclaration -> "property ${simpleName.asString()} ${this.location.lineNumber}"
82-
is KSFunctionDeclaration -> "function ${simpleName.asString()} ${this.location.lineNumber}"
80+
is KSClassDeclaration -> "class ${(qualifiedName ?: simpleName).asString()}"
81+
is KSPropertyDeclaration -> "property ${simpleName.asString()}"
82+
is KSFunctionDeclaration -> "function ${simpleName.asString()}"
8383
is KSValueParameter -> name?.let {
84-
"parameter ${it.asString()} ${this.location.lineNumber}"
85-
} ?: "no-name-value-parameter ${this.location.lineNumber}"
84+
"parameter ${it.asString()}"
85+
} ?: "no-name-value-parameter"
8686

87-
is KSPropertyGetter -> "getter of ${receiver.toSignature()}" // lineNumber handled by recursive call
88-
is KSPropertySetter -> "setter of ${receiver.toSignature()}" // lineNumber handled by recursive call
89-
is KSBackingField -> "field of ${property.toSignature()}" // lineNumber handled by recursive call
90-
else -> {
91-
error("unexpected annotated")
92-
}
87+
is KSPropertyGetter -> "getter of ${receiver.toSignature()}"
88+
is KSPropertySetter -> "setter of ${receiver.toSignature()}"
89+
is KSBackingField -> "field of ${property.toSignature()}"
90+
else -> error("unexpected annotated")
9391
}
9492
}
9593

@@ -98,17 +96,11 @@ class AnnotationsInDependenciesProcessor(override val enableNewFeatures: Boolean
9896
(it.qualifiedName ?: it.simpleName).asString()
9997
}
10098
val args = this.arguments.map {
101-
"[${it.name?.asString()} = ${it.value} : ${it.location.lineNumber}]"
99+
"[${it.name?.asString()} = ${it.value}]"
102100
}.joinToString(",")
103-
return "$type{$args} : ${this.location.lineNumber}"
101+
return "$type{$args}"
104102
}
105103

106-
private val Location.lineNumber: String
107-
get() = when (this) {
108-
is FileLocation -> this.lineNumber.toString()
109-
is NonExistLocation -> "<no line>"
110-
}
111-
112104
class AnnotationVisitor(enableNewFeatures: Boolean) :
113105
KSTopDownVisitor<MutableMap<KSAnnotated, List<KSAnnotation>>, Unit>(enableNewFeatures) {
114106
override fun defaultHandler(node: KSNode, data: MutableMap<KSAnnotated, List<KSAnnotation>>) {

kotlin-analysis-api/testData/annotationsInDependencies.kt

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,78 @@
1919
// TEST PROCESSOR: AnnotationsInDependenciesProcessor
2020
// EXPECTED:
2121
// main.KotlinClass ->
22-
// class main.KotlinClass 180 : annotations.ClassTarget{[value = onClass : 179]} : 179
23-
// class main.KotlinClass 180 : annotations.NoTargetAnnotation{[value = onClass : 178]} : 178
24-
// function myFun 193 : annotations.FunctionTarget{[value = onMyFun : 192]} : 192
25-
// function myFun 193 : annotations.NoTargetAnnotation{[value = onMyFun : 191]} : 191
26-
// getter of property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line>
27-
// getter of property prop 189 : annotations.PropertyGetterTarget{[value = get: : 185]} : <no line>
28-
// parameter param1 196 : annotations.NoTargetAnnotation{[value = onParam1 : 194]} : <no line>
29-
// parameter param1 196 : annotations.ValueParameterTarget{[value = onParam1 : 195]} : <no line>
30-
// parameter param2 199 : annotations.NoTargetAnnotation{[value = onParam2 : 197]} : <no line>
31-
// parameter param2 199 : annotations.ValueParameterTarget{[value = onParam2 : 198]} : <no line>
32-
// parameter value <no line> : annotations.AllTarget{[value = all: : 188]} : <no line>
33-
// parameter value <no line> : annotations.ValueParameterTarget{[value = onProp : 187]} : <no line>
34-
// property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line>
35-
// property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line>
36-
// property prop 189 : annotations.FieldTarget2{[value = field: : 186]} : <no line>
37-
// property prop 189 : annotations.FieldTarget{[value = onProp : 182]} : <no line>
38-
// property prop 189 : annotations.NoTargetAnnotation{[value = onProp : 181]} : <no line>
39-
// property prop 189 : annotations.PropertyTarget{[value = onProp : 183]} : <no line>
40-
// setter of property prop 189 : annotations.PropertySetterTarget{[value = set: : 184]} : <no line>
22+
// class main.KotlinClass : annotations.ClassTarget{[value = onClass]}
23+
// class main.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]}
24+
// function myFun : annotations.FunctionTarget{[value = onMyFun]}
25+
// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]}
26+
// getter of property prop : annotations.AllTarget{[value = all:]}
27+
// getter of property prop : annotations.PropertyGetterTarget{[value = get:]}
28+
// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]}
29+
// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]}
30+
// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]}
31+
// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]}
32+
// parameter value : annotations.AllTarget{[value = all:]}
33+
// parameter value : annotations.ValueParameterTarget{[value = onProp]}
34+
// property prop : annotations.AllTarget{[value = all:]}
35+
// property prop : annotations.AllTarget{[value = all:]}
36+
// property prop : annotations.FieldTarget2{[value = field:]}
37+
// property prop : annotations.FieldTarget{[value = onProp]}
38+
// property prop : annotations.NoTargetAnnotation{[value = onProp]}
39+
// property prop : annotations.PropertyTarget{[value = onProp]}
40+
// setter of property prop : annotations.PropertySetterTarget{[value = set:]}
4141
// lib.KotlinClass ->
42-
// class lib.KotlinClass <no line> : annotations.ClassTarget{[value = onClass : <no line>]} : <no line>
43-
// class lib.KotlinClass <no line> : annotations.NoTargetAnnotation{[value = onClass : <no line>]} : <no line>
44-
// function myFun <no line> : annotations.FunctionTarget{[value = onMyFun : <no line>]} : <no line>
45-
// function myFun <no line> : annotations.NoTargetAnnotation{[value = onMyFun : <no line>]} : <no line>
46-
// getter of property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
47-
// getter of property prop <no line> : annotations.PropertyGetterTarget{[value = get: : <no line>]} : <no line>
48-
// parameter param1 <no line> : annotations.NoTargetAnnotation{[value = onParam1 : <no line>]} : <no line>
49-
// parameter param1 <no line> : annotations.ValueParameterTarget{[value = onParam1 : <no line>]} : <no line>
50-
// parameter param2 <no line> : annotations.NoTargetAnnotation{[value = onParam2 : <no line>]} : <no line>
51-
// parameter param2 <no line> : annotations.ValueParameterTarget{[value = onParam2 : <no line>]} : <no line>
52-
// parameter propInConstructor <no line> : annotations.ValueParameterTarget{[value = propInConstructor : <no line>]} : <no line>
53-
// parameter value <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
54-
// property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
55-
// property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
56-
// property prop <no line> : annotations.FieldTarget2{[value = field: : <no line>]} : <no line>
57-
// property prop <no line> : annotations.FieldTarget{[value = onProp : <no line>]} : <no line>
58-
// property prop <no line> : annotations.NoTargetAnnotation{[value = onProp : <no line>]} : <no line>
59-
// property prop <no line> : annotations.PropertyTarget{[value = onProp : <no line>]} : <no line>
60-
// setter of property prop <no line> : annotations.PropertySetterTarget{[value = set: : <no line>]} : <no line>
42+
// class lib.KotlinClass : annotations.ClassTarget{[value = onClass]}
43+
// class lib.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]}
44+
// function myFun : annotations.FunctionTarget{[value = onMyFun]}
45+
// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]}
46+
// getter of property prop : annotations.AllTarget{[value = all:]}
47+
// getter of property prop : annotations.PropertyGetterTarget{[value = get:]}
48+
// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]}
49+
// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]}
50+
// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]}
51+
// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]}
52+
// parameter propInConstructor : annotations.ValueParameterTarget{[value = propInConstructor]}
53+
// parameter value : annotations.AllTarget{[value = all:]}
54+
// property prop : annotations.AllTarget{[value = all:]}
55+
// property prop : annotations.AllTarget{[value = all:]}
56+
// property prop : annotations.FieldTarget2{[value = field:]}
57+
// property prop : annotations.FieldTarget{[value = onProp]}
58+
// property prop : annotations.NoTargetAnnotation{[value = onProp]}
59+
// property prop : annotations.PropertyTarget{[value = onProp]}
60+
// setter of property prop : annotations.PropertySetterTarget{[value = set:]}
6161
// main.DataClass ->
62-
// class main.DataClass 206 : annotations.ClassTarget{[value = onDataClass : 205]} : 205
63-
// class main.DataClass 206 : annotations.NoTargetAnnotation{[value = onDataClass : 204]} : 204
64-
// getter of property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line>
65-
// getter of property constructorParam 217 : annotations.PropertyGetterTarget{[value = get: : 211]} : <no line>
66-
// parameter constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line>
67-
// parameter constructorParam 217 : annotations.NoTargetAnnotation{[value = onConstructorParam : 207]} : <no line>
68-
// parameter constructorParam 217 : annotations.ValueParameterTarget{[value = onConstructorParam : 215]} : <no line>
69-
// parameter value <no line> : annotations.AllTarget{[value = all: : 216]} : <no line>
70-
// parameter value <no line> : annotations.ValueParameterTarget{[value = onConstructorParam : 214]} : <no line>
71-
// property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line>
72-
// property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line>
73-
// property constructorParam 217 : annotations.FieldTarget2{[value = field: : 212]} : <no line>
74-
// property constructorParam 217 : annotations.FieldTarget{[value = onConstructorParam : 208]} : <no line>
75-
// property constructorParam 217 : annotations.NoTargetAnnotation{[value = onConstructorParam : 207]} : <no line>
76-
// property constructorParam 217 : annotations.PropertyTarget{[value = onConstructorParam : 209]} : <no line>
77-
// property constructorParam 217 : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField : 213]} : <no line>
78-
// setter of property constructorParam 217 : annotations.PropertySetterTarget{[value = set: : 210]} : <no line>
62+
// class main.DataClass : annotations.ClassTarget{[value = onDataClass]}
63+
// class main.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]}
64+
// getter of property constructorParam : annotations.AllTarget{[value = all:]}
65+
// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]}
66+
// parameter constructorParam : annotations.AllTarget{[value = all:]}
67+
// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]}
68+
// parameter constructorParam : annotations.ValueParameterTarget{[value = onConstructorParam]}
69+
// parameter value : annotations.AllTarget{[value = all:]}
70+
// parameter value : annotations.ValueParameterTarget{[value = onConstructorParam]}
71+
// property constructorParam : annotations.AllTarget{[value = all:]}
72+
// property constructorParam : annotations.AllTarget{[value = all:]}
73+
// property constructorParam : annotations.FieldTarget2{[value = field:]}
74+
// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]}
75+
// property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]}
76+
// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]}
77+
// property constructorParam : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField]}
78+
// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]}
7979
// lib.DataClass ->
80-
// class lib.DataClass <no line> : annotations.ClassTarget{[value = onDataClass : <no line>]} : <no line>
81-
// class lib.DataClass <no line> : annotations.NoTargetAnnotation{[value = onDataClass : <no line>]} : <no line>
82-
// getter of property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
83-
// getter of property constructorParam <no line> : annotations.PropertyGetterTarget{[value = get: : <no line>]} : <no line>
84-
// parameter constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
85-
// parameter constructorParam <no line> : annotations.NoTargetAnnotation{[value = onConstructorParam : <no line>]} : <no line>
86-
// parameter value <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
87-
// property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
88-
// property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line>
89-
// property constructorParam <no line> : annotations.FieldTarget2{[value = field: : <no line>]} : <no line>
90-
// property constructorParam <no line> : annotations.FieldTarget{[value = onConstructorParam : <no line>]} : <no line>
91-
// property constructorParam <no line> : annotations.NoTargetAnnotation{[value = onConstructorParam : <no line>]} : <no line>
92-
// property constructorParam <no line> : annotations.PropertyTarget{[value = onConstructorParam : <no line>]} : <no line>
93-
// setter of property constructorParam <no line> : annotations.PropertySetterTarget{[value = set: : <no line>]} : <no line>
80+
// class lib.DataClass : annotations.ClassTarget{[value = onDataClass]}
81+
// class lib.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]}
82+
// getter of property constructorParam : annotations.AllTarget{[value = all:]}
83+
// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]}
84+
// parameter constructorParam : annotations.AllTarget{[value = all:]}
85+
// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]}
86+
// parameter value : annotations.AllTarget{[value = all:]}
87+
// property constructorParam : annotations.AllTarget{[value = all:]}
88+
// property constructorParam : annotations.AllTarget{[value = all:]}
89+
// property constructorParam : annotations.FieldTarget2{[value = field:]}
90+
// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]}
91+
// property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]}
92+
// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]}
93+
// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]}
9494
// END
9595
// MODULE: annotations
9696
// FILE: Annotations.kt

0 commit comments

Comments
 (0)