Skip to content

Commit 6190bad

Browse files
committed
(WIP) fix
1 parent a163f5a commit 6190bad

File tree

2 files changed

+6
-42
lines changed

2 files changed

+6
-42
lines changed

sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/checks/ApiExtensions.kt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.analysis.api.resolution.KaExplicitReceiverValue
2828
import org.jetbrains.kotlin.analysis.api.resolution.KaFunctionCall
2929
import org.jetbrains.kotlin.analysis.api.resolution.KaImplicitReceiverValue
3030
import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
31-
import org.jetbrains.kotlin.analysis.api.resolution.singleVariableAccessCall
3231
import org.jetbrains.kotlin.analysis.api.resolution.successfulCallOrNull
3332
import org.jetbrains.kotlin.analysis.api.resolution.successfulFunctionCallOrNull
3433
import org.jetbrains.kotlin.analysis.api.resolution.symbol
@@ -64,14 +63,12 @@ import org.jetbrains.kotlin.psi.KtCallElement
6463
import org.jetbrains.kotlin.psi.KtCallExpression
6564
import org.jetbrains.kotlin.psi.KtClass
6665
import org.jetbrains.kotlin.psi.KtClassOrObject
67-
import org.jetbrains.kotlin.psi.KtConstantExpression
6866
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
6967
import org.jetbrains.kotlin.psi.KtElement
7068
import org.jetbrains.kotlin.psi.KtExpression
7169
import org.jetbrains.kotlin.psi.KtFunction
7270
import org.jetbrains.kotlin.psi.KtFunctionLiteral
7371
import org.jetbrains.kotlin.psi.KtLambdaArgument
74-
import org.jetbrains.kotlin.psi.KtLambdaExpression
7572
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
7673
import org.jetbrains.kotlin.psi.KtNamedFunction
7774
import org.jetbrains.kotlin.psi.KtParameter
@@ -882,7 +879,6 @@ fun KaType.simpleName(): String? = withKaSession {
882879
return lowerBoundIfFlexible().symbol?.name?.asString()
883880
}
884881

885-
@Deprecated("use kotlin-analysis-api instead", ReplaceWith("this.determineType()"))
886882
fun PsiElement?.determineType(bindingContext: BindingContext): KotlinType? =
887883
this?.let {
888884
when (this) {
@@ -901,34 +897,6 @@ fun PsiElement?.determineType(bindingContext: BindingContext): KotlinType? =
901897

902898
}
903899

904-
fun PsiElement?.determineType(): KaType? = withKaSession {
905-
this?.let {
906-
when (this@determineType) {
907-
is KtCallExpression -> determineTypeFromCall()
908-
is KtParameter -> symbol.returnType
909-
is KtTypeReference -> type
910-
is KtProperty -> determineTypeFromCall()
911-
is KtDotQualifiedExpression -> determineTypeFromCall()
912-
is KtReferenceExpression -> determineTypeFromCall()
913-
is KtFunction -> (symbol as KaFunctionSymbol).returnType
914-
is KtClass -> returnType
915-
is KtConstantExpression -> this@determineType.expressionType
916-
is KtStringTemplateExpression -> this@determineType.expressionType
917-
is KtLambdaExpression -> this@determineType.expressionType
918-
is KtExpression -> determineTypeFromCall()
919-
is KtValueArgument -> this@determineType.getArgumentExpression()?.determineType()
920-
else -> null
921-
}
922-
}
923-
}
924-
925-
private fun KtElement.determineTypeFromCall(): KaType? = withKaSession {
926-
this@determineTypeFromCall.resolveToCall()?.let {
927-
(it.successfulFunctionCallOrNull() ?: it.singleVariableAccessCall())
928-
?.partiallyAppliedSymbol?.symbol?.returnType
929-
}
930-
}
931-
932900
fun KotlinType.isSupertypeOf(other: KotlinType): Boolean {
933901
return findCorrespondingSupertype(other, this).let { it != null && it != other }
934902
}

sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/DelegationPatternCheck.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class DelegationPatternCheck : AbstractCheck() {
6060
}
6161
}
6262

63-
private fun checkNamedFunction(function: KtNamedFunction, superInterfaces: Set<KaClassSymbol>, context: KotlinFileContext) {
63+
private fun checkNamedFunction(function: KtNamedFunction, superInterfaces: Set<KaClassSymbol>, context: KotlinFileContext) = withKaSession {
6464
if (!(function.isPublic && function.overrides())) return
65-
val delegeeType = getDelegeeOrNull(function)?.determineType() ?: return
65+
val delegeeType = getDelegeeOrNull(function)?.expressionType ?: return
6666

6767
if (getCommonSuperInterfaces(superInterfaces, delegeeType).any {
6868
isFunctionInInterface(function, it)
@@ -72,13 +72,9 @@ class DelegationPatternCheck : AbstractCheck() {
7272
}
7373
}
7474

75-
private fun isFunctionInInterface(
76-
function: KtNamedFunction,
77-
superInterface1: KaClassSymbol
78-
): Boolean = withKaSession {
79-
val classDeclaration = superInterface1.psi as? KtClass ?: return false
80-
return classDeclaration.declarations.any {
81-
it is KtNamedFunction && haveCompatibleFunctionSignature(it.symbol, function.symbol)
75+
private fun isFunctionInInterface(function: KtNamedFunction, superInterface: KaClassSymbol): Boolean = withKaSession {
76+
superInterface.declaredMemberScope.declarations.any {
77+
it is KaFunctionSymbol && haveCompatibleFunctionSignature(it, function.symbol)
8278
}
8379
}
8480

@@ -131,7 +127,7 @@ private fun getDelegeeOrNull(function: KtNamedFunction): KtNameReferenceExpressi
131127
private fun isDelegatedParameter(parameter: KtParameter, arguments: KtValueArgument): Boolean = withKaSession {
132128
val argumentExpression = arguments.getArgumentExpression() as? KtNameReferenceExpression ?: return false
133129
if (parameter.name != argumentExpression.getReferencedName()) return false
134-
val argumentType = argumentExpression.determineType() ?: return false
130+
val argumentType = argumentExpression.expressionType ?: return false
135131
return parameter.symbol.returnType.semanticallyEquals(argumentType)
136132
}
137133

0 commit comments

Comments
 (0)