Revert "Instantiation of annotations for JVM IR with the corresponding feature flag"
because of incorrect rebase
This reverts commit ce0a3a57
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
* 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.resolve.calls
|
||||
@@ -227,8 +238,7 @@ class CallExpressionResolver(
|
||||
if (functionDescriptor is ConstructorDescriptor) {
|
||||
val constructedClass = functionDescriptor.constructedClass
|
||||
if (DescriptorUtils.isAnnotationClass(constructedClass) && !canInstantiateAnnotationClass(callExpression, context.trace)) {
|
||||
val supported = context.languageVersionSettings.supportsFeature(LanguageFeature.InstantiationOfAnnotationClasses) && constructedClass.declaredTypeParameters.isEmpty()
|
||||
if (!supported) context.trace.report(ANNOTATION_CLASS_CONSTRUCTOR_CALL.on(callExpression))
|
||||
context.trace.report(ANNOTATION_CLASS_CONSTRUCTOR_CALL.on(callExpression))
|
||||
}
|
||||
if (DescriptorUtils.isEnumClass(constructedClass)) {
|
||||
context.trace.report(ENUM_CLASS_CONSTRUCTOR_CALL.on(callExpression))
|
||||
@@ -505,7 +515,7 @@ class CallExpressionResolver(
|
||||
|
||||
companion object {
|
||||
|
||||
fun canInstantiateAnnotationClass(expression: KtCallExpression, trace: BindingTrace): Boolean {
|
||||
private fun canInstantiateAnnotationClass(expression: KtCallExpression, trace: BindingTrace): Boolean {
|
||||
//noinspection unchecked
|
||||
var parent: PsiElement? = PsiTreeUtil.getParentOfType(expression, KtValueArgument::class.java, KtParameter::class.java)
|
||||
if (parent is KtValueArgument) {
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
|
||||
/**
|
||||
* Additional checker that prohibits usage of LanguageFeature.InstantiationOfAnnotationClasses on backends
|
||||
* that do not support this feature yet
|
||||
*/
|
||||
object InstantiationOfAnnotationClassesCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.InstantiationOfAnnotationClasses)) return
|
||||
val calledDescriptor = resolvedCall.resultingDescriptor as? ConstructorDescriptor ?: return
|
||||
val constructedClass = calledDescriptor.constructedClass
|
||||
val expression = resolvedCall.call.callElement as? KtCallExpression ?: return
|
||||
if (DescriptorUtils.isAnnotationClass(constructedClass) && !CallExpressionResolver.canInstantiateAnnotationClass(
|
||||
expression,
|
||||
context.trace
|
||||
)
|
||||
) {
|
||||
val supported = constructedClass.declaredTypeParameters.isEmpty()
|
||||
if (supported) {
|
||||
context.trace.report(Errors.ANNOTATION_CLASS_CONSTRUCTOR_CALL.on(expression))
|
||||
} else {
|
||||
// already reported in CallExpressionResolver.getCallExpressionTypeInfoWithoutFinalTypeCheck
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user