drop deprecated syntax for class objects

This commit is contained in:
Dmitry Jemerov
2015-04-24 17:17:18 +02:00
parent 2bc4dde959
commit 683d727c72
23 changed files with 3 additions and 339 deletions
@@ -150,7 +150,6 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
val annotation = holder.createWarningAnnotation(textRange, getDefaultMessage(diagnostic))
when (factory) {
Errors.DEPRECATED_CLASS_OBJECT_SYNTAX,
Errors.DEPRECATED_SYMBOL,
Errors.DEPRECATED_SYMBOL_WITH_MESSAGE
-> annotation.setTextAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES)
@@ -59,13 +59,6 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
}
}
@Override
public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) {
if (declaration.isCompanion()) {
memberSuspects.add(declaration.getClassKeyword());
}
}
@Override
public void visitNamedFunction(@NotNull JetNamedFunction function) {
PsiElement equalsToken = function.getEqualsToken();
@@ -1,59 +0,0 @@
/*
* 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.idea.project.PluginJetFilesProvider
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.*
import java.util.ArrayList
public class ClassObjectToCompanionObjectFix(private val elem: JetObjectDeclaration) : JetIntentionAction<JetObjectDeclaration>(elem) {
override fun getText(): String = JetBundle.message("migrate.class.object.to.companion")
override fun getFamilyName(): String = JetBundle.message("migrate.class.object.to.companion.family")
override fun invoke(project: Project, editor: Editor, file: JetFile) {
changeClassKeywordToCompanionModifier(elem)
}
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) =
(diagnostic.getPsiElement() as? JetObjectDeclaration)?.let { ClassObjectToCompanionObjectFix(it) }
public fun createWholeProjectFixFactory(): JetSingleIntentionActionFactory = createIntentionFactory {
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetObjectDeclaration>(
predicate = { it.getClassKeyword() != null },
taskProcessor = { changeClassKeywordToCompanionModifier(it) },
modalTitle = JetBundle.message("migrate.class.object.to.companion.in.whole.project.modal.title"),
name = JetBundle.message("migrate.class.object.to.companion.in.whole.project"),
familyName = JetBundle.message("migrate.class.object.to.companion.in.whole.project.family")
)
}
private fun changeClassKeywordToCompanionModifier(objectDeclaration: JetObjectDeclaration) {
objectDeclaration.getClassKeyword()?.delete()
if (!objectDeclaration.hasModifier(JetTokens.COMPANION_KEYWORD)) {
objectDeclaration.addModifier(JetTokens.COMPANION_KEYWORD)
}
}
}
}
@@ -308,8 +308,6 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromReferenceExpressionActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromCallWithConstructorCalleeActionFactory.INSTANCE$);
QuickFixes.factories.put(DEPRECATED_CLASS_OBJECT_SYNTAX, ClassObjectToCompanionObjectFix.Factory);
QuickFixes.factories.put(DEPRECATED_CLASS_OBJECT_SYNTAX, ClassObjectToCompanionObjectFix.Factory.createWholeProjectFixFactory());
QuickFixes.factories.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, AddInitKeywordFix.Factory);
QuickFixes.factories.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, AddInitKeywordFix.Factory.createWholeProjectFixFactory());
@@ -1,17 +0,0 @@
class A {
<warning textAttributesKey="DEPRECATED_ATTRIBUTES">class object</warning> {
}
}
class B {
<warning textAttributesKey="DEPRECATED_ATTRIBUTES">class object C</warning> {
}
}
class C {
companion <warning textAttributesKey="DEPRECATED_ATTRIBUTES">class object G</warning> {
}
}
@@ -1,7 +0,0 @@
// "Replace 'class' keyword with 'companion' modifier" "true"
class A {
public companion object {
}
}
@@ -1,7 +0,0 @@
// "Replace 'class' keyword with 'companion' modifier" "true"
class A {
public class<caret> object {
}
}
@@ -1,29 +0,0 @@
class D {
companion public object Named {
}
}
trait H {
companion object {
}
}
class E {
companion object {
class D {
companion object {
class D {
companion object
}
}
}
}
}
class K {
companion object Companion
class Object
}
@@ -1,19 +0,0 @@
// "Replace 'class' keyword with 'companion' modifier in whole project" "true"
class A {
public companion object {
}
}
class B {
companion object {
}
}
class C {
companion object Named {
}
}
@@ -1,19 +0,0 @@
// "Replace 'class' keyword with 'companion' modifier in whole project" "true"
class A {
public class<caret> object {
}
}
class B {
class object {
}
}
class C {
class object Named {
}
}
@@ -1,29 +0,0 @@
class D {
companion public class object Named {
}
}
trait H {
companion class object {
}
}
class E {
class object {
class D {
class object {
class D {
class object
}
}
}
}
}
class K {
companion object Companion
class Object
}
@@ -127,12 +127,6 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
doTest(fileName);
}
@TestMetadata("DeprecatedClassObjectSyntax.kt")
public void testDeprecatedClassObjectSyntax() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/DeprecatedClassObjectSyntax.kt");
doTest(fileName);
}
@TestMetadata("ExtensionFunctions.kt")
public void testExtensionFunctions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/ExtensionFunctions.kt");
@@ -858,12 +858,6 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
}
@TestMetadata("classObjectToDefaultMultiple.before.Main.kt")
public void testClassObjectToDefaultMultiple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/classObjectToDefaultMultiple.before.Main.kt");
doTestWithExtraFile(fileName);
}
@TestMetadata("idea/testData/quickfix/migration/lambdaSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -3022,12 +3022,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
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/migration/lambdaSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)