Deprecate annotations in brackets
This commit is contained in:
@@ -130,6 +130,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetExpression> ANNOTATION_PARAMETER_MUST_BE_CLASS_LITERAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetExpression> ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetExpression> ANNOTATION_PARAMETER_MUST_BE_ENUM_CONST = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetAnnotation> DEPRECATED_ANNOTATION_SYNTAX = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Classes and traits
|
||||
|
||||
|
||||
+1
@@ -566,6 +566,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(ANNOTATION_PARAMETER_MUST_BE_ENUM_CONST, "An enum annotation parameter must be a enum constant");
|
||||
MAP.put(ANNOTATION_PARAMETER_MUST_BE_CLASS_LITERAL, "An annotation parameter must be a `javaClass<T>()` call");
|
||||
MAP.put(ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL, "An annotation parameter must be a class literal (T::class)");
|
||||
MAP.put(DEPRECATED_ANNOTATION_SYNTAX, "This syntax for annotations is deprecated. Use '@' before annotation identifier instead");
|
||||
|
||||
MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters");
|
||||
|
||||
|
||||
@@ -17,6 +17,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.psi.stubs.KotlinPlaceHolderStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
|
||||
@@ -38,6 +39,13 @@ public class JetAnnotation extends JetElementImplStub<KotlinPlaceHolderStub<JetA
|
||||
return visitor.visitAnnotation(this, data);
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
PsiElement parent = getParentByStub();
|
||||
if (parent instanceof JetFileAnnotationList) return false;
|
||||
if (!(parent instanceof JetModifierList)) return true;
|
||||
return !(((JetModifierList) parent).getOwner() instanceof JetPrimaryConstructor);
|
||||
}
|
||||
|
||||
public List<JetAnnotationEntry> getEntries() {
|
||||
return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION_ENTRY);
|
||||
}
|
||||
|
||||
@@ -76,4 +76,8 @@ public abstract class JetModifierList extends JetElementImplStub<KotlinModifierL
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiElement getOwner() {
|
||||
return getParentByStub();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.JetNodeTypes;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
|
||||
@@ -34,7 +35,7 @@ import static org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes.ANNOTA
|
||||
* Type reference element.
|
||||
* Underlying token is {@link org.jetbrains.kotlin.JetNodeTypes#TYPE_REFERENCE}
|
||||
*/
|
||||
public class JetTypeReference extends JetElementImplStub<KotlinPlaceHolderStub<JetTypeReference>> implements JetAnnotationsContainer {
|
||||
public class JetTypeReference extends JetElementImplStub<KotlinPlaceHolderStub<JetTypeReference>> implements JetAnnotated, JetAnnotationsContainer {
|
||||
|
||||
public JetTypeReference(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
@@ -54,7 +55,15 @@ public class JetTypeReference extends JetElementImplStub<KotlinPlaceHolderStub<J
|
||||
return JetStubbedPsiUtil.getStubOrPsiChild(this, JetStubElementTypes.TYPE_ELEMENT_TYPES, JetTypeElement.ARRAY_FACTORY);
|
||||
}
|
||||
|
||||
public List<JetAnnotationEntry> getAnnotations() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetAnnotation> getAnnotations() {
|
||||
return getStubOrPsiChildrenAsList(JetStubElementTypes.ANNOTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetAnnotationEntry> getAnnotationEntries() {
|
||||
return PsiUtilPackage.collectAnnotationEntriesFromStubOrPsi(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.DEPRECATED_ANNOTATION_SYNTAX;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
@@ -122,6 +123,8 @@ public class AnnotationResolver {
|
||||
if (modifierList == null) {
|
||||
return Annotations.EMPTY;
|
||||
}
|
||||
reportDeprecatedAnnotationSyntax(modifierList.getAnnotations(), trace);
|
||||
|
||||
List<JetAnnotationEntry> annotationEntryElements = modifierList.getAnnotationEntries();
|
||||
|
||||
return resolveAnnotationEntries(scope, annotationEntryElements, trace, shouldResolveArguments);
|
||||
@@ -388,4 +391,16 @@ public class AnnotationResolver {
|
||||
trace.report(Errors.UNSUPPORTED.on(annotationEntry, "Annotations for type parameters are not supported yet"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportDeprecatedAnnotationSyntax(@NotNull List<JetAnnotation> annotations, @NotNull BindingTrace trace) {
|
||||
for (JetAnnotation annotation : annotations) {
|
||||
reportDeprecatedAnnotationSyntax(annotation, trace);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportDeprecatedAnnotationSyntax(@NotNull JetAnnotation annotation, @NotNull BindingTrace trace) {
|
||||
if (annotation.isDeprecated()) {
|
||||
trace.report(DEPRECATED_ANNOTATION_SYNTAX.on(annotation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +237,7 @@ public class DeclarationsChecker {
|
||||
}
|
||||
|
||||
private void checkClass(BodiesResolveContext c, JetClass aClass, ClassDescriptorWithResolutionScopes classDescriptor) {
|
||||
AnnotationResolver.reportDeprecatedAnnotationSyntax(aClass.getAnnotations(), trace);
|
||||
checkOpenMembers(classDescriptor);
|
||||
checkPrimaryConstructor(aClass, classDescriptor);
|
||||
checkTypeParameters(aClass);
|
||||
|
||||
@@ -103,7 +103,8 @@ public class TypeResolver(
|
||||
}
|
||||
|
||||
private fun doResolvePossiblyBareType(c: TypeResolutionContext, typeReference: JetTypeReference): PossiblyBareType {
|
||||
val annotations = annotationResolver.resolveAnnotationsWithArguments(c.scope, typeReference.getAnnotations(), c.trace)
|
||||
AnnotationResolver.reportDeprecatedAnnotationSyntax(typeReference.getAnnotations(), c.trace);
|
||||
val annotations = annotationResolver.resolveAnnotationsWithArguments(c.scope, typeReference.getAnnotationEntries(), c.trace)
|
||||
|
||||
val typeElement = typeReference.getTypeElement()
|
||||
|
||||
|
||||
+1
@@ -1497,6 +1497,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
||||
AnnotationResolver.reportDeprecatedAnnotationSyntax(expression.getAnnotations(), context.trace);
|
||||
components.annotationResolver.resolveAnnotationsWithArguments(
|
||||
context.scope, expression.getAnnotationEntries(), context.trace);
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
[file: Ann]
|
||||
annotation class Ann(val arg: Int = 1)
|
||||
|
||||
fun bar(block: () -> Int) = block()
|
||||
|
||||
data class Q(val x: Int, val y: Int)
|
||||
|
||||
fun bar2(): Array<Q> = null!!
|
||||
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann Ann]<!> class A [Ann] (<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> val prop: Int) {
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> val x = 1
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> fun foo(<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> x: Int) {
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> class B
|
||||
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> fun local() {}
|
||||
|
||||
2 + <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann Ann]<!> 2
|
||||
|
||||
for (<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> (a, <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> b) in bar2()) {}
|
||||
}
|
||||
|
||||
fun x(): <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> String {
|
||||
<!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> val x: <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> String = ""
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
val y: Array<[<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>] String?> = arrayOfNulls(1)
|
||||
val block: ([<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>] x: <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> String) -> <!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> String = { "" }
|
||||
trait B
|
||||
trait D : [<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>] B
|
||||
|
||||
Ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!><!DEPRECATED_ANNOTATION_SYNTAX!>[Ann]<!> 1<!>) class MyClass
|
||||
@@ -0,0 +1,56 @@
|
||||
package
|
||||
|
||||
internal val block: ([Ann()] kotlin.String) -> [Ann()] kotlin.String
|
||||
internal val y: kotlin.Array<kotlin.String?>
|
||||
internal fun bar(/*0*/ block: () -> kotlin.Int): kotlin.Int
|
||||
internal fun bar2(): kotlin.Array<Q>
|
||||
|
||||
Ann() Ann() internal final class A {
|
||||
Ann() public constructor A(/*0*/ Ann() prop: kotlin.Int)
|
||||
Ann() internal final val prop: kotlin.Int
|
||||
Ann() internal final val x: kotlin.Int = 1
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
Ann() internal 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
|
||||
internal final fun x(): [Ann()] kotlin.String
|
||||
}
|
||||
|
||||
internal final annotation class Ann : kotlin.Annotation {
|
||||
public constructor Ann(/*0*/ arg: kotlin.Int = ...)
|
||||
internal 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
|
||||
}
|
||||
|
||||
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 trait D : 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
|
||||
}
|
||||
|
||||
Ann() internal final class MyClass {
|
||||
public constructor MyClass()
|
||||
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() internal final class Q {
|
||||
public constructor Q(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
|
||||
internal final val x: kotlin.Int
|
||||
internal final val y: kotlin.Int
|
||||
internal final /*synthesized*/ fun component1(): kotlin.Int
|
||||
internal 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
|
||||
}
|
||||
@@ -657,6 +657,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("bracketsDeprecation.kt")
|
||||
public void testBracketsDeprecation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/bracketsDeprecation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorCall.kt")
|
||||
public void testConstructorCall() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/ConstructorCall.kt");
|
||||
|
||||
Reference in New Issue
Block a user