Drop annotations deprecation related things: diagnostics, quickfixes

This commit is contained in:
Denis Zharkov
2015-09-14 17:38:48 +03:00
parent 787d392df0
commit 38bafaa35c
48 changed files with 2 additions and 789 deletions
@@ -140,11 +140,6 @@ public interface Errors {
DiagnosticFactory0<PsiElement> INAPPLICABLE_PARAM_TARGET = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> REDUNDANT_ANNOTATION_TARGET = DiagnosticFactory1.create(WARNING);
DiagnosticFactory0<JetAnnotationEntry> DEPRECATED_UNESCAPED_ANNOTATION = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<PsiElement> DEPRECATED_ESCAPED_MODIFIER = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<JetAnnotationEntry, String> DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER = DiagnosticFactory1.create(WARNING);
DiagnosticFactory0<JetAnnotationEntry> DEPRECATED_ANNOTATION_USE = DiagnosticFactory0.create(WARNING);
// Classes and traits
DiagnosticFactory0<JetTypeProjection> PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE =
@@ -223,7 +218,6 @@ public interface Errors {
DiagnosticFactory1<PsiElement, DeclarationDescriptor> DEPRECATED_SYMBOL = DiagnosticFactory1.create(WARNING);
DiagnosticFactory2<PsiElement, DeclarationDescriptor, String> DEPRECATED_SYMBOL_WITH_MESSAGE = DiagnosticFactory2.create(WARNING);
DiagnosticFactory1<JetSimpleNameExpression, ClassDescriptor> DEPRECATED_DECAPITALIZED_ANNOTATION = DiagnosticFactory1.create(WARNING);
// Objects
@@ -132,11 +132,6 @@ public class DefaultErrorMessages {
MAP.put(INAPPLICABLE_PARAM_TARGET, "''@param:'' annotations could be applied only to primary constructor parameters");
MAP.put(REDUNDANT_ANNOTATION_TARGET, "Redundant annotation target ''{0}''", STRING);
MAP.put(DEPRECATED_UNESCAPED_ANNOTATION, "Annotations without '@' are deprecated now");
MAP.put(DEPRECATED_ESCAPED_MODIFIER, "Modifiers with '@' are deprecated now");
MAP.put(DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER, "This annotation will become a modifier soon. Use ''{0}'' modifier instead", STRING);
MAP.put(DEPRECATED_ANNOTATION_USE, "This annotation use is deprecated");
MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in interface");
MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter");
@@ -274,7 +269,6 @@ public class DefaultErrorMessages {
MAP.put(DEPRECATED_SYMBOL, "''{0}'' is deprecated.", DEPRECATION_RENDERER);
MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING);
MAP.put(DEPRECATED_DECAPITALIZED_ANNOTATION, "Decapitalized annotations are deprecated. Use ''{0}'' instead", DEPRECATION_RENDERER);
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
MAP.put(ENUM_CLASS_CONSTRUCTOR_CALL, "Enum types cannot be instantiated");
@@ -108,12 +108,6 @@ public class JetAnnotationEntry extends JetElementImplStub<KotlinAnnotationEntry
return findChildByType(JetTokens.AT);
}
public boolean hasAtSymbolOrInList() {
if (getStub() != null) return true;
return getAtSymbol() != null || getParent() instanceof JetAnnotation;
}
@Nullable
public JetAnnotationUseSiteTarget getUseSiteTarget() {
JetAnnotationUseSiteTarget target = getStubOrPsiChild(JetStubElementTypes.ANNOTATION_TARGET);
@@ -70,20 +70,6 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: continue
val classDescriptor = TypeUtils.getClassDescriptor(descriptor.type) ?: continue
if (classDescriptor.fqNameSafe in ANNOTATIONS_SHOULD_BE_REPLACED_WITH_MODIFIERS_FQ_NAMES) {
if (descriptor.isInlineOptionsWithLocalBreaks()) {
trace.report(Errors.DEPRECATED_ANNOTATION_USE.on(entry))
}
else {
trace.report(Errors.DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER.on(entry, ANNOTATION_MODIFIERS_MAP[classDescriptor.fqNameSafe]!!))
}
}
else {
if (!entry.hasAtSymbolOrInList()) {
trace.report(Errors.DEPRECATED_UNESCAPED_ANNOTATION.on(entry))
}
}
val useSiteTarget = entry.useSiteTarget?.getAnnotationUseSiteTarget()
val existingTargetsForAnnotation = entryTypesWithAnnotations.getOrPut(descriptor.type) { arrayListOf() }
val duplicateAnnotation = useSiteTarget in existingTargetsForAnnotation
@@ -98,21 +84,6 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
additionalCheckers.forEach { it.checkEntries(entries, actualTargets.defaultTargets, trace) }
}
private fun AnnotationDescriptor.isInlineOptionsWithLocalBreaks(): Boolean {
val descriptor = type.constructor.declarationDescriptor
if (descriptor !is ClassDescriptor) return false
if (descriptor.fqNameSafe == KotlinBuiltIns.FQ_NAMES.inlineOptions) {
val vararg = (allValueArguments.values().firstOrNull() as? ArrayValue)?.value ?: return false
return vararg.all {
arg ->
val enumValue = (arg as? EnumValue) ?: return false
return enumValue.value.name.asString() == InlineOption.LOCAL_CONTINUE_AND_BREAK.name()
}
}
return false
}
private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: TargetList, trace: BindingTrace) {
val applicableTargets = applicableTargetSet(entry, trace)
val useSiteTarget = entry.useSiteTarget?.getAnnotationUseSiteTarget()
@@ -204,9 +204,6 @@ public object ModifierCheckerCore {
else if (!checkParent(trace, second, parentDescriptor)) {
incorrectNodes += second
}
else if ((second.elementType is JetModifierKeywordToken) && second.psi.textContains('@')) {
trace.report(Errors.DEPRECATED_ESCAPED_MODIFIER.on(second.psi))
}
}
}
}
@@ -33,10 +33,6 @@ import org.jetbrains.kotlin.resolve.annotations.argumentValue
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.PROPERTY_GETTER
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.PROPERTY_SETTER
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.scopes.DECAPITALIZED_DEPRECATED_ANNOTATIONS
import org.jetbrains.kotlin.resolve.scopes.DECAPITALIZED_SHORT_NAMES
public class DeprecatedSymbolValidator : SymbolUsageValidator {
private val JAVA_DEPRECATED = FqName(java.lang.Deprecated::class.java.name)
@@ -50,9 +46,6 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator {
else if (targetDescriptor is PropertyDescriptor) {
propertyGetterWorkaround(targetDescriptor, trace, element)
}
else {
checkDecapitalizedAnnotation(element, targetDescriptor, trace)
}
}
override fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) {
@@ -71,32 +64,6 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator {
val (annotation, target) = deprecated
trace.report(createDeprecationDiagnostic(element, target, annotation))
}
else {
checkDecapitalizedAnnotation(element, targetDescriptor, trace)
}
}
private fun checkDecapitalizedAnnotation(element: PsiElement, targetDescriptor: DeclarationDescriptor, trace: BindingTrace) {
val effectiveTargetDescriptor = when (targetDescriptor) {
is ConstructorDescriptor -> targetDescriptor.containingDeclaration
else -> targetDescriptor
} as? ClassDescriptor ?: return
val unsafeFqName = effectiveTargetDescriptor.fqNameUnsafe
if (!unsafeFqName.isSafe) return
val simpleName = unwrapSimpleName(element) ?: return
if (unsafeFqName.toSafe() in DECAPITALIZED_DEPRECATED_ANNOTATIONS && simpleName.getReferencedName() in DECAPITALIZED_SHORT_NAMES) {
trace.report(Errors.DEPRECATED_DECAPITALIZED_ANNOTATION.on(simpleName, effectiveTargetDescriptor))
}
}
private fun unwrapSimpleName(element: PsiElement): JetSimpleNameExpression? {
return when (element) {
is JetConstructorCalleeExpression -> (element.typeReference?.typeElement as? JetUserType)?.referenceExpression
is JetSimpleNameExpression -> element
else -> null
}
}
private fun DeclarationDescriptor.getDeprecatedAnnotation(): Pair<AnnotationDescriptor, DeclarationDescriptor>? {
@@ -1,32 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -NOT_YET_SUPPORTED_IN_INLINE
import kotlin.external as myNative
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@annotation<!> <!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@data<!> <!DEPRECATED_ESCAPED_MODIFIER!>@public<!> class Ann(val arg: Int = 1)
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@inline<!> <!DEPRECATED_ESCAPED_MODIFIER!>@private<!> fun bar(block: () -> Int) = block()
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@data<!> class Q(val x: Int, val y: Int)
fun bar2(): Array<Q> = null!!
<!DEPRECATED_ESCAPED_MODIFIER!>@open<!> class A <!DEPRECATED_ESCAPED_MODIFIER!>@private<!> constructor(<!DEPRECATED_ESCAPED_MODIFIER!>@private<!> val prop: Int) {
<!DEPRECATED_ESCAPED_MODIFIER!>@private<!> val x = 1
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@inline<!> fun foo(<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@noinline<!> x: Int) {
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@data<!> class Local
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@inline<!> fun localFun() {}
}
<!DEPRECATED_ESCAPED_MODIFIER!>@private<!> object O1 {}
<!DEPRECATED_ESCAPED_MODIFIER!>@public<!> <!DEPRECATED_ESCAPED_MODIFIER!>@companion<!> object O2 {}
}
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>kotlin.inline<!> fun baz() { }
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>kotlin.data<!> class Data
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>myNative<!> fun nativeFun(): Int
<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@tailRecursive<!> fun tailFun(): Int = tailFun()
inline fun inlineFun(<!DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER!>@inlineOptions(InlineOption.ONLY_LOCAL_RETURN)<!> block: () -> Int) {}
inline fun inlineFun2(<!DEPRECATED_ANNOTATION_USE!>@inlineOptions(InlineOption.LOCAL_CONTINUE_AND_BREAK)<!> block: () -> Int) {}
@@ -1,63 +0,0 @@
package
kotlin.inline() private fun bar(/*0*/ block: () -> kotlin.Int): kotlin.Int
public fun bar2(): kotlin.Array<Q>
kotlin.inline() public fun baz(): kotlin.Unit
kotlin.inline() public fun inlineFun(/*0*/ kotlin.inlineOptions(value = {InlineOption.ONLY_LOCAL_RETURN}) block: () -> kotlin.Int): kotlin.Unit
kotlin.inline() public fun inlineFun2(/*0*/ kotlin.inlineOptions(value = {InlineOption.LOCAL_CONTINUE_AND_BREAK}) block: () -> kotlin.Int): kotlin.Unit
kotlin.external() public fun nativeFun(): kotlin.Int
kotlin.tailRecursive() public fun tailFun(): kotlin.Int
public open class A {
private constructor A(/*0*/ prop: kotlin.Int)
private final val prop: kotlin.Int
private final val x: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.inline() public final fun foo(/*0*/ kotlin.noinline() x: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
private object O1 {
private constructor O1()
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
}
public companion object O2 {
private constructor O2()
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
}
}
kotlin.annotation.annotation() kotlin.data() public final class Ann : kotlin.Annotation {
public constructor Ann(/*0*/ arg: kotlin.Int = ...)
public final val arg: kotlin.Int
public final /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ arg: kotlin.Int = ...): Ann
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
}
kotlin.data() public final class Data {
public constructor Data()
public final /*synthesized*/ fun copy(): Data
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
}
kotlin.data() public final class Q {
public constructor Q(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
public final val x: kotlin.Int
public final val y: kotlin.Int
public final /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun component2(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int = ...): Q
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
}
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
annotation class Ann(val arg: Int = 1)
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> class A <!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> constructor(<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> val prop: Int) {
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> val x = 1
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> fun foo(<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> x: Int) {}
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> object O1 {}
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> companion object O2 {}
}
<!DEPRECATED_UNESCAPED_ANNOTATION!>Ann<!> object O3 {}
@@ -1,40 +0,0 @@
package
Ann() public final class A {
Ann() public constructor A(/*0*/ Ann() prop: kotlin.Int)
public final val prop: kotlin.Int
Ann() public final val x: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
Ann() public final fun foo(/*0*/ Ann() x: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
Ann() public object O1 {
private constructor O1()
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
}
Ann() public companion object O2 {
private constructor O2()
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
}
}
kotlin.annotation.annotation() public final class Ann : kotlin.Annotation {
public constructor Ann(/*0*/ arg: kotlin.Int = ...)
public final val arg: kotlin.Int
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
}
Ann() public object O3 {
private constructor O3()
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
}
@@ -1,23 +0,0 @@
// !DIAGNOSTICS: -DEPRECATED_UNESCAPED_ANNOTATION -UNUSED_PARAMETER
import kotlin.Extension as extension
import kotlin.jvm.<!DEPRECATED_DECAPITALIZED_ANNOTATION!>strictfp<!> as sfp
class A {
@<!DEPRECATED_DECAPITALIZED_ANNOTATION!>deprecated<!>("") fun foo() {}
companion object {
@<!DEPRECATED_DECAPITALIZED_ANNOTATION!>jvmStatic<!> fun bar() {}
}
<!DEPRECATED_SYMBOL_WITH_MESSAGE!>throws<!>(java.lang.RuntimeException::class)
<!DEPRECATED_DECAPITALIZED_ANNOTATION!>synchronized<!> fun <T> baz() {
@<!DEPRECATED_DECAPITALIZED_ANNOTATION!>suppress<!>("UNCHECKED_CAST")
(1 as T)
}
kotlin.jvm.<!DEPRECATED_DECAPITALIZED_ANNOTATION!>jvmName<!>("y")
<!DEPRECATED_DECAPITALIZED_ANNOTATION!>jvmOverloads<!>()
fun x(x: Int = 1) {}
}
sfp fun bar(
x: <!DEPRECATED_DECAPITALIZED_ANNOTATION!>deprecated<!>
): @<!DEPRECATED_DECAPITALIZED_ANNOTATION!>extension<!> String.() -> Int = null!!
@@ -1,21 +0,0 @@
package
kotlin.jvm.Strictfp() public fun bar(/*0*/ x: kotlin.Deprecated): @[kotlin.Extension()] kotlin.String.() -> kotlin.Int
public final class A {
public constructor A()
kotlin.throws(exceptionClasses = {java.lang.RuntimeException::class}) kotlin.jvm.Synchronized() public final fun </*0*/ T> baz(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.Deprecated(value = "") public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
kotlin.jvm.JvmName(name = "y") kotlin.jvm.JvmOverloads() public final fun x(/*0*/ x: kotlin.Int = ...): kotlin.Unit
public companion object Companion {
private constructor Companion()
kotlin.jvm.JvmStatic() public final fun bar(): kotlin.Unit
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
}
}
@@ -1002,27 +1002,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
}
}
@TestMetadata("compiler/testData/diagnostics/tests/annotations/migration")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Migration extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInMigration() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/annotations/migration"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("escapedModifiers.kt")
public void testEscapedModifiers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/migration/escapedModifiers.kt");
doTest(fileName);
}
@TestMetadata("unescapedAnnotation.kt")
public void testUnescapedAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/migration/unescapedAnnotation.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/annotations/options")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -91,12 +91,6 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
doTest(fileName);
}
@TestMetadata("decapitalized.kt")
public void testDecapitalized() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.kt");
doTest(fileName);
}
@TestMetadata("defaultValueMustBeConstant.kt")
public void testDefaultValueMustBeConstant() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
@@ -18,20 +18,7 @@ package org.jetbrains.kotlin.descriptors.annotations
import org.jetbrains.kotlin.name.FqName
val ADDITIONAL_ANNOTATIONS_MAP: Map<FqName, String> = mapOf(
FqName("kotlin.tailRecursive") to "tailrec",
FqName("kotlin.jvm.native") to "external",
FqName("kotlin.inlineOptions") to "crossinline"
)
// Please synchronize this set with JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY
public val ANNOTATION_MODIFIERS_FQ_NAMES: Set<FqName> =
arrayOf("data", "inline", "noinline", "tailrec", "external", "annotation.annotation", "crossinline").map { FqName("kotlin.$it") }.toSet()
public val ANNOTATIONS_SHOULD_BE_REPLACED_WITH_MODIFIERS_FQ_NAMES: Set<FqName> =
ANNOTATION_MODIFIERS_FQ_NAMES + ADDITIONAL_ANNOTATIONS_MAP.keySet()
public val ANNOTATION_MODIFIERS_MAP: Map<FqName, String> =
ANNOTATION_MODIFIERS_FQ_NAMES.map { it to it.shortName().asString() }.toMap() +
ADDITIONAL_ANNOTATIONS_MAP
@@ -153,8 +153,7 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
when (factory) {
Errors.DEPRECATED_SYMBOL,
Errors.DEPRECATED_SYMBOL_WITH_MESSAGE,
Errors.DEPRECATED_TRAIT_KEYWORD,
Errors.DEPRECATED_DECAPITALIZED_ANNOTATION
Errors.DEPRECATED_TRAIT_KEYWORD
-> annotation.setTextAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES)
}
@@ -100,10 +100,6 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
Errors.USELESS_ELVIS,
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION,
Errors.DEPRECATED_SYMBOL_WITH_MESSAGE,
Errors.DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER,
Errors.DEPRECATED_DECAPITALIZED_ANNOTATION,
Errors.DEPRECATED_ESCAPED_MODIFIER,
Errors.DEPRECATED_UNESCAPED_ANNOTATION,
Errors.ACCESS_TO_PRIVATE_TOP_LEVEL_FROM_ANOTHER_FILE
)
@@ -325,11 +325,5 @@ public class QuickFixRegistrar : QuickFixContributor {
UPPER_BOUND_VIOLATED.registerFactory(AddGenericUpperBoundFix.Factory)
TYPE_INFERENCE_UPPER_BOUND_VIOLATED.registerFactory(AddGenericUpperBoundFix.Factory)
DEPRECATED_UNESCAPED_ANNOTATION.registerFactory(UnescapedAnnotationFix.Factory)
DEPRECATED_ESCAPED_MODIFIER.registerFactory(EscapedModifierFix.Factory)
DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER.registerFactory(ReplaceAnnotationWithModifierFix.Factory)
DEPRECATED_DECAPITALIZED_ANNOTATION.registerFactory(DecapitalizedAnnotationFix.Factory)
DEPRECATED_ANNOTATION_USE.registerFactory(RemoveAnnotationFix.Factory)
}
}
@@ -1,56 +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.migration
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
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.idea.quickfix.replaceWith.ClassUsageReplacementStrategy
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
public class DecapitalizedAnnotationFix(
element: JetSimpleNameExpression,
private val classDescriptor: ClassDescriptor,
private val replacer: () -> JetElement
) : JetIntentionAction<JetSimpleNameExpression>(element), CleanupFix {
override fun getFamilyName() = "Replace deprecated decapitalized annotations"
override fun getText() = "Replace with '${classDescriptor.fqNameSafe.asString()}'"
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
replacer()
}
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val diagnosticWithParameters = Errors.DEPRECATED_DECAPITALIZED_ANNOTATION.cast(diagnostic)
val classDescriptor = diagnosticWithParameters.a
val element = diagnosticWithParameters.psiElement
val replacement = JetPsiFactory(element).createType(classDescriptor.fqNameSafe.asString()).typeElement as JetUserType
val replacer = ClassUsageReplacementStrategy(replacement).createReplacer(element) ?: return null
return DecapitalizedAnnotationFix(element, classDescriptor, replacer)
}
}
}
@@ -1,42 +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.migration
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
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.lexer.JetModifierKeywordToken
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.JetPsiFactory
public class EscapedModifierFix(element: PsiElement) : JetIntentionAction<PsiElement>(element), CleanupFix {
override fun getText() = "Remove '@'"
override fun getFamilyName() = text
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
val modifier = element.node.elementType as JetModifierKeywordToken
element.replace(JetPsiFactory(project).createModifier(modifier))
}
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) = EscapedModifierFix(diagnostic.psiElement)
}
}
@@ -1,39 +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.migration
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.quickfix.JetIntentionAction
import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType
import org.jetbrains.kotlin.psi.JetAnnotationEntry
import org.jetbrains.kotlin.psi.JetFile
public class RemoveAnnotationFix(element: JetAnnotationEntry) : JetIntentionAction<JetAnnotationEntry>(element) {
override fun getFamilyName(): String = getText()
override fun getText(): String = "Remove annotation"
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
element.delete()
}
object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) = diagnostic.createIntentionForFirstParentOfType(::RemoveAnnotationFix)
}
}
@@ -1,70 +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.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.diagnostics.Errors
import org.jetbrains.kotlin.idea.core.CommentSaver
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.lexer.JetModifierKeywordToken
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
public class ReplaceAnnotationWithModifierFix(
element: JetAnnotationEntry,
private val replacement: JetModifierKeywordToken
) : JetIntentionAction<JetAnnotationEntry>(element), CleanupFix {
override fun getFamilyName() = "Replace with modifier"
override fun getText() = "Replace with '${replacement.value}'"
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
val psiFactory = JetPsiFactory(project)
val modifier = psiFactory.createModifier(replacement)
val parent = element.parent
if (parent !is JetAnnotation) {
val commentSaver = CommentSaver(element, saveLineBreaks = true)
val result = element.replace(modifier)
commentSaver.restore(result)
}
else {
// within annotation list
val modifierListOwner = (parent.parent?.parent as? JetModifierListOwner) ?: return
// insert modifier
modifierListOwner.addModifier(replacement)
parent.removeEntry(element)
}
}
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val annotationEntry = diagnostic.psiElement.getNonStrictParentOfType<JetAnnotationEntry>() ?: return null
val modifierValue = Errors.DEPRECATED_ANNOTATION_THAT_BECOMES_MODIFIER.cast(diagnostic).a
return ReplaceAnnotationWithModifierFix(
annotationEntry, JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY.first() { it.value == modifierValue }
)
}
}
}
@@ -1,38 +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.migration
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.JetAnnotationEntry
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.*
public class UnescapedAnnotationFix(element: JetAnnotationEntry) : JetIntentionAction<JetAnnotationEntry>(element), CleanupFix {
override fun getText() = "Add '@' before annotation"
override fun getFamilyName() = text
override fun invoke(project: Project, editor: Editor?, file: JetFile) = element.addAtSymbol()
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) = diagnostic.createIntentionForFirstParentOfType(::UnescapedAnnotationFix)
}
}
+1 -20
View File
@@ -41,23 +41,4 @@ fun unnecessaryCast(x: String) = x as String
fun unnecessaryElvis(x: String) = x ?: ""
JavaAnn(1, "abc") class MyClass
annotation class Ann()
Ann class A1
Ann() class A2
kotlin.data class A3
@inline @private fun <T> baz() {
@suppress("UNCHECKED_CAST")
(1 as T)
@data class Local
}
deprecated("123", ReplaceWith("34")) class Obsolete
native fun nativeFun(): Int
@JavaAnn(1, "abc") class MyClass
-19
View File
@@ -41,22 +41,3 @@ fun unnecessaryCast(x: String) = x
fun unnecessaryElvis(x: String) = x
@JavaAnn(1, arg1 = "abc") class MyClass
annotation class Ann()
@Ann class A1
@Ann() class A2
data class A3
inline private fun <T> baz() {
@Suppress("UNCHECKED_CAST")
(1 as T)
data class Local
}
@Deprecated("123", ReplaceWith("34")) class Obsolete
external fun nativeFun(): Int
@@ -1,5 +0,0 @@
// "Replace with 'data'" "true"
@data<caret>
/* abc*/(1)
class A
@@ -1,4 +0,0 @@
// "Replace with 'data'" "true"
data/* abc*/
class A
@@ -1,5 +0,0 @@
// "Replace with 'inline'" "true"
annotation class Ann(val x: Int)
kotlin.inline<caret> fun foo() {}
@@ -1,5 +0,0 @@
// "Replace with 'inline'" "true"
annotation class Ann(val x: Int)
inline fun foo() {}
@@ -1,6 +0,0 @@
// "Replace with 'data'" "true"
annotation class Ann
@[dat<caret>a Ann]
/* abc*/
class A
@@ -1,6 +0,0 @@
// "Replace with 'data'" "true"
annotation class Ann
@[Ann]
data /* abc*/
class A
@@ -1,5 +0,0 @@
// "Replace with 'data'" "true"
@[dat<caret>a]
/* abc*/
class A
@@ -1,4 +0,0 @@
// "Replace with 'data'" "true"
data /* abc*/
class A
@@ -1,3 +0,0 @@
// "Replace with 'kotlin.Deprecated'" "true"
@deprecated<caret>("")
class A
@@ -1,3 +0,0 @@
// "Replace with 'kotlin.Deprecated'" "true"
@Deprecated<caret>("")
class A
@@ -1,3 +0,0 @@
// "Replace with 'kotlin.Deprecated'" "true"
fun foo(x: kotlin.deprecated<caret>) {}
@@ -1,3 +0,0 @@
// "Replace with 'kotlin.Deprecated'" "true"
fun foo(x: Deprecated) {}
-5
View File
@@ -1,5 +0,0 @@
// "Remove '@'" "true"
@private<caret>
/* abc*/
class A
@@ -1,5 +0,0 @@
// "Remove '@'" "true"
private
/* abc*/
class A
-3
View File
@@ -1,3 +0,0 @@
// "Replace with 'crossinline'" "true"
inline fun inlineFun(@inlineOptions(InlineOption.ONLY_LOCAL_RETURN)<caret> block: () -> Int) {}
@@ -1,3 +0,0 @@
// "Replace with 'crossinline'" "true"
inline fun inlineFun(crossinline block: () -> Int) {}
@@ -1,3 +0,0 @@
// "Remove annotation" "true"
inline fun inlineFun(@inlineOptions(InlineOption.LOCAL_CONTINUE_AND_BREAK)<caret> block: () -> Int) {}
@@ -1,3 +0,0 @@
// "Remove annotation" "true"
inline fun inlineFun(block: () -> Int) {}
-8
View File
@@ -1,8 +0,0 @@
// "Replace with 'tailrec'" "true"
@tailRecursive<caret>
fun foo() {
if (1 > 2) {
foo()
}
}
-8
View File
@@ -1,8 +0,0 @@
// "Replace with 'tailrec'" "true"
tailrec
fun foo() {
if (1 > 2) {
foo()
}
}
@@ -1,7 +0,0 @@
// "Add '@' before annotation" "true"
annotation class Ann(val x: Int)
Ann<caret>
/* abc*/(1)
class A
@@ -1,7 +0,0 @@
// "Add '@' before annotation" "true"
annotation class Ann(val x: Int)
@Ann<caret>
/* abc*/(1)
class A
@@ -4019,60 +4019,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("annotationModifier.kt")
public void testAnnotationModifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/annotationModifier.kt");
doTest(fileName);
}
@TestMetadata("annotationModifier2.kt")
public void testAnnotationModifier2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/annotationModifier2.kt");
doTest(fileName);
}
@TestMetadata("annotationModifier3.kt")
public void testAnnotationModifier3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/annotationModifier3.kt");
doTest(fileName);
}
@TestMetadata("annotationModifier4.kt")
public void testAnnotationModifier4() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/annotationModifier4.kt");
doTest(fileName);
}
@TestMetadata("escapedModifier.kt")
public void testEscapedModifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/escapedModifier.kt");
doTest(fileName);
}
@TestMetadata("inlineOptions.kt")
public void testInlineOptions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/inlineOptions.kt");
doTest(fileName);
}
@TestMetadata("inlineOptionsWithBreak.kt")
public void testInlineOptionsWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/inlineOptionsWithBreak.kt");
doTest(fileName);
}
@TestMetadata("tailRec.kt")
public void testTailRec() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/tailRec.kt");
doTest(fileName);
}
@TestMetadata("unescapedAnnotation.kt")
public void testUnescapedAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/unescapedAnnotation.kt");
doTest(fileName);
}
@TestMetadata("idea/testData/quickfix/migration/conflictingExtension")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -4166,27 +4112,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/migration/decapitalizedAnnotation")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DecapitalizedAnnotation extends AbstractQuickFixTest {
public void testAllFilesPresentInDecapitalizedAnnotation() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/decapitalizedAnnotation"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("annotationPosition.kt")
public void testAnnotationPosition() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/decapitalizedAnnotation/annotationPosition.kt");
doTest(fileName);
}
@TestMetadata("valueParameter.kt")
public void testValueParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/decapitalizedAnnotation/valueParameter.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/migration/lambdaSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)