Add quick fix for adding @JvmDefault annotation
This commit is contained in:
+16
@@ -4,6 +4,7 @@ public interface JavaInterface {
|
|||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open fun test(): kotlin.Unit
|
public open fun test(): kotlin.Unit
|
||||||
|
public abstract fun testAbstract(): kotlin.Unit
|
||||||
public open fun testForNonDefault(): kotlin.Unit
|
public open fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
@@ -13,6 +14,7 @@ public open class KotlinClass : JavaInterface {
|
|||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ fun test(): kotlin.Unit
|
public open override /*1*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ fun testAbstract(): kotlin.Unit
|
||||||
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
@@ -21,14 +23,25 @@ public interface KotlinInterface : JavaInterface {
|
|||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
@kotlin.jvm.JvmDefault public open override /*1*/ fun test(): kotlin.Unit
|
@kotlin.jvm.JvmDefault public open override /*1*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ fun testAbstract(): kotlin.Unit
|
||||||
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface KotlinInterface2 : JavaInterface, KotlinInterface {
|
||||||
|
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
@kotlin.jvm.JvmDefault public open override /*2*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*2*/ fun testAbstract(): kotlin.Unit
|
||||||
|
public open override /*2*/ fun testForNonDefault(): kotlin.Unit
|
||||||
|
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
public interface KotlinInterfaceForIndirect : JavaInterface {
|
public interface KotlinInterfaceForIndirect : JavaInterface {
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun test(): kotlin.Unit
|
public open override /*1*/ /*fake_override*/ fun test(): kotlin.Unit
|
||||||
|
public abstract override /*1*/ /*fake_override*/ fun testAbstract(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun testForNonDefault(): kotlin.Unit
|
public open override /*1*/ /*fake_override*/ fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
@@ -37,6 +50,7 @@ public interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect
|
|||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
@kotlin.jvm.JvmDefault public open override /*1*/ fun test(): kotlin.Unit
|
@kotlin.jvm.JvmDefault public open override /*1*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ fun testAbstract(): kotlin.Unit
|
||||||
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
public open override /*1*/ fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
@@ -45,6 +59,7 @@ public interface KotlinInterfaceManySuper : JavaInterface, KotlinInterfaceX {
|
|||||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
@kotlin.jvm.JvmDefault public open override /*2*/ fun test(): kotlin.Unit
|
@kotlin.jvm.JvmDefault public open override /*2*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*2*/ fun testAbstract(): kotlin.Unit
|
||||||
public open override /*2*/ fun testForNonDefault(): kotlin.Unit
|
public open override /*2*/ fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
@@ -53,6 +68,7 @@ public interface KotlinInterfaceX {
|
|||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open fun test(): kotlin.Unit
|
public open fun test(): kotlin.Unit
|
||||||
|
public open fun testAbstract(): kotlin.Unit
|
||||||
public open fun testForNonDefault(): kotlin.Unit
|
public open fun testForNonDefault(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. 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.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||||
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
|
import org.jetbrains.kotlin.resolve.annotations.JVM_DEFAULT_FQ_NAME
|
||||||
|
|
||||||
|
class AddJvmDefaultAnnotation(declaration: KtCallableDeclaration) : KotlinQuickFixAction<KtCallableDeclaration>(declaration) {
|
||||||
|
override fun getText(): String = "Add '@JvmDefault' annotation"
|
||||||
|
|
||||||
|
override fun getFamilyName(): String = text
|
||||||
|
|
||||||
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
|
element?.addAnnotation(JVM_DEFAULT_FQ_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
|
val psiElement = diagnostic.psiElement
|
||||||
|
if (psiElement is KtNamedFunction || psiElement is KtProperty)
|
||||||
|
return AddJvmDefaultAnnotation(psiElement as KtCallableDeclaration)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -519,5 +519,8 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION.registerFactory(SurroundWithArrayOfWithSpreadOperatorInFunctionFix)
|
ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION.registerFactory(SurroundWithArrayOfWithSpreadOperatorInFunctionFix)
|
||||||
|
|
||||||
JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE.registerFactory(KotlinAddRequiredModuleFix)
|
JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE.registerFactory(KotlinAddRequiredModuleFix)
|
||||||
|
|
||||||
|
JVM_DEFAULT_REQUIRED_FOR_OVERRIDE.registerFactory(AddJvmDefaultAnnotation)
|
||||||
|
NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT.registerFactory(AddJvmDefaultAnnotation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Foo {
|
||||||
|
@JvmDefault
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface Bar: Foo {
|
||||||
|
|
||||||
|
<caret>override fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Foo {
|
||||||
|
@JvmDefault
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface Bar: Foo {
|
||||||
|
|
||||||
|
@JvmDefault
|
||||||
|
override fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Bar : Foo {
|
||||||
|
<caret>@JvmDefault
|
||||||
|
override fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
public interface Foo {
|
||||||
|
default void foo() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Bar : Foo {
|
||||||
|
<caret>override fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Foo {
|
||||||
|
@JvmDefault
|
||||||
|
val foo: String
|
||||||
|
get() = ""
|
||||||
|
}
|
||||||
|
interface Bar: Foo {
|
||||||
|
|
||||||
|
<caret>override val foo: String
|
||||||
|
get() = ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// "Add '@JvmDefault' annotation" "true"
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// COMPILER_ARGUMENTS: -Xenable-jvm-default
|
||||||
|
// WITH_RUNTIME
|
||||||
|
interface Foo {
|
||||||
|
@JvmDefault
|
||||||
|
val foo: String
|
||||||
|
get() = ""
|
||||||
|
}
|
||||||
|
interface Bar: Foo {
|
||||||
|
|
||||||
|
@JvmDefault
|
||||||
|
override val foo: String
|
||||||
|
get() = ""
|
||||||
|
}
|
||||||
+15
@@ -25,6 +25,21 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/addJvmDefault")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class AddJvmDefault extends AbstractQuickFixMultiFileTest {
|
||||||
|
public void testAllFilesPresentInAddJvmDefault() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/addJvmDefault"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javaDefaultOverride.before.Main.kt")
|
||||||
|
public void testJavaDefaultOverride() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addJvmDefault/javaDefaultOverride.before.Main.kt");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/addStarProjections")
|
@TestMetadata("idea/testData/quickfix/addStarProjections")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -754,6 +754,27 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/addJvmDefault")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class AddJvmDefault extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInAddJvmDefault() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/addJvmDefault"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionOverride.kt")
|
||||||
|
public void testFunctionOverride() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addJvmDefault/functionOverride.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propertyOverride.kt")
|
||||||
|
public void testPropertyOverride() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addJvmDefault/propertyOverride.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/addNewLineAfterAnnotations")
|
@TestMetadata("idea/testData/quickfix/addNewLineAfterAnnotations")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user