Add extension point for back-ends to perform platform-specific checks of class literals
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.types.expressions
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
|
interface ClassLiteralChecker {
|
||||||
|
fun check(expression: KtClassLiteralExpression, type: KotlinType, context: ResolutionContext<*>)
|
||||||
|
}
|
||||||
+5
-1
@@ -76,7 +76,8 @@ class DoubleColonExpressionResolver(
|
|||||||
val dataFlowAnalyzer: DataFlowAnalyzer,
|
val dataFlowAnalyzer: DataFlowAnalyzer,
|
||||||
val reflectionTypes: ReflectionTypes,
|
val reflectionTypes: ReflectionTypes,
|
||||||
val typeResolver: TypeResolver,
|
val typeResolver: TypeResolver,
|
||||||
val languageVersionSettings: LanguageVersionSettings
|
val languageVersionSettings: LanguageVersionSettings,
|
||||||
|
val additionalCheckers: Iterable<ClassLiteralChecker>
|
||||||
) {
|
) {
|
||||||
private lateinit var expressionTypingServices: ExpressionTypingServices
|
private lateinit var expressionTypingServices: ExpressionTypingServices
|
||||||
|
|
||||||
@@ -137,6 +138,9 @@ class DoubleColonExpressionResolver(
|
|||||||
else if (!result.possiblyBareType.isBare && !isAllowedInClassLiteral(type)) {
|
else if (!result.possiblyBareType.isBare && !isAllowedInClassLiteral(type)) {
|
||||||
c.trace.report(CLASS_LITERAL_LHS_NOT_A_CLASS.on(expression))
|
c.trace.report(CLASS_LITERAL_LHS_NOT_A_CLASS.on(expression))
|
||||||
}
|
}
|
||||||
|
for (additionalChecker in additionalCheckers) {
|
||||||
|
additionalChecker.check(expression, type, c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the expression is not a call expression without value arguments (such as "A<B>") or a qualified expression
|
// Returns true if the expression is not a call expression without value arguments (such as "A<B>") or a qualified expression
|
||||||
|
|||||||
Reference in New Issue
Block a user