Track changes in inline function when friend paths are disabled in JS
This commit is contained in:
+27
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -959,4 +959,28 @@ public class IncrementalJsCompilerRunnerTestGenerated extends AbstractIncrementa
|
|||||||
doTest(fileName);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -135,10 +135,7 @@ import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest
|
|||||||
import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
|
import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
|
||||||
import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest
|
import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest
|
||||||
import org.jetbrains.kotlin.idea.stubs.AbstractStubBuilderTest
|
import org.jetbrains.kotlin.idea.stubs.AbstractStubBuilderTest
|
||||||
import org.jetbrains.kotlin.incremental.AbstractIncrementalJsCompilerRunnerTest
|
import org.jetbrains.kotlin.incremental.*
|
||||||
import org.jetbrains.kotlin.incremental.AbstractIncrementalJvmCompilerRunnerTest
|
|
||||||
import org.jetbrains.kotlin.incremental.AbstractIncrementalMultiplatformJsCompilerRunnerTest
|
|
||||||
import org.jetbrains.kotlin.incremental.AbstractIncrementalMultiplatformJvmCompilerRunnerTest
|
|
||||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
|
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
|
||||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
|
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
|
||||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
|
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
|
||||||
@@ -921,6 +918,11 @@ fun main(args: Array<String>) {
|
|||||||
testClass<AbstractIncrementalJsCompilerRunnerTest> {
|
testClass<AbstractIncrementalJsCompilerRunnerTest> {
|
||||||
model("incremental/pureKotlin", extension = null, recursive = false)
|
model("incremental/pureKotlin", extension = null, recursive = false)
|
||||||
model("incremental/classHierarchyAffected", extension = null, recursive = false)
|
model("incremental/classHierarchyAffected", extension = null, recursive = false)
|
||||||
|
model("incremental/js", extension = null, excludeParentDirs = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
testClass<AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest> {
|
||||||
|
model("incremental/js/friendsModuleDisabled", extension = null, recursive = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass<AbstractIncrementalMultiplatformJvmCompilerRunnerTest> {
|
testClass<AbstractIncrementalMultiplatformJvmCompilerRunnerTest> {
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
fun dummy() {}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
internal inline fun foo() = 0
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
internal inline fun foo() = 1
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
================ Step #1 =================
|
||||||
|
|
||||||
|
Compiling files:
|
||||||
|
src/inline.kt
|
||||||
|
src/usage.kt
|
||||||
|
End of files
|
||||||
|
Exit code: OK
|
||||||
|
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
fun usage() = foo()
|
||||||
+38
-28
@@ -17,7 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.js.translate.expression
|
package org.jetbrains.kotlin.js.translate.expression
|
||||||
|
|
||||||
import com.intellij.openapi.vfs.VfsUtilCore
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
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.*
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.descriptor
|
import org.jetbrains.kotlin.js.backend.ast.metadata.descriptor
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.functionDescriptor
|
import org.jetbrains.kotlin.js.backend.ast.metadata.functionDescriptor
|
||||||
@@ -103,36 +105,12 @@ fun TranslationContext.wrapWithInlineMetadata(
|
|||||||
): JsExpression {
|
): JsExpression {
|
||||||
val sourceInfo = descriptor.source.getPsi()
|
val sourceInfo = descriptor.source.getPsi()
|
||||||
return if (descriptor.isInline) {
|
return if (descriptor.isInline) {
|
||||||
|
val incrementalResults = config.configuration[JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER]
|
||||||
|
incrementalResults?.reportInlineFunction(descriptor, function, sourceInfo)
|
||||||
|
|
||||||
if (descriptor.shouldBeExported(config)) {
|
if (descriptor.shouldBeExported(config)) {
|
||||||
val metadata = InlineMetadata.compose(function, descriptor, this)
|
val metadata = InlineMetadata.compose(function, descriptor, this)
|
||||||
val functionWithMetadata = metadata.functionWithMetadata(outerContext, sourceInfo)
|
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 -> {
|
|
||||||
"<get>" + descriptor.correspondingProperty.fqNameSafe.asString()
|
|
||||||
}
|
|
||||||
is PropertySetterDescriptor -> {
|
|
||||||
"<set>" + 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
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val block =
|
val block =
|
||||||
@@ -147,3 +125,35 @@ fun TranslationContext.wrapWithInlineMetadata(
|
|||||||
function
|
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 -> {
|
||||||
|
"<get>" + descriptor.correspondingProperty.fqNameSafe.asString()
|
||||||
|
}
|
||||||
|
is PropertySetterDescriptor -> {
|
||||||
|
"<set>" + 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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user