quickfix to migrate function type parameter lists to new syntax
This commit is contained in:
@@ -140,6 +140,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
|||||||
|
|
||||||
betweenInside(FUN_KEYWORD, IDENTIFIER, FUN).spaces(1)
|
betweenInside(FUN_KEYWORD, IDENTIFIER, FUN).spaces(1)
|
||||||
betweenInside(FUN_KEYWORD, TYPE_REFERENCE, FUN).spaces(1)
|
betweenInside(FUN_KEYWORD, TYPE_REFERENCE, FUN).spaces(1)
|
||||||
|
betweenInside(TYPE_PARAMETER_LIST, IDENTIFIER, FUN).spaces(1)
|
||||||
betweenInside(FUN_KEYWORD, VALUE_PARAMETER_LIST, FUN).spacing(0, 0, 0, false, 0)
|
betweenInside(FUN_KEYWORD, VALUE_PARAMETER_LIST, FUN).spacing(0, 0, 0, false, 0)
|
||||||
betweenInside(TYPE_REFERENCE, DOT, FUN).spacing(0, 0, 0, false, 0)
|
betweenInside(TYPE_REFERENCE, DOT, FUN).spacing(0, 0, 0, false, 0)
|
||||||
betweenInside(DOT, IDENTIFIER, FUN).spacing(0, 0, 0, false, 0)
|
betweenInside(DOT, IDENTIFIER, FUN).spacing(0, 0, 0, false, 0)
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
|
|||||||
Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION,
|
Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION,
|
||||||
Errors.BACKING_FIELD_SYNTAX_DEPRECATED,
|
Errors.BACKING_FIELD_SYNTAX_DEPRECATED,
|
||||||
Errors.OPERATOR_MODIFIER_REQUIRED,
|
Errors.OPERATOR_MODIFIER_REQUIRED,
|
||||||
Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS
|
Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS,
|
||||||
|
Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClas
|
|||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateLocalVariableActionFactory
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateLocalVariableActionFactory
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByRefActionFactory
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByRefActionFactory
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.migration.MigrateTypeParameterListFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
|
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
|
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens.*
|
import org.jetbrains.kotlin.lexer.JetTokens.*
|
||||||
@@ -335,5 +336,7 @@ public class QuickFixRegistrar : QuickFixContributor {
|
|||||||
UNDERSCORE_IS_DEPRECATED.registerFactory(RenameUnderscoreFix)
|
UNDERSCORE_IS_DEPRECATED.registerFactory(RenameUnderscoreFix)
|
||||||
|
|
||||||
CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.registerFactory(AddTypeToLHSOfCallableReferenceFix)
|
CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.registerFactory(AddTypeToLHSOfCallableReferenceFix)
|
||||||
|
|
||||||
|
DEPRECATED_TYPE_PARAMETER_SYNTAX.registerFactory(MigrateTypeParameterListFix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 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.idea.quickfix.migration
|
||||||
|
|
||||||
|
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.quickfix.CleanupFix
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetIntentionAction
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
||||||
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
|
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
import org.jetbrains.kotlin.psi.JetTypeParameterList
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
|
||||||
|
class MigrateTypeParameterListFix(typeParameterList: JetTypeParameterList)
|
||||||
|
: JetIntentionAction<JetTypeParameterList>(typeParameterList), CleanupFix {
|
||||||
|
|
||||||
|
override fun getFamilyName(): String = "Migrate type parameter list syntax"
|
||||||
|
override fun getText(): String = familyName
|
||||||
|
|
||||||
|
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
|
||||||
|
val function = element.getStrictParentOfType<JetNamedFunction>() ?: return
|
||||||
|
function.addBefore(element, function.nameIdentifier)
|
||||||
|
element.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : JetSingleIntentionActionFactory() {
|
||||||
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
|
val typeParameterList = diagnostic.psiElement as? JetTypeParameterList ?: return null
|
||||||
|
return MigrateTypeParameterListFix(typeParameterList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,3 +60,6 @@ class C {
|
|||||||
|
|
||||||
fun bar() = ::foo
|
fun bar() = ::foo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun typed<T>() {
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,3 +59,6 @@ class C {
|
|||||||
|
|
||||||
fun bar() = C::foo
|
fun bar() = C::foo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> typed() {
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// "Migrate type parameter list syntax" "true"
|
||||||
|
fun f<caret><T>() {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// "Migrate type parameter list syntax" "true"
|
||||||
|
fun <T> f() {}
|
||||||
@@ -4321,6 +4321,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/migration/typeParameterList")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class TypeParameterList extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInTypeParameterList() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/typeParameterList"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("basic.kt")
|
||||||
|
public void testBasic() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/typeParameterList/basic.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/modifiers")
|
@TestMetadata("idea/testData/quickfix/modifiers")
|
||||||
|
|||||||
Reference in New Issue
Block a user