[IR] Print annotations in source range compiler tests

This commit is contained in:
Sergej Jaskiewicz
2022-08-02 14:50:00 +02:00
committed by Space
parent 9dc7fe24f6
commit 5e34ae5e0d
11 changed files with 109 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
internal annotation class MyAnnotation(val description: String)
@MyAnnotation("fooAnotation")
fun foo() {}
+36
View File
@@ -0,0 +1,36 @@
@0:0..5:0 FILE fqName:<root> fileName:/annotations.kt
@0:0..1:63 CLASS ANNOTATION_CLASS name:MyAnnotation modality:OPEN visibility:internal superTypes:[kotlin.Annotation]
annotations:
@0:0..102 CONSTRUCTOR_CALL 'public constructor <init> (vararg allowedTargets: kotlin.annotation.AnnotationTarget) [primary] declared in kotlin.annotation.Target' type=kotlin.annotation.Target origin=null
@0:8..33 VARARG type=kotlin.Array<out kotlin.annotation.AnnotationTarget> varargElementType=kotlin.annotation.AnnotationTarget
@0:8..33 GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:FUNCTION' type=kotlin.annotation.AnnotationTarget
@0:8..33 GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:PROPERTY_GETTER' type=kotlin.annotation.AnnotationTarget
@0:8..33 GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:PROPERTY_SETTER' type=kotlin.annotation.AnnotationTarget
@1:20..63 CONSTRUCTOR visibility:public <> (description:kotlin.String) returnType:<root>.MyAnnotation [primary]
@1:39..62 VALUE_PARAMETER name:description index:0 type:kotlin.String
@0:0..1:63 BLOCK_BODY
@0:0..1:63 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@0:0..1:63 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:MyAnnotation modality:OPEN visibility:internal superTypes:[kotlin.Annotation]'
@1:39..62 PROPERTY name:description visibility:public modality:FINAL [val]
@1:39..62 FIELD PROPERTY_BACKING_FIELD name:description type:kotlin.String visibility:private [final]
@1:39..62 EXPRESSION_BODY
@1:39..62 GET_VAR 'description: kotlin.String declared in <root>.MyAnnotation.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
@1:39..62 FUN DEFAULT_PROPERTY_ACCESSOR name:<get-description> visibility:public modality:FINAL <> ($this:<root>.MyAnnotation) returnType:kotlin.String
@1:39..62 VALUE_PARAMETER name:<this> type:<root>.MyAnnotation
@1:39..62 BLOCK_BODY
@1:39..62 RETURN type=kotlin.Nothing from='public final fun <get-description> (): kotlin.String declared in <root>.MyAnnotation'
@1:39..62 GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:description type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
@1:39..62 GET_VAR '<this>: <root>.MyAnnotation declared in <root>.MyAnnotation.<get-description>' type=<root>.MyAnnotation origin=null
@1:20..63 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@0:0..1:63 VALUE_PARAMETER name:<this> type:kotlin.Any
@1:20..63 VALUE_PARAMETER name:other index:0 type:kotlin.Any?
@1:20..63 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
@0:0..1:63 VALUE_PARAMETER name:<this> type:kotlin.Any
@1:20..63 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
@0:0..1:63 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:0..1:63 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.MyAnnotation
@4:0..12 FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
annotations:
@3:0..29 CONSTRUCTOR_CALL 'public constructor <init> (description: kotlin.String) [primary] declared in <root>.MyAnnotation' type=<root>.MyAnnotation origin=null
@3:14..28 CONST String type=kotlin.String value="fooAnotation"
@4:10..12 BLOCK_BODY
@@ -11,6 +11,10 @@
@11:4..18 VALUE_PARAMETER name:<this> type:test.Test
@11:16..18 BLOCK_BODY
@17:4..18 FUN name:test2 visibility:public modality:FINAL <> ($this:test.Test) returnType:kotlin.Unit
annotations:
@14:4..16:5 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@15:8..25 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@15:8..25 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@14:4..17:18 VALUE_PARAMETER name:<this> type:test.Test
@17:16..18 BLOCK_BODY
@21:4..18 FUN name:test3 visibility:private modality:FINAL <> ($this:test.Test) returnType:kotlin.Unit
@@ -25,6 +25,10 @@
@10:4..18 GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
@10:4..18 GET_VAR '<this>: test.Test declared in test.Test.<get-test1>' type=test.Test origin=null
@13:4..16:18 PROPERTY name:test2 visibility:public modality:FINAL [val]
annotations:
@13:4..15:5 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@14:8..25 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@14:8..25 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@13:4..16:18 FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.Int visibility:private [final]
@16:16..18 EXPRESSION_BODY
@16:16..18 CONST Int type=kotlin.Int value=42
@@ -64,6 +68,10 @@
@34:16..18 CONST Int type=kotlin.Int value=42
@37:4..41:18 PROPERTY name:test7 visibility:public modality:FINAL [val]
@41:8..18 FUN name:<get-test7> visibility:public modality:FINAL <> ($this:test.Test) returnType:kotlin.Int
annotations:
@38:8..40:9 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@39:12..29 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@39:12..29 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@38:8..41:18 VALUE_PARAMETER name:<this> type:test.Test
@41:16..18 BLOCK_BODY
@41:18..18 RETURN type=kotlin.Nothing from='public final fun <get-test7> (): kotlin.Int declared in test.Test'
@@ -164,6 +172,10 @@
@69:4..75:9 GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test13 type:kotlin.Int visibility:private' type=kotlin.Int origin=null
@69:4..75:9 GET_VAR '<this>: test.Test declared in test.Test.<get-test13>' type=test.Test origin=null
@73:8..75:9 FUN name:<set-test13> visibility:public modality:FINAL <> ($this:test.Test, value:kotlin.Int) returnType:kotlin.Unit
annotations:
@70:8..72:9 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@71:12..29 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@71:12..29 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@70:8..75:9 VALUE_PARAMETER name:<this> type:test.Test
@73:12..17 VALUE_PARAMETER name:value index:0 type:kotlin.Int
@73:19..75:9 BLOCK_BODY
@@ -39,6 +39,10 @@
@10:0..11 VALUE_PARAMETER name:<this> type:kotlin.Any
@10:0..11 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test3
@13:0..14:11 CLASS CLASS name:Test4 modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations:
@13:0..23 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@13:10..22 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@13:10..22 CONST String type=kotlin.String value="UNUSED_VAR"
@14:0..11 CONSTRUCTOR visibility:public <> () returnType:<root>.Test4 [primary]
@13:0..14:11 BLOCK_BODY
@13:0..14:11 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@@ -57,6 +61,8 @@
@17:0..18:11 ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
@17:0..18:11 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:Test5 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.Test5>]'
@17:0..18:11 PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
annotations:
@-1:-1..-1 CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.internal.IntrinsicConstEvaluation' type=kotlin.internal.IntrinsicConstEvaluation origin=null
@18:0..11 FUN FAKE_OVERRIDE name:<get-name> visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.Test5>) returnType:kotlin.String [fake_override]
@17:0..18:11 VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.Test5>
@17:0..18:11 PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
@@ -73,6 +73,10 @@
@5:0..9:23 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test3
@11:0..13:23 CLASS CLASS name:Test4 modality:FINAL visibility:public superTypes:[kotlin.Any]
@13:0..23 CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:<root>.Test4 [primary]
annotations:
@12:0..28 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@12:10..27 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@12:10..27 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@13:12..22 VALUE_PARAMETER name:x index:0 type:kotlin.Int
@11:0..13:23 BLOCK_BODY
@11:0..13:23 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@@ -15,6 +15,10 @@
@9:29..36 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@9:4..36 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
@12:4..32 CONSTRUCTOR visibility:public <> (x:kotlin.Any) returnType:<root>.C
annotations:
@11:4..32 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@11:14..31 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@11:14..31 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@12:16..22 VALUE_PARAMETER name:x index:0 type:kotlin.Any
@11:4..12:32 BLOCK_BODY
@12:25..32 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@@ -4,6 +4,10 @@
@9:0..14 FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
@9:12..14 BLOCK_BODY
@15:0..14 FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit
annotations:
@12:0..14:1 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@13:4..21 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@13:4..21 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@15:12..14 BLOCK_BODY
@19:0..14 FUN name:test3 visibility:private modality:FINAL <> () returnType:kotlin.Unit
@19:12..14 BLOCK_BODY
@@ -16,6 +16,10 @@
@9:0..14 RETURN type=kotlin.Nothing from='public final fun <get-test1> (): kotlin.Int declared in test'
@9:0..14 GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.Int visibility:private [final,static]' type=kotlin.Int origin=null
@12:0..15:14 PROPERTY name:test2 visibility:public modality:FINAL [val]
annotations:
@12:0..14:1 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@13:4..21 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@13:4..21 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@12:0..15:14 FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.Int visibility:private [final,static]
@15:12..14 EXPRESSION_BODY
@15:12..14 CONST Int type=kotlin.Int value=42
@@ -48,6 +52,10 @@
@33:12..14 CONST Int type=kotlin.Int value=42
@36:0..40:14 PROPERTY name:test7 visibility:public modality:FINAL [val]
@40:4..14 FUN name:<get-test7> visibility:public modality:FINAL <> () returnType:kotlin.Int
annotations:
@37:4..39:5 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@38:8..25 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@38:8..25 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@40:12..14 BLOCK_BODY
@40:14..14 RETURN type=kotlin.Nothing from='public final fun <get-test7> (): kotlin.Int declared in test'
@40:12..14 CONST Int type=kotlin.Int value=42
@@ -125,6 +133,10 @@
@64:0..68:32 RETURN type=kotlin.Nothing from='public final fun <get-test13> (): kotlin.Int declared in test'
@64:0..68:32 GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test13 type:kotlin.Int visibility:private [static]' type=kotlin.Int origin=null
@68:4..32 FUN name:<set-test13> visibility:public modality:FINAL <> (value:kotlin.Int) returnType:kotlin.Unit
annotations:
@65:4..67:5 CONSTRUCTOR_CALL 'public constructor <init> (vararg names: kotlin.String) [primary] declared in kotlin.Suppress' type=kotlin.Suppress origin=null
@66:8..25 VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
@66:8..25 CONST String type=kotlin.String value="UNUSED_VARIABLE"
@68:8..13 VALUE_PARAMETER name:value index:0 type:kotlin.Int
@68:15..32 BLOCK_BODY
@68:17..22 SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test13 type:kotlin.Int visibility:private [static]' type=kotlin.Unit origin=EQ
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
import org.jetbrains.kotlin.ir.util.RenderIrElementVisitor
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
@@ -47,10 +48,25 @@ abstract class AbstractIrSourceRangesTestCase : AbstractIrGeneratorTestCase() {
val printer = Printer(out, " ")
val elementRenderer = RenderIrElementVisitor()
override fun visitElement(element: IrElement) {
private fun printElement(element: IrElement) {
val sourceRangeInfo = fileEntry.getSourceRangeInfo(element.startOffset, element.endOffset)
printer.println("@${sourceRangeInfo.render()} ${element.accept(elementRenderer, null)}")
}
override fun visitElement(element: IrElement) {
printElement(element)
printer.pushIndent()
if (element is IrAnnotationContainer && element.annotations.isNotEmpty()) {
printer.println("annotations:")
printer.pushIndent()
for (annotation in element.annotations) {
printElement(annotation)
printer.pushIndent()
annotation.acceptChildrenVoid(this)
printer.popIndent()
}
printer.popIndent()
}
element.acceptChildrenVoid(this)
printer.popIndent()
}
@@ -29,6 +29,11 @@ public class IrSourceRangesTestCaseGenerated extends AbstractIrSourceRangesTestC
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/sourceRanges"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("annotations.kt")
public void testAnnotations() throws Exception {
runTest("compiler/testData/ir/sourceRanges/annotations.kt");
}
@TestMetadata("augmentedAssignmentWithExpression.kt")
public void testAugmentedAssignmentWithExpression() throws Exception {
runTest("compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.kt");