Implement raw FIR builder (initial version)
All necessary FIR tree implementations were created FIR renderer & three first builder tests were added #KT-24013 Fixed
This commit is contained in:
@@ -5,5 +5,390 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.builder
|
||||
|
||||
class RawFirBuilder {
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAnnotationCallImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirBlockBodyImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub
|
||||
import org.jetbrains.kotlin.fir.types.FirUserType
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.impl.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.modalityModifierType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class RawFirBuilder(val session: FirSession) {
|
||||
|
||||
fun buildFirFile(file: KtFile): FirFile {
|
||||
return file.accept(Visitor(), Unit) as FirFile
|
||||
}
|
||||
|
||||
private val KtModifierListOwner.visibility: Visibility
|
||||
get() {
|
||||
val modifierType = visibilityModifierType()
|
||||
return when (modifierType) {
|
||||
KtTokens.PUBLIC_KEYWORD -> Visibilities.PUBLIC
|
||||
KtTokens.PROTECTED_KEYWORD -> Visibilities.PROTECTED
|
||||
KtTokens.INTERNAL_KEYWORD -> Visibilities.INTERNAL
|
||||
KtTokens.PRIVATE_KEYWORD -> Visibilities.PRIVATE
|
||||
else -> Visibilities.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
private val KtDeclaration.modality: Modality
|
||||
get() {
|
||||
val modifierType = modalityModifierType()
|
||||
return when (modifierType) {
|
||||
KtTokens.FINAL_KEYWORD -> Modality.FINAL
|
||||
KtTokens.SEALED_KEYWORD -> Modality.SEALED
|
||||
KtTokens.ABSTRACT_KEYWORD -> Modality.ABSTRACT
|
||||
KtTokens.OPEN_KEYWORD -> Modality.OPEN
|
||||
else -> Modality.FINAL // FIX ME
|
||||
}
|
||||
}
|
||||
|
||||
private inner class Visitor : KtVisitor<FirElement, Unit>() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <R : FirElement> KtElement?.convertSafe(): R? =
|
||||
this?.accept(this@Visitor, Unit) as? R
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <R : FirElement> KtElement.convert(): R =
|
||||
this.accept(this@Visitor, Unit) as R
|
||||
|
||||
private fun KtTypeReference?.toFirOrImplicitType(): FirType =
|
||||
convertSafe<FirUserType>() ?: FirImplicitTypeImpl(session, this)
|
||||
|
||||
private fun KtTypeReference?.toFirOrErrorType(): FirType =
|
||||
convertSafe<FirUserType>() ?: FirErrorTypeImpl(session, this, false)
|
||||
|
||||
private fun KtExpression?.toFirBody(): FirBody? =
|
||||
convertSafe<FirExpression>()?.let { it as? FirBody ?: FirExpressionBodyImpl(session, it) }
|
||||
|
||||
private fun KtPropertyAccessor?.toFirPropertyAccessor(
|
||||
property: KtProperty,
|
||||
propertyType: FirType,
|
||||
isGetter: Boolean
|
||||
): FirPropertyAccessor {
|
||||
if (this == null) {
|
||||
return FirDefaultPropertyAccessor(session, property, isGetter, propertyType)
|
||||
}
|
||||
val firAccessor = FirPropertyAccessorImpl(
|
||||
session,
|
||||
this,
|
||||
isGetter,
|
||||
visibility,
|
||||
returnTypeReference.toFirOrImplicitType(),
|
||||
bodyExpression.toFirBody()
|
||||
)
|
||||
extractAnnotationsTo(firAccessor)
|
||||
extractValueParametersTo(firAccessor, propertyType)
|
||||
if (!isGetter && firAccessor.valueParameters.isEmpty()) {
|
||||
firAccessor.valueParameters += FirDefaultSetterValueParameter(session, this, propertyType)
|
||||
}
|
||||
return firAccessor
|
||||
}
|
||||
|
||||
private fun KtParameter.toFirValueParameter(defaultType: FirType? = null): FirValueParameter {
|
||||
val firValueParameter = FirValueParameterImpl(
|
||||
session,
|
||||
this,
|
||||
hasValOrVar(),
|
||||
nameAsSafeName,
|
||||
when {
|
||||
typeReference != null -> typeReference.toFirOrErrorType()
|
||||
defaultType != null -> defaultType
|
||||
else -> null.toFirOrErrorType()
|
||||
},
|
||||
defaultValue?.convert(),
|
||||
isCrossinline = hasModifier(KtTokens.CROSSINLINE_KEYWORD),
|
||||
isNoinline = hasModifier(KtTokens.NOINLINE_KEYWORD),
|
||||
isVararg = isVarArg
|
||||
)
|
||||
extractAnnotationsTo(firValueParameter)
|
||||
return firValueParameter
|
||||
}
|
||||
|
||||
private fun KtModifierListOwner.extractAnnotationsTo(container: FirAbstractAnnotatedDeclaration) {
|
||||
for (annotationEntry in annotationEntries) {
|
||||
container.annotations += annotationEntry.convert<FirAnnotationCall>()
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(container: FirAbstractMemberDeclaration) {
|
||||
for (typeParameter in typeParameters) {
|
||||
container.typeParameters += typeParameter.convert<FirTypeParameter>()
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtDeclarationWithBody.extractValueParametersTo(
|
||||
container: FirAbstractFunction,
|
||||
defaultType: FirType? = null
|
||||
) {
|
||||
for (valueParameter in valueParameters) {
|
||||
container.valueParameters += valueParameter.toFirValueParameter(defaultType)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitKtFile(file: KtFile, data: Unit): FirElement {
|
||||
val firFile = FirFileImpl(session, file, file.name, file.packageFqName)
|
||||
for (annotationEntry in file.annotationEntries) {
|
||||
firFile.annotations += annotationEntry.convert<FirAnnotationCall>()
|
||||
}
|
||||
for (importDirective in file.importDirectives) {
|
||||
firFile.imports += FirImportImpl(
|
||||
session,
|
||||
importDirective,
|
||||
importDirective.importedFqName,
|
||||
importDirective.isAllUnder,
|
||||
importDirective.aliasName
|
||||
)
|
||||
}
|
||||
for (declaration in file.declarations) {
|
||||
firFile.declarations += declaration.convert<FirDeclaration>()
|
||||
}
|
||||
return firFile
|
||||
}
|
||||
|
||||
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement {
|
||||
val classKind = when (classOrObject) {
|
||||
is KtObjectDeclaration -> ClassKind.OBJECT
|
||||
is KtClass -> when {
|
||||
classOrObject.isInterface() -> ClassKind.INTERFACE
|
||||
classOrObject.isEnum() -> ClassKind.ENUM_CLASS
|
||||
classOrObject.isAnnotation() -> ClassKind.ANNOTATION_CLASS
|
||||
else -> ClassKind.CLASS
|
||||
}
|
||||
else -> throw AssertionError("Unexpected class or object: ${classOrObject.text}")
|
||||
}
|
||||
val firClass = FirClassImpl(
|
||||
session,
|
||||
classOrObject,
|
||||
classOrObject.nameAsSafeName,
|
||||
classOrObject.visibility,
|
||||
classOrObject.modality,
|
||||
classKind,
|
||||
isCompanion = (classOrObject as? KtObjectDeclaration)?.isCompanion() == true,
|
||||
isData = (classOrObject as? KtClass)?.isData() == true
|
||||
)
|
||||
classOrObject.extractAnnotationsTo(firClass)
|
||||
classOrObject.extractTypeParametersTo(firClass)
|
||||
for (superTypeListEntry in classOrObject.superTypeListEntries) {
|
||||
when (superTypeListEntry) {
|
||||
is KtSuperTypeEntry -> {
|
||||
firClass.superTypes += superTypeListEntry.typeReference.toFirOrErrorType()
|
||||
}
|
||||
is KtSuperTypeCallEntry -> {
|
||||
firClass.superTypes += superTypeListEntry.calleeExpression.typeReference.toFirOrErrorType()
|
||||
// TODO: primary constructor!
|
||||
}
|
||||
is KtDelegatedSuperTypeEntry -> {
|
||||
val type = superTypeListEntry.typeReference.toFirOrErrorType()
|
||||
firClass.superTypes += FirDelegatedTypeImpl(
|
||||
type,
|
||||
superTypeListEntry.delegateExpression.convertSafe()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (declaration in classOrObject.declarations) {
|
||||
firClass.declarations += declaration.convert<FirDeclaration>()
|
||||
}
|
||||
return firClass
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(typeAlias: KtTypeAlias, data: Unit): FirElement {
|
||||
val firTypeAlias = FirTypeAliasImpl(
|
||||
session,
|
||||
typeAlias,
|
||||
typeAlias.nameAsSafeName,
|
||||
typeAlias.visibility,
|
||||
typeAlias.getTypeReference().toFirOrErrorType()
|
||||
)
|
||||
typeAlias.extractAnnotationsTo(firTypeAlias)
|
||||
return firTypeAlias
|
||||
}
|
||||
|
||||
override fun visitNamedFunction(function: KtNamedFunction, data: Unit): FirElement {
|
||||
val firFunction = FirMemberFunctionImpl(
|
||||
session,
|
||||
function,
|
||||
function.nameAsSafeName,
|
||||
function.visibility,
|
||||
function.modality,
|
||||
function.hasModifier(KtTokens.OVERRIDE_KEYWORD),
|
||||
function.hasModifier(KtTokens.OPERATOR_KEYWORD),
|
||||
function.hasModifier(KtTokens.INFIX_KEYWORD),
|
||||
function.hasModifier(KtTokens.INLINE_KEYWORD),
|
||||
function.receiverTypeReference.convertSafe(),
|
||||
function.typeReference.toFirOrImplicitType(),
|
||||
function.bodyExpression.toFirBody()
|
||||
)
|
||||
function.extractAnnotationsTo(firFunction)
|
||||
function.extractTypeParametersTo(firFunction)
|
||||
for (valueParameter in function.valueParameters) {
|
||||
firFunction.valueParameters += valueParameter.convert<FirValueParameter>()
|
||||
}
|
||||
return firFunction
|
||||
}
|
||||
|
||||
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor, data: Unit): FirElement {
|
||||
val firConstructor = FirSecondaryConstructorImpl(
|
||||
session,
|
||||
constructor,
|
||||
constructor.visibility,
|
||||
constructor.getDelegationCall().convert(),
|
||||
constructor.bodyExpression.toFirBody()
|
||||
)
|
||||
constructor.extractValueParametersTo(firConstructor)
|
||||
return super.visitSecondaryConstructor(constructor, data)
|
||||
}
|
||||
|
||||
override fun visitAnonymousInitializer(initializer: KtAnonymousInitializer, data: Unit): FirElement {
|
||||
return FirAnonymousInitializerImpl(
|
||||
session,
|
||||
initializer,
|
||||
initializer.body.toFirBody()
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitProperty(property: KtProperty, data: Unit): FirElement {
|
||||
val propertyType = property.typeReference.toFirOrImplicitType()
|
||||
val firProperty = FirMemberPropertyImpl(
|
||||
session,
|
||||
property,
|
||||
property.nameAsSafeName,
|
||||
property.visibility,
|
||||
property.modality,
|
||||
property.hasModifier(KtTokens.OVERRIDE_KEYWORD),
|
||||
property.receiverTypeReference.convertSafe(),
|
||||
propertyType,
|
||||
property.isVar,
|
||||
property.initializer?.convert(),
|
||||
property.getter.toFirPropertyAccessor(property, propertyType, isGetter = true),
|
||||
property.setter.toFirPropertyAccessor(property, propertyType, isGetter = false),
|
||||
property.delegateExpression?.convert()
|
||||
)
|
||||
property.extractAnnotationsTo(firProperty)
|
||||
property.extractTypeParametersTo(firProperty)
|
||||
return firProperty
|
||||
}
|
||||
|
||||
override fun visitTypeReference(typeReference: KtTypeReference, data: Unit): FirElement {
|
||||
val typeElement = typeReference.typeElement
|
||||
val isNullable = typeElement is KtNullableType
|
||||
|
||||
fun KtTypeElement?.unwrapNullable(): KtTypeElement? =
|
||||
if (this is KtNullableType) this.innerType.unwrapNullable() else this
|
||||
|
||||
val unwrappedElement = typeElement.unwrapNullable()
|
||||
val firType = when (unwrappedElement) {
|
||||
is KtDynamicType -> FirDynamicTypeImpl(session, typeReference, isNullable)
|
||||
is KtUserType -> {
|
||||
val referenceExpression = unwrappedElement.referenceExpression
|
||||
if (referenceExpression != null) {
|
||||
val userType = FirUserTypeImpl(
|
||||
session, typeReference, isNullable,
|
||||
referenceExpression.getReferencedNameAsName()
|
||||
)
|
||||
for (typeArgument in unwrappedElement.typeArguments) {
|
||||
userType.arguments += typeArgument.convert<FirTypeProjection>()
|
||||
}
|
||||
userType
|
||||
} else {
|
||||
FirErrorTypeImpl(session, typeReference, isNullable)
|
||||
}
|
||||
}
|
||||
is KtFunctionType -> {
|
||||
val functionType = FirFunctionTypeImpl(
|
||||
session,
|
||||
typeReference,
|
||||
isNullable,
|
||||
unwrappedElement.receiverTypeReference.convertSafe(),
|
||||
unwrappedElement.returnTypeReference.toFirOrImplicitType()
|
||||
)
|
||||
for (valueParameter in unwrappedElement.parameters) {
|
||||
functionType.valueParameters += valueParameter.convert<FirValueParameter>()
|
||||
}
|
||||
functionType
|
||||
}
|
||||
null -> FirErrorTypeImpl(session, typeReference, isNullable)
|
||||
else -> throw AssertionError("Unexpected type element: ${unwrappedElement.text}")
|
||||
}
|
||||
|
||||
for (annotationEntry in typeReference.annotationEntries) {
|
||||
firType.annotations += annotationEntry.convert<FirAnnotationCall>()
|
||||
}
|
||||
return firType
|
||||
}
|
||||
|
||||
override fun visitAnnotationEntry(annotationEntry: KtAnnotationEntry, data: Unit): FirElement {
|
||||
return FirAnnotationCallImpl(
|
||||
session,
|
||||
annotationEntry,
|
||||
annotationEntry.useSiteTarget?.getAnnotationUseSiteTarget(),
|
||||
annotationEntry.typeReference.toFirOrErrorType()
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit): FirElement {
|
||||
val firTypeParameter = FirTypeParameterImpl(
|
||||
session,
|
||||
parameter,
|
||||
parameter.nameAsSafeName,
|
||||
parameter.variance
|
||||
)
|
||||
parameter.extractAnnotationsTo(firTypeParameter)
|
||||
val extendsBound = parameter.extendsBound
|
||||
// TODO: handle where, here or (preferable) in parent
|
||||
if (extendsBound != null) {
|
||||
firTypeParameter.bounds += extendsBound.convert<FirType>()
|
||||
}
|
||||
return firTypeParameter
|
||||
}
|
||||
|
||||
override fun visitTypeProjection(typeProjection: KtTypeProjection, data: Unit): FirElement {
|
||||
val projectionKind = typeProjection.projectionKind
|
||||
if (projectionKind == KtProjectionKind.STAR) {
|
||||
return FirStarProjectionImpl(session, typeProjection)
|
||||
}
|
||||
val typeReference = typeProjection.typeReference
|
||||
val firType = typeReference.toFirOrErrorType()
|
||||
return FirTypeProjectionWithVarianceImpl(
|
||||
session,
|
||||
typeProjection,
|
||||
when (projectionKind) {
|
||||
KtProjectionKind.IN -> Variance.IN_VARIANCE
|
||||
KtProjectionKind.OUT -> Variance.OUT_VARIANCE
|
||||
KtProjectionKind.NONE -> Variance.INVARIANT
|
||||
KtProjectionKind.STAR -> throw AssertionError("* should not be here")
|
||||
},
|
||||
firType
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitParameter(parameter: KtParameter, data: Unit): FirElement =
|
||||
parameter.toFirValueParameter()
|
||||
|
||||
override fun visitBlockExpression(expression: KtBlockExpression, data: Unit): FirElement {
|
||||
return FirBlockBodyImpl(session, expression)
|
||||
}
|
||||
|
||||
override fun visitExpression(expression: KtExpression, data: Unit): FirElement {
|
||||
return FirExpressionStub(session, expression)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,22 @@
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
|
||||
interface FirElement {
|
||||
val psi: PsiElement?
|
||||
|
||||
val session: FirSession
|
||||
|
||||
fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitElement(this, data)
|
||||
|
||||
fun accept(visitor: FirVisitorVoid) =
|
||||
accept(visitor, null)
|
||||
|
||||
fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {}
|
||||
|
||||
fun acceptChildren(visitor: FirVisitorVoid) =
|
||||
acceptChildren(visitor, null)
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
||||
private val printer = Printer(builder)
|
||||
|
||||
private var lineBeginning = true
|
||||
|
||||
private fun print(vararg objects: Any) {
|
||||
if (lineBeginning) {
|
||||
lineBeginning = false
|
||||
printer.print(*objects)
|
||||
} else {
|
||||
printer.printWithNoIndent(*objects)
|
||||
}
|
||||
}
|
||||
|
||||
private fun println(vararg objects: Any) {
|
||||
print(*objects)
|
||||
printer.printlnWithNoIndent()
|
||||
lineBeginning = true
|
||||
}
|
||||
|
||||
private fun pushIndent() {
|
||||
printer.pushIndent()
|
||||
}
|
||||
|
||||
private fun popIndent() {
|
||||
printer.popIndent()
|
||||
}
|
||||
|
||||
override fun visitElement(element: FirElement) {
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
override fun visitFile(file: FirFile) {
|
||||
println("FILE: ${file.name}")
|
||||
pushIndent()
|
||||
super.visitFile(file)
|
||||
popIndent()
|
||||
}
|
||||
|
||||
private fun List<FirElement>.renderSeparated() {
|
||||
for ((index, element) in this.withIndex()) {
|
||||
if (index > 0) {
|
||||
print(", ")
|
||||
}
|
||||
element.accept(this@FirRenderer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<FirValueParameter>.renderParameters() {
|
||||
print("(")
|
||||
renderSeparated()
|
||||
print(")")
|
||||
}
|
||||
|
||||
private fun List<FirAnnotationCall>.renderAnnotations() {
|
||||
for (annotation in this) {
|
||||
visitAnnotationCall(annotation)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Variance.renderVariance() {
|
||||
label.let {
|
||||
print(it)
|
||||
if (it.isNotEmpty()) {
|
||||
print(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallableMember(callableMember: FirCallableMember) {
|
||||
visitMemberDeclaration(callableMember)
|
||||
val receiverType = callableMember.receiverType
|
||||
if (receiverType != null) {
|
||||
receiverType.accept(this)
|
||||
print(".")
|
||||
}
|
||||
if (callableMember is FirFunction) {
|
||||
callableMember.valueParameters.renderParameters()
|
||||
} else if (callableMember is FirProperty) {
|
||||
print(if (callableMember.isVar) "(var)" else "(val)")
|
||||
}
|
||||
print(": ")
|
||||
callableMember.returnType.accept(this)
|
||||
}
|
||||
|
||||
override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
memberDeclaration.annotations.renderAnnotations()
|
||||
if (memberDeclaration.typeParameters.isNotEmpty()) {
|
||||
print("<")
|
||||
memberDeclaration.typeParameters.renderSeparated()
|
||||
print("> ")
|
||||
}
|
||||
print(memberDeclaration.visibility.toString() + " " + memberDeclaration.modality.name.toLowerCase() + " ")
|
||||
if (memberDeclaration is FirCallableMember && memberDeclaration.isOverride) {
|
||||
print("override ")
|
||||
}
|
||||
if (memberDeclaration is FirNamedFunction) {
|
||||
if (memberDeclaration.isOperator) {
|
||||
print("operator ")
|
||||
}
|
||||
if (memberDeclaration.isInfix) {
|
||||
print("infix ")
|
||||
}
|
||||
if (memberDeclaration.isInline) {
|
||||
print("inline ")
|
||||
}
|
||||
}
|
||||
visitNamedDeclaration(memberDeclaration)
|
||||
}
|
||||
|
||||
override fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration) {
|
||||
visitDeclaration(namedDeclaration)
|
||||
print(" " + namedDeclaration.name)
|
||||
}
|
||||
|
||||
override fun visitDeclaration(declaration: FirDeclaration) {
|
||||
print(
|
||||
when (declaration) {
|
||||
is FirClass -> "class"
|
||||
is FirTypeAlias -> "typealias"
|
||||
is FirNamedFunction -> "function"
|
||||
is FirProperty -> "property"
|
||||
else -> "unknown"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(enumEntry: FirEnumEntry) {
|
||||
visitClass(enumEntry)
|
||||
}
|
||||
|
||||
override fun visitClass(klass: FirClass) {
|
||||
visitMemberDeclaration(klass)
|
||||
val attributes = listOfNotNull(
|
||||
"companion".takeIf { klass.isCompanion },
|
||||
"data".takeIf { klass.isData }
|
||||
)
|
||||
print(attributes.joinToString(prefix = "(", postfix = ")"))
|
||||
if (klass.superTypes.isNotEmpty()) {
|
||||
print(" : ")
|
||||
klass.superTypes.renderSeparated()
|
||||
}
|
||||
println(" {")
|
||||
pushIndent()
|
||||
for (declaration in klass.declarations) {
|
||||
declaration.accept(this)
|
||||
println()
|
||||
}
|
||||
popIndent()
|
||||
println("}")
|
||||
}
|
||||
|
||||
override fun visitProperty(property: FirProperty) {
|
||||
visitCallableMember(property)
|
||||
property.initializer?.let {
|
||||
print(" = ")
|
||||
it.accept(this)
|
||||
}
|
||||
pushIndent()
|
||||
property.delegate?.let {
|
||||
print("by ")
|
||||
it.accept(this)
|
||||
}
|
||||
println()
|
||||
property.getter.accept(this)
|
||||
if (property.getter.body == null) {
|
||||
println()
|
||||
}
|
||||
if (property.isVar) {
|
||||
property.setter.accept(this)
|
||||
if (property.setter.body == null) {
|
||||
println()
|
||||
}
|
||||
}
|
||||
popIndent()
|
||||
}
|
||||
|
||||
override fun visitNamedFunction(namedFunction: FirNamedFunction) {
|
||||
visitCallableMember(namedFunction)
|
||||
namedFunction.body?.accept(this)
|
||||
if (namedFunction.body == null) {
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitConstructor(constructor: FirConstructor) {
|
||||
constructor.annotations.renderAnnotations()
|
||||
print(constructor.visibility.toString() + " constructor")
|
||||
constructor.valueParameters.renderParameters()
|
||||
constructor.delegatedConstructor?.accept(this)
|
||||
constructor.body?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor) {
|
||||
propertyAccessor.annotations.renderAnnotations()
|
||||
print(propertyAccessor.visibility.toString() + " ")
|
||||
print(if (propertyAccessor.isGetter) "get" else "set")
|
||||
propertyAccessor.valueParameters.renderParameters()
|
||||
print(": ")
|
||||
propertyAccessor.returnType.accept(this)
|
||||
propertyAccessor.body?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitFunction(function: FirFunction) {
|
||||
function.valueParameters.renderParameters()
|
||||
visitDeclarationWithBody(function)
|
||||
}
|
||||
|
||||
override fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer) {
|
||||
print("init")
|
||||
anonymousInitializer.body?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitDeclarationWithBody(declarationWithBody: FirDeclarationWithBody) {
|
||||
visitDeclaration(declarationWithBody)
|
||||
declarationWithBody.body?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitBody(body: FirBody) {
|
||||
println(" {")
|
||||
pushIndent()
|
||||
for (statement in body.statements) {
|
||||
statement.accept(this)
|
||||
println()
|
||||
}
|
||||
popIndent()
|
||||
println("}")
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(typeAlias: FirTypeAlias) {
|
||||
typeAlias.annotations.renderAnnotations()
|
||||
visitMemberDeclaration(typeAlias)
|
||||
print(" = ")
|
||||
typeAlias.abbreviatedType.accept(this)
|
||||
println()
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(typeParameter: FirTypeParameter) {
|
||||
typeParameter.annotations.renderAnnotations()
|
||||
typeParameter.variance.renderVariance()
|
||||
print(typeParameter.name)
|
||||
if (typeParameter.bounds.isNotEmpty()) {
|
||||
print(" : ")
|
||||
typeParameter.bounds.renderSeparated()
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypedDeclaration(typedDeclaration: FirTypedDeclaration) {
|
||||
visitDeclaration(typedDeclaration)
|
||||
}
|
||||
|
||||
override fun visitValueParameter(valueParameter: FirValueParameter) {
|
||||
valueParameter.annotations.renderAnnotations()
|
||||
if (valueParameter.isCrossinline) {
|
||||
print("crossinline ")
|
||||
}
|
||||
if (valueParameter.isNoinline) {
|
||||
print("noinline ")
|
||||
}
|
||||
if (valueParameter.isVararg) {
|
||||
print("vararg ")
|
||||
}
|
||||
print(valueParameter.name.toString() + ": ")
|
||||
valueParameter.returnType.accept(this)
|
||||
valueParameter.defaultValue?.let {
|
||||
print(" = ")
|
||||
it.accept(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitVariable(variable: FirVariable) {
|
||||
visitDeclaration(variable)
|
||||
}
|
||||
|
||||
override fun visitImport(import: FirImport) {
|
||||
visitElement(import)
|
||||
}
|
||||
|
||||
override fun visitStatement(statement: FirStatement) {
|
||||
visitElement(statement)
|
||||
}
|
||||
|
||||
override fun visitExpression(expression: FirExpression) {
|
||||
print("STUB")
|
||||
}
|
||||
|
||||
override fun visitCall(call: FirCall) {
|
||||
visitExpression(call)
|
||||
}
|
||||
|
||||
override fun visitAnnotationCall(annotationCall: FirAnnotationCall) {
|
||||
visitCall(annotationCall)
|
||||
}
|
||||
|
||||
override fun visitConstructorCall(constructorCall: FirConstructorCall) {
|
||||
visitCall(constructorCall)
|
||||
}
|
||||
|
||||
override fun visitType(type: FirType) {
|
||||
type.annotations.renderAnnotations()
|
||||
visitElement(type)
|
||||
}
|
||||
|
||||
override fun visitDelegatedType(delegatedType: FirDelegatedType) {
|
||||
delegatedType.accept(this)
|
||||
print(" by ")
|
||||
delegatedType.delegate?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitErrorType(errorType: FirErrorType) {
|
||||
visitType(errorType)
|
||||
print("<ERROR TYPE>")
|
||||
}
|
||||
|
||||
override fun visitImplicitType(implicitType: FirImplicitType) {
|
||||
print("<implicit>")
|
||||
}
|
||||
|
||||
override fun visitTypeWithNullability(typeWithNullability: FirTypeWithNullability) {
|
||||
if (typeWithNullability.isNullable) {
|
||||
print("?")
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitDynamicType(dynamicType: FirDynamicType) {
|
||||
dynamicType.annotations.renderAnnotations()
|
||||
print("<dynamic>")
|
||||
visitTypeWithNullability(dynamicType)
|
||||
}
|
||||
|
||||
override fun visitFunctionType(functionType: FirFunctionType) {
|
||||
print("( ")
|
||||
functionType.receiverType?.let {
|
||||
it.accept(this)
|
||||
print(".")
|
||||
}
|
||||
functionType.valueParameters.renderParameters()
|
||||
print(": ")
|
||||
functionType.returnType.accept(this)
|
||||
print(" )")
|
||||
visitTypeWithNullability(functionType)
|
||||
}
|
||||
|
||||
override fun visitResolvedType(resolvedType: FirResolvedType) {
|
||||
resolvedType.annotations.renderAnnotations()
|
||||
print("R/")
|
||||
print(resolvedType.type)
|
||||
print("/")
|
||||
visitTypeWithNullability(resolvedType)
|
||||
}
|
||||
|
||||
override fun visitUserType(userType: FirUserType) {
|
||||
userType.annotations.renderAnnotations()
|
||||
print(userType.name)
|
||||
if (userType.arguments.isNotEmpty()) {
|
||||
print("<")
|
||||
userType.arguments.renderSeparated()
|
||||
print(">")
|
||||
}
|
||||
visitTypeWithNullability(userType)
|
||||
}
|
||||
|
||||
override fun visitTypeProjection(typeProjection: FirTypeProjection) {
|
||||
visitElement(typeProjection)
|
||||
}
|
||||
|
||||
override fun visitTypeProjectionWithVariance(typeProjectionWithVariance: FirTypeProjectionWithVariance) {
|
||||
typeProjectionWithVariance.variance.renderVariance()
|
||||
typeProjectionWithVariance.type.accept(this)
|
||||
}
|
||||
|
||||
override fun visitStarProjection(starProjection: FirStarProjection) {
|
||||
print("*")
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -5,8 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
// Probably not a function
|
||||
@Deprecated("May be not needed")
|
||||
interface FirAnonymousInitializer : FirDeclarationWithBody {
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// Probably not a function
|
||||
interface FirAnonymousInitializer : FirDeclarationWithBody {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitAnonymousInitializer(this, data)
|
||||
}
|
||||
@@ -5,9 +5,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// Good name needed (something with receiver, type parameters, return type, and name)
|
||||
interface FirCallableMember : FirMemberDeclaration, FirTypedDeclaration {
|
||||
val receiverType: FirType
|
||||
interface FirCallableMember : @VisitedSupertype FirDeclaration, FirMemberDeclaration, FirTypedDeclaration {
|
||||
val isOverride: Boolean
|
||||
|
||||
val receiverType: FirType?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitCallableMember(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
receiverType?.accept(visitor, data)
|
||||
super<FirMemberDeclaration>.acceptChildren(visitor, data)
|
||||
returnType.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// May be all containers should be properties and not base classes
|
||||
// About descriptors: introduce something like FirDescriptor which is FirUnresolved at the beginning and FirSymbol(descriptor) at the end
|
||||
interface FirClass : FirDeclarationContainer, FirMemberDeclaration {
|
||||
// including delegated types
|
||||
val superTypes: List<FirType>
|
||||
@@ -17,4 +20,17 @@ interface FirClass : FirDeclarationContainer, FirMemberDeclaration {
|
||||
val isCompanion: Boolean
|
||||
|
||||
val isData: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitClass(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super.acceptChildren(visitor, data)
|
||||
for (superType in superTypes) {
|
||||
superType.accept(visitor, data)
|
||||
}
|
||||
for (declaration in declarations) {
|
||||
declaration.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.expressions.FirConstructorCall
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirConstructor : FirFunction {
|
||||
interface FirConstructor : FirFunction, FirAnnotationContainer {
|
||||
val delegatedConstructor: FirConstructorCall?
|
||||
|
||||
val visibility: Visibility
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitConstructor(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
delegatedConstructor?.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,10 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirDeclaration : FirElement
|
||||
interface FirDeclaration : FirElement {
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitDeclaration(this, data)
|
||||
}
|
||||
+10
-1
@@ -6,7 +6,16 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirDeclarationWithBody : FirDeclaration {
|
||||
val body: FirBody
|
||||
val body: FirBody?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitDeclarationWithBody(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
body?.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,18 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirEnumEntry : FirClass {
|
||||
val arguments: List<FirExpression>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitEnumEntry(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
for (argument in arguments) {
|
||||
argument.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// Is it necessary?
|
||||
interface FirErrorDeclaration : FirDeclaration {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitErrorDeclaration(this, data)
|
||||
}
|
||||
@@ -5,6 +5,26 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
interface FirFile : FirPackageFragment {
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface FirFile : @VisitedSupertype FirPackageFragment, FirDeclaration, FirAnnotationContainer {
|
||||
val name: String
|
||||
|
||||
val packageFqName: FqName
|
||||
|
||||
val imports: List<FirImport>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitFile(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
for (import in imports) {
|
||||
import.accept(visitor, data)
|
||||
}
|
||||
super<FirPackageFragment>.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,20 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// May be should inherit FirTypeParameterContainer
|
||||
interface FirFunction : FirDeclarationWithBody, FirAnnotationContainer {
|
||||
val valueParameters: List<FirValueParameter>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunction(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
for (parameter in valueParameters) {
|
||||
parameter.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,16 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface FirImport : FirElement {
|
||||
val importedFqName: FqName?
|
||||
|
||||
val isAllUnder: Boolean
|
||||
|
||||
val aliasName: String?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitImport(this, data)
|
||||
}
|
||||
@@ -8,9 +8,21 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirMemberDeclaration : FirTypeParameterContainer, FirNamedDeclaration, FirAnnotationContainer {
|
||||
val visibility: Visibility
|
||||
|
||||
val modality: Modality
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitMemberDeclaration(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
for (typeParameter in typeParameters) {
|
||||
typeParameter.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
interface FirNamedDeclaration : FirDeclaration {
|
||||
val name: Name
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitNamedDeclaration(this, data)
|
||||
}
|
||||
@@ -5,5 +5,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
interface FirNamedFunction : FirFunction, FirCallableMember {
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirNamedFunction : @VisitedSupertype FirFunction, FirCallableMember {
|
||||
val isOperator: Boolean
|
||||
|
||||
val isInfix: Boolean
|
||||
|
||||
val isInline: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitNamedFunction(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super<FirCallableMember>.acceptChildren(visitor, data)
|
||||
super<FirFunction>.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,16 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirPackageFragment : FirElement, FirDeclarationContainer {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitPackageFragment(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
for (declaration in declarations) {
|
||||
declaration.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// May be should not inherit FirVariable
|
||||
interface FirProperty : FirCallableMember, FirVariable {
|
||||
interface FirProperty : @VisitedSupertype FirDeclaration, FirCallableMember, FirVariable {
|
||||
// Should it be nullable or have some default?
|
||||
val getter: FirPropertyAccessor
|
||||
|
||||
val setter: FirPropertyAccessor
|
||||
|
||||
val delegate: FirExpression?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitProperty(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super<FirCallableMember>.acceptChildren(visitor, data)
|
||||
initializer?.accept(visitor, data)
|
||||
delegate?.accept(visitor, data)
|
||||
getter.accept(visitor, data)
|
||||
setter.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,21 @@
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirPropertyAccessor : FirFunction {
|
||||
interface FirPropertyAccessor : @VisitedSupertype FirFunction, FirTypedDeclaration {
|
||||
val isGetter: Boolean
|
||||
|
||||
val isSetter: Boolean get() = !isGetter
|
||||
|
||||
val visibility: Visibility
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitPropertyAccessor(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super<FirTypedDeclaration>.acceptChildren(visitor, data)
|
||||
super<FirFunction>.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,17 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirTypeAlias : FirMemberDeclaration, FirAnnotationContainer {
|
||||
val abbreviatedType: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeAlias(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
abbreviatedType.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,22 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface FirTypeParameter : FirNamedDeclaration, FirAnnotationContainer {
|
||||
val variance: Variance
|
||||
|
||||
val bounds: List<FirType>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeParameter(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
for (bound in bounds) {
|
||||
bound.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,17 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirTypedDeclaration : FirDeclaration, FirAnnotationContainer {
|
||||
val returnType: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypedDeclaration(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
returnType.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirValueParameter : FirTypedDeclaration, FirNamedDeclaration {
|
||||
interface FirValueParameter : @VisitedSupertype FirDeclaration, FirTypedDeclaration, FirNamedDeclaration {
|
||||
val isCrossinline: Boolean
|
||||
|
||||
val isNoinline: Boolean
|
||||
@@ -15,4 +17,12 @@ interface FirValueParameter : FirTypedDeclaration, FirNamedDeclaration {
|
||||
val isVararg: Boolean
|
||||
|
||||
val defaultValue: FirExpression?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitValueParameter(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super<FirTypedDeclaration>.acceptChildren(visitor, data)
|
||||
defaultValue?.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
|
||||
abstract class FirAbstractAnnotatedDeclaration(
|
||||
final override val session: FirSession,
|
||||
final override val psi: PsiElement?
|
||||
) : FirAnnotationContainer, FirDeclaration {
|
||||
final override val annotations = mutableListOf<FirAnnotationCall>()
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMember
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class FirAbstractCallableMember(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
modality: Modality,
|
||||
final override val isOverride: Boolean,
|
||||
final override val receiverType: FirType?,
|
||||
final override val returnType: FirType
|
||||
) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality), FirCallableMember
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
|
||||
abstract class FirAbstractFunction(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
final override val body: FirBody?
|
||||
) : FirAbstractAnnotatedDeclaration(session, psi), FirFunction {
|
||||
final override val valueParameters = mutableListOf<FirValueParameter>()
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class FirAbstractMemberDeclaration(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
final override val visibility: Visibility,
|
||||
final override val modality: Modality
|
||||
) : FirAbstractNamedAnnotatedDeclaration(session, psi, name), FirMemberDeclaration {
|
||||
final override val typeParameters = mutableListOf<FirTypeParameter>()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class FirAbstractNamedAnnotatedDeclaration(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
final override val name: Name
|
||||
) : FirAbstractAnnotatedDeclaration(session, psi), FirNamedDeclaration
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousInitializer
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
|
||||
class FirAnonymousInitializerImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val body: FirBody?
|
||||
) : FirAnonymousInitializer
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirClassImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
modality: Modality,
|
||||
override val classKind: ClassKind,
|
||||
override val isCompanion: Boolean,
|
||||
override val isData: Boolean
|
||||
) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality), FirClass {
|
||||
override val superTypes = mutableListOf<FirType>()
|
||||
|
||||
override val declarations = mutableListOf<FirDeclaration>()
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirUnitType
|
||||
|
||||
class FirDefaultPropertyAccessor(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val isGetter: Boolean,
|
||||
propertyType: FirType
|
||||
) : FirPropertyAccessor {
|
||||
override val visibility =
|
||||
Visibilities.UNKNOWN
|
||||
|
||||
override val valueParameters: List<FirValueParameter> =
|
||||
if (isGetter) emptyList() else listOf(FirDefaultSetterValueParameter(session, psi, propertyType))
|
||||
|
||||
override val returnType: FirType =
|
||||
if (isGetter) propertyType else FirUnitType(session, psi)
|
||||
|
||||
override val body: FirBody? =
|
||||
null
|
||||
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = emptyList()
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirDefaultSetterValueParameter(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
override val returnType: FirType
|
||||
) : FirAbstractNamedAnnotatedDeclaration(session, psi, name), FirValueParameter {
|
||||
override val isCrossinline = false
|
||||
|
||||
override val isNoinline = false
|
||||
|
||||
override val isVararg = false
|
||||
|
||||
override val defaultValue: FirExpression? = null
|
||||
|
||||
companion object {
|
||||
val name = Name.identifier("value")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirImport
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class FirFileImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
override val name: String,
|
||||
override val packageFqName: FqName
|
||||
) : FirAbstractAnnotatedDeclaration(session, psi), FirFile {
|
||||
override val imports = mutableListOf<FirImport>()
|
||||
|
||||
override val declarations = mutableListOf<FirDeclaration>()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirImport
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class FirImportImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val importedFqName: FqName?,
|
||||
override val isAllUnder: Boolean,
|
||||
override val aliasName: String?
|
||||
) : FirImport
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirMemberFunctionImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
modality: Modality,
|
||||
isOverride: Boolean,
|
||||
override val isOperator: Boolean,
|
||||
override val isInfix: Boolean,
|
||||
override val isInline: Boolean,
|
||||
receiverType: FirType?,
|
||||
returnType: FirType,
|
||||
override val body: FirBody?
|
||||
) : FirAbstractCallableMember(session, psi, name, visibility, modality, isOverride, receiverType, returnType),
|
||||
FirNamedFunction {
|
||||
override val valueParameters = mutableListOf<FirValueParameter>()
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirMemberPropertyImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
modality: Modality,
|
||||
isOverride: Boolean,
|
||||
receiverType: FirType?,
|
||||
returnType: FirType,
|
||||
override val isVar: Boolean,
|
||||
override val initializer: FirExpression?,
|
||||
override val getter: FirPropertyAccessor,
|
||||
override val setter: FirPropertyAccessor,
|
||||
override val delegate: FirExpression?
|
||||
) : FirAbstractCallableMember(session, psi, name, visibility, modality, isOverride, receiverType, returnType),
|
||||
FirProperty
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirAbstractNamedDeclaration(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val name: Name
|
||||
) : FirNamedDeclaration, FirAnnotationContainer {
|
||||
override val annotations = mutableListOf<FirAnnotationCall>()
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package org.jetbrains.kotlin.fir.declarations.impl
|
||||
|
||||
class FirPackageFragmentImpl {
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
|
||||
class FirPropertyAccessorImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
override val isGetter: Boolean,
|
||||
override val visibility: Visibility,
|
||||
override val returnType: FirType,
|
||||
body: FirBody?
|
||||
) : FirAbstractFunction(session, psi, body), FirPropertyAccessor
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.expressions.FirConstructorCall
|
||||
|
||||
class FirSecondaryConstructorImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
override val visibility: Visibility,
|
||||
override val delegatedConstructor: FirConstructorCall?,
|
||||
body: FirBody?
|
||||
) : FirAbstractFunction(session, psi, body), FirConstructor
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeAlias
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirTypeAliasImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
override val abbreviatedType: FirType
|
||||
) : FirAbstractMemberDeclaration(session, psi, name, visibility, Modality.FINAL), FirTypeAlias
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class FirTypeParameterImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
name: Name,
|
||||
override val variance: Variance
|
||||
) : FirAbstractNamedAnnotatedDeclaration(session, psi, name), FirTypeParameter {
|
||||
override val bounds = mutableListOf<FirType>()
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.declarations.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirValueParameterImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
val isProperty: Boolean,
|
||||
name: Name,
|
||||
override val returnType: FirType,
|
||||
override val defaultValue: FirExpression?,
|
||||
override val isCrossinline: Boolean,
|
||||
override val isNoinline: Boolean,
|
||||
override val isVararg: Boolean
|
||||
) : FirAbstractNamedAnnotatedDeclaration(session, psi, name), FirValueParameter
|
||||
@@ -7,9 +7,19 @@ package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirAnnotationCall : FirCall {
|
||||
val annotationType: FirType
|
||||
|
||||
val useSiteTarget: AnnotationUseSiteTarget
|
||||
// May be should be not-null (with correct default target)
|
||||
val useSiteTarget: AnnotationUseSiteTarget?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitAnnotationCall(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
annotationType.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirAnnotationContainer {
|
||||
val annotations: List<FirAnnotationCall>
|
||||
|
||||
fun <D> acceptAnnotations(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
for (annotation in annotations) {
|
||||
annotation.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
// Should we have FirBlockBody / FirExpressionBody?
|
||||
interface FirBody {
|
||||
// Is it FirExpression or just FirElement?
|
||||
interface FirBody : FirExpression {
|
||||
val statements: List<FirStatement>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitBody(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
for (statement in statements) {
|
||||
statement.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirCall : FirExpression {
|
||||
val arguments: List<FirExpression>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitCall(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
for (argument in arguments) {
|
||||
argument.accept(visitor, data)
|
||||
}
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,16 @@
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirConstructorCall : FirCall {
|
||||
val constructedType: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitConstructorCall(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
constructedType.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirExpression : FirStatement {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitExpression(this, data)
|
||||
}
|
||||
@@ -6,6 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirStatement : FirElement {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitStatement(this, data)
|
||||
}
|
||||
@@ -5,9 +5,25 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirVariable : @VisitedSupertype FirDeclaration, FirTypedDeclaration, FirNamedDeclaration, FirStatement {
|
||||
val isVar: Boolean
|
||||
|
||||
val isVal: Boolean
|
||||
get() = !isVar
|
||||
|
||||
interface FirVariable : FirTypedDeclaration, FirNamedDeclaration, FirStatement {
|
||||
val initializer: FirExpression?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitVariable(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
initializer?.accept(visitor, data)
|
||||
super<FirTypedDeclaration>.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.expressions.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
|
||||
class FirAnnotationCallImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val useSiteTarget: AnnotationUseSiteTarget?,
|
||||
override val annotationType: FirType
|
||||
) : FirAnnotationCall {
|
||||
override val arguments = mutableListOf<FirExpression>()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.expressions.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
|
||||
class FirBlockBodyImpl(override val session: FirSession, override val psi: PsiElement?) : FirBody {
|
||||
override val statements = mutableListOf<FirStatement>()
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.expressions.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
|
||||
class FirExpressionBodyImpl(
|
||||
override val session: FirSession,
|
||||
private val expression: FirExpression
|
||||
) : FirBody {
|
||||
override val statements = listOf(expression)
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = expression.psi
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.expressions.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
|
||||
@Deprecated("Temporary class until we have normal expressions")
|
||||
class FirExpressionStub(override val session: FirSession, override val psi: PsiElement?) : FirExpression
|
||||
@@ -6,7 +6,18 @@
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirDelegatedType : FirExplicitType {
|
||||
val delegate: FirExpression
|
||||
interface FirDelegatedType : FirType {
|
||||
val delegate: FirExpression?
|
||||
|
||||
val type: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitDelegatedType(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super.acceptChildren(visitor, data)
|
||||
delegate?.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirDynamicType : FirTypeWithNullability {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitDynamicType(this, data)
|
||||
}
|
||||
+5
-1
@@ -5,5 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
interface FirExplicitType : FirType, FirTypeProjectionContainer {
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirErrorType : FirType {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitErrorType(this, data)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirFunctionType : FirTypeWithNullability {
|
||||
val receiverType: FirType?
|
||||
|
||||
// May be it should inherit FirFunction?
|
||||
val valueParameters: List<FirValueParameter>
|
||||
|
||||
val returnType: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunctionType(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
receiverType?.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
for (parameter in valueParameters) {
|
||||
parameter.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirImplicitType : FirType {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitImplicitType(this, data)
|
||||
}
|
||||
@@ -5,8 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
interface FirResolvedType : FirType {
|
||||
interface FirResolvedType : FirTypeWithNullability {
|
||||
val type: KotlinType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitResolvedType(this, data)
|
||||
}
|
||||
@@ -5,4 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
interface FirStarProjection : FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirStarProjection : FirTypeProjection {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitStarProjection(this, data)
|
||||
}
|
||||
@@ -6,6 +6,15 @@
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirType : FirElement {
|
||||
interface FirType : FirElement, FirAnnotationContainer {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitType(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
acceptAnnotations(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirTypeProjection : FirElement {
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeProjection(this, data)
|
||||
}
|
||||
+10
-1
@@ -5,10 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface FirTypeProjectionWithVariance {
|
||||
interface FirTypeProjectionWithVariance : FirTypeProjection {
|
||||
val variance: Variance
|
||||
|
||||
val type: FirType
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeProjectionWithVariance(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
type.accept(visitor, data)
|
||||
super.acceptChildren(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirTypeWithNullability : FirType {
|
||||
val isNullable: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeWithNullability(this, data)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
interface FirUserType : FirTypeWithNullability, FirTypeProjectionContainer {
|
||||
val name: Name
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitUserType(this, data)
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
super.acceptChildren(visitor, data)
|
||||
for (argument in arguments) {
|
||||
argument.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeWithNullability
|
||||
|
||||
abstract class FirAbstractAnnotatedType(
|
||||
final override val session: FirSession,
|
||||
final override val psi: PsiElement?,
|
||||
final override val isNullable: Boolean
|
||||
) : FirTypeWithNullability {
|
||||
override val annotations = mutableListOf<FirAnnotationCall>()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirDelegatedType
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
class FirDelegatedTypeImpl(
|
||||
override val type: FirType,
|
||||
override val delegate: FirExpression?
|
||||
) : FirType by type, FirDelegatedType {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R {
|
||||
return super<FirDelegatedType>.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> acceptChildren(visitor: FirVisitor<Unit, D>, data: D) {
|
||||
type.acceptChildren(visitor, data)
|
||||
delegate?.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.types.FirDynamicType
|
||||
|
||||
class FirDynamicTypeImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
isNullable: Boolean
|
||||
) : FirAbstractAnnotatedType(session, psi, isNullable), FirDynamicType
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.types.FirErrorType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
class FirErrorTypeImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
isNullable: Boolean
|
||||
) : FirAbstractAnnotatedType(session, psi, isNullable), FirErrorType {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R {
|
||||
return super<FirErrorType>.accept(visitor, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.types.FirFunctionType
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
|
||||
class FirFunctionTypeImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
isNullable: Boolean,
|
||||
override val receiverType: FirType?,
|
||||
override val returnType: FirType
|
||||
) : FirAbstractAnnotatedType(session, psi, isNullable), FirFunctionType {
|
||||
override val valueParameters = mutableListOf<FirValueParameter>()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitType
|
||||
|
||||
class FirImplicitTypeImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?
|
||||
) : FirImplicitType {
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = emptyList()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.types.FirStarProjection
|
||||
|
||||
class FirStarProjectionImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?
|
||||
) : FirStarProjection
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.types.FirType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class FirTypeProjectionWithVarianceImpl(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?,
|
||||
override val variance: Variance,
|
||||
override val type: FirType
|
||||
) : FirTypeProjectionWithVariance
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class FirUnitType(
|
||||
override val session: FirSession,
|
||||
override val psi: PsiElement?
|
||||
) : FirResolvedType {
|
||||
override val type: KotlinType
|
||||
get() = DefaultBuiltIns.Instance.unitType
|
||||
|
||||
override val isNullable = false
|
||||
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = emptyList()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.types.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.types.FirUserType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirUserTypeImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?,
|
||||
isNullable: Boolean,
|
||||
override val name: Name
|
||||
) : FirAbstractAnnotatedType(session, psi, isNullable), FirUserType {
|
||||
override val arguments = mutableListOf<FirTypeProjection>()
|
||||
}
|
||||
@@ -188,7 +188,7 @@ abstract class AbstractVisitorGenerator(val referencesData: DataCollector.Refere
|
||||
|
||||
class SimpleVisitorGenerator(referencesData: DataCollector.ReferencesData) : AbstractVisitorGenerator(referencesData) {
|
||||
override fun Printer.generateContent() {
|
||||
println("abstract class $SIMPLE_VISITOR_NAME<R, D> {")
|
||||
println("abstract class $SIMPLE_VISITOR_NAME<out R, in D> {")
|
||||
indented {
|
||||
generateFunction(
|
||||
"visitElement",
|
||||
@@ -242,7 +242,10 @@ class UnitVisitorGenerator(referencesData: DataCollector.ReferencesData) : Abstr
|
||||
generateVisit(klass, parent)
|
||||
}
|
||||
|
||||
referencesData.back.keys.forEach {
|
||||
val trampolines = referencesData.back.let {
|
||||
it.keys + it.values.flatten()
|
||||
}.distinct()
|
||||
trampolines.forEach {
|
||||
generateTrampolineVisit(it)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.fir.visitors
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
|
||||
/** This file generated by :compiler:fir:tree:generateVisitors. DO NOT MODIFY MANUALLY! */
|
||||
abstract class FirVisitor<out R, in D> {
|
||||
abstract fun visitElement(element: FirElement, data: D): R
|
||||
|
||||
open fun visitDeclaration(declaration: FirDeclaration, data: D): R {
|
||||
return visitElement(declaration, data)
|
||||
}
|
||||
|
||||
open fun visitCallableMember(callableMember: FirCallableMember, data: D): R {
|
||||
return visitDeclaration(callableMember, data)
|
||||
}
|
||||
|
||||
open fun visitDeclarationWithBody(declarationWithBody: FirDeclarationWithBody, data: D): R {
|
||||
return visitDeclaration(declarationWithBody, data)
|
||||
}
|
||||
|
||||
open fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer, data: D): R {
|
||||
return visitDeclarationWithBody(anonymousInitializer, data)
|
||||
}
|
||||
|
||||
open fun visitFunction(function: FirFunction, data: D): R {
|
||||
return visitDeclarationWithBody(function, data)
|
||||
}
|
||||
|
||||
open fun visitConstructor(constructor: FirConstructor, data: D): R {
|
||||
return visitFunction(constructor, data)
|
||||
}
|
||||
|
||||
open fun visitNamedFunction(namedFunction: FirNamedFunction, data: D): R {
|
||||
return visitFunction(namedFunction, data)
|
||||
}
|
||||
|
||||
open fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: D): R {
|
||||
return visitFunction(propertyAccessor, data)
|
||||
}
|
||||
|
||||
open fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration, data: D): R {
|
||||
return visitDeclaration(errorDeclaration, data)
|
||||
}
|
||||
|
||||
open fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration, data: D): R {
|
||||
return visitDeclaration(namedDeclaration, data)
|
||||
}
|
||||
|
||||
open fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration, data: D): R {
|
||||
return visitNamedDeclaration(memberDeclaration, data)
|
||||
}
|
||||
|
||||
open fun visitClass(klass: FirClass, data: D): R {
|
||||
return visitMemberDeclaration(klass, data)
|
||||
}
|
||||
|
||||
open fun visitEnumEntry(enumEntry: FirEnumEntry, data: D): R {
|
||||
return visitClass(enumEntry, data)
|
||||
}
|
||||
|
||||
open fun visitTypeAlias(typeAlias: FirTypeAlias, data: D): R {
|
||||
return visitMemberDeclaration(typeAlias, data)
|
||||
}
|
||||
|
||||
open fun visitTypeParameter(typeParameter: FirTypeParameter, data: D): R {
|
||||
return visitNamedDeclaration(typeParameter, data)
|
||||
}
|
||||
|
||||
open fun visitProperty(property: FirProperty, data: D): R {
|
||||
return visitDeclaration(property, data)
|
||||
}
|
||||
|
||||
open fun visitTypedDeclaration(typedDeclaration: FirTypedDeclaration, data: D): R {
|
||||
return visitDeclaration(typedDeclaration, data)
|
||||
}
|
||||
|
||||
open fun visitValueParameter(valueParameter: FirValueParameter, data: D): R {
|
||||
return visitDeclaration(valueParameter, data)
|
||||
}
|
||||
|
||||
open fun visitVariable(variable: FirVariable, data: D): R {
|
||||
return visitDeclaration(variable, data)
|
||||
}
|
||||
|
||||
open fun visitImport(import: FirImport, data: D): R {
|
||||
return visitElement(import, data)
|
||||
}
|
||||
|
||||
open fun visitPackageFragment(packageFragment: FirPackageFragment, data: D): R {
|
||||
return visitElement(packageFragment, data)
|
||||
}
|
||||
|
||||
open fun visitFile(file: FirFile, data: D): R {
|
||||
return visitPackageFragment(file, data)
|
||||
}
|
||||
|
||||
open fun visitStatement(statement: FirStatement, data: D): R {
|
||||
return visitElement(statement, data)
|
||||
}
|
||||
|
||||
open fun visitExpression(expression: FirExpression, data: D): R {
|
||||
return visitStatement(expression, data)
|
||||
}
|
||||
|
||||
open fun visitBody(body: FirBody, data: D): R {
|
||||
return visitExpression(body, data)
|
||||
}
|
||||
|
||||
open fun visitCall(call: FirCall, data: D): R {
|
||||
return visitExpression(call, data)
|
||||
}
|
||||
|
||||
open fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: D): R {
|
||||
return visitCall(annotationCall, data)
|
||||
}
|
||||
|
||||
open fun visitConstructorCall(constructorCall: FirConstructorCall, data: D): R {
|
||||
return visitCall(constructorCall, data)
|
||||
}
|
||||
|
||||
open fun visitType(type: FirType, data: D): R {
|
||||
return visitElement(type, data)
|
||||
}
|
||||
|
||||
open fun visitDelegatedType(delegatedType: FirDelegatedType, data: D): R {
|
||||
return visitType(delegatedType, data)
|
||||
}
|
||||
|
||||
open fun visitErrorType(errorType: FirErrorType, data: D): R {
|
||||
return visitType(errorType, data)
|
||||
}
|
||||
|
||||
open fun visitImplicitType(implicitType: FirImplicitType, data: D): R {
|
||||
return visitType(implicitType, data)
|
||||
}
|
||||
|
||||
open fun visitTypeWithNullability(typeWithNullability: FirTypeWithNullability, data: D): R {
|
||||
return visitType(typeWithNullability, data)
|
||||
}
|
||||
|
||||
open fun visitDynamicType(dynamicType: FirDynamicType, data: D): R {
|
||||
return visitTypeWithNullability(dynamicType, data)
|
||||
}
|
||||
|
||||
open fun visitFunctionType(functionType: FirFunctionType, data: D): R {
|
||||
return visitTypeWithNullability(functionType, data)
|
||||
}
|
||||
|
||||
open fun visitResolvedType(resolvedType: FirResolvedType, data: D): R {
|
||||
return visitTypeWithNullability(resolvedType, data)
|
||||
}
|
||||
|
||||
open fun visitUserType(userType: FirUserType, data: D): R {
|
||||
return visitTypeWithNullability(userType, data)
|
||||
}
|
||||
|
||||
open fun visitTypeProjection(typeProjection: FirTypeProjection, data: D): R {
|
||||
return visitElement(typeProjection, data)
|
||||
}
|
||||
|
||||
open fun visitStarProjection(starProjection: FirStarProjection, data: D): R {
|
||||
return visitTypeProjection(starProjection, data)
|
||||
}
|
||||
|
||||
open fun visitTypeProjectionWithVariance(typeProjectionWithVariance: FirTypeProjectionWithVariance, data: D): R {
|
||||
return visitTypeProjection(typeProjectionWithVariance, data)
|
||||
}
|
||||
|
||||
}
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.fir.visitors
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
|
||||
/** This file generated by :compiler:fir:tree:generateVisitors. DO NOT MODIFY MANUALLY! */
|
||||
abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
|
||||
abstract fun visitElement(element: FirElement)
|
||||
|
||||
open fun visitDeclaration(declaration: FirDeclaration) {
|
||||
visitElement(declaration, null)
|
||||
}
|
||||
|
||||
open fun visitCallableMember(callableMember: FirCallableMember) {
|
||||
visitDeclaration(callableMember, null)
|
||||
}
|
||||
|
||||
open fun visitDeclarationWithBody(declarationWithBody: FirDeclarationWithBody) {
|
||||
visitDeclaration(declarationWithBody, null)
|
||||
}
|
||||
|
||||
open fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer) {
|
||||
visitDeclarationWithBody(anonymousInitializer, null)
|
||||
}
|
||||
|
||||
open fun visitFunction(function: FirFunction) {
|
||||
visitDeclarationWithBody(function, null)
|
||||
}
|
||||
|
||||
open fun visitConstructor(constructor: FirConstructor) {
|
||||
visitFunction(constructor, null)
|
||||
}
|
||||
|
||||
open fun visitNamedFunction(namedFunction: FirNamedFunction) {
|
||||
visitFunction(namedFunction, null)
|
||||
}
|
||||
|
||||
open fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor) {
|
||||
visitFunction(propertyAccessor, null)
|
||||
}
|
||||
|
||||
open fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration) {
|
||||
visitDeclaration(errorDeclaration, null)
|
||||
}
|
||||
|
||||
open fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration) {
|
||||
visitDeclaration(namedDeclaration, null)
|
||||
}
|
||||
|
||||
open fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
visitNamedDeclaration(memberDeclaration, null)
|
||||
}
|
||||
|
||||
open fun visitClass(klass: FirClass) {
|
||||
visitMemberDeclaration(klass, null)
|
||||
}
|
||||
|
||||
open fun visitEnumEntry(enumEntry: FirEnumEntry) {
|
||||
visitClass(enumEntry, null)
|
||||
}
|
||||
|
||||
open fun visitTypeAlias(typeAlias: FirTypeAlias) {
|
||||
visitMemberDeclaration(typeAlias, null)
|
||||
}
|
||||
|
||||
open fun visitTypeParameter(typeParameter: FirTypeParameter) {
|
||||
visitNamedDeclaration(typeParameter, null)
|
||||
}
|
||||
|
||||
open fun visitProperty(property: FirProperty) {
|
||||
visitDeclaration(property, null)
|
||||
}
|
||||
|
||||
open fun visitTypedDeclaration(typedDeclaration: FirTypedDeclaration) {
|
||||
visitDeclaration(typedDeclaration, null)
|
||||
}
|
||||
|
||||
open fun visitValueParameter(valueParameter: FirValueParameter) {
|
||||
visitDeclaration(valueParameter, null)
|
||||
}
|
||||
|
||||
open fun visitVariable(variable: FirVariable) {
|
||||
visitDeclaration(variable, null)
|
||||
}
|
||||
|
||||
open fun visitImport(import: FirImport) {
|
||||
visitElement(import, null)
|
||||
}
|
||||
|
||||
open fun visitPackageFragment(packageFragment: FirPackageFragment) {
|
||||
visitElement(packageFragment, null)
|
||||
}
|
||||
|
||||
open fun visitFile(file: FirFile) {
|
||||
visitPackageFragment(file, null)
|
||||
}
|
||||
|
||||
open fun visitStatement(statement: FirStatement) {
|
||||
visitElement(statement, null)
|
||||
}
|
||||
|
||||
open fun visitExpression(expression: FirExpression) {
|
||||
visitStatement(expression, null)
|
||||
}
|
||||
|
||||
open fun visitBody(body: FirBody) {
|
||||
visitExpression(body, null)
|
||||
}
|
||||
|
||||
open fun visitCall(call: FirCall) {
|
||||
visitExpression(call, null)
|
||||
}
|
||||
|
||||
open fun visitAnnotationCall(annotationCall: FirAnnotationCall) {
|
||||
visitCall(annotationCall, null)
|
||||
}
|
||||
|
||||
open fun visitConstructorCall(constructorCall: FirConstructorCall) {
|
||||
visitCall(constructorCall, null)
|
||||
}
|
||||
|
||||
open fun visitType(type: FirType) {
|
||||
visitElement(type, null)
|
||||
}
|
||||
|
||||
open fun visitDelegatedType(delegatedType: FirDelegatedType) {
|
||||
visitType(delegatedType, null)
|
||||
}
|
||||
|
||||
open fun visitErrorType(errorType: FirErrorType) {
|
||||
visitType(errorType, null)
|
||||
}
|
||||
|
||||
open fun visitImplicitType(implicitType: FirImplicitType) {
|
||||
visitType(implicitType, null)
|
||||
}
|
||||
|
||||
open fun visitTypeWithNullability(typeWithNullability: FirTypeWithNullability) {
|
||||
visitType(typeWithNullability, null)
|
||||
}
|
||||
|
||||
open fun visitDynamicType(dynamicType: FirDynamicType) {
|
||||
visitTypeWithNullability(dynamicType, null)
|
||||
}
|
||||
|
||||
open fun visitFunctionType(functionType: FirFunctionType) {
|
||||
visitTypeWithNullability(functionType, null)
|
||||
}
|
||||
|
||||
open fun visitResolvedType(resolvedType: FirResolvedType) {
|
||||
visitTypeWithNullability(resolvedType, null)
|
||||
}
|
||||
|
||||
open fun visitUserType(userType: FirUserType) {
|
||||
visitTypeWithNullability(userType, null)
|
||||
}
|
||||
|
||||
open fun visitTypeProjection(typeProjection: FirTypeProjection) {
|
||||
visitElement(typeProjection, null)
|
||||
}
|
||||
|
||||
open fun visitStarProjection(starProjection: FirStarProjection) {
|
||||
visitTypeProjection(starProjection, null)
|
||||
}
|
||||
|
||||
open fun visitTypeProjectionWithVariance(typeProjectionWithVariance: FirTypeProjectionWithVariance) {
|
||||
visitTypeProjection(typeProjectionWithVariance, null)
|
||||
}
|
||||
|
||||
final override fun visitDeclarationWithBody(declarationWithBody: FirDeclarationWithBody, data: Nothing?) {
|
||||
visitDeclarationWithBody(declarationWithBody)
|
||||
}
|
||||
|
||||
final override fun visitDeclaration(declaration: FirDeclaration, data: Nothing?) {
|
||||
visitDeclaration(declaration)
|
||||
}
|
||||
|
||||
final override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration, data: Nothing?) {
|
||||
visitMemberDeclaration(memberDeclaration)
|
||||
}
|
||||
|
||||
final override fun visitFunction(function: FirFunction, data: Nothing?) {
|
||||
visitFunction(function)
|
||||
}
|
||||
|
||||
final override fun visitElement(element: FirElement, data: Nothing?) {
|
||||
visitElement(element)
|
||||
}
|
||||
|
||||
final override fun visitClass(klass: FirClass, data: Nothing?) {
|
||||
visitClass(klass)
|
||||
}
|
||||
|
||||
final override fun visitPackageFragment(packageFragment: FirPackageFragment, data: Nothing?) {
|
||||
visitPackageFragment(packageFragment)
|
||||
}
|
||||
|
||||
final override fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration, data: Nothing?) {
|
||||
visitNamedDeclaration(namedDeclaration)
|
||||
}
|
||||
|
||||
final override fun visitCall(call: FirCall, data: Nothing?) {
|
||||
visitCall(call)
|
||||
}
|
||||
|
||||
final override fun visitExpression(expression: FirExpression, data: Nothing?) {
|
||||
visitExpression(expression)
|
||||
}
|
||||
|
||||
final override fun visitStatement(statement: FirStatement, data: Nothing?) {
|
||||
visitStatement(statement)
|
||||
}
|
||||
|
||||
final override fun visitType(type: FirType, data: Nothing?) {
|
||||
visitType(type)
|
||||
}
|
||||
|
||||
final override fun visitTypeWithNullability(typeWithNullability: FirTypeWithNullability, data: Nothing?) {
|
||||
visitTypeWithNullability(typeWithNullability)
|
||||
}
|
||||
|
||||
final override fun visitTypeProjection(typeProjection: FirTypeProjection, data: Nothing?) {
|
||||
visitTypeProjection(typeProjection)
|
||||
}
|
||||
|
||||
final override fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer, data: Nothing?) {
|
||||
visitAnonymousInitializer(anonymousInitializer)
|
||||
}
|
||||
|
||||
final override fun visitCallableMember(callableMember: FirCallableMember, data: Nothing?) {
|
||||
visitCallableMember(callableMember)
|
||||
}
|
||||
|
||||
final override fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration, data: Nothing?) {
|
||||
visitErrorDeclaration(errorDeclaration)
|
||||
}
|
||||
|
||||
final override fun visitProperty(property: FirProperty, data: Nothing?) {
|
||||
visitProperty(property)
|
||||
}
|
||||
|
||||
final override fun visitTypedDeclaration(typedDeclaration: FirTypedDeclaration, data: Nothing?) {
|
||||
visitTypedDeclaration(typedDeclaration)
|
||||
}
|
||||
|
||||
final override fun visitValueParameter(valueParameter: FirValueParameter, data: Nothing?) {
|
||||
visitValueParameter(valueParameter)
|
||||
}
|
||||
|
||||
final override fun visitVariable(variable: FirVariable, data: Nothing?) {
|
||||
visitVariable(variable)
|
||||
}
|
||||
|
||||
final override fun visitTypeAlias(typeAlias: FirTypeAlias, data: Nothing?) {
|
||||
visitTypeAlias(typeAlias)
|
||||
}
|
||||
|
||||
final override fun visitConstructor(constructor: FirConstructor, data: Nothing?) {
|
||||
visitConstructor(constructor)
|
||||
}
|
||||
|
||||
final override fun visitNamedFunction(namedFunction: FirNamedFunction, data: Nothing?) {
|
||||
visitNamedFunction(namedFunction)
|
||||
}
|
||||
|
||||
final override fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: Nothing?) {
|
||||
visitPropertyAccessor(propertyAccessor)
|
||||
}
|
||||
|
||||
final override fun visitImport(import: FirImport, data: Nothing?) {
|
||||
visitImport(import)
|
||||
}
|
||||
|
||||
final override fun visitEnumEntry(enumEntry: FirEnumEntry, data: Nothing?) {
|
||||
visitEnumEntry(enumEntry)
|
||||
}
|
||||
|
||||
final override fun visitFile(file: FirFile, data: Nothing?) {
|
||||
visitFile(file)
|
||||
}
|
||||
|
||||
final override fun visitTypeParameter(typeParameter: FirTypeParameter, data: Nothing?) {
|
||||
visitTypeParameter(typeParameter)
|
||||
}
|
||||
|
||||
final override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: Nothing?) {
|
||||
visitAnnotationCall(annotationCall)
|
||||
}
|
||||
|
||||
final override fun visitConstructorCall(constructorCall: FirConstructorCall, data: Nothing?) {
|
||||
visitConstructorCall(constructorCall)
|
||||
}
|
||||
|
||||
final override fun visitBody(body: FirBody, data: Nothing?) {
|
||||
visitBody(body)
|
||||
}
|
||||
|
||||
final override fun visitDelegatedType(delegatedType: FirDelegatedType, data: Nothing?) {
|
||||
visitDelegatedType(delegatedType)
|
||||
}
|
||||
|
||||
final override fun visitErrorType(errorType: FirErrorType, data: Nothing?) {
|
||||
visitErrorType(errorType)
|
||||
}
|
||||
|
||||
final override fun visitImplicitType(implicitType: FirImplicitType, data: Nothing?) {
|
||||
visitImplicitType(implicitType)
|
||||
}
|
||||
|
||||
final override fun visitDynamicType(dynamicType: FirDynamicType, data: Nothing?) {
|
||||
visitDynamicType(dynamicType)
|
||||
}
|
||||
|
||||
final override fun visitFunctionType(functionType: FirFunctionType, data: Nothing?) {
|
||||
visitFunctionType(functionType)
|
||||
}
|
||||
|
||||
final override fun visitResolvedType(resolvedType: FirResolvedType, data: Nothing?) {
|
||||
visitResolvedType(resolvedType)
|
||||
}
|
||||
|
||||
final override fun visitUserType(userType: FirUserType, data: Nothing?) {
|
||||
visitUserType(userType)
|
||||
}
|
||||
|
||||
final override fun visitStarProjection(starProjection: FirStarProjection, data: Nothing?) {
|
||||
visitStarProjection(starProjection)
|
||||
}
|
||||
|
||||
final override fun visitTypeProjectionWithVariance(typeProjectionWithVariance: FirTypeProjectionWithVariance, data: Nothing?) {
|
||||
visitTypeProjectionWithVariance(typeProjectionWithVariance)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -455,6 +455,8 @@ fun KtModifierListOwner.visibilityModifierTypeOrDefault(): KtModifierKeywordToke
|
||||
|
||||
fun KtDeclaration.modalityModifier() = modifierFromTokenSet(MODALITY_MODIFIERS)
|
||||
|
||||
fun KtDeclaration.modalityModifierType(): KtModifierKeywordToken? = modalityModifier()?.node?.elementType as KtModifierKeywordToken?
|
||||
|
||||
fun KtStringTemplateExpression.isPlain() = entries.all { it is KtLiteralStringTemplateEntry }
|
||||
fun KtStringTemplateExpression.isPlainWithEscapes() =
|
||||
entries.all { it is KtLiteralStringTemplateEntry || it is KtEscapeStringTemplateEntry }
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
interface SomeInterface {
|
||||
fun foo(x: Int, y: String): String
|
||||
|
||||
val bar: Boolean
|
||||
}
|
||||
|
||||
class SomeClass : SomeInterface {
|
||||
private val baz = 42
|
||||
|
||||
override fun foo(x: Int, y: String): String {
|
||||
return y + x + baz
|
||||
}
|
||||
|
||||
override var bar: Boolean
|
||||
get() = true
|
||||
set(value) {}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
FILE: simpleClass.kt
|
||||
unknown final class SomeInterface() {
|
||||
unknown final function foo(x: Int, y: String): String
|
||||
|
||||
unknown final property bar(val): Boolean
|
||||
unknown get(): Boolean
|
||||
|
||||
}
|
||||
unknown final class SomeClass() : SomeInterface {
|
||||
private final property baz(val): <implicit> = STUB
|
||||
unknown get(): <implicit>
|
||||
|
||||
unknown final override function foo(x: Int, y: String): String {
|
||||
}
|
||||
|
||||
unknown final override property bar(var): Boolean
|
||||
unknown get(): <implicit> {
|
||||
STUB
|
||||
}
|
||||
unknown set(value: Boolean): <implicit> {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,3 @@
|
||||
FILE: simpleFun.kt
|
||||
unknown final function foo(): <implicit> {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
interface List<out T : Any> {
|
||||
operator fun get(index: Int): T
|
||||
|
||||
infix fun concat(other: List<T>): List<T>
|
||||
}
|
||||
|
||||
typealias StringList = List<out String>
|
||||
typealias AnyList = List<*>
|
||||
|
||||
abstract class AbstractList<out T : Any> : List<T>
|
||||
|
||||
class SomeList : AbstractList<Int>() {
|
||||
override fun get(index: Int): Int = 42
|
||||
|
||||
override fun concat(other: List<Int>): List<Int> = this
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
FILE: typeParameters.kt
|
||||
<out T : Any> unknown final class List() {
|
||||
unknown final operator function get(index: Int): T
|
||||
|
||||
unknown final infix function concat(other: List<T>): List<T>
|
||||
|
||||
}
|
||||
unknown final typealias StringList = List<out String>
|
||||
unknown final typealias AnyList = List<*>
|
||||
<out T : Any> unknown abstract class AbstractList() : List<T> {
|
||||
}
|
||||
unknown final class SomeList() : AbstractList<Int> {
|
||||
unknown final override function get(index: Int): Int {
|
||||
STUB
|
||||
}
|
||||
|
||||
unknown final override function concat(other: List<Int>): List<Int> {
|
||||
STUB
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ dependencies {
|
||||
testCompile(project(":core:deserialization"))
|
||||
testCompile(project(":compiler:util"))
|
||||
testCompile(project(":compiler:backend"))
|
||||
testCompile(project(":compiler:fir:tree"))
|
||||
testCompile(project(":compiler:fir:psi2fir"))
|
||||
testCompile(project(":compiler:ir.ir2cfg"))
|
||||
testCompile(project(":compiler:frontend"))
|
||||
testCompile(project(":compiler:frontend.java"))
|
||||
|
||||
@@ -10,6 +10,8 @@ dependencies {
|
||||
testCompile(project(":core:deserialization"))
|
||||
testCompile(project(":compiler:util"))
|
||||
testCompile(project(":compiler:backend"))
|
||||
testCompile(project(":compiler:fir:tree"))
|
||||
testCompile(project(":compiler:fir:psi2fir"))
|
||||
testCompile(project(":compiler:ir.ir2cfg"))
|
||||
testCompile(project(":compiler:frontend"))
|
||||
testCompile(project(":compiler:frontend.java"))
|
||||
|
||||
@@ -10,6 +10,8 @@ dependencies {
|
||||
testCompile(project(":core:deserialization"))
|
||||
testCompile(project(":compiler:util"))
|
||||
testCompile(project(":compiler:backend"))
|
||||
testCompile(project(":compiler:fir:tree"))
|
||||
testCompile(project(":compiler:fir:psi2fir"))
|
||||
testCompile(project(":compiler:ir.ir2cfg"))
|
||||
testCompile(project(":compiler:frontend"))
|
||||
testCompile(project(":compiler:frontend.java"))
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.builder
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry
|
||||
import com.intellij.openapi.util.Getter
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.cli.common.script.CliScriptDefinitionProvider
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.script.ScriptDefinitionProvider
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.testFramework.KtParsingTestCase
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase(
|
||||
".",
|
||||
"kt",
|
||||
KotlinParserDefinition()
|
||||
) {
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
project.registerService(ScriptDefinitionProvider::class.java, CliScriptDefinitionProvider::class.java)
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
|
||||
|
||||
private fun createFile(filePath: String, fileType: IElementType): PsiFile {
|
||||
val psiFactory = KtPsiFactory(myProject)
|
||||
return when (fileType) {
|
||||
KtNodeTypes.EXPRESSION_CODE_FRAGMENT ->
|
||||
psiFactory.createExpressionCodeFragment(loadFile(filePath), null)
|
||||
KtNodeTypes.BLOCK_CODE_FRAGMENT ->
|
||||
psiFactory.createBlockCodeFragment(loadFile(filePath), null)
|
||||
else ->
|
||||
createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(filePath)), loadFile(filePath))
|
||||
}
|
||||
}
|
||||
|
||||
protected fun doRawFirTest(filePath: String) {
|
||||
doBaseTest(filePath, KtNodeTypes.KT_FILE)
|
||||
}
|
||||
|
||||
private fun doBaseTest(filePath: String, fileType: IElementType) {
|
||||
myFileExt = FileUtilRt.getExtension(PathUtil.getFileName(filePath))
|
||||
val file = createFile(filePath, fileType) as KtFile
|
||||
myFile = file
|
||||
|
||||
val firFile = RawFirBuilder(object : FirSession {}).buildFirFile(file)
|
||||
val firFileDump = StringBuilder().also { FirRenderer(it).visitFile(firFile) }.toString()
|
||||
val expectedPath = filePath.replace(".kt", ".txt")
|
||||
KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump)
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
super.tearDown()
|
||||
FileTypeRegistry.ourInstanceGetter = Getter<FileTypeRegistry> { FileTypeManager.getInstance() }
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. 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.fir.builder;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
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("compiler/testData/fir/rawBuilder")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCase {
|
||||
public void testAllFilesPresentInRawBuilder() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/fir/rawBuilder/declarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Declarations extends AbstractRawFirBuilderTestCase {
|
||||
public void testAllFilesPresentInDeclarations() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/rawBuilder/declarations/simpleClass.kt");
|
||||
doRawFirTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFun.kt")
|
||||
public void testSimpleFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/rawBuilder/declarations/simpleFun.kt");
|
||||
doRawFirTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameters.kt")
|
||||
public void testTypeParameters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/rawBuilder/declarations/typeParameters.kt");
|
||||
doRawFirTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.defaultConstructor.AbstractDefaultArgumentsReflectionTest
|
||||
import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest
|
||||
import org.jetbrains.kotlin.codegen.ir.*
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
|
||||
import org.jetbrains.kotlin.generators.tests.generator.testGroup
|
||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
|
||||
@@ -197,6 +198,10 @@ fun main(args: Array<String>) {
|
||||
model("ir/sourceRanges")
|
||||
}
|
||||
|
||||
testClass<AbstractRawFirBuilderTestCase> {
|
||||
model("fir/rawBuilder", testMethod = "doRawFirTest")
|
||||
}
|
||||
|
||||
testClass<AbstractBytecodeListingTest> {
|
||||
model("codegen/bytecodeListing")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user