diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index d84882d0171..30810504b5f 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -54,7 +54,7 @@ class ClassGenerator( fun generateClass(ktClassOrObject: KtPureClassOrObject): IrClass { val classDescriptor = ktClassOrObject.findClassDescriptor(this.context.bindingContext) - val startOffset = ktClassOrObject.getStartOffsetOfClassDeclarationKeywordOrNull() ?: ktClassOrObject.pureStartOffset + val startOffset = ktClassOrObject.getStartOffsetOfClassDeclarationOrNull() ?: ktClassOrObject.pureStartOffset val endOffset = ktClassOrObject.pureEndOffset return context.symbolTable.declareClass( diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/declarationStartOffset.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/declarationStartOffset.kt index f3e0ba65c89..86b2405548b 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/declarationStartOffset.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/declarationStartOffset.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.psi2ir.generators import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments import org.jetbrains.kotlin.psi2ir.getChildTokenStartOffsetOrNull private val FUNCTION_DECL_TOKENS = TokenSet.create(KtTokens.FUN_KEYWORD) @@ -26,9 +27,9 @@ internal fun KtPureElement.getStartOffsetOfFunctionDeclarationKeywordOrNull(): I else -> null } -internal fun KtPureClassOrObject.getStartOffsetOfClassDeclarationKeywordOrNull(): Int? = +internal fun KtPureClassOrObject.getStartOffsetOfClassDeclarationOrNull(): Int? = when (this) { - is KtClassOrObject -> getChildTokenStartOffsetOrNull(CLASS_DECL_TOKENS) + is KtClassOrObject -> startOffsetSkippingComments else -> null } diff --git a/compiler/testData/ir/sourceRanges/comments.txt b/compiler/testData/ir/sourceRanges/comments.txt index 517510d5724..a2745e9bef3 100644 --- a/compiler/testData/ir/sourceRanges/comments.txt +++ b/compiler/testData/ir/sourceRanges/comments.txt @@ -5,8 +5,8 @@ @1:0..33:1 BLOCK_BODY @1:0..33:1 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @1:0..33:1 INSTANCE_INITIALIZER_CALL classDescriptor='Foo' - @8:10..10:36 CLASS CLASS name:Inner modality:FINAL visibility:public flags:inner superTypes:[kotlin.Any] - @8:10..10:36 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Foo.Inner flags: + @8:4..10:36 CLASS CLASS name:Inner modality:FINAL visibility:public flags:inner superTypes:[kotlin.Any] + @8:4..10:36 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Foo.Inner flags: @8:60..10:36 CONSTRUCTOR visibility:private <> ($this:Foo, x:kotlin.Int) returnType:Foo.Inner flags:primary @8:52..79 VALUE_PARAMETER name: type:Foo flags: @8:72..78 VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: diff --git a/compiler/testData/ir/sourceRanges/declarations/classes.txt b/compiler/testData/ir/sourceRanges/declarations/classes.txt index 5bc5cb2590b..86d8f460620 100644 --- a/compiler/testData/ir/sourceRanges/declarations/classes.txt +++ b/compiler/testData/ir/sourceRanges/declarations/classes.txt @@ -12,8 +12,8 @@ @0:0..11 VALUE_PARAMETER name: type:kotlin.Any flags: @0:0..11 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: @0:0..11 VALUE_PARAMETER name: type:kotlin.Any flags: - @4:0..11 CLASS CLASS name:Test2 modality:FINAL visibility:internal flags: superTypes:[kotlin.Any] - @4:0..11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2 flags: + @3:0..4:11 CLASS CLASS name:Test2 modality:FINAL visibility:internal flags: superTypes:[kotlin.Any] + @3:0..4:11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2 flags: @4:0..11 CONSTRUCTOR visibility:public <> () returnType:Test2 flags:primary @3:0..4:11 BLOCK_BODY @3:0..4:11 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -38,8 +38,8 @@ @10:0..11 VALUE_PARAMETER name: type:kotlin.Any flags: @10:0..11 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: @10:0..11 VALUE_PARAMETER name: type:kotlin.Any flags: - @14:0..11 CLASS CLASS name:Test4 modality:FINAL visibility:public flags: superTypes:[kotlin.Any] - @14:0..11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test4 flags: + @13:0..14:11 CLASS CLASS name:Test4 modality:FINAL visibility:public flags: superTypes:[kotlin.Any] + @13:0..14:11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test4 flags: @14:0..11 CONSTRUCTOR visibility:public <> () returnType:Test4 flags:primary @13:0..14:11 BLOCK_BODY @13:0..14:11 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -51,8 +51,8 @@ @13:0..14:11 VALUE_PARAMETER name: type:kotlin.Any flags: @14:0..11 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: @13:0..14:11 VALUE_PARAMETER name: type:kotlin.Any flags: - @18:0..11 CLASS ENUM_CLASS name:Test5 modality:FINAL visibility:public flags: superTypes:[kotlin.Enum] - @18:0..11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test5 flags: + @17:0..18:11 CLASS ENUM_CLASS name:Test5 modality:FINAL visibility:public flags: superTypes:[kotlin.Enum] + @17:0..18:11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test5 flags: @18:0..11 CONSTRUCTOR visibility:private <> () returnType:Test5 flags:primary @17:0..18:11 BLOCK_BODY @17:0..18:11 ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -79,13 +79,13 @@ @17:0..18:11 VALUE_PARAMETER name: type:kotlin.Enum flags: @18:0..11 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum) returnType:kotlin.String flags: @17:0..18:11 VALUE_PARAMETER name: type:kotlin.Enum flags: - @18:0..11 FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array flags: - @18:0..11 SYNTHETIC_BODY kind=ENUM_VALUES + @17:0..18:11 FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array flags: + @17:0..18:11 SYNTHETIC_BODY kind=ENUM_VALUES @-1:-1..-1 FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:Test5 flags: @-1:-1..-1 VALUE_PARAMETER name:value index:0 type:kotlin.String flags: - @18:0..11 SYNTHETIC_BODY kind=ENUM_VALUEOF - @22:0..11 CLASS ANNOTATION_CLASS name:Test6 modality:FINAL visibility:public flags: superTypes:[kotlin.Annotation] - @22:0..11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test6 flags: + @17:0..18:11 SYNTHETIC_BODY kind=ENUM_VALUEOF + @21:0..22:11 CLASS ANNOTATION_CLASS name:Test6 modality:FINAL visibility:public flags: superTypes:[kotlin.Annotation] + @21:0..22:11 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test6 flags: @22:0..11 CONSTRUCTOR visibility:public <> () returnType:Test6 flags:primary @22:0..11 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: @21:0..22:11 VALUE_PARAMETER name: type:kotlin.Any flags: diff --git a/compiler/testData/ir/sourceRanges/declarations/kt29862.kt b/compiler/testData/ir/sourceRanges/declarations/kt29862.kt new file mode 100644 index 00000000000..24ad17c157d --- /dev/null +++ b/compiler/testData/ir/sourceRanges/declarations/kt29862.kt @@ -0,0 +1,15 @@ +abstract class Test1( + val x: Int +) { +} + +public +abstract +class Test2( + val x: Int +) { + inner + class TestInner( + val x: Int + ) +} diff --git a/compiler/testData/ir/sourceRanges/declarations/kt29862.txt b/compiler/testData/ir/sourceRanges/declarations/kt29862.txt new file mode 100644 index 00000000000..50cdbffbe43 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/declarations/kt29862.txt @@ -0,0 +1,74 @@ +@0:0..15:0 FILE fqName: fileName:/kt29862.kt + @0:0..3:1 CLASS CLASS name:Test1 modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any] + @0:0..3:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test1 flags: + @0:9..3:1 CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:Test1 flags:primary + @1:4..14 VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: + @0:0..3:1 BLOCK_BODY + @0:0..3:1 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + @0:0..3:1 INSTANCE_INITIALIZER_CALL classDescriptor='Test1' + @1:4..14 PROPERTY name:x visibility:public modality:FINAL flags:val + @1:4..14 FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public flags:final + @1:4..14 EXPRESSION_BODY + @1:4..14 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER + @1:4..14 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test1) returnType:kotlin.Int flags: + @1:4..14 VALUE_PARAMETER name: type:Test1 flags: + @1:4..14 BLOCK_BODY + @1:4..14 RETURN type=kotlin.Nothing from='(): Int' + @1:4..14 GET_FIELD 'x: Int' type=kotlin.Int origin=null + @1:4..14 GET_VAR 'this@Test1: Test1' type=Test1 origin=null + @0:9..3:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: + @0:0..3:1 VALUE_PARAMETER name: type:kotlin.Any flags: + @0:9..3:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + @0:9..3:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int flags: + @0:0..3:1 VALUE_PARAMETER name: type:kotlin.Any flags: + @0:9..3:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: + @0:0..3:1 VALUE_PARAMETER name: type:kotlin.Any flags: + @5:0..14:1 CLASS CLASS name:Test2 modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any] + @5:0..14:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2 flags: + @7:0..14:1 CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:Test2 flags:primary + @8:4..14 VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: + @5:0..14:1 BLOCK_BODY + @5:0..14:1 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + @5:0..14:1 INSTANCE_INITIALIZER_CALL classDescriptor='Test2' + @8:4..14 PROPERTY name:x visibility:public modality:FINAL flags:val + @8:4..14 FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public flags:final + @8:4..14 EXPRESSION_BODY + @8:4..14 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER + @8:4..14 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test2) returnType:kotlin.Int flags: + @8:4..14 VALUE_PARAMETER name: type:Test2 flags: + @8:4..14 BLOCK_BODY + @8:4..14 RETURN type=kotlin.Nothing from='(): Int' + @8:4..14 GET_FIELD 'x: Int' type=kotlin.Int origin=null + @8:4..14 GET_VAR 'this@Test2: Test2' type=Test2 origin=null + @10:4..13:5 CLASS CLASS name:TestInner modality:FINAL visibility:public flags:inner superTypes:[kotlin.Any] + @10:4..13:5 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2.TestInner flags: + @11:4..13:5 CONSTRUCTOR visibility:public <> ($this:Test2, x:kotlin.Int) returnType:Test2.TestInner flags:primary + @11:19..13:5 VALUE_PARAMETER name: type:Test2 flags: + @12:8..18 VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: + @10:4..13:5 BLOCK_BODY + @10:4..13:5 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + @10:4..13:5 INSTANCE_INITIALIZER_CALL classDescriptor='TestInner' + @12:8..18 PROPERTY name:x visibility:public modality:FINAL flags:val + @12:8..18 FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public flags:final + @12:8..18 EXPRESSION_BODY + @12:8..18 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER + @12:8..18 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test2.TestInner) returnType:kotlin.Int flags: + @12:8..18 VALUE_PARAMETER name: type:Test2.TestInner flags: + @12:8..18 BLOCK_BODY + @12:8..18 RETURN type=kotlin.Nothing from='(): Int' + @12:8..18 GET_FIELD 'x: Int' type=kotlin.Int origin=null + @12:8..18 GET_VAR 'this@TestInner: TestInner' type=Test2.TestInner origin=null + @11:4..13:5 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: + @10:4..13:5 VALUE_PARAMETER name: type:kotlin.Any flags: + @11:4..13:5 VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + @11:4..13:5 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int flags: + @10:4..13:5 VALUE_PARAMETER name: type:kotlin.Any flags: + @11:4..13:5 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: + @10:4..13:5 VALUE_PARAMETER name: type:kotlin.Any flags: + @7:0..14:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: + @5:0..14:1 VALUE_PARAMETER name: type:kotlin.Any flags: + @7:0..14:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + @7:0..14:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int flags: + @5:0..14:1 VALUE_PARAMETER name: type:kotlin.Any flags: + @7:0..14:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: + @5:0..14:1 VALUE_PARAMETER name: type:kotlin.Any flags: diff --git a/compiler/testData/ir/sourceRanges/declarations/synthesizedDataClassMembers.txt b/compiler/testData/ir/sourceRanges/declarations/synthesizedDataClassMembers.txt index 3db9c2f0b9d..f85c042cdf5 100644 --- a/compiler/testData/ir/sourceRanges/declarations/synthesizedDataClassMembers.txt +++ b/compiler/testData/ir/sourceRanges/declarations/synthesizedDataClassMembers.txt @@ -1,6 +1,6 @@ @0:0..4:1 FILE fqName: fileName:/synthesizedDataClassMembers.kt - @0:5..4:1 CLASS CLASS name:C modality:FINAL visibility:public flags:data superTypes:[kotlin.Any] - @0:5..4:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:C flags: + @0:0..4:1 CLASS CLASS name:C modality:FINAL visibility:public flags:data superTypes:[kotlin.Any] + @0:0..4:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:C flags: @0:5..4:1 CONSTRUCTOR visibility:public <> (x:kotlin.Int, y:kotlin.String, z:kotlin.Any) returnType:C flags:primary @1:8..18 VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: @2:8..21 VALUE_PARAMETER name:y index:1 type:kotlin.String flags: diff --git a/compiler/testData/ir/sourceRanges/kt17108.txt b/compiler/testData/ir/sourceRanges/kt17108.txt index c668b117bc8..62fb03456c4 100644 --- a/compiler/testData/ir/sourceRanges/kt17108.txt +++ b/compiler/testData/ir/sourceRanges/kt17108.txt @@ -1,6 +1,6 @@ @0:0..26:1 FILE fqName: fileName:/kt17108.kt - @4:7..26:1 CLASS INTERFACE name:Boolean modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any] - @4:7..26:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Boolean flags: + @4:0..26:1 CLASS INTERFACE name:Boolean modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any] + @4:0..26:1 VALUE_PARAMETER INSTANCE_RECEIVER name: type:Boolean flags: @8:20..38 FUN name:not visibility:public modality:ABSTRACT <> ($this:Boolean) returnType:Boolean flags: @8:4..38 VALUE_PARAMETER name: type:Boolean flags: @13:10..42 FUN name:and visibility:public modality:ABSTRACT <> ($this:Boolean, other:Boolean) returnType:Boolean flags: diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrSourceRangesTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrSourceRangesTestCaseGenerated.java index fdc1dc2682d..80cc7b2260b 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrSourceRangesTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrSourceRangesTestCaseGenerated.java @@ -76,6 +76,11 @@ public class IrSourceRangesTestCaseGenerated extends AbstractIrSourceRangesTestC runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides.kt"); } + @TestMetadata("kt29862.kt") + public void testKt29862() throws Exception { + runTest("compiler/testData/ir/sourceRanges/declarations/kt29862.kt"); + } + @TestMetadata("primaryConstructors.kt") public void testPrimaryConstructors() throws Exception { runTest("compiler/testData/ir/sourceRanges/declarations/primaryConstructors.kt");