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
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user