From 95291cdc18c118020a6bb68bf4c12fa6282fdd5d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 28 Jun 2016 18:40:33 +0300 Subject: [PATCH] Minor, move some checkers to more appropriate places --- .../kotlin/codegen/FunctionCodegen.java | 7 ++-- .../kotlin/load/kotlin/annotationUtil.kt | 32 ------------------- .../jvm/checkers/ExternalFunChecker.kt} | 17 ++++------ .../checkers}/JavaAnnotationCallChecker.kt | 18 +++++++++-- .../jvm/platform/JvmPlatformConfigurator.kt | 4 +-- .../checkers}/ConstructorHeaderCallChecker.kt | 7 ++-- ...aceJavaAnnotationPositionedArgumentsFix.kt | 11 +++---- 7 files changed, 33 insertions(+), 63 deletions(-) delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/annotationUtil.kt rename compiler/frontend.java/src/org/jetbrains/kotlin/{load/kotlin/native.kt => resolve/jvm/checkers/ExternalFunChecker.kt} (83%) rename compiler/frontend.java/src/org/jetbrains/kotlin/{load/kotlin => resolve/jvm/checkers}/JavaAnnotationCallChecker.kt (81%) rename compiler/frontend/src/org/jetbrains/kotlin/resolve/{ => calls/checkers}/ConstructorHeaderCallChecker.kt (92%) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index c253d046400..aa993287a24 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -39,7 +39,6 @@ import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo; import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature; import org.jetbrains.kotlin.load.java.JvmAbi; import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers; -import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeKt; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.psi.KtElement; import org.jetbrains.kotlin.psi.KtFunction; @@ -173,9 +172,7 @@ public class FunctionCodegen { flags |= ACC_SYNTHETIC; } - boolean isNative = NativeKt.hasNativeAnnotation(functionDescriptor); - - if (isNative && owner instanceof MultifileClassFacadeContext) { + if (functionDescriptor.isExternal() && owner instanceof MultifileClassFacadeContext) { // Native methods are only defined in facades and do not need package part implementations return; } @@ -217,7 +214,7 @@ public class FunctionCodegen { return; } - if (!isNative) { + if (!functionDescriptor.isExternal()) { generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen); } else if (staticInCompanionObject) { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/annotationUtil.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/annotationUtil.kt deleted file mode 100644 index d9502d63cd6..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/annotationUtil.kt +++ /dev/null @@ -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 = - resolvedCall.valueArguments.filter { - p -> - p.key.name != JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME && - p.value is ExpressionValueArgument && - !((p.value as ExpressionValueArgument).valueArgument?.isNamed() ?: true) - } - diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt similarity index 83% rename from compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt rename to compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt index 395383641bb..38d67aa8303 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ExternalFunChecker.kt @@ -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)) } - } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/JavaAnnotationCallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaAnnotationCallChecker.kt similarity index 81% rename from compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/JavaAnnotationCallChecker.kt rename to compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaAnnotationCallChecker.kt index 8fd74f918ab..58b1e3e5989 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/JavaAnnotationCallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaAnnotationCallChecker.kt @@ -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 = + resolvedCall.valueArguments.filter { + p -> + p.key.name != JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME && + p.value is ExpressionValueArgument && + !((p.value as ExpressionValueArgument).valueArgument?.isNamed() ?: true) + } + } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index 2cb7a13c865..bc7eacddc46 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -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(), diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ConstructorHeaderCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ConstructorHeaderCallChecker.kt similarity index 92% rename from compiler/frontend/src/org/jetbrains/kotlin/resolve/ConstructorHeaderCallChecker.kt rename to compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ConstructorHeaderCallChecker.kt index 063f4209652..a619b17abee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ConstructorHeaderCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ConstructorHeaderCallChecker.kt @@ -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,15 +14,14 @@ * limitations under the License. */ -package org.jetbrains.kotlin.resolve +package org.jetbrains.kotlin.resolve.calls.checkers import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.psi.KtInstanceExpressionWithLabel -import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker -import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext +import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt index 3035dcee151..d614d056401 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt @@ -21,12 +21,12 @@ import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType -import org.jetbrains.kotlin.load.kotlin.getJavaAnnotationCallValueArgumentsThatShouldBeNamed import org.jetbrains.kotlin.psi.KtAnnotationEntry import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument +import org.jetbrains.kotlin.resolve.jvm.checkers.JavaAnnotationCallChecker class ReplaceJavaAnnotationPositionedArgumentsFix(element: KtAnnotationEntry) : KotlinQuickFixAction(element), CleanupFix { @@ -37,12 +37,11 @@ class ReplaceJavaAnnotationPositionedArgumentsFix(element: KtAnnotationEntry) val resolvedCall = element.getResolvedCall(element.analyze()) ?: return val psiFactory = KtPsiFactory(project) - getJavaAnnotationCallValueArgumentsThatShouldBeNamed(resolvedCall).forEach argumentProcessor@{ - argument -> - val valueArgument = (argument.value as? ExpressionValueArgument)?.valueArgument ?: return@argumentProcessor - val expression = valueArgument.getArgumentExpression() ?: return@argumentProcessor + for ((key, value) in JavaAnnotationCallChecker.getJavaAnnotationCallValueArgumentsThatShouldBeNamed(resolvedCall)) { + val valueArgument = (value as? ExpressionValueArgument)?.valueArgument ?: continue + val expression = valueArgument.getArgumentExpression() ?: continue - valueArgument.asElement().replace(psiFactory.createArgument(expression, argument.key.name)) + valueArgument.asElement().replace(psiFactory.createArgument(expression, key.name)) } }