FIR Java model: support static members & enum entries
Related to KT-29218
This commit is contained in:
@@ -11,8 +11,6 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMember
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableClass
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCall
|
||||
import org.jetbrains.kotlin.fir.java.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||
@@ -91,7 +89,6 @@ class JavaSymbolProvider(
|
||||
// TODO: may be we can process fields & methods later.
|
||||
// However, they should be built up to override resolve stage
|
||||
for (javaField in javaClass.fields) {
|
||||
if (javaField.isStatic) continue // TODO: statics
|
||||
val fieldName = javaField.name
|
||||
val fieldId = CallableId(classId.packageFqName, classId.relativeClassName, fieldName)
|
||||
val fieldSymbol = FirFieldSymbol(fieldId)
|
||||
@@ -100,14 +97,14 @@ class JavaSymbolProvider(
|
||||
session, fieldSymbol, fieldName,
|
||||
javaField.visibility, javaField.modality,
|
||||
returnTypeRef = returnType.toFirJavaTypeRef(session),
|
||||
isVar = !javaField.isFinal
|
||||
isVar = !javaField.isFinal,
|
||||
isStatic = javaField.isStatic
|
||||
).apply {
|
||||
addAnnotationsFrom(javaField)
|
||||
}
|
||||
declarations += firJavaField
|
||||
}
|
||||
for (javaMethod in javaClass.methods) {
|
||||
if (javaMethod.isStatic) continue // TODO: statics
|
||||
val methodName = javaMethod.name
|
||||
val methodId = CallableId(classId.packageFqName, classId.relativeClassName, methodName)
|
||||
val methodSymbol = FirFunctionSymbol(methodId)
|
||||
@@ -115,7 +112,8 @@ class JavaSymbolProvider(
|
||||
val firJavaMethod = FirJavaMethod(
|
||||
session, methodSymbol, methodName,
|
||||
javaMethod.visibility, javaMethod.modality,
|
||||
returnTypeRef = returnType.toFirJavaTypeRef(session)
|
||||
returnTypeRef = returnType.toFirJavaTypeRef(session),
|
||||
isStatic = javaMethod.isStatic
|
||||
).apply {
|
||||
for (typeParameter in javaMethod.typeParameters) {
|
||||
typeParameters += createTypeParameterSymbol(session, typeParameter.name).fir
|
||||
|
||||
@@ -22,7 +22,8 @@ class FirJavaField(
|
||||
visibility: Visibility,
|
||||
modality: Modality?,
|
||||
returnTypeRef: FirJavaTypeRef,
|
||||
override val isVar: Boolean
|
||||
override val isVar: Boolean,
|
||||
isStatic: Boolean
|
||||
) : FirAbstractCallableMember(
|
||||
session, psi = null, symbol = symbol, name = name,
|
||||
visibility = visibility, modality = modality,
|
||||
@@ -34,4 +35,8 @@ class FirJavaField(
|
||||
|
||||
override val initializer: FirExpression?
|
||||
get() = null
|
||||
|
||||
init {
|
||||
status.isStatic = isStatic
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ class FirJavaMethod(
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
modality: Modality?,
|
||||
returnTypeRef: FirJavaTypeRef
|
||||
returnTypeRef: FirJavaTypeRef,
|
||||
isStatic: Boolean
|
||||
) : FirMemberFunctionImpl(
|
||||
session, null, symbol, name,
|
||||
visibility, modality,
|
||||
@@ -29,4 +30,8 @@ class FirJavaMethod(
|
||||
isOperator = true, // All Java methods with name that allows to use it in operator form are considered operators
|
||||
isInfix = false, isInline = false, isTailRec = false, isExternal = false, isSuspend = false,
|
||||
receiverTypeRef = null, returnTypeRef = returnTypeRef
|
||||
)
|
||||
) {
|
||||
init {
|
||||
status.isStatic = isStatic
|
||||
}
|
||||
}
|
||||
+1
@@ -94,6 +94,7 @@ class JavaClassEnhancementScope(
|
||||
delegate = null
|
||||
).apply {
|
||||
annotations += firField.annotations
|
||||
status.isStatic = firField.isStatic
|
||||
}
|
||||
}
|
||||
return symbol
|
||||
|
||||
@@ -148,8 +148,13 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
||||
if (memberDeclaration.isActual) {
|
||||
print("actual ")
|
||||
}
|
||||
if (memberDeclaration is FirCallableMember && memberDeclaration.isOverride) {
|
||||
print("override ")
|
||||
if (memberDeclaration is FirCallableMember) {
|
||||
if (memberDeclaration.isOverride) {
|
||||
print("override ")
|
||||
}
|
||||
if (memberDeclaration.isStatic) {
|
||||
print("static ")
|
||||
}
|
||||
}
|
||||
if (memberDeclaration is FirRegularClass) {
|
||||
if (memberDeclaration.isInner) {
|
||||
|
||||
@@ -16,6 +16,8 @@ interface FirCallableMember :
|
||||
FirTypedDeclaration, FirSymbolOwner<FirCallableMember> {
|
||||
val isOverride: Boolean get() = status.isOverride
|
||||
|
||||
val isStatic: Boolean get() = status.isStatic
|
||||
|
||||
val receiverTypeRef: FirTypeRef?
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
|
||||
@@ -46,6 +46,8 @@ interface FirDeclarationStatus : FirElement {
|
||||
|
||||
val isSuspend: Boolean
|
||||
|
||||
val isStatic: Boolean
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
|
||||
|
||||
+8
-1
@@ -112,6 +112,12 @@ open class FirDeclarationStatusImpl(
|
||||
this[SUSPEND] = value
|
||||
}
|
||||
|
||||
override var isStatic: Boolean
|
||||
get() = this[STATIC]
|
||||
set(value) {
|
||||
this[STATIC] = value
|
||||
}
|
||||
|
||||
private enum class Modifier(val mask: Int) {
|
||||
EXPECT(0x1),
|
||||
ACTUAL(0x2),
|
||||
@@ -126,7 +132,8 @@ open class FirDeclarationStatusImpl(
|
||||
INNER(0x400),
|
||||
COMPANION(0x800),
|
||||
DATA(0x1000),
|
||||
SUSPEND(0x2000)
|
||||
SUSPEND(0x2000),
|
||||
STATIC(0x4000)
|
||||
}
|
||||
|
||||
fun resolved(visibility: Visibility, modality: Modality): FirDeclarationStatus {
|
||||
|
||||
@@ -3,8 +3,14 @@ public open class PrivateMembers : R|java/lang/Object| {
|
||||
private get(): R|kotlin/Int|
|
||||
private set(value: R|kotlin/Int|): kotlin/Unit
|
||||
|
||||
private open static property staticField(var): R|kotlin/Int|
|
||||
private get(): R|kotlin/Int|
|
||||
private set(value: R|kotlin/Int|): kotlin/Unit
|
||||
|
||||
private open operator function method(): R|kotlin/Unit|
|
||||
|
||||
private open static operator function staticMethod(): R|kotlin/Unit|
|
||||
|
||||
private final function PrivateMembers(): R|test/PrivateMembers|
|
||||
|
||||
}
|
||||
|
||||
+9
@@ -1,2 +1,11 @@
|
||||
public final enum class AnnotatedEnumEntry : R|java/lang/Enum<test/AnnotatedEnumEntry>| {
|
||||
@R|test/AnnotatedEnumEntry.Anno|(String(a)) public final static property E1(val): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
public get(): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
|
||||
@R|test/AnnotatedEnumEntry.Anno|(String(b)) @R|test/AnnotatedEnumEntry.Anno2|() public final static property E2(val): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
public get(): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
|
||||
public final static property E3(val): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
public get(): R|ft<test/AnnotatedEnumEntry, test/AnnotatedEnumEntry?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
public open class AnnotatedField : R|java/lang/Object| {
|
||||
@R|test/AnnotatedField.Anno|(String(static)) public final static property x(val): R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
@R|test/AnnotatedField.Anno|(String(member)) public final property y(val): R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
public open class EnumArgumentWithCustomToString : R|java/lang/Object| {
|
||||
@R|test/EnumArgumentWithCustomToString.EnumAnno|(<Strange Java enum value: test/EnumArgumentWithCustomToString.E.CAKE>#()) @R|test/EnumArgumentWithCustomToString.EnumArrayAnno|(<implicitArrayOf>(<Strange Java enum value: test/EnumArgumentWithCustomToString.E.CAKE>#(), <Strange Java enum value: test/EnumArgumentWithCustomToString.E.CAKE>#())) public/*package*/ open operator function annotated(): R|kotlin/Unit|
|
||||
@R|test/EnumArgumentWithCustomToString.EnumAnno|(R|test/EnumArgumentWithCustomToString.E.CAKE|()) @R|test/EnumArgumentWithCustomToString.EnumArrayAnno|(<implicitArrayOf>(R|test/EnumArgumentWithCustomToString.E.CAKE|(), R|test/EnumArgumentWithCustomToString.E.CAKE|())) public/*package*/ open operator function annotated(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -1,4 +1,7 @@
|
||||
public final enum class EnumConstructorParameter : R|java/lang/Enum<test/EnumConstructorParameter>| {
|
||||
public final static property INSTANCE(val): R|ft<test/EnumConstructorParameter, test/EnumConstructorParameter?>|!
|
||||
public get(): R|ft<test/EnumConstructorParameter, test/EnumConstructorParameter?>|!
|
||||
|
||||
private final function EnumConstructorParameter(@R|test/EnumConstructorParameter.Anno|(String(string)) s: R|ft<kotlin/String, kotlin/String?>|!): R|test/EnumConstructorParameter|
|
||||
|
||||
private final function EnumConstructorParameter(x: R|kotlin/Int|): R|test/EnumConstructorParameter|
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
public open class NestedEnumArgument : R|java/lang/Object| {
|
||||
@R|test/NestedEnumArgument.Anno|(<Strange Java enum value: test/NestedEnumArgument.E.FIRST>#()) public/*package*/ open operator function foo(): R|kotlin/Unit|
|
||||
@R|test/NestedEnumArgument.Anno|(R|test/NestedEnumArgument.E.FIRST|()) public/*package*/ open operator function foo(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -1,2 +1,5 @@
|
||||
public abstract interface StringConstantInParam : R|java/lang/Object| {
|
||||
public final static property HEL(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
public get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
public final enum class EnumMembers : R|java/lang/Enum<test/EnumMembers>| {
|
||||
public final static property FIRST(val): R|ft<test/EnumMembers, test/EnumMembers?>|!
|
||||
public get(): R|ft<test/EnumMembers, test/EnumMembers?>|!
|
||||
|
||||
public final static property SECOND(val): R|ft<test/EnumMembers, test/EnumMembers?>|!
|
||||
public get(): R|ft<test/EnumMembers, test/EnumMembers?>|!
|
||||
|
||||
public final property isFirst(val): R|kotlin/Boolean|
|
||||
public get(): R|kotlin/Boolean|
|
||||
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
public open enum class EnumWithSpecializedEntry : R|java/lang/Enum<test/EnumWithSpecializedEntry>| {
|
||||
public final static property E1(val): R|ft<test/EnumWithSpecializedEntry, test/EnumWithSpecializedEntry?>|!
|
||||
public get(): R|ft<test/EnumWithSpecializedEntry, test/EnumWithSpecializedEntry?>|!
|
||||
|
||||
public final static property E2(val): R|ft<test/EnumWithSpecializedEntry, test/EnumWithSpecializedEntry?>|!
|
||||
public get(): R|ft<test/EnumWithSpecializedEntry, test/EnumWithSpecializedEntry?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
public final enum class JavaEnum : R|java/lang/Enum<test/JavaEnum>| {
|
||||
public final static property ENTRY(val): R|ft<test/JavaEnum, test/JavaEnum?>|!
|
||||
public get(): R|ft<test/JavaEnum, test/JavaEnum?>|!
|
||||
|
||||
public final static property ANOTHER(val): R|ft<test/JavaEnum, test/JavaEnum?>|!
|
||||
public get(): R|ft<test/JavaEnum, test/JavaEnum?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
public open class Basic : R|java/lang/Object| {
|
||||
public open operator function foo(r: R|ft<java/lang/Runnable, java/lang/Runnable?>|!): R|kotlin/Unit|
|
||||
|
||||
public open static operator function bar(r: R|ft<java/lang/Runnable, java/lang/Runnable?>|!): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -1,2 +1,4 @@
|
||||
public open class SeveralSamParameters : R|java/lang/Object| {
|
||||
public open static operator function findMaxAndInvokeCallback(comparator: R|ft<java/util/Comparator<ft<kotlin/String, kotlin/String?>>, java/util/Comparator<ft<kotlin/String, kotlin/String?>>?>|!, a: R|ft<kotlin/String, kotlin/String?>|!, b: R|ft<kotlin/String, kotlin/String?>|!, afterRunnable: R|ft<java/lang/Runnable, java/lang/Runnable?>|!): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
}
|
||||
|
||||
+6
@@ -1,2 +1,8 @@
|
||||
public open class TypeParameterOfMethod : R|java/lang/Object| {
|
||||
public open static operator function max(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
|
||||
|
||||
public open static operator function max2(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
|
||||
|
||||
public open static operator function method(a: R|ft<java/util/Comparator<ft<A, A?>>, java/util/Comparator<ft<A, A?>>?>|!, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
public final enum class Enum : R|java/lang/Enum<test/Enum>| {
|
||||
public final static property A(val): R|ft<test/Enum, test/Enum?>|!
|
||||
public get(): R|ft<test/Enum, test/Enum?>|!
|
||||
|
||||
public final static property B(val): R|ft<test/Enum, test/Enum?>|!
|
||||
public get(): R|ft<test/Enum, test/Enum?>|!
|
||||
|
||||
public final static property C(val): R|ft<test/Enum, test/Enum?>|!
|
||||
public get(): R|ft<test/Enum, test/Enum?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
public open class Simple : R|java/lang/Object| {
|
||||
public open static operator function bar(): R|kotlin/Unit|
|
||||
|
||||
public open operator function foo(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,20 @@
|
||||
public open class StaticFinal : R|java/lang/Object| {
|
||||
public final static property publicNonNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
public get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
public final static property publicNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
public get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
public/*package*/ final static property packageNonNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
public/*package*/ get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
public/*package*/ final static property packageNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
public/*package*/ get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
private final static property privateNonNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
private get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
private final static property privateNull(val): R|ft<kotlin/String, kotlin/String?>|!
|
||||
private get(): R|ft<kotlin/String, kotlin/String?>|!
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,18 @@
|
||||
public final enum class StaticMembersInEnum : R|java/lang/Enum<test/StaticMembersInEnum>| {
|
||||
public final static property ENTRY(val): R|ft<test/StaticMembersInEnum, test/StaticMembersInEnum?>|!
|
||||
public get(): R|ft<test/StaticMembersInEnum, test/StaticMembersInEnum?>|!
|
||||
|
||||
public open static property STATIC_FIELD(var): R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
public set(value: R|kotlin/Int|): kotlin/Unit
|
||||
|
||||
public final static property CONSTANT(val): R|ft<test/StaticMembersInEnum, test/StaticMembersInEnum?>|!
|
||||
public get(): R|ft<test/StaticMembersInEnum, test/StaticMembersInEnum?>|!
|
||||
|
||||
public open static operator function foo(): R|kotlin/Unit|
|
||||
|
||||
public open static operator function values(x: R|kotlin/Int|): R|kotlin/Unit|
|
||||
|
||||
public open static operator function valueOf(x: R|kotlin/Int|): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user