Skip to content

Commit

Permalink
Fix static resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Aug 12, 2020
1 parent 60ccdd0 commit f494a30
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
const val project = "0.8.1"
const val project = "0.9.0"
const val idePlugin = "1.1.0"

const val kotlin = "1.4.0-rc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BlockingBridgeLineMarkerProvider : LineMarkerProvider {
fun PsiReferenceExpression.hasBridgeCalls(): Boolean {
val resolved = this.resolve() as? KtLightMethod ?: return false

return resolved.isCompanionedWithBlockingBrideInThisOrSuper()
return resolved.canHaveBridgeFunctions()
}

fun PsiElement.getLineNumber(start: Boolean = true): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
import org.jetbrains.kotlin.asJava.classes.KtUltraLightClassForFacade
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.search.declarationsSearch.forEachOverridingMethod
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
Expand Down Expand Up @@ -60,20 +61,20 @@ class JvmBlockingBridgePsiAugmentProvider : PsiAugmentProvider() {

internal fun PsiExtensibleClass.generateAugmentElements(): List<PsiElement> {
return this.ownMethods.asSequence()
.filter { it.isCompanionedWithBlockingBrideInThisOrSuper() }
.filter { it.canHaveBridgeFunctions() }
.filterIsInstance<KtLightMethod>()
.map { it.generateLightMethod() }
.toList()
}

internal fun PsiMethod.isCompanionedWithBlockingBrideInThisOrSuper(): Boolean {
internal fun PsiMethod.canHaveBridgeFunctions(): Boolean {
return if (isSuspend()
&& Name.isValidIdentifier(this.name)
&& this.hasAnnotation(JvmBlockingBridge::class.qualifiedName!!)
) {
true
} else {
return findOverrides()?.any { it.isCompanionedWithBlockingBrideInThisOrSuper() } == true
return findOverrides()?.any { it.canHaveBridgeFunctions() } == true
}
}

Expand Down Expand Up @@ -138,14 +139,24 @@ internal fun KtLightMethod.generateLightMethod(): PsiMethod {
for (it in originMethod.parameterList.parameters.dropLast(1)) {
addParameter(it)
}
if (isJvmStatic()) {

if (isJvmStatic() || originMethod.parent is KtUltraLightClassForFacade) {
addModifier(PsiModifier.STATIC)
}

PsiModifier.MODIFIERS
VISIBILITIES_MODIFIERS
.filter { originMethod.hasModifierProperty(it) }
.forEach { addModifier(it) }

addModifier(
if (containingClass?.isInterface == true) {
PsiModifier.OPEN
} else when (containingClass?.modality) {
Modality.OPEN, Modality.ABSTRACT, Modality.SEALED -> PsiModifier.OPEN
else -> PsiModifier.FINAL
}
)

for (typeParameter in originMethod.typeParameters) {
addTypeParameter(typeParameter)
}
Expand Down Expand Up @@ -196,4 +207,26 @@ class BlockingBridgeStubMethod(manager: PsiManager, language: Language, name: St
return _body ?: super.getBody()
}

}
}

internal val VISIBILITIES_MODIFIERS = arrayOf(
PsiModifier.PUBLIC,
PsiModifier.PACKAGE_LOCAL,
PsiModifier.PRIVATE,
PsiModifier.PROTECTED,
)

internal val PsiModifierListOwner.modality: Modality
get() {
if (this is PsiMember && this.containingClass?.isInterface == true) {
return Modality.OPEN //
}

return when {
this.hasModifierProperty(PsiModifier.OPEN) -> Modality.OPEN
this.hasModifierProperty(PsiModifier.FINAL) -> Modality.FINAL
this.hasModifierProperty(PsiModifier.ABSTRACT) -> Modality.ABSTRACT
this.hasModifierProperty("sealed") -> Modality.ABSTRACT
else -> Modality.FINAL
}
}

0 comments on commit f494a30

Please sign in to comment.