IC IDE: Add intention to add @JvmInline annotation to value class on JVM
#KTIJ-5663 Fixed
This commit is contained in:
@@ -1636,6 +1636,7 @@ add.braces=Add braces
|
|||||||
add.indices.to.for.loop=Add indices to 'for' loop
|
add.indices.to.for.loop=Add indices to 'for' loop
|
||||||
add.jvmoverloads.annotation=Add '@JvmOverloads' annotation
|
add.jvmoverloads.annotation=Add '@JvmOverloads' annotation
|
||||||
add.jvmstatic.annotation=Add '@JvmStatic' annotation
|
add.jvmstatic.annotation=Add '@JvmStatic' annotation
|
||||||
|
add.jvminline.annotation=Add '@JvmInline' annotation
|
||||||
add.labeled.return.to.last.expression.in.a.lambda=Add labeled return to last expression in a lambda
|
add.labeled.return.to.last.expression.in.a.lambda=Add labeled return to last expression in a lambda
|
||||||
add.missing.component=Add missing component
|
add.missing.component=Add missing component
|
||||||
add.names.to.call.arguments=Add names to call arguments
|
add.names.to.call.arguments=Add names to call arguments
|
||||||
|
|||||||
@@ -360,6 +360,11 @@
|
|||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
</intentionAction>
|
</intentionAction>
|
||||||
|
|
||||||
|
<intentionAction>
|
||||||
|
<className>org.jetbrains.kotlin.idea.intentions.AddJvmInlineIntention</className>
|
||||||
|
<category>Kotlin</category>
|
||||||
|
</intentionAction>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.RemoveArgumentNameIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.RemoveArgumentNameIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
|
||||||
|
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||||
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
|
import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_FQ_NAME
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
|
class AddJvmInlineIntention : SelfTargetingRangeIntention<KtClass>(
|
||||||
|
KtClass::class.java,
|
||||||
|
KotlinBundle.lazyMessage("add.jvminline.annotation")
|
||||||
|
), HighPriorityAction {
|
||||||
|
override fun applyTo(element: KtClass, editor: Editor?) {
|
||||||
|
runWriteAction {
|
||||||
|
element.addAnnotation(JVM_INLINE_ANNOTATION_FQ_NAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applicabilityRange(element: KtClass): TextRange? {
|
||||||
|
if (!element.isValue()) return null
|
||||||
|
|
||||||
|
val modifier = element.modifierList?.getModifier(KtTokens.VALUE_KEYWORD) ?: return null
|
||||||
|
return modifier.textRange
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
|
val valueModifier = ErrorsJvm.VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION.cast(diagnostic)
|
||||||
|
val modifierListOwner = valueModifier.psiElement.getParentOfType<KtModifierListOwner>(strict = true) ?: return null
|
||||||
|
return if (valueModifier != null) AddJvmInlineIntention() else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.idea.intentions.AddJvmInlineIntention
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
// ERROR: Value classes without @JvmInline annotation are not supported yet
|
||||||
|
// SKIP_ERRORS_AFTER
|
||||||
|
|
||||||
|
<caret>value class VC(val i: Int)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
// ERROR: Value classes without @JvmInline annotation are not supported yet
|
||||||
|
// SKIP_ERRORS_AFTER
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class VC(val i: Int)
|
||||||
@@ -932,6 +932,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/intentions/addJvmInline")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class AddJvmInline extends AbstractIntentionTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInAddJvmInline() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addJvmInline"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("valueClass.kt")
|
||||||
|
public void testValueClass() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/addJvmInline/valueClass.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/intentions/addJvmOverloads")
|
@TestMetadata("idea/testData/intentions/addJvmOverloads")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user