[FIR IDE] LC add jvmstatic method into companion object

This commit is contained in:
Igor Yakovlev
2020-12-08 02:28:30 +03:00
parent d32d0a65f0
commit 3895ad375c
9 changed files with 34 additions and 14 deletions
@@ -47,7 +47,7 @@ internal class FirLightAnnotationClassSymbol(
.filterNot { it is KtFunctionSymbol && it.visibility == KtSymbolVisibility.PRIVATE } .filterNot { it is KtFunctionSymbol && it.visibility == KtSymbolVisibility.PRIVATE }
.filterNot { it is KtConstructorSymbol } .filterNot { it is KtConstructorSymbol }
createMethods(visibleDeclarations, isTopLevel = false, result) createMethods(visibleDeclarations, result)
} }
result result
@@ -60,7 +60,7 @@ internal class FirLightAnonymousClassForSymbol(
analyzeWithSymbolAsContext(anonymousObjectSymbol) { analyzeWithSymbolAsContext(anonymousObjectSymbol) {
val callableSymbols = anonymousObjectSymbol.getDeclaredMemberScope().getCallableSymbols() val callableSymbols = anonymousObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
createMethods(callableSymbols, isTopLevel = false, result) createMethods(callableSymbols, result)
} }
result result
@@ -128,7 +128,7 @@ internal class FirLightClassForEnumEntry(
analyzeWithSymbolAsContext(enumEntrySymbol) { analyzeWithSymbolAsContext(enumEntrySymbol) {
val callableSymbols = enumEntrySymbol.getDeclaredMemberScope().getCallableSymbols() val callableSymbols = enumEntrySymbol.getDeclaredMemberScope().getCallableSymbols()
createMethods(callableSymbols, isTopLevel = false, result) createMethods(callableSymbols, result)
} }
return result return result
@@ -82,7 +82,7 @@ class FirLightClassForFacade(
} }
} }
createMethods(symbols.asSequence(), isTopLevel = true, result) createMethods(symbols.asSequence(), result, isTopLevel = true)
} }
private val _ownMethods: List<KtLightMethod> by lazyPub { private val _ownMethods: List<KtLightMethod> by lazyPub {
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.idea.asJava package org.jetbrains.kotlin.idea.asJava
import com.intellij.psi.* import com.intellij.psi.*
import org.jetbrains.kotlin.asJava.builder.memberIndex
import org.jetbrains.kotlin.asJava.classes.METHOD_INDEX_BASE
import org.jetbrains.kotlin.asJava.classes.METHOD_INDEX_FOR_DEFAULT_CTOR import org.jetbrains.kotlin.asJava.classes.METHOD_INDEX_FOR_DEFAULT_CTOR
import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightField import org.jetbrains.kotlin.asJava.elements.KtLightField
@@ -100,7 +102,8 @@ internal open class FirLightClassForSymbol(
} }
} }
createMethods(visibleDeclarations, isTopLevel = false, result) val suppressStatic = classOrObjectSymbol.classKind == KtClassKind.COMPANION_OBJECT
createMethods(visibleDeclarations, result, suppressStaticForMethods = suppressStatic)
} }
if (result.none { it.isConstructor }) { if (result.none { it.isConstructor }) {
@@ -116,6 +119,8 @@ internal open class FirLightClassForSymbol(
} }
} }
addMethodsFromCompanionIfNeeded(result)
result result
} }
@@ -140,6 +145,17 @@ internal open class FirLightClassForSymbol(
} }
} }
private fun addMethodsFromCompanionIfNeeded(result: MutableList<KtLightMethod>) {
classOrObjectSymbol.companionObject?.run {
analyzeWithSymbolAsContext(this) {
val methods = getDeclaredMemberScope().getCallableSymbols()
.filterIsInstance<KtFunctionSymbol>()
.filter { it.hasJvmStaticAnnotation() }
createMethods(methods, result)
}
}
}
private fun addInstanceFieldIfNeeded(result: MutableList<KtLightField>) { private fun addInstanceFieldIfNeeded(result: MutableList<KtLightField>) {
val isNamedObject = classOrObjectSymbol.classKind == KtClassKind.OBJECT val isNamedObject = classOrObjectSymbol.classKind == KtClassKind.OBJECT
if (isNamedObject && classOrObjectSymbol.symbolKind != KtSymbolKind.LOCAL) { if (isNamedObject && classOrObjectSymbol.symbolKind != KtSymbolKind.LOCAL) {
@@ -43,7 +43,7 @@ internal class FirLightInterfaceClassSymbol(
val visibleDeclarations = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols() val visibleDeclarations = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
.filterNot { it is KtFunctionSymbol && it.visibility == KtSymbolVisibility.PRIVATE } .filterNot { it is KtFunctionSymbol && it.visibility == KtSymbolVisibility.PRIVATE }
createMethods(visibleDeclarations, isTopLevel = false, result) createMethods(visibleDeclarations, result)
} }
result result
@@ -98,10 +98,10 @@ private fun lightClassForEnumEntry(ktEnumEntry: KtEnumEntry): KtLightClass? {
internal fun FirLightClassBase.createMethods( internal fun FirLightClassBase.createMethods(
declarations: Sequence<KtCallableSymbol>, declarations: Sequence<KtCallableSymbol>,
isTopLevel: Boolean, result: MutableList<KtLightMethod>,
result: MutableList<KtLightMethod> isTopLevel: Boolean = false,
suppressStaticForMethods: Boolean = false
) { ) {
var methodIndex = METHOD_INDEX_BASE
for (declaration in declarations) { for (declaration in declarations) {
if (declaration is KtFunctionSymbol && declaration.isInline) continue if (declaration is KtFunctionSymbol && declaration.isInline) continue
@@ -112,13 +112,15 @@ internal fun FirLightClassBase.createMethods(
when (declaration) { when (declaration) {
is KtFunctionSymbol -> { is KtFunctionSymbol -> {
var methodIndex = METHOD_INDEX_BASE
result.add( result.add(
FirLightSimpleMethodForSymbol( FirLightSimpleMethodForSymbol(
functionSymbol = declaration, functionSymbol = declaration,
lightMemberOrigin = null, lightMemberOrigin = null,
containingClass = this@createMethods, containingClass = this@createMethods,
isTopLevel = isTopLevel, isTopLevel = isTopLevel,
methodIndex = methodIndex++ methodIndex = methodIndex,
suppressStatic = suppressStaticForMethods
) )
) )
@@ -150,7 +152,7 @@ internal fun FirLightClassBase.createMethods(
constructorSymbol = declaration, constructorSymbol = declaration,
lightMemberOrigin = null, lightMemberOrigin = null,
containingClass = this@createMethods, containingClass = this@createMethods,
methodIndex++ methodIndex = METHOD_INDEX_BASE
) )
) )
} }
@@ -139,6 +139,7 @@ internal class FirLightAccessorMethodForSymbol(
override fun equals(other: Any?): Boolean = override fun equals(other: Any?): Boolean =
this === other || this === other ||
(other is FirLightAccessorMethodForSymbol && (other is FirLightAccessorMethodForSymbol &&
isGetter == other.isGetter &&
kotlinOrigin == other.kotlinOrigin && kotlinOrigin == other.kotlinOrigin &&
propertyAccessorSymbol == other.propertyAccessorSymbol) propertyAccessorSymbol == other.propertyAccessorSymbol)
@@ -22,13 +22,14 @@ internal class FirLightSimpleMethodForSymbol(
containingClass: FirLightClassBase, containingClass: FirLightClassBase,
methodIndex: Int, methodIndex: Int,
isTopLevel: Boolean, isTopLevel: Boolean,
argumentsSkipMask: BitSet? = null argumentsSkipMask: BitSet? = null,
suppressStatic: Boolean = false
) : FirLightMethodForSymbol( ) : FirLightMethodForSymbol(
functionSymbol = functionSymbol, functionSymbol = functionSymbol,
lightMemberOrigin = lightMemberOrigin, lightMemberOrigin = lightMemberOrigin,
containingClass = containingClass, containingClass = containingClass,
methodIndex = methodIndex, methodIndex = methodIndex,
argumentsSkipMask = argumentsSkipMask argumentsSkipMask = argumentsSkipMask,
) { ) {
private val _name: String by lazyPub { private val _name: String by lazyPub {
@@ -96,7 +97,7 @@ internal class FirLightSimpleMethodForSymbol(
modifiers.add(_visibility) modifiers.add(_visibility)
if (functionSymbol.hasJvmStaticAnnotation()) { if (!suppressStatic && functionSymbol.hasJvmStaticAnnotation()) {
modifiers.add(PsiModifier.STATIC) modifiers.add(PsiModifier.STATIC)
} }
if (functionSymbol.hasAnnotation("kotlin/jvm/Strictfp", null)) { if (functionSymbol.hasAnnotation("kotlin/jvm/Strictfp", null)) {