diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest.kt new file mode 100644 index 00000000000..a5d496cd167 --- /dev/null +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest.kt @@ -0,0 +1,27 @@ +/* + * 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.incremental + +import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments +import java.io.File + +abstract class AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest : AbstractIncrementalJsCompilerRunnerTest() { + override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments = + super.createCompilerArguments(destinationDir, testDir).apply { + friendModulesDisabled = true + } +} \ No newline at end of file diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerTestGenerated.java index 5c76189f7af..82756dd5335 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerTestGenerated.java @@ -959,4 +959,28 @@ public class IncrementalJsCompilerRunnerTestGenerated extends AbstractIncrementa doTest(fileName); } } + + @TestMetadata("jps-plugin/testData/incremental/js") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Js extends AbstractIncrementalJsCompilerRunnerTest { + public void testAllFilesPresentInJs() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/js"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true); + } + + @TestMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FriendsModuleDisabled extends AbstractIncrementalJsCompilerRunnerTest { + public void testAllFilesPresentInFriendsModuleDisabled() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/js/friendsModuleDisabled"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true); + } + + @TestMetadata("internalInlineFunctionIsChanged") + public void testInternalInlineFunctionIsChanged() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/"); + doTest(fileName); + } + } + } } diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerWithFriendModulesDisabledTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerWithFriendModulesDisabledTestGenerated.java new file mode 100644 index 00000000000..d867a19d7ad --- /dev/null +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunnerWithFriendModulesDisabledTestGenerated.java @@ -0,0 +1,44 @@ +/* + * 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.incremental; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class IncrementalJsCompilerRunnerWithFriendModulesDisabledTestGenerated extends AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest { + public void testAllFilesPresentInFriendsModuleDisabled() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/js/friendsModuleDisabled"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false); + } + + @TestMetadata("internalInlineFunctionIsChanged") + public void testInternalInlineFunctionIsChanged() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/"); + doTest(fileName); + } +} diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 368d60863b2..b014640fcbd 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -135,10 +135,7 @@ import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest import org.jetbrains.kotlin.idea.stubs.AbstractStubBuilderTest -import org.jetbrains.kotlin.incremental.AbstractIncrementalJsCompilerRunnerTest -import org.jetbrains.kotlin.incremental.AbstractIncrementalJvmCompilerRunnerTest -import org.jetbrains.kotlin.incremental.AbstractIncrementalMultiplatformJsCompilerRunnerTest -import org.jetbrains.kotlin.incremental.AbstractIncrementalMultiplatformJvmCompilerRunnerTest +import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest @@ -921,6 +918,11 @@ fun main(args: Array) { testClass { model("incremental/pureKotlin", extension = null, recursive = false) model("incremental/classHierarchyAffected", extension = null, recursive = false) + model("incremental/js", extension = null, excludeParentDirs = true) + } + + testClass { + model("incremental/js/friendsModuleDisabled", extension = null, recursive = false) } testClass { diff --git a/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/dummy.kt b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/dummy.kt new file mode 100644 index 00000000000..3f0c1c77242 --- /dev/null +++ b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/dummy.kt @@ -0,0 +1 @@ +fun dummy() {} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt new file mode 100644 index 00000000000..9e1c744c446 --- /dev/null +++ b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt @@ -0,0 +1 @@ +internal inline fun foo() = 0 \ No newline at end of file diff --git a/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt.new b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt.new new file mode 100644 index 00000000000..b8f030e8000 --- /dev/null +++ b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/inline.kt.new @@ -0,0 +1 @@ +internal inline fun foo() = 1 \ No newline at end of file diff --git a/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/js-build.log b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/js-build.log new file mode 100644 index 00000000000..c93f1481460 --- /dev/null +++ b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/js-build.log @@ -0,0 +1,8 @@ +================ Step #1 ================= + +Compiling files: + src/inline.kt + src/usage.kt +End of files +Exit code: OK + diff --git a/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/usage.kt b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/usage.kt new file mode 100644 index 00000000000..40dfa767a58 --- /dev/null +++ b/jps-plugin/testData/incremental/js/friendsModuleDisabled/internalInlineFunctionIsChanged/usage.kt @@ -0,0 +1 @@ +fun usage() = foo() \ No newline at end of file diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/FunctionTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/FunctionTranslator.kt index 9f67c613292..1c727186ddb 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/FunctionTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/FunctionTranslator.kt @@ -17,7 +17,9 @@ package org.jetbrains.kotlin.js.translate.expression import com.intellij.openapi.vfs.VfsUtilCore +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer import org.jetbrains.kotlin.js.backend.ast.* import org.jetbrains.kotlin.js.backend.ast.metadata.descriptor import org.jetbrains.kotlin.js.backend.ast.metadata.functionDescriptor @@ -103,36 +105,12 @@ fun TranslationContext.wrapWithInlineMetadata( ): JsExpression { val sourceInfo = descriptor.source.getPsi() return if (descriptor.isInline) { + val incrementalResults = config.configuration[JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER] + incrementalResults?.reportInlineFunction(descriptor, function, sourceInfo) + if (descriptor.shouldBeExported(config)) { val metadata = InlineMetadata.compose(function, descriptor, this) - val functionWithMetadata = metadata.functionWithMetadata(outerContext, sourceInfo) - config.configuration[JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER]?.apply { - val psiFile = (descriptor.source.containingFile as? PsiSourceFile)?.psiFile ?: return@apply - val file = VfsUtilCore.virtualToIoFile(psiFile.virtualFile) - - val fqName = when (descriptor) { - is PropertyGetterDescriptor -> { - "" + descriptor.correspondingProperty.fqNameSafe.asString() - } - is PropertySetterDescriptor -> { - "" + descriptor.correspondingProperty.fqNameSafe.asString() - } - else -> descriptor.fqNameSafe.asString() - } - - val offset = sourceInfo?.node?.startOffset - val document = psiFile.viewProvider.document - var sourceLine = -1 - var sourceColumn = -1 - if (offset != null && document != null) { - sourceLine = document.getLineNumber(offset) - sourceColumn = offset - document.getLineStartOffset(sourceLine) - } - - processInlineFunction(file, fqName, functionWithMetadata, sourceLine, sourceColumn) - } - - functionWithMetadata + metadata.functionWithMetadata(outerContext, sourceInfo) } else { val block = @@ -147,3 +125,35 @@ fun TranslationContext.wrapWithInlineMetadata( function } } + +private fun IncrementalResultsConsumer.reportInlineFunction( + descriptor: FunctionDescriptor, + translatedFunction: JsExpression, + sourceInfo: PsiElement? +) { + val psiFile = (descriptor.source.containingFile as? PsiSourceFile)?.psiFile ?: return + val file = VfsUtilCore.virtualToIoFile(psiFile.virtualFile) + + if (effectiveVisibility(descriptor.visibility, descriptor, true).privateApi) return + + val fqName = when (descriptor) { + is PropertyGetterDescriptor -> { + "" + descriptor.correspondingProperty.fqNameSafe.asString() + } + is PropertySetterDescriptor -> { + "" + descriptor.correspondingProperty.fqNameSafe.asString() + } + else -> descriptor.fqNameSafe.asString() + } + + val offset = sourceInfo?.node?.startOffset + val document = psiFile.viewProvider.document + var sourceLine = -1 + var sourceColumn = -1 + if (offset != null && document != null) { + sourceLine = document.getLineNumber(offset) + sourceColumn = offset - document.getLineStartOffset(sourceLine) + } + + processInlineFunction(file, fqName, translatedFunction, sourceLine, sourceColumn) +}