diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotation.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotation.java index 88c9d77a27e..0c2e11c727d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotation.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotation.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; @@ -40,13 +41,15 @@ public class JetAnnotation extends JetElementImplStub getEntries() { return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION_ENTRY); } + + public boolean hasFileKeyword() { + return findChildByType(JetTokens.FILE_KEYWORD) != null; + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt index 880909bc1f5..7ac418cda17 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt @@ -53,6 +53,7 @@ public class DeclarationResolver { public fun resolveAnnotationsOnFiles(c: TopDownAnalysisContext, scopeProvider: FileScopeProvider) { val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileScope(it) } for ((file, fileScope) in filesToScope) { + AnnotationResolver.reportDeprecatedAnnotationSyntax(file.getAnnotations(), _trace) _annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getAnnotationEntries(), _trace) _annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getDanglingAnnotations(), _trace) } diff --git a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt index 03d050ab017..ae8a5d0a94f 100644 --- a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt +++ b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt @@ -1,7 +1,7 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER annotation class Ann(val x: Int = 6) -@Ann(1) @Ann(2) @Ann(3) @private class A [Ann] constructor() { +@Ann(1) @Ann(2) @Ann(3) @private class A @Ann constructor() { @Ann(x = 5) fun foo() { 1 + @Ann(1) 1 * @Ann("") 6 diff --git a/compiler/testData/diagnostics/tests/annotations/bracketsDeprecation.kt b/compiler/testData/diagnostics/tests/annotations/bracketsDeprecation.kt index 42169a9ccbd..c1a48f860ce 100644 --- a/compiler/testData/diagnostics/tests/annotations/bracketsDeprecation.kt +++ b/compiler/testData/diagnostics/tests/annotations/bracketsDeprecation.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -[file: Ann] +[file: Ann] +@file:[Ann] annotation class Ann(val arg: Int = 1) fun bar(block: () -> Int) = block() @@ -8,7 +9,7 @@ data class Q(val x: Int, val y: Int) fun bar2(): Array = null!! -[Ann Ann] class A [Ann] constructor([Ann] val prop: Int) { +[Ann Ann] class A [Ann] constructor([Ann] val prop: Int) { [Ann] val x = 1 [Ann] fun foo([Ann] x: Int) { [Ann] class B diff --git a/compiler/testData/diagnostics/tests/deprecated/typeUsage.kt b/compiler/testData/diagnostics/tests/deprecated/typeUsage.kt index 04b012ebbcf..1086498d0ad 100644 --- a/compiler/testData/diagnostics/tests/deprecated/typeUsage.kt +++ b/compiler/testData/diagnostics/tests/deprecated/typeUsage.kt @@ -4,7 +4,7 @@ open class Obsolete { } deprecated("Class") -open class Obsolete2 [deprecated("Constructor")] constructor() { +open class Obsolete2 deprecated("Constructor") constructor() { fun use() {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt index 4156fa9eafd..24de58acddb 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt @@ -32,7 +32,7 @@ var vardef: Int = 1 set @platformName("C") -class C [platformName("primary")] constructor() { +class C platformName("primary") constructor() { platformName("ctr") constructor(x: Int): this() {} @platformName("a") fun foo() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt index dcdb51f9224..82912ad0563 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt @@ -6,4 +6,4 @@ class A { } } -class C [platformStatic] constructor() +class C platformStatic constructor() diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt index 947d5d6ca79..fd4b4e00613 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt @@ -7,4 +7,4 @@ class A { native constructor(x: Int) } -class C [native] constructor() +class C native constructor() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt index c84ef1570c6..d6961d98557 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt @@ -22,10 +22,12 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.addConstructorKeyword import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType import org.jetbrains.kotlin.psi.JetAnnotation import org.jetbrains.kotlin.psi.JetFile +import org.jetbrains.kotlin.psi.JetPrimaryConstructor import org.jetbrains.kotlin.psi.JetPsiFactory public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentionAction(element) { @@ -51,11 +53,15 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio private fun replaceWithAtAnnotationEntries(annotation: JetAnnotation) { val psiFactory = JetPsiFactory(annotation) + val hasFileKeyword = annotation.hasFileKeyword() + val parent = annotation.getParent() + val owner = parent.getParent() var prevElement: PsiElement = annotation for (entry in annotation.getEntries()) { - val newEntry = psiFactory.createAnnotationEntry("@" + entry.getText()) + val newEntry = if (hasFileKeyword) createFileAnnotationEntry(psiFactory, entry.getText()) + else psiFactory.createAnnotationEntry("@" + entry.getText()) val added = parent.addAfter(newEntry, prevElement) if (prevElement != annotation) { @@ -65,7 +71,14 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio prevElement = added } + if (owner is JetPrimaryConstructor) { + owner.addConstructorKeyword() + } + annotation.delete() } + + private fun createFileAnnotationEntry(psiFactory: JetPsiFactory, text: String) = + psiFactory.createFile("@file:$text").getAnnotationEntries().first() } } diff --git a/idea/testData/checker/AnnotationOnFile.kt b/idea/testData/checker/AnnotationOnFile.kt index 9668a31589e..893e1f14484 100644 --- a/idea/testData/checker/AnnotationOnFile.kt +++ b/idea/testData/checker/AnnotationOnFile.kt @@ -1,18 +1,18 @@ -[file: kotlin.deprecated("message")] -[file: suppress(BAR)] -[file: suppress(BAZ)] +@file:kotlin.deprecated("message") +@file:suppress(BAR) +@file:suppress(BAZ) -[kotlin.deprecated("message")] -[suppress(BAR)] -[suppress(BAZ)] +@kotlin.deprecated("message") +@suppress(BAR) +@suppress(BAZ) -[file: myAnnotation(1, "string")] -[file: boo.myAnnotation(1, BAR)] -[file: myAnnotation(N, BAZ)] +@file:myAnnotation(1, "string") +@file:boo.myAnnotation(1, BAR) +@file:myAnnotation(N, BAZ) -[myAnnotation(1, "string")] -[boo.myAnnotation(1, "string")] -[myAnnotation(N, BAZ)] +@myAnnotation(1, "string") +@boo.myAnnotation(1, "string") +@myAnnotation(N, BAZ) package boo diff --git a/idea/testData/multiModuleHighlighting/visibility/m1/m1.kt b/idea/testData/multiModuleHighlighting/visibility/m1/m1.kt index 1e75e52a742..682f78683e3 100644 --- a/idea/testData/multiModuleHighlighting/visibility/m1/m1.kt +++ b/idea/testData/multiModuleHighlighting/visibility/m1/m1.kt @@ -15,7 +15,7 @@ fun testVisibility() { ClassInM2() } -public open class A internal () { +public open class A internal constructor() { private fun pri() { } fun int() { diff --git a/idea/testData/quickfix/migration/bracketsAnnotations/manyFilesMuitliple.after.data.Sample.kt b/idea/testData/quickfix/migration/bracketsAnnotations/manyFilesMuitliple.after.data.Sample.kt index ca2b83ce9eb..bc154aa61c3 100644 --- a/idea/testData/quickfix/migration/bracketsAnnotations/manyFilesMuitliple.after.data.Sample.kt +++ b/idea/testData/quickfix/migration/bracketsAnnotations/manyFilesMuitliple.after.data.Sample.kt @@ -1,3 +1,3 @@ -[file: Ann] +@file:Ann -@Ann class B [Ann(1)]() +@Ann class B @Ann(1) constructor()