Store file-level annotations in IrFile (should be on some descriptor, really).
This commit is contained in:
committed by
Dmitry Petrov
parent
e23325b014
commit
4e270ef487
@@ -33,9 +33,12 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
||||
val irFile = IrFileImpl(fileEntry, fileName, packageFragmentDescriptor)
|
||||
context.sourceManager.putFileEntry(irFile, fileEntry)
|
||||
|
||||
for (ktAnnotationEntry in ktFile.annotationEntries) {
|
||||
irFile.addAnnotation(getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry))
|
||||
}
|
||||
|
||||
for (ktDeclaration in ktFile.declarations) {
|
||||
val irDeclaration = irDeclarationGenerator.generateMemberDeclaration(ktDeclaration)
|
||||
irFile.addDeclaration(irDeclaration)
|
||||
irFile.addDeclaration(irDeclarationGenerator.generateMemberDeclaration(ktDeclaration))
|
||||
}
|
||||
|
||||
irModule.addFile(irFile)
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import java.util.*
|
||||
|
||||
interface IrFile : IrElement {
|
||||
val name: String
|
||||
val fileEntry: SourceLocationManager.FileEntry
|
||||
val fileAnnotations: List<AnnotationDescriptor>
|
||||
val packageFragmentDescriptor: PackageFragmentDescriptor
|
||||
val declarations: List<IrDeclaration>
|
||||
}
|
||||
@@ -33,6 +36,12 @@ class IrFileImpl(
|
||||
override val name: String,
|
||||
override val packageFragmentDescriptor: PackageFragmentDescriptor
|
||||
) : IrElementBase(0, fileEntry.maxOffset), IrFile {
|
||||
override val fileAnnotations: MutableList<AnnotationDescriptor> = SmartList()
|
||||
|
||||
fun addAnnotation(annotation: AnnotationDescriptor) {
|
||||
fileAnnotations.add(annotation)
|
||||
}
|
||||
|
||||
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
||||
|
||||
fun addDeclaration(declaration: IrDeclaration) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
fun IrElement.dump(): String {
|
||||
@@ -41,10 +42,28 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
||||
val printer = Printer(out, " ")
|
||||
val elementRenderer = RenderIrElementVisitor()
|
||||
|
||||
companion object {
|
||||
val ANNOTATIONS_RENDERER = DescriptorRenderer.withOptions { verbose = true }
|
||||
}
|
||||
|
||||
override fun visitElement(element: IrElement, data: String) {
|
||||
element.dumpLabeledSubTree(data)
|
||||
}
|
||||
|
||||
override fun visitFile(declaration: IrFile, data: String) {
|
||||
declaration.dumpLabeledElementWith(data) {
|
||||
if (declaration.fileAnnotations.isNotEmpty()) {
|
||||
printer.println("fileAnnotations:")
|
||||
indented {
|
||||
declaration.fileAnnotations.forEach {
|
||||
printer.println(ANNOTATIONS_RENDERER.renderAnnotation(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
declaration.declarations.forEach { it.accept(this, "") }
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction, data: String) {
|
||||
visitFunctionWithParameters(declaration, data)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
@file:JvmName("FileWithAnnotations")
|
||||
|
||||
fun foo() {}
|
||||
|
||||
val bar = 42
|
||||
@@ -0,0 +1,8 @@
|
||||
FILE /fileWithAnnotations.kt
|
||||
fileAnnotations:
|
||||
@kotlin.jvm.JvmName(name = "FileWithAnnotations")
|
||||
FUN public fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
PROPERTY public val bar: kotlin.Int = 42
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='42'
|
||||
@@ -202,6 +202,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fileWithAnnotations.kt")
|
||||
public void testFileWithAnnotations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/fileWithAnnotations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localDelegatedProperties.kt")
|
||||
public void testLocalDelegatedProperties() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/localDelegatedProperties.kt");
|
||||
|
||||
Reference in New Issue
Block a user