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.
diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AnnotationsInDependenciesProcessor.kt b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AnnotationsInDependenciesProcessor.kt index d4c0cfe..c1b2c00 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AnnotationsInDependenciesProcessor.kt +++ b/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AnnotationsInDependenciesProcessor.kt
@@ -77,19 +77,17 @@ private fun KSAnnotated.toSignature(): String { return when (this) { - is KSClassDeclaration -> "class ${(qualifiedName ?: simpleName).asString()} ${this.location.lineNumber}" - is KSPropertyDeclaration -> "property ${simpleName.asString()} ${this.location.lineNumber}" - is KSFunctionDeclaration -> "function ${simpleName.asString()} ${this.location.lineNumber}" + is KSClassDeclaration -> "class ${(qualifiedName ?: simpleName).asString()}" + is KSPropertyDeclaration -> "property ${simpleName.asString()}" + is KSFunctionDeclaration -> "function ${simpleName.asString()}" is KSValueParameter -> name?.let { - "parameter ${it.asString()} ${this.location.lineNumber}" - } ?: "no-name-value-parameter ${this.location.lineNumber}" + "parameter ${it.asString()}" + } ?: "no-name-value-parameter" - is KSPropertyGetter -> "getter of ${receiver.toSignature()}" // lineNumber handled by recursive call - is KSPropertySetter -> "setter of ${receiver.toSignature()}" // lineNumber handled by recursive call - is KSBackingField -> "field of ${property.toSignature()}" // lineNumber handled by recursive call - else -> { - error("unexpected annotated") - } + is KSPropertyGetter -> "getter of ${receiver.toSignature()}" + is KSPropertySetter -> "setter of ${receiver.toSignature()}" + is KSBackingField -> "field of ${property.toSignature()}" + else -> error("unexpected annotated") } } @@ -98,17 +96,11 @@ (it.qualifiedName ?: it.simpleName).asString() } val args = this.arguments.map { - "[${it.name?.asString()} = ${it.value} : ${it.location.lineNumber}]" + "[${it.name?.asString()} = ${it.value}]" }.joinToString(",") - return "$type{$args} : ${this.location.lineNumber}" + return "$type{$args}" } - private val Location.lineNumber: String - get() = when (this) { - is FileLocation -> this.lineNumber.toString() - is NonExistLocation -> "<no line>" - } - class AnnotationVisitor(enableNewFeatures: Boolean) : KSTopDownVisitor<MutableMap<KSAnnotated, List<KSAnnotation>>, Unit>(enableNewFeatures) { override fun defaultHandler(node: KSNode, data: MutableMap<KSAnnotated, List<KSAnnotation>>) {
diff --git a/kotlin-analysis-api/testData/annotationsInDependencies.kt b/kotlin-analysis-api/testData/annotationsInDependencies.kt index 7f9edab..1f4922c 100644 --- a/kotlin-analysis-api/testData/annotationsInDependencies.kt +++ b/kotlin-analysis-api/testData/annotationsInDependencies.kt
@@ -19,78 +19,78 @@ // TEST PROCESSOR: AnnotationsInDependenciesProcessor // EXPECTED: // main.KotlinClass -> -// class main.KotlinClass 180 : annotations.ClassTarget{[value = onClass : 179]} : 179 -// class main.KotlinClass 180 : annotations.NoTargetAnnotation{[value = onClass : 178]} : 178 -// function myFun 193 : annotations.FunctionTarget{[value = onMyFun : 192]} : 192 -// function myFun 193 : annotations.NoTargetAnnotation{[value = onMyFun : 191]} : 191 -// getter of property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line> -// getter of property prop 189 : annotations.PropertyGetterTarget{[value = get: : 185]} : <no line> -// parameter param1 196 : annotations.NoTargetAnnotation{[value = onParam1 : 194]} : <no line> -// parameter param1 196 : annotations.ValueParameterTarget{[value = onParam1 : 195]} : <no line> -// parameter param2 199 : annotations.NoTargetAnnotation{[value = onParam2 : 197]} : <no line> -// parameter param2 199 : annotations.ValueParameterTarget{[value = onParam2 : 198]} : <no line> -// parameter value <no line> : annotations.AllTarget{[value = all: : 188]} : <no line> -// parameter value <no line> : annotations.ValueParameterTarget{[value = onProp : 187]} : <no line> -// property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line> -// property prop 189 : annotations.AllTarget{[value = all: : 188]} : <no line> -// property prop 189 : annotations.FieldTarget2{[value = field: : 186]} : <no line> -// property prop 189 : annotations.FieldTarget{[value = onProp : 182]} : <no line> -// property prop 189 : annotations.NoTargetAnnotation{[value = onProp : 181]} : <no line> -// property prop 189 : annotations.PropertyTarget{[value = onProp : 183]} : <no line> -// setter of property prop 189 : annotations.PropertySetterTarget{[value = set: : 184]} : <no line> +// class main.KotlinClass : annotations.ClassTarget{[value = onClass]} +// class main.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} +// function myFun : annotations.FunctionTarget{[value = onMyFun]} +// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} +// getter of property prop : annotations.AllTarget{[value = all:]} +// getter of property prop : annotations.PropertyGetterTarget{[value = get:]} +// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} +// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} +// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} +// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} +// parameter value : annotations.AllTarget{[value = all:]} +// parameter value : annotations.ValueParameterTarget{[value = onProp]} +// property prop : annotations.AllTarget{[value = all:]} +// property prop : annotations.AllTarget{[value = all:]} +// property prop : annotations.FieldTarget2{[value = field:]} +// property prop : annotations.FieldTarget{[value = onProp]} +// property prop : annotations.NoTargetAnnotation{[value = onProp]} +// property prop : annotations.PropertyTarget{[value = onProp]} +// setter of property prop : annotations.PropertySetterTarget{[value = set:]} // lib.KotlinClass -> -// class lib.KotlinClass <no line> : annotations.ClassTarget{[value = onClass : <no line>]} : <no line> -// class lib.KotlinClass <no line> : annotations.NoTargetAnnotation{[value = onClass : <no line>]} : <no line> -// function myFun <no line> : annotations.FunctionTarget{[value = onMyFun : <no line>]} : <no line> -// function myFun <no line> : annotations.NoTargetAnnotation{[value = onMyFun : <no line>]} : <no line> -// getter of property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// getter of property prop <no line> : annotations.PropertyGetterTarget{[value = get: : <no line>]} : <no line> -// parameter param1 <no line> : annotations.NoTargetAnnotation{[value = onParam1 : <no line>]} : <no line> -// parameter param1 <no line> : annotations.ValueParameterTarget{[value = onParam1 : <no line>]} : <no line> -// parameter param2 <no line> : annotations.NoTargetAnnotation{[value = onParam2 : <no line>]} : <no line> -// parameter param2 <no line> : annotations.ValueParameterTarget{[value = onParam2 : <no line>]} : <no line> -// parameter propInConstructor <no line> : annotations.ValueParameterTarget{[value = propInConstructor : <no line>]} : <no line> -// parameter value <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property prop <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property prop <no line> : annotations.FieldTarget2{[value = field: : <no line>]} : <no line> -// property prop <no line> : annotations.FieldTarget{[value = onProp : <no line>]} : <no line> -// property prop <no line> : annotations.NoTargetAnnotation{[value = onProp : <no line>]} : <no line> -// property prop <no line> : annotations.PropertyTarget{[value = onProp : <no line>]} : <no line> -// setter of property prop <no line> : annotations.PropertySetterTarget{[value = set: : <no line>]} : <no line> +// class lib.KotlinClass : annotations.ClassTarget{[value = onClass]} +// class lib.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} +// function myFun : annotations.FunctionTarget{[value = onMyFun]} +// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} +// getter of property prop : annotations.AllTarget{[value = all:]} +// getter of property prop : annotations.PropertyGetterTarget{[value = get:]} +// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} +// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} +// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} +// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} +// parameter propInConstructor : annotations.ValueParameterTarget{[value = propInConstructor]} +// parameter value : annotations.AllTarget{[value = all:]} +// property prop : annotations.AllTarget{[value = all:]} +// property prop : annotations.AllTarget{[value = all:]} +// property prop : annotations.FieldTarget2{[value = field:]} +// property prop : annotations.FieldTarget{[value = onProp]} +// property prop : annotations.NoTargetAnnotation{[value = onProp]} +// property prop : annotations.PropertyTarget{[value = onProp]} +// setter of property prop : annotations.PropertySetterTarget{[value = set:]} // main.DataClass -> -// class main.DataClass 206 : annotations.ClassTarget{[value = onDataClass : 205]} : 205 -// class main.DataClass 206 : annotations.NoTargetAnnotation{[value = onDataClass : 204]} : 204 -// getter of property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line> -// getter of property constructorParam 217 : annotations.PropertyGetterTarget{[value = get: : 211]} : <no line> -// parameter constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line> -// parameter constructorParam 217 : annotations.NoTargetAnnotation{[value = onConstructorParam : 207]} : <no line> -// parameter constructorParam 217 : annotations.ValueParameterTarget{[value = onConstructorParam : 215]} : <no line> -// parameter value <no line> : annotations.AllTarget{[value = all: : 216]} : <no line> -// parameter value <no line> : annotations.ValueParameterTarget{[value = onConstructorParam : 214]} : <no line> -// property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line> -// property constructorParam 217 : annotations.AllTarget{[value = all: : 216]} : <no line> -// property constructorParam 217 : annotations.FieldTarget2{[value = field: : 212]} : <no line> -// property constructorParam 217 : annotations.FieldTarget{[value = onConstructorParam : 208]} : <no line> -// property constructorParam 217 : annotations.NoTargetAnnotation{[value = onConstructorParam : 207]} : <no line> -// property constructorParam 217 : annotations.PropertyTarget{[value = onConstructorParam : 209]} : <no line> -// property constructorParam 217 : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField : 213]} : <no line> -// setter of property constructorParam 217 : annotations.PropertySetterTarget{[value = set: : 210]} : <no line> +// class main.DataClass : annotations.ClassTarget{[value = onDataClass]} +// class main.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} +// getter of property constructorParam : annotations.AllTarget{[value = all:]} +// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} +// parameter constructorParam : annotations.AllTarget{[value = all:]} +// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// parameter constructorParam : annotations.ValueParameterTarget{[value = onConstructorParam]} +// parameter value : annotations.AllTarget{[value = all:]} +// parameter value : annotations.ValueParameterTarget{[value = onConstructorParam]} +// property constructorParam : annotations.AllTarget{[value = all:]} +// property constructorParam : annotations.AllTarget{[value = all:]} +// property constructorParam : annotations.FieldTarget2{[value = field:]} +// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} +// property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} +// property constructorParam : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField]} +// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} // lib.DataClass -> -// class lib.DataClass <no line> : annotations.ClassTarget{[value = onDataClass : <no line>]} : <no line> -// class lib.DataClass <no line> : annotations.NoTargetAnnotation{[value = onDataClass : <no line>]} : <no line> -// getter of property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// getter of property constructorParam <no line> : annotations.PropertyGetterTarget{[value = get: : <no line>]} : <no line> -// parameter constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// parameter constructorParam <no line> : annotations.NoTargetAnnotation{[value = onConstructorParam : <no line>]} : <no line> -// parameter value <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property constructorParam <no line> : annotations.AllTarget{[value = all: : <no line>]} : <no line> -// property constructorParam <no line> : annotations.FieldTarget2{[value = field: : <no line>]} : <no line> -// property constructorParam <no line> : annotations.FieldTarget{[value = onConstructorParam : <no line>]} : <no line> -// property constructorParam <no line> : annotations.NoTargetAnnotation{[value = onConstructorParam : <no line>]} : <no line> -// property constructorParam <no line> : annotations.PropertyTarget{[value = onConstructorParam : <no line>]} : <no line> -// setter of property constructorParam <no line> : annotations.PropertySetterTarget{[value = set: : <no line>]} : <no line> +// class lib.DataClass : annotations.ClassTarget{[value = onDataClass]} +// class lib.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} +// getter of property constructorParam : annotations.AllTarget{[value = all:]} +// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} +// parameter constructorParam : annotations.AllTarget{[value = all:]} +// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// parameter value : annotations.AllTarget{[value = all:]} +// property constructorParam : annotations.AllTarget{[value = all:]} +// property constructorParam : annotations.AllTarget{[value = all:]} +// property constructorParam : annotations.FieldTarget2{[value = field:]} +// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} +// property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} +// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} // END // MODULE: annotations // FILE: Annotations.kt