Add quick fix for deprecated 'class object' syntax

This commit is contained in:
Pavel V. Talanov
2015-03-06 19:29:17 +03:00
parent 3cfcef9da4
commit 81f9d34d1a
7 changed files with 66 additions and 1 deletions
@@ -95,4 +95,4 @@ private val MODIFIERS_ORDER = listOf(PUBLIC_KEYWORD, PROTECTED_KEYWORD, PRIVATE_
FINAL_KEYWORD, OPEN_KEYWORD, ABSTRACT_KEYWORD,
OVERRIDE_KEYWORD,
INNER_KEYWORD,
ANNOTATION_KEYWORD, ENUM_KEYWORD)
ANNOTATION_KEYWORD, ENUM_KEYWORD, DEFAULT_KEYWORD)
@@ -179,6 +179,8 @@ options.kotlin.attribute.descriptor.smart.cast=Smart-cast value
options.kotlin.attribute.descriptor.label=Label
change.to.function.invocation=Change to function invocation
migrate.sure=Replace sure() calls by !! in project
migrate.class.object.to.default=Replace 'class' keyword with 'default' modifier
migrate.class.object.to.default.family=Replace 'class' Keyword with 'default' Modifier
remove.val.var.from.parameter=Remove ''{0}'' from parameter
add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project
add.when.else.branch.action.family.name=Add Else Branch
@@ -0,0 +1,41 @@
/*
* 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
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.JetBundle
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.JetObjectDeclaration
public class ClassObjectToDefaultObjectFix(private val elem: JetObjectDeclaration) : JetIntentionAction<JetObjectDeclaration>(elem) {
override fun getText(): String = JetBundle.message("migrate.class.object.to.default")
override fun getFamilyName(): String = JetBundle.message("migrate.class.object.to.default.family")
override fun invoke(project: Project, editor: Editor, file: JetFile) {
elem.getClassKeyword()?.delete()
elem.addModifier(JetTokens.DEFAULT_KEYWORD)
}
default object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) =
(diagnostic.getPsiElement() as? JetObjectDeclaration)?.let { ClassObjectToDefaultObjectFix(it) }
}
}
@@ -294,5 +294,7 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromTypeReferenceActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromReferenceExpressionActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromCallWithConstructorCalleeActionFactory.INSTANCE$);
QuickFixes.factories.put(DEPRECATED_CLASS_OBJECT_SYNTAX, ClassObjectToDefaultObjectFix.Factory);
}
}
@@ -0,0 +1,7 @@
// "Replace 'class' keyword with 'default' modifier" "true"
class A {
public default object {
}
}
@@ -0,0 +1,7 @@
// "Replace 'class' keyword with 'default' modifier" "true"
class A {
public class<caret> object {
}
}
@@ -2850,6 +2850,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
public void testAllFilesPresentInMigration() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeClassObjectToDefaultSingle.kt")
public void testClassObjectToDefaultSingle() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/beforeClassObjectToDefaultSingle.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/modifiers")