diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 5ccf4815bff..3f350c47e4e 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -1040,7 +1040,11 @@ fun main(args: Array) { } testClass { - model("resoreSymbolFromLibrary", extension = "txt") + model("resoreSymbolFromLibrary") + } + + testClass { + model("symbolByReference") } testClass { diff --git a/idea/idea-frontend-fir/testData/components/expressionType/assignmentExpressionTarget.kt b/idea/idea-frontend-fir/testData/components/expressionType/assignmentExpressionTarget.kt index 5e9c2cbc3bd..a81a6c8028b 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/assignmentExpressionTarget.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/assignmentExpressionTarget.kt @@ -2,8 +2,7 @@ fun test(s: String) { var i: Int = 0 i = s.length } -// RESULT +// RESULT // expression: i // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/binaryExpression.kt b/idea/idea-frontend-fir/testData/components/expressionType/binaryExpression.kt index fa89fbff8f9..c4e34f1dbab 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/binaryExpression.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/binaryExpression.kt @@ -1,6 +1,5 @@ val x = 1 + 2 -// RESULT +// RESULT // expression: 1 + 2 // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/breakExpression.kt b/idea/idea-frontend-fir/testData/components/expressionType/breakExpression.kt index bb19092e2bb..76819150ae7 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/breakExpression.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/breakExpression.kt @@ -3,8 +3,7 @@ fun x(): Int { break } } -// RESULT +// RESULT // expression: break // type: kotlin.Nothing - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/forExpression.kt b/idea/idea-frontend-fir/testData/components/expressionType/forExpression.kt index 60c61653d7c..573ed368f8e 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/forExpression.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/forExpression.kt @@ -1,8 +1,7 @@ fun x(): Int { for(i in 1..2) {} } -// RESULT +// RESULT // expression: for(i in 1..2) {} // type: kotlin.Unit - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/functionCall.kt b/idea/idea-frontend-fir/testData/components/expressionType/functionCall.kt index 04c50d16756..1b13c05a025 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/functionCall.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/functionCall.kt @@ -1,7 +1,6 @@ val a = 12 val x = 12.toByte() -// RESULT +// RESULT // expression: 12.toByte() // type: kotlin.Byte - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/inParens.kt b/idea/idea-frontend-fir/testData/components/expressionType/inParens.kt index 4ac23c00ca2..29b384c0f42 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/inParens.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/inParens.kt @@ -1,6 +1,5 @@ val x = (1 + 2) + 3 -// RESULT +// RESULT // expression: (1 + 2) // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplate.kt b/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplate.kt index 004ce964ce5..fce9d334d66 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplate.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplate.kt @@ -1,7 +1,6 @@ val a = 10 val x = "abc${a}defg" -// RESULT +// RESULT // expression: a // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplateWithBinrary.kt b/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplateWithBinrary.kt index 5be24f40895..e5d1a373bd7 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplateWithBinrary.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/insideStringTemplateWithBinrary.kt @@ -1,7 +1,6 @@ val a = 10 val x = "abc${a + 20}defg" -// RESULT +// RESULT // expression: a // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/intLiteral.kt b/idea/idea-frontend-fir/testData/components/expressionType/intLiteral.kt index cc9cdd9cccf..b910fb77b6e 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/intLiteral.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/intLiteral.kt @@ -1,6 +1,5 @@ val x = 1 -// RESULT +// RESULT // expression: 1 // type: kotlin.Int - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/property.kt b/idea/idea-frontend-fir/testData/components/expressionType/property.kt index 827a6f9e6ae..73d10ea4fbd 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/property.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/property.kt @@ -1,7 +1,6 @@ val a = 10 val x = 1 -// RESULT +// RESULT // expression: val x = 1 // type: kotlin.Unit - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/returnExpression.kt b/idea/idea-frontend-fir/testData/components/expressionType/returnExpression.kt index 158272facd3..f73e8976105 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/returnExpression.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/returnExpression.kt @@ -1,8 +1,7 @@ fun x(): Int { return 1 } -// RESULT +// RESULT // expression: return 1 // type: kotlin.Nothing - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/stringLiteral.kt b/idea/idea-frontend-fir/testData/components/expressionType/stringLiteral.kt index a8239a8098c..780aaea518e 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/stringLiteral.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/stringLiteral.kt @@ -1,6 +1,5 @@ val x = "abc" -// RESULT +// RESULT // expression: "abc" // type: kotlin.String - diff --git a/idea/idea-frontend-fir/testData/components/expressionType/whileExpression.kt b/idea/idea-frontend-fir/testData/components/expressionType/whileExpression.kt index 938ae5b08c7..61aad1166cd 100644 --- a/idea/idea-frontend-fir/testData/components/expressionType/whileExpression.kt +++ b/idea/idea-frontend-fir/testData/components/expressionType/whileExpression.kt @@ -1,8 +1,7 @@ fun x(): Int { while(true) {} } -// RESULT +// RESULT // expression: while(true) {} // type: kotlin.Unit - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/inOtherFile.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/inOtherFile.kt index 479bfd1624d..bae86371fdc 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/inOtherFile.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/inOtherFile.kt @@ -9,11 +9,10 @@ abstract class B { abstract fun foo(x: String): Int } -// RESULT +// RESULT // ALL: // B.foo(x: Int): Int // DIRECT: // B.foo(x: Int): Int - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride.kt index 99b7dac969a..3ace33c3f1e 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride.kt @@ -22,8 +22,8 @@ interface D { fun foo(x: String) } -// RESULT +// RESULT // ALL: // C.foo(x: String): Unit // D.foo(x: String): Unit @@ -31,4 +31,3 @@ interface D { // DIRECT: // C.foo(x: String): Unit // D.foo(x: String): Unit - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride2.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride2.kt index 22fd5063883..47dc67a2f05 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride2.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/intersectionOverride2.kt @@ -22,8 +22,8 @@ interface D { fun foo(x: String) } -// RESULT +// RESULT // ALL: // C.foo(x: String): Unit // D.foo(x: String): Unit @@ -31,4 +31,3 @@ interface D { // DIRECT: // C.foo(x: String): Unit // D.foo(x: String): Unit - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/javaAccessors.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/javaAccessors.kt index 6c0557445e8..81e44610ddf 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/javaAccessors.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/javaAccessors.kt @@ -16,12 +16,11 @@ abstract class C { abstract val x: Int } -// RESULT +// RESULT // ALL: // B.x: Int // C.x: Int // DIRECT: // B.x: Int - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/multipleInterfaces.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/multipleInterfaces.kt index c8a275368af..37de6ce6b3f 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/multipleInterfaces.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/multipleInterfaces.kt @@ -25,8 +25,8 @@ interface D { fun foo(x: String) } -// RESULT +// RESULT // ALL: // B.foo(x: String): Unit // C.foo(x: String): Unit @@ -36,4 +36,3 @@ interface D { // B.foo(x: String): Unit // C.foo(x: String): Unit // D.foo(x: String): Unit - diff --git a/idea/idea-frontend-fir/testData/components/overridenDeclarations/sequenceOfOverrides.kt b/idea/idea-frontend-fir/testData/components/overridenDeclarations/sequenceOfOverrides.kt index 17f583a8244..5f9e7adcacc 100644 --- a/idea/idea-frontend-fir/testData/components/overridenDeclarations/sequenceOfOverrides.kt +++ b/idea/idea-frontend-fir/testData/components/overridenDeclarations/sequenceOfOverrides.kt @@ -18,8 +18,8 @@ open class D { open fun foo(x: Int) {} } -// RESULT +// RESULT // ALL: // B.foo(x: Int): Unit // C.foo(x: Int): Unit @@ -27,4 +27,3 @@ open class D { // DIRECT: // B.foo(x: Int): Unit - diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.kt similarity index 91% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.kt index 2ce8ba20e3a..bd4bc9b1524 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.kt @@ -1,8 +1,9 @@ // RUNTIME -class: kotlin/Lazy +// class: kotlin/Lazy -// SYMBOLS: +// RESULT +/* KtFirNamedClassOrObjectSymbol: annotationClassIds: [] annotations: [] @@ -21,3 +22,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [KtFirTypeParameterSymbol(T)] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.kt similarity index 92% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.kt index 37c08aa8c28..3de352f72b4 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.kt @@ -1,8 +1,9 @@ // RUNTIME -class: java/lang/String +// class: java/lang/String -// SYMBOLS: +// RESULT +/* KtFirNamedClassOrObjectSymbol: annotationClassIds: [] annotations: [] @@ -21,3 +22,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.kt similarity index 74% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.kt index c28030f53cf..4c9b75ff70c 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.kt @@ -1,11 +1,13 @@ // RUNTIME -callable: kotlin/LazyThreadSafetyMode.SYNCHRONIZED +// callable: kotlin/LazyThreadSafetyMode.SYNCHRONIZED -// SYMBOLS: +// RESULT +/* KtFirEnumEntrySymbol: annotatedType: [] kotlin/LazyThreadSafetyMode containingEnumClassIdIfNonLocal: kotlin/LazyThreadSafetyMode name: SYNCHRONIZED origin: LIBRARY symbolKind: MEMBER +*/ diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.kt similarity index 89% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.kt index eff23d693cc..d0214a57e37 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.kt @@ -1,6 +1,7 @@ -callable: kotlin/collections/List.get +// callable: kotlin/collections/List.get -// SYMBOLS: +// RESULT +/* KtFirFunctionSymbol: annotatedType: [] E annotationClassIds: [] @@ -21,3 +22,4 @@ KtFirFunctionSymbol: typeParameters: [] valueParameters: [KtFirFunctionValueParameterSymbol(index)] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.kt similarity index 94% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.kt index 69fc5b3c7aa..b54822d4288 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.kt @@ -1,6 +1,7 @@ -callable: kotlin/collections/List.listIterator +// callable: kotlin/collections/List.listIterator -// SYMBOLS: +// RESULT +/* KtFirFunctionSymbol: annotatedType: [] kotlin/collections/ListIterator annotationClassIds: [] @@ -42,3 +43,4 @@ KtFirFunctionSymbol: typeParameters: [] valueParameters: [KtFirFunctionValueParameterSymbol(index)] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.txt b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.kt similarity index 87% rename from idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.txt rename to idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.kt index 7295a95bc27..667f624c480 100644 --- a/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.txt +++ b/idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.kt @@ -1,6 +1,7 @@ -class: kotlin/collections/MutableMap.MutableEntry +// class: kotlin/collections/MutableMap.MutableEntry -// SYMBOLS: +// RESULT +/* KtFirNamedClassOrObjectSymbol: annotationClassIds: [] annotations: [] @@ -19,3 +20,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: MEMBER typeParameters: [KtFirTypeParameterSymbol(K), KtFirTypeParameterSymbol(V)] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolByReference/accessorField.kt b/idea/idea-frontend-fir/testData/symbolByReference/accessorField.kt index fd5ca20e60c..99811654c9d 100644 --- a/idea/idea-frontend-fir/testData/symbolByReference/accessorField.kt +++ b/idea/idea-frontend-fir/testData/symbolByReference/accessorField.kt @@ -2,4 +2,14 @@ var x: Int = 0 get() = field set(value) { field = value - } \ No newline at end of file + } + +// RESULT +/* +KtFirBackingFieldSymbol: + annotatedType: [] kotlin/Int + name: field + origin: PROPERTY_BACKING_FIELD + owningProperty: KtFirKotlinPropertySymbol(x) + symbolKind: LOCAL +*/ diff --git a/idea/idea-frontend-fir/testData/symbolByReference/constructorViaTypeAlias.kt b/idea/idea-frontend-fir/testData/symbolByReference/constructorViaTypeAlias.kt index a4cd967257e..071a76770ca 100644 --- a/idea/idea-frontend-fir/testData/symbolByReference/constructorViaTypeAlias.kt +++ b/idea/idea-frontend-fir/testData/symbolByReference/constructorViaTypeAlias.kt @@ -3,8 +3,8 @@ fun x() { val a = ArrayList(listOf(1)) } -// RESULT +// RESULT /* KtFirConstructorSymbol: annotatedType: [] java/util/ArrayList @@ -19,4 +19,3 @@ KtFirConstructorSymbol: valueParameters: [KtFirConstructorValueParameterSymbol(c)] visibility: PUBLIC */ - diff --git a/idea/idea-frontend-fir/testData/symbolPointer/class.kt b/idea/idea-frontend-fir/testData/symbolPointer/class.kt index 018baa7dadc..ec99d3b7c71 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/class.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/class.kt @@ -1,7 +1,8 @@ class A { } -// SYMBOLS: +// RESULT +/* KtFirNamedClassOrObjectSymbol: annotationClassIds: [] annotations: [] @@ -20,3 +21,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/classPrimaryConstructor.kt b/idea/idea-frontend-fir/testData/symbolPointer/classPrimaryConstructor.kt index 46e128b40bb..6783f671562 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/classPrimaryConstructor.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/classPrimaryConstructor.kt @@ -1,7 +1,8 @@ class A() { } -// SYMBOLS: +// RESULT +/* KtFirConstructorSymbol: annotatedType: [] A annotationClassIds: [] @@ -33,3 +34,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/classSecondaryConstructors.kt b/idea/idea-frontend-fir/testData/symbolPointer/classSecondaryConstructors.kt index 5562cb78688..c56d0b32f18 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/classSecondaryConstructors.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/classSecondaryConstructors.kt @@ -3,7 +3,8 @@ class A() { constructor(y: Int, z: String) : this(y) } -// SYMBOLS: +// RESULT +/* KtFirConstructorSymbol: annotatedType: [] A annotationClassIds: [] @@ -91,3 +92,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/enum.kt b/idea/idea-frontend-fir/testData/symbolPointer/enum.kt index 9eae962aeb7..4863e3e79bd 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/enum.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/enum.kt @@ -2,7 +2,8 @@ enum class X { Y, Z; } -// SYMBOLS: +// RESULT +/* KtFirEnumEntrySymbol: annotatedType: [] X containingEnumClassIdIfNonLocal: X @@ -35,3 +36,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/memberFunctions.kt b/idea/idea-frontend-fir/testData/symbolPointer/memberFunctions.kt index 51398d940f0..3317fdda835 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/memberFunctions.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/memberFunctions.kt @@ -3,7 +3,8 @@ class A { fun y() } -// SYMBOLS: +// RESULT +/* KtFirFunctionSymbol: annotatedType: [] kotlin/Int annotationClassIds: [] @@ -64,3 +65,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/memberProperties.kt b/idea/idea-frontend-fir/testData/symbolPointer/memberProperties.kt index b789e12ba3a..04c0166925c 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/memberProperties.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/memberProperties.kt @@ -3,7 +3,8 @@ class A { val Int.y get() = this } -// SYMBOLS: +// RESULT +/* KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int annotationClassIds: [] @@ -84,3 +85,4 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/topLevelFunctions.kt b/idea/idea-frontend-fir/testData/symbolPointer/topLevelFunctions.kt index 6a6af8012fc..7af8f072c9d 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/topLevelFunctions.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/topLevelFunctions.kt @@ -1,7 +1,8 @@ fun x(): Int = 10 fun y() {} -// SYMBOLS: +// RESULT +/* KtFirFunctionSymbol: annotatedType: [] kotlin/Int annotationClassIds: [] @@ -43,3 +44,4 @@ KtFirFunctionSymbol: typeParameters: [] valueParameters: [] visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/testData/symbolPointer/topLevelProperties.kt b/idea/idea-frontend-fir/testData/symbolPointer/topLevelProperties.kt index baa16ea7dde..d664a191afc 100644 --- a/idea/idea-frontend-fir/testData/symbolPointer/topLevelProperties.kt +++ b/idea/idea-frontend-fir/testData/symbolPointer/topLevelProperties.kt @@ -1,7 +1,8 @@ val x: Int = 10 val Int.y get() = this -// SYMBOLS: +// RESULT +/* KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int annotationClassIds: [] @@ -63,3 +64,4 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: TOP_LEVEL visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/AbstractSymbolByFqNameTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/AbstractSymbolByFqNameTest.kt index f86a3e0ae1c..7a144ca3b12 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/AbstractSymbolByFqNameTest.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/AbstractSymbolByFqNameTest.kt @@ -14,12 +14,13 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File +import java.nio.file.Paths abstract class AbstractSymbolByFqNameTest : KotlinLightCodeInsightFixtureTestCase() { protected fun doTest(path: String) { val fakeKtFile = myFixture.configureByText("file.kt", "fun a() {}") as KtFile - val symbolData = SymbolByFqName.getSymbolDataFromFile(path) + val symbolData = SymbolByFqName.getSymbolDataFromFile(Paths.get(path)) val renderedSymbols = executeOnPooledThreadInReadAction { analyze(fakeKtFile) { diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/SymbolByFqName.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/SymbolByFqName.kt index be8690b764c..2ec6f57a2b7 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/SymbolByFqName.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/SymbolByFqName.kt @@ -13,12 +13,17 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import java.io.File +import java.nio.file.Path object SymbolByFqName { - fun getSymbolDataFromFile(filePath: String): SymbolData { - val testFileText = FileUtil.loadFile(File(filePath)) - val identifier = testFileText.lineSequence().first { line -> SymbolData.identifiers.any { line.startsWith(it) } } - return SymbolData.create(identifier) + fun getSymbolDataFromFile(filePath: Path): SymbolData { + val testFileText = FileUtil.loadFile(filePath.toFile()) + val identifier = testFileText.lineSequence().first { line -> + SymbolData.identifiers.any { identifier -> + line.startsWith(identifier) || line.startsWith("// $identifier") + } + } + return SymbolData.create(identifier.removePrefix("// ")) } fun textWithRenderedSymbolData(filePath: String, rendered: String): String = buildString { diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferencePointerRestoreTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferencePointerRestoreTest.kt new file mode 100644 index 00000000000..a9aaedcfe89 --- /dev/null +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferencePointerRestoreTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.frontend.api.symbols + +import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession +import org.jetbrains.kotlin.idea.references.mainReference +import org.jetbrains.kotlin.idea.test.framework.TestFileStructure +import org.jetbrains.kotlin.psi.KtNameReferenceExpression + +abstract class AbstractSymbolByReferencePointerRestoreTest : AbstractSymbolPointerRestoreTest() { + override fun KtAnalysisSession.collectSymbols(fileStructure: TestFileStructure): List { + val referenceExpression = getElementOfTypeAtCaret() + return listOfNotNull(referenceExpression.mainReference.resolveToSymbol()) + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferenceTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferenceTest.kt index 4f42f4f4572..eb17689979e 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferenceTest.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolByReferenceTest.kt @@ -27,7 +27,8 @@ abstract class AbstractSymbolByReferenceTest : AbstractKtIdeaTest() { val actual = TestStructureRenderer.render( fileStructure, - TestStructureExpectedDataBlock(renderedSymbol) + TestStructureExpectedDataBlock(renderedSymbol), + renderingMode = TestStructureRenderer.RenderingMode.ALL_BLOCKS_IN_MULTI_LINE_COMMENT, ) KotlinTestUtils.assertEqualsToFile(fileStructure.filePath.toFile(), actual) } diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromLibraryPointerRestoreTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromLibraryPointerRestoreTest.kt index e37308593af..b09356e3673 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromLibraryPointerRestoreTest.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromLibraryPointerRestoreTest.kt @@ -7,11 +7,12 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.SymbolByFqName +import org.jetbrains.kotlin.idea.test.framework.TestFileStructure import org.jetbrains.kotlin.psi.KtFile abstract class AbstractSymbolFromLibraryPointerRestoreTest : AbstractSymbolPointerRestoreTest() { - override fun KtAnalysisSession.collectSymbols(filePath: String, ktFile: KtFile): List { - val symbolData = SymbolByFqName.getSymbolDataFromFile(filePath) + override fun KtAnalysisSession.collectSymbols(fileStructure: TestFileStructure): List { + val symbolData = SymbolByFqName.getSymbolDataFromFile(fileStructure.filePath) return with(symbolData) { toSymbols() } } } \ No newline at end of file diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromSourcePointerRestoreTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromSourcePointerRestoreTest.kt index c787524b279..0cae2839aa1 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromSourcePointerRestoreTest.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolFromSourcePointerRestoreTest.kt @@ -6,13 +6,14 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession +import org.jetbrains.kotlin.idea.test.framework.TestFileStructure import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType abstract class AbstractSymbolFromSourcePointerRestoreTest : AbstractSymbolPointerRestoreTest() { - override fun KtAnalysisSession.collectSymbols(filePath: String, ktFile: KtFile): List = - ktFile.collectDescendantsOfType().map { declaration -> + override fun KtAnalysisSession.collectSymbols(fileStructure: TestFileStructure): List = + fileStructure.mainKtFile.collectDescendantsOfType().map { declaration -> declaration.getSymbol() } } \ No newline at end of file diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolPointerRestoreTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolPointerRestoreTest.kt index be9b931d685..d77aabfbe33 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolPointerRestoreTest.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/AbstractSymbolPointerRestoreTest.kt @@ -7,74 +7,81 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.command.CommandProcessor -import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.editor.Document import com.intellij.psi.PsiDocumentManager -import org.jetbrains.kotlin.idea.executeOnPooledThreadInReadAction +import org.jetbrains.kotlin.idea.analyseOnPooledThreadInReadAction import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession -import org.jetbrains.kotlin.idea.frontend.api.SymbolByFqName -import org.jetbrains.kotlin.idea.frontend.api.analyze import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.framework.AbstractKtIdeaTest +import org.jetbrains.kotlin.idea.test.framework.TestFileStructure +import org.jetbrains.kotlin.idea.test.framework.TestStructureExpectedDataBlock +import org.jetbrains.kotlin.idea.test.framework.TestStructureRenderer import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.util.suffixIfNot -import org.junit.Assert -import java.io.File -abstract class AbstractSymbolPointerRestoreTest : KotlinLightCodeInsightFixtureTestCase() { - abstract fun KtAnalysisSession.collectSymbols(filePath: String, ktFile: KtFile): List +abstract class AbstractSymbolPointerRestoreTest : AbstractKtIdeaTest() { + abstract fun KtAnalysisSession.collectSymbols(fileStructure: TestFileStructure): List - protected fun doTest(path: String) { - val file = File(path) - val ktFile = myFixture.configureByText(file.name.suffixIfNot(".kt"), FileUtil.loadFile(file)) as KtFile - - val pointersWithRendered = executeOnPooledThreadInReadAction { - analyze(ktFile) { - collectSymbols(path, ktFile).map { symbol -> - PointerWithRenderedSymbol( - symbol.createPointer(), - DebugSymbolRenderer.render(symbol) - ) - } + override fun doTestByFileStructure(fileStructure: TestFileStructure) { + val pointersWithRendered = analyseOnPooledThreadInReadAction(fileStructure.mainKtFile) { + collectSymbols(fileStructure).map { symbol -> + PointerWithRenderedSymbol( + symbol.createPointer(), + DebugSymbolRenderer.render(symbol) + ) } } - val actual = SymbolByFqName.textWithRenderedSymbolData( - path, - pointersWithRendered.joinToString(separator = "\n") { it.rendered }, + val actual = TestStructureRenderer.render( + fileStructure, + TestStructureExpectedDataBlock(values = pointersWithRendered.map { it.rendered }), + renderingMode = TestStructureRenderer.RenderingMode.ALL_BLOCKS_IN_MULTI_LINE_COMMENT, ) - KotlinTestUtils.assertEqualsToFile(File(path), actual) + KotlinTestUtils.assertEqualsToFile(fileStructure.filePath.toFile(), actual) + doOutOfBlockModification(fileStructure.mainKtFile) + restoreSymbolsInOtherReadActionAndCompareResults(fileStructure, pointersWithRendered) + } + + private fun restoreSymbolsInOtherReadActionAndCompareResults( + fileStructure: TestFileStructure, + pointersWithRendered: List + ) { + val restored = analyseOnPooledThreadInReadAction(fileStructure.mainKtFile) { + pointersWithRendered.map { (pointer, expectedRender) -> + val restored = pointer.restoreSymbol() ?: error("Symbol $expectedRender was not not restored correctly") + DebugSymbolRenderer.render(restored) + } + } + val actualRestored = TestStructureRenderer.render( + fileStructure, + TestStructureExpectedDataBlock(values = restored), + renderingMode = TestStructureRenderer.RenderingMode.ALL_BLOCKS_IN_MULTI_LINE_COMMENT, + ) + + KotlinTestUtils.assertEqualsToFile(fileStructure.filePath.toFile(), actualRestored) + } + + private fun doOutOfBlockModification(ktFile: KtFile) { CommandProcessor.getInstance().runUndoTransparentAction { runWriteAction { - KtPsiFactory(ktFile).apply { - ktFile.add(createNewLine(lineBreaks = 2)) - ktFile.add(createProperty("val aaaaaa: Int = 10")) - } - PsiDocumentManager.getInstance(project).apply { - commitDocument(getDocument(ktFile) ?: error("Cannot find document for ktFile")) - } + val document = PsiDocumentManager.getInstance(project).getDocument(ktFile) ?: error("Cannot find document for ktFile") + val initialText = ktFile.text + val ktPsiFactory = KtPsiFactory(ktFile) + ktFile.add(ktPsiFactory.createNewLine(lineBreaks = 2)) + ktFile.add(ktPsiFactory.createProperty("val aaaaaa: Int = 10")) + commitDocument(document) + document.setText(initialText) + commitDocument(document) } } + } - // another read action - executeOnPooledThreadInReadAction { - analyze(ktFile) { - val restored = pointersWithRendered.map { (pointer, expectedRender) -> - val restored = pointer.restoreSymbol() ?: error("Symbol $expectedRender was not not restored correctly") - DebugSymbolRenderer.render(restored) - } - val actualRestored = SymbolByFqName.textWithRenderedSymbolData( - path, - restored.joinToString(separator = "\n"), - ) - - KotlinTestUtils.assertEqualsToFile(File(path), actualRestored) - } - } + private fun commitDocument(document: Document) { + PsiDocumentManager.getInstance(project).commitDocument(document) } } diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolByReferencePointerRestoreTestGenerated.java b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolByReferencePointerRestoreTestGenerated.java new file mode 100644 index 00000000000..3a727beb6c0 --- /dev/null +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolByReferencePointerRestoreTestGenerated.java @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.frontend.api.symbols; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/idea-frontend-fir/testData/symbolByReference") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class SymbolByReferencePointerRestoreTestGenerated extends AbstractSymbolByReferencePointerRestoreTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("accessorField.kt") + public void testAccessorField() throws Exception { + runTest("idea/idea-frontend-fir/testData/symbolByReference/accessorField.kt"); + } + + public void testAllFilesPresentInSymbolByReference() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/testData/symbolByReference"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("constructorViaTypeAlias.kt") + public void testConstructorViaTypeAlias() throws Exception { + runTest("idea/idea-frontend-fir/testData/symbolByReference/constructorViaTypeAlias.kt"); + } +} diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolFromLibraryPointerRestoreTestGenerated.java b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolFromLibraryPointerRestoreTestGenerated.java index 4db3f42be10..585f8ef1f45 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolFromLibraryPointerRestoreTestGenerated.java +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolFromLibraryPointerRestoreTestGenerated.java @@ -26,36 +26,36 @@ public class SymbolFromLibraryPointerRestoreTestGenerated extends AbstractSymbol } public void testAllFilesPresentInResoreSymbolFromLibrary() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary"), Pattern.compile("^(.+)\\.txt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary"), Pattern.compile("^(.+)\\.kt$"), null, true); } - @TestMetadata("class.txt") + @TestMetadata("class.kt") public void testClass() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/class.kt"); } - @TestMetadata("classFromJdk.txt") + @TestMetadata("classFromJdk.kt") public void testClassFromJdk() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/classFromJdk.kt"); } - @TestMetadata("enumEntry.txt") + @TestMetadata("enumEntry.kt") public void testEnumEntry() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/enumEntry.kt"); } - @TestMetadata("memberFunction.txt") + @TestMetadata("memberFunction.kt") public void testMemberFunction() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunction.kt"); } - @TestMetadata("memberFunctionWithOverloads.txt") + @TestMetadata("memberFunctionWithOverloads.kt") public void testMemberFunctionWithOverloads() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/memberFunctionWithOverloads.kt"); } - @TestMetadata("nestedClass.txt") + @TestMetadata("nestedClass.kt") public void testNestedClass() throws Exception { - runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.txt"); + runTest("idea/idea-frontend-fir/testData/resoreSymbolFromLibrary/nestedClass.kt"); } } diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/test/framework/TestStructureRenderer.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/test/framework/TestStructureRenderer.kt index 81a3a283c9a..7288556bd14 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/test/framework/TestStructureRenderer.kt +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/test/framework/TestStructureRenderer.kt @@ -8,19 +8,25 @@ package org.jetbrains.kotlin.idea.test.framework import org.jetbrains.kotlin.psi.psiUtil.getStartOffsetIn object TestStructureRenderer { - fun render(testStructure: TestFileStructure, vararg expectedData: TestStructureExpectedDataBlock): String = buildString { + fun render( + testStructure: TestFileStructure, + vararg expectedData: TestStructureExpectedDataBlock, + renderingMode: RenderingMode = RenderingMode.EVERY_LINE_WITH_SINGLE_LINE_COMMENT, + ): String = + render(testStructure, expectedData.toList(), renderingMode) + + fun render( + testStructure: TestFileStructure, + expectedData: List, + renderingMode: RenderingMode = RenderingMode.EVERY_LINE_WITH_SINGLE_LINE_COMMENT + ): String = buildString { renderFiles(testStructure) - renderExpectedData(expectedData.toList()) + appendLine() + renderExpectedData(expectedData, renderingMode) renderCaretSymbol(testStructure) renderExpressionTag(testStructure) } - fun render(testStructure: TestFileStructure, expectedData: List): String = buildString { - renderFiles(testStructure) - renderExpectedData(expectedData) - renderCaretSymbol(testStructure) - } - private fun StringBuilder.renderCaretSymbol(testStructure: TestFileStructure) { testStructure.caretPosition?.let { position -> insert(position, KtTest.CARET_SYMBOL) @@ -45,29 +51,33 @@ object TestStructureRenderer { } } - private fun StringBuilder.renderExpectedData(expectedData: List) { - if (expectedData.isNotEmpty()) { - appendLine(KtTest.RESULT_DIRECTIVE) - appendLine() - expectedData.forEach { block -> - renderExpectedDataBlock(block) + private fun StringBuilder.renderExpectedData(expectedData: List, renderingMode: RenderingMode) { + if (expectedData.isEmpty()) return + appendLine(KtTest.RESULT_DIRECTIVE) + if (renderingMode == RenderingMode.ALL_BLOCKS_IN_MULTI_LINE_COMMENT) { + appendLine("/*") + } + expectedData.forEachIndexed { index, block -> + renderExpectedDataBlock( + block, + asSingleLineComment = renderingMode == RenderingMode.EVERY_LINE_WITH_SINGLE_LINE_COMMENT + ) + if (index != expectedData.lastIndex) { appendLine() } } + if (renderingMode == RenderingMode.ALL_BLOCKS_IN_MULTI_LINE_COMMENT) { + appendLine("*/") + } } - private fun StringBuilder.renderExpectedDataBlock(block: TestStructureExpectedDataBlock) { - block.name?.let { name -> appendLine("// $name") } - block.values.forEach { value -> - if (value.lines().size > 1) { - appendLine( - """|/* - |${value.trim()} - |*/ - """.trimMargin() - ) - } else { - appendLine("// $value") + private fun StringBuilder.renderExpectedDataBlock(block: TestStructureExpectedDataBlock, asSingleLineComment: Boolean) { + val singleLineCommentPrefix = if (asSingleLineComment) "// " else "" + block.name?.let { name -> appendLine("$singleLineCommentPrefix$name") } + block.values.forEachIndexed { index, value -> + appendLine("$singleLineCommentPrefix${value.trim()}") + if (index != block.values.lastIndex && !asSingleLineComment) { + appendLine() } } } @@ -77,4 +87,9 @@ object TestStructureRenderer { appendLine(file.psiFile.text) appendLine() } + + enum class RenderingMode { + EVERY_LINE_WITH_SINGLE_LINE_COMMENT, + ALL_BLOCKS_IN_MULTI_LINE_COMMENT + } } \ No newline at end of file