drop deprecated syntax for class objects
This commit is contained in:
@@ -215,8 +215,6 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_COMPANION_OBJECTS = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> COMPANION_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEPRECATED_CLASS_OBJECT_SYNTAX = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<PsiElement, DeclarationDescriptor> DEPRECATED_SYMBOL = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory2<PsiElement, DeclarationDescriptor, String> DEPRECATED_SYMBOL_WITH_MESSAGE = DiagnosticFactory2.create(WARNING);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public object PositioningStrategies {
|
||||
}
|
||||
is JetObjectDeclaration -> {
|
||||
return markRange(
|
||||
element.getClassKeyword() ?: element.getObjectKeyword(),
|
||||
element.getObjectKeyword(),
|
||||
element.getNameIdentifier() ?: element.getObjectKeyword()
|
||||
)
|
||||
}
|
||||
|
||||
-1
@@ -251,7 +251,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class");
|
||||
MAP.put(COMPANION_OBJECT_NOT_ALLOWED, "A companion object is not allowed here");
|
||||
|
||||
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for companion objects was deprecated. Use 'companion' modifier instead");
|
||||
MAP.put(DEPRECATED_SYMBOL, "''{0}'' is deprecated.", DEPRECATION);
|
||||
MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION, STRING);
|
||||
|
||||
|
||||
@@ -821,12 +821,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
IElementType keywordToken = tt();
|
||||
IElementType declType = null;
|
||||
if (keywordToken == CLASS_KEYWORD) {
|
||||
if (lookahead(1) == OBJECT_KEYWORD) {
|
||||
declType = parseDeprecatedClassObject();
|
||||
}
|
||||
else {
|
||||
declType = parseClass(isEnum);
|
||||
}
|
||||
declType = parseClass(isEnum);
|
||||
}
|
||||
else if (keywordToken == TRAIT_KEYWORD) {
|
||||
declType = parseClass(isEnum);
|
||||
@@ -977,18 +972,6 @@ public class JetParsing extends AbstractJetParsing {
|
||||
initializer.done(type);
|
||||
}
|
||||
|
||||
/*
|
||||
* companionObject
|
||||
* : modifiers "class" object
|
||||
* ;
|
||||
*/
|
||||
private IElementType parseDeprecatedClassObject() {
|
||||
assert _at(CLASS_KEYWORD) && lookahead(1) == OBJECT_KEYWORD;
|
||||
advance(); // CLASS_KEYWORD
|
||||
parseObject(NameParsingMode.ALLOWED, true);
|
||||
return OBJECT_DECLARATION;
|
||||
}
|
||||
|
||||
/*
|
||||
* typeAlias
|
||||
* : modifiers "typealias" SimpleName (typeParameters typeConstraints)? "=" type
|
||||
|
||||
@@ -99,7 +99,7 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
if (stub != null) {
|
||||
return stub.isCompanion();
|
||||
}
|
||||
return getClassKeyword() != null || hasModifier(JetTokens.COMPANION_KEYWORD);
|
||||
return hasModifier(JetTokens.COMPANION_KEYWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,11 +182,6 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
return findChildByType(JetTokens.OBJECT_KEYWORD);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getClassKeyword() {
|
||||
return findChildByType(JetTokens.CLASS_KEYWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IncorrectOperationException {
|
||||
JetPsiUtil.deleteClass(this);
|
||||
|
||||
@@ -230,19 +230,12 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||
checkDeprecatedClassObjectSyntax(declaration);
|
||||
reportErrorIfHasIllegalModifier(declaration);
|
||||
if (declaration.isLocal() && !declaration.isCompanion() && !declaration.isObjectLiteral()) {
|
||||
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeprecatedClassObjectSyntax(@NotNull JetObjectDeclaration declaration) {
|
||||
if (declaration.getClassKeyword() != null) {
|
||||
trace.report(DEPRECATED_CLASS_OBJECT_SYNTAX.on(declaration));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkClass(BodiesResolveContext c, JetClass aClass, ClassDescriptorWithResolutionScopes classDescriptor) {
|
||||
checkOpenMembers(classDescriptor);
|
||||
checkPrimaryConstructor(aClass, classDescriptor);
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
trait G
|
||||
|
||||
class A {
|
||||
<!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object A<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
trait B {
|
||||
<!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object<!> : G {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
companion <!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object<!>
|
||||
}
|
||||
|
||||
fun main() {
|
||||
A
|
||||
A.A
|
||||
g(B.Companion)
|
||||
g(B)
|
||||
|
||||
A.ext()
|
||||
A.A.ext()
|
||||
}
|
||||
|
||||
fun g(g: G) { <!UNUSED_EXPRESSION!>g<!> }
|
||||
|
||||
fun A.A.ext() {
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package
|
||||
|
||||
internal fun g(/*0*/ g: G): kotlin.Unit
|
||||
internal fun main(): kotlin.Unit
|
||||
internal fun A.A.ext(): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
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 toString(): kotlin.String
|
||||
|
||||
internal companion object A {
|
||||
private constructor A()
|
||||
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 toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
internal trait B {
|
||||
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 toString(): kotlin.String
|
||||
|
||||
internal companion object Companion : G {
|
||||
private constructor Companion()
|
||||
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 toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
internal final class C {
|
||||
public constructor C()
|
||||
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 toString(): kotlin.String
|
||||
|
||||
internal companion object Companion {
|
||||
private constructor Companion()
|
||||
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 toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
internal trait G {
|
||||
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 toString(): kotlin.String
|
||||
}
|
||||
@@ -1482,12 +1482,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("deprecatedClassObjectSyntax.kt")
|
||||
public void testDeprecatedClassObjectSyntax() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classObjects/deprecatedClassObjectSyntax.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("importClassInClassObject.kt")
|
||||
public void testImportClassInClassObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classObjects/importClassInClassObject.kt");
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user