Add @JvmInline annotation in common code if JVM target is present
#KTIJ-8863 Fixed #KT-46088 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
00bc04b3df
commit
f5379c5a04
@@ -14,7 +14,8 @@ import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.platform.has
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
@@ -26,7 +27,7 @@ class InlineClassDeprecatedFix(
|
||||
|
||||
private val text = KotlinBundle.message(
|
||||
"replace.with.0",
|
||||
(if (TargetPlatformDetector.getPlatform(element.containingKtFile).isJvm()) "@JvmInline " else "") + "value"
|
||||
(if (element.containingKtFile.hasJvmTarget()) "@JvmInline " else "") + "value"
|
||||
)
|
||||
|
||||
override fun getText() = text
|
||||
@@ -36,7 +37,7 @@ class InlineClassDeprecatedFix(
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
element?.removeModifier(KtTokens.INLINE_KEYWORD)
|
||||
element?.addModifier(KtTokens.VALUE_KEYWORD)
|
||||
if (TargetPlatformDetector.getPlatform(file).isJvm()) {
|
||||
if (file.hasJvmTarget()) {
|
||||
element?.addAnnotation(JVM_INLINE_ANNOTATION_FQ_NAME)
|
||||
}
|
||||
}
|
||||
@@ -48,4 +49,7 @@ class InlineClassDeprecatedFix(
|
||||
return if (deprecatedModifier != null) InlineClassDeprecatedFix(modifierListOwner) else null
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtFile.hasJvmTarget(): Boolean =
|
||||
TargetPlatformDetector.getPlatform(this).has<JvmPlatform>()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Replace with 'value'" "true"
|
||||
|
||||
<caret>inline class IC1(val i: Int)
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Replace with 'value'" "true"
|
||||
|
||||
value class IC1(val i: Int)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Replace with '@JvmInline value'" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
<caret>inline class IC(val i: Int)
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with '@JvmInline value'" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
@kotlin.jvm.JvmInline
|
||||
value class IC(val i: Int)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Replace with '@JvmInline value'" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
<caret>inline class IC(val i: Int)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Replace with '@JvmInline value'" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
@kotlin.jvm.JvmInline
|
||||
value class IC(val i: Int)
|
||||
+28
@@ -853,6 +853,34 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/multiModuleQuickFix/inlineToValue")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class InlineToValue extends AbstractQuickFixMultiModuleTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInInlineToValue() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/multiModuleQuickFix/inlineToValue"), Pattern.compile("^([^\\.]+)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("commonWithJvm")
|
||||
public void testCommonWithJvm() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/inlineToValue/commonWithJvm/");
|
||||
}
|
||||
|
||||
@TestMetadata("JS")
|
||||
public void testJS() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/inlineToValue/JS/");
|
||||
}
|
||||
|
||||
@TestMetadata("JVM")
|
||||
public void testJVM() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/inlineToValue/JVM/");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/multiModuleQuickFix/makeOverridenMemberOpen")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user