From 5f2c7d3c84fa64697492d5083a1c28215405ac22 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 5 Sep 2018 18:31:23 +0300 Subject: [PATCH] Do not report OPTIONAL_DECLARATION_USAGE_... in IDE for platform modules #KT-26585 Fixed Also fixes MultiPlatformHighlightingTestGenerated.testMultifileFacade --- .../resolve/checkers/OptionalExpectationUsageChecker.kt | 6 +++++- .../jvmNameInCommon/common_dep(stdlib)/common.kt | 2 ++ .../multiplatform/jvmNameInCommon/jvm_dep(stdlib)/test.kt | 5 +++++ .../resolve/MultiPlatformHighlightingTestGenerated.java | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/common_dep(stdlib)/common.kt create mode 100644 idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/jvm_dep(stdlib)/test.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/OptionalExpectationUsageChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/OptionalExpectationUsageChecker.kt index 496ac9e6920..6fd1c5c43b7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/OptionalExpectationUsageChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/OptionalExpectationUsageChecker.kt @@ -9,6 +9,9 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.resolve.MultiTargetPlatform +import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.resolve.getMultiTargetPlatform import org.jetbrains.kotlin.resolve.multiplatform.isCommonSource class OptionalExpectationUsageChecker : ClassifierUsageChecker { @@ -20,7 +23,8 @@ class OptionalExpectationUsageChecker : ClassifierUsageChecker { } val ktFile = element.containingFile as KtFile - if (ktFile.isCommonSource != true) { + // The first part is for the compiler, and the second one is for IDE + if (ktFile.isCommonSource != true && targetDescriptor.module.getMultiTargetPlatform() != MultiTargetPlatform.Common) { context.trace.report(Errors.OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE.on(element)) } } diff --git a/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/common_dep(stdlib)/common.kt b/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/common_dep(stdlib)/common.kt new file mode 100644 index 00000000000..6753c379bd5 --- /dev/null +++ b/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/common_dep(stdlib)/common.kt @@ -0,0 +1,2 @@ +@kotlin.jvm.JvmName("declarationFunName") +fun declaration() { } \ No newline at end of file diff --git a/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/jvm_dep(stdlib)/test.kt b/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/jvm_dep(stdlib)/test.kt new file mode 100644 index 00000000000..95a26d57f25 --- /dev/null +++ b/idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/jvm_dep(stdlib)/test.kt @@ -0,0 +1,5 @@ +// !CHECK_HIGHLIGHTING + +fun test() { + declaration() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiPlatformHighlightingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiPlatformHighlightingTestGenerated.java index 9978b2008c9..f6ef438463c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiPlatformHighlightingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiPlatformHighlightingTestGenerated.java @@ -109,6 +109,11 @@ public class MultiPlatformHighlightingTestGenerated extends AbstractMultiPlatfor runTest("idea/testData/multiModuleHighlighting/multiplatform/jvmKotlinReferencesCommonKotlinThroughJavaDifferentJvmImpls/"); } + @TestMetadata("jvmNameInCommon") + public void testJvmNameInCommon() throws Exception { + runTest("idea/testData/multiModuleHighlighting/multiplatform/jvmNameInCommon/"); + } + @TestMetadata("multifileFacade") public void testMultifileFacade() throws Exception { runTest("idea/testData/multiModuleHighlighting/multiplatform/multifileFacade/");