Implementation of Kotlin's 'target' annotation mapping to Java's 'Target' annotation + tests

This commit is contained in:
Mikhail Glukhikh
2015-07-14 19:42:05 +03:00
parent 2a1058ed63
commit af5e7f58da
62 changed files with 547 additions and 54 deletions
@@ -0,0 +1,9 @@
package test;
@meta @interface MyAnn {
}
@meta class My {
}
@@ -0,0 +1,2 @@
annotation.java:7:1:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.ANNOTATION_CLASS)
annotation class meta
@@ -0,0 +1,9 @@
package test
test.meta() public/*package*/ final class MyAnn : kotlin.Annotation {
public/*package*/ constructor MyAnn()
}
kotlin.annotation.target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.ANNOTATION_TYPE}) internal final class meta : kotlin.Annotation {
public constructor meta()
}
@@ -0,0 +1,8 @@
package test;
@base class My {
@base int foo(@base int i) {
return i + 1;
}
}
@@ -0,0 +1,3 @@
package test
annotation class base
@@ -0,0 +1,10 @@
package test
test.base() public/*package*/ open class My {
public/*package*/ constructor My()
test.base() public/*package*/ open fun foo(/*0*/ test.base() kotlin.Int): kotlin.Int
}
kotlin.annotation.annotation() internal final class base : kotlin.Annotation {
public constructor base()
}
@@ -0,0 +1,8 @@
package test;
@classifier class My {
@classifier int foo() {
return 1;
}
}
@@ -0,0 +1 @@
classifier.java:5:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.CLASSIFIER)
annotation class classifier
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.TYPE}) internal final class classifier : kotlin.Annotation {
public constructor classifier()
}
@@ -0,0 +1,10 @@
package test;
class My {
@constructor My() {}
@constructor int foo() {
return 1;
}
}
@@ -0,0 +1,3 @@
constructor.java:7:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.CONSTRUCTOR)
annotation class constructor
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.CONSTRUCTOR}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.CONSTRUCTOR}) internal final class constructor : kotlin.Annotation {
public constructor constructor()
}
@@ -0,0 +1,8 @@
package test;
@empty class My {
@empty int foo(@empty int i) {
return i + 1;
}
}
@@ -0,0 +1,4 @@
empty.java:3:1:compiler.err.annotation.type.not.applicable
empty.java:5:20:compiler.err.annotation.type.not.applicable
empty.java:5:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target()
annotation class empty
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {}) internal final class empty : kotlin.Annotation {
public constructor empty()
}
@@ -0,0 +1,7 @@
package test;
class My {
@field int prop;
@field int get() { return prop; }
}
@@ -0,0 +1,4 @@
field.java:6:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.FIELD)
annotation class field
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.FIELD}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.FIELD}) internal final class field : kotlin.Annotation {
public constructor field()
}
@@ -0,0 +1,8 @@
package test;
@function class My {
@function int foo() {
return 1;
}
}
@@ -0,0 +1,2 @@
function.java:3:1:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.FUNCTION)
annotation class function
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class function : kotlin.Annotation {
public constructor function()
}
@@ -0,0 +1,8 @@
package test;
@getter class My {
@getter int foo() {
return 1;
}
}
@@ -0,0 +1,3 @@
getter.java:3:1:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.PROPERTY_GETTER)
annotation class getter
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_GETTER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class getter : kotlin.Annotation {
public constructor getter()
}
@@ -0,0 +1,9 @@
package test;
class My {
int foo(@local int i) {
@local int j = i + 1;
return j;
}
}
@@ -0,0 +1,3 @@
local.java:5:13:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.LOCAL_VARIABLE)
annotation class local
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.LOCAL_VARIABLE}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.LOCAL_VARIABLE}) internal final class local : kotlin.Annotation {
public constructor local()
}
@@ -0,0 +1,8 @@
package test;
@multiple class My {
@multiple int foo(@multiple int i) {
return i + 1;
}
}
@@ -0,0 +1,2 @@
multiple.java:5:23:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION)
annotation class multiple
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.TYPE, ElementType.METHOD}) internal final class multiple : kotlin.Annotation {
public constructor multiple()
}
@@ -0,0 +1,5 @@
@pck package test;
@pck class My {
}
@@ -0,0 +1,2 @@
package-info.java:3:1:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.PACKAGE)
annotation class pck
@@ -0,0 +1,8 @@
package test
test.pck() public/*package*/ interface `package-info` {
}
kotlin.annotation.target(allowedTargets = {AnnotationTarget.PACKAGE}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.PACKAGE}) internal final class pck : kotlin.Annotation {
public constructor pck()
}
@@ -0,0 +1,8 @@
package test;
@parameter class My {
@parameter int foo(@parameter int i) {
return i + 1;
}
}
@@ -0,0 +1,2 @@
parameter.java:3:1:compiler.err.annotation.type.not.applicable
parameter.java:5:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.VALUE_PARAMETER)
annotation class parameter
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.PARAMETER}) internal final class parameter : kotlin.Annotation {
public constructor parameter()
}
@@ -0,0 +1,7 @@
package test;
class My {
@property int prop;
@property int get() { return prop; }
}
@@ -0,0 +1,4 @@
property.java:4:5:compiler.err.annotation.type.not.applicable
property.java:6:5:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.PROPERTY)
annotation class property
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {}) internal final class property : kotlin.Annotation {
public constructor property()
}
@@ -0,0 +1,8 @@
package test;
@setter class My {
@setter int foo() {
return 1;
}
}
@@ -0,0 +1,3 @@
setter.java:3:1:compiler.err.annotation.type.not.applicable
@@ -0,0 +1,4 @@
package test
target(AnnotationTarget.PROPERTY_SETTER)
annotation class setter
@@ -0,0 +1,5 @@
package test
kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_SETTER}) kotlin.annotation.annotation() java.lang.annotation.Target(value = {ElementType.METHOD}) internal final class setter : kotlin.Annotation {
public constructor setter()
}