Minor, move some checkers to more appropriate places

This commit is contained in:
Alexander Udalov
2016-06-28 18:40:33 +03:00
parent ff72348105
commit 95291cdc18
7 changed files with 33 additions and 63 deletions
@@ -1,32 +0,0 @@
/*
* Copyright 2010-2015 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.load.kotlin
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
fun getJavaAnnotationCallValueArgumentsThatShouldBeNamed(resolvedCall: ResolvedCall<*>): Map<ValueParameterDescriptor, ResolvedValueArgument> =
resolvedCall.valueArguments.filter {
p ->
p.key.name != JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME &&
p.value is ExpressionValueArgument &&
!((p.value as ExpressionValueArgument).valueArgument?.isNamed() ?: true)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -14,36 +14,32 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.load.kotlin.nativeDeclarations
package org.jetbrains.kotlin.resolve.jvm.checkers
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
fun DeclarationDescriptor.hasNativeAnnotation(): Boolean {
return this is FunctionDescriptor && this.isExternal
}
class NativeFunChecker : SimpleDeclarationChecker {
class ExternalFunChecker : SimpleDeclarationChecker {
override fun check(
declaration: KtDeclaration,
descriptor: DeclarationDescriptor,
diagnosticHolder: DiagnosticSink,
bindingContext: BindingContext
) {
if (!descriptor.hasNativeAnnotation()) return
if (descriptor !is FunctionDescriptor || !descriptor.isExternal) return
if (DescriptorUtils.isInterface(descriptor.containingDeclaration)) {
diagnosticHolder.report(ErrorsJvm.EXTERNAL_DECLARATION_IN_INTERFACE.on(declaration))
}
else if (descriptor is CallableMemberDescriptor &&
descriptor.modality == Modality.ABSTRACT) {
descriptor.modality == Modality.ABSTRACT) {
diagnosticHolder.report(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_BE_ABSTRACT.on(declaration))
}
@@ -54,6 +50,5 @@ class NativeFunChecker : SimpleDeclarationChecker {
if (InlineUtil.isInline(descriptor)) {
diagnosticHolder.report(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_BE_INLINED.on(declaration))
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -14,12 +14,13 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.load.kotlin
package org.jetbrains.kotlin.resolve.jvm.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.components.JavaAnnotationMapper
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
import org.jetbrains.kotlin.psi.KtAnnotationEntry
@@ -28,6 +29,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
@@ -66,4 +68,16 @@ class JavaAnnotationCallChecker : CallChecker {
context.trace.report(diagnostic.on(argumentExpression))
}
}
companion object {
fun getJavaAnnotationCallValueArgumentsThatShouldBeNamed(
resolvedCall: ResolvedCall<*>
): Map<ValueParameterDescriptor, ResolvedValueArgument> =
resolvedCall.valueArguments.filter {
p ->
p.key.name != JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME &&
p.value is ExpressionValueArgument &&
!((p.value as ExpressionValueArgument).valueArgument?.isNamed() ?: true)
}
}
}
@@ -20,8 +20,6 @@ import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useImpl
import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.jvm.RuntimeAssertionsTypeChecker
import org.jetbrains.kotlin.load.kotlin.JavaAnnotationCallChecker
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeFunChecker
import org.jetbrains.kotlin.resolve.PlatformConfigurator
import org.jetbrains.kotlin.resolve.jvm.JvmOverloadFilter
import org.jetbrains.kotlin.resolve.jvm.JvmTypeSpecificityComparator
@@ -38,7 +36,7 @@ object JvmPlatformConfigurator : PlatformConfigurator(
SynchronizedAnnotationChecker(),
LocalFunInlineChecker(),
ReifiedTypeParameterAnnotationChecker(),
NativeFunChecker(),
ExternalFunChecker(),
OverloadsAnnotationChecker(),
JvmFieldApplicabilityChecker(),
TypeParameterBoundIsNotArrayChecker(),