1 /* 2 * Copyright 2020 Google LLC 3 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 // WITH_RUNTIME 19 // TEST PROCESSOR: AnnotationsInDependenciesProcessor 20 // EXPECTED: 21 // main.KotlinClass -> 22 // class main.KotlinClass : annotations.ClassTarget{[value = onClass]} 23 // class main.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} 24 // function myFun : annotations.FunctionTarget{[value = onMyFun]} 25 // function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} 26 // getter of property prop : annotations.PropertyGetterTarget{[value = get:]} 27 // parameter <set-?> : annotations.ValueParameterTarget{[value = onPropSetter]} 28 // parameter <set-?> : annotations.ValueParameterTarget{[value = onProp]} 29 // parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} 30 // parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} 31 // parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} 32 // parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} 33 // property prop : annotations.FieldTarget2{[value = field:]} 34 // property prop : annotations.FieldTarget{[value = onProp]} 35 // property prop : annotations.NoTargetAnnotation{[value = onProp]} 36 // property prop : annotations.PropertyTarget{[value = onProp]} 37 // setter of property prop : annotations.PropertySetterTarget{[value = set:]} 38 // lib.KotlinClass -> 39 // class lib.KotlinClass : annotations.ClassTarget{[value = onClass]} 40 // class lib.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} 41 // function myFun : annotations.FunctionTarget{[value = onMyFun]} 42 // function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} 43 // getter of property prop : annotations.PropertyGetterTarget{[value = get:]} 44 // parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} 45 // parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} 46 // parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} 47 // parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} 48 // parameter propInConstructor : annotations.ValueParameterTarget{[value = propInConstructor]} 49 // property prop : annotations.FieldTarget2{[value = field:]} 50 // property prop : annotations.FieldTarget{[value = onProp]} 51 // property prop : annotations.NoTargetAnnotation{[value = onProp]} 52 // property prop : annotations.PropertyTarget{[value = onProp]} 53 // setter of property prop : annotations.PropertySetterTarget{[value = set:]} 54 // main.DataClass -> 55 // class main.DataClass : annotations.ClassTarget{[value = onDataClass]} 56 // class main.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} 57 // getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} 58 // parameter <set-?> : annotations.ValueParameterTarget{[value = onConstructorParam]} 59 // parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} 60 // parameter constructorParam : annotations.ValueParameterTarget{[value = onConstructorParam]} 61 // property constructorParam : annotations.FieldTarget2{[value = field:]} 62 // property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} 63 // property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} 64 // property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} 65 // property constructorParam : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField]} 66 // setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} 67 // lib.DataClass -> 68 // class lib.DataClass : annotations.ClassTarget{[value = onDataClass]} 69 // class lib.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} 70 // getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} 71 // parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} 72 // property constructorParam : annotations.FieldTarget2{[value = field:]} 73 // property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} 74 // property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} 75 // setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} 76 // END 77 // MODULE: annotations 78 // FILE: Annotations.kt 79 package annotations; 80 annotation class NoTargetAnnotation(val value:String) 81 82 @Target(AnnotationTarget.FIELD) 83 annotation class FieldTarget(val value:String) 84 85 @Target(AnnotationTarget.FIELD) 86 annotation class FieldTarget2(val value:String) 87 88 @Target(AnnotationTarget.PROPERTY) 89 annotation class PropertyTarget(val value:String) 90 91 @Target(AnnotationTarget.PROPERTY_SETTER) 92 annotation class PropertySetterTarget(val value:String) 93 94 @Target(AnnotationTarget.PROPERTY_GETTER) 95 annotation class PropertyGetterTarget(val value:String) 96 97 @Target(AnnotationTarget.CLASS) 98 annotation class ClassTarget(val value:String) 99 100 @Target(AnnotationTarget.FUNCTION) 101 annotation class FunctionTarget(val value:String) 102 103 @Target(AnnotationTarget.VALUE_PARAMETER) 104 annotation class ValueParameterTarget(val value:String) 105 106 @Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD) 107 annotation class ValueParameterAndFieldTarget(val value: String) 108 109 // MODULE: lib(annotations) 110 // FILE: ClassInLib.kt 111 package lib; 112 import annotations.*; 113 @NoTargetAnnotation("onClass") 114 @ClassTarget("onClass") 115 class KotlinClass(@ValueParameterTarget("propInConstructor") val propInConstructor: String ) { 116 @NoTargetAnnotation("onProp") 117 @FieldTarget("onProp") 118 @PropertyTarget("onProp") 119 @set:PropertySetterTarget("set:") 120 @get:PropertyGetterTarget("get:") 121 @field:FieldTarget2("field:") 122 var prop : String = "" 123 124 @NoTargetAnnotation("onMyFun") 125 @FunctionTarget("onMyFun") myFunnull126 fun myFun( 127 @NoTargetAnnotation("onParam1") 128 @ValueParameterTarget("onParam1") 129 param1: String, 130 @NoTargetAnnotation("onParam2") 131 @ValueParameterTarget("onParam2") 132 param2: Int 133 ) { 134 } 135 } 136 137 @NoTargetAnnotation("onDataClass") 138 @ClassTarget("onDataClass") 139 class DataClass( 140 @NoTargetAnnotation("onConstructorParam") 141 @FieldTarget("onConstructorParam") 142 @PropertyTarget("onConstructorParam") 143 @set:PropertySetterTarget("set:") 144 @get:PropertyGetterTarget("get:") 145 @field:FieldTarget2("field:") 146 var constructorParam : String = "" 147 ) 148 // FILE: lib/JavaClass.java 149 package lib; 150 import annotations.*; 151 public class JavaClass {} 152 // MODULE: main(lib, annotations) 153 // FILE: ClassInModule2.kt 154 package main; 155 import annotations.*; 156 @NoTargetAnnotation("onClass") 157 @ClassTarget("onClass") 158 class KotlinClass { 159 @NoTargetAnnotation("onProp") 160 @FieldTarget("onProp") 161 @PropertyTarget("onProp") 162 @set:PropertySetterTarget("set:") 163 @get:PropertyGetterTarget("get:") 164 @field:FieldTarget2("field:") 165 @setparam:ValueParameterTarget("onProp") 166 var prop : String = "" 167 @setparam:ValueParameterTarget("onPropSetter") 168 set 169 170 @NoTargetAnnotation("onMyFun") 171 @FunctionTarget("onMyFun") myFunnull172 fun myFun( 173 @NoTargetAnnotation("onParam1") 174 @ValueParameterTarget("onParam1") 175 param1: String, 176 @NoTargetAnnotation("onParam2") 177 @ValueParameterTarget("onParam2") 178 param2: Int 179 ) { 180 } 181 } 182 183 @NoTargetAnnotation("onDataClass") 184 @ClassTarget("onDataClass") 185 class DataClass( 186 @NoTargetAnnotation("onConstructorParam") 187 @FieldTarget("onConstructorParam") 188 @PropertyTarget("onConstructorParam") 189 @set:PropertySetterTarget("set:") 190 @get:PropertyGetterTarget("get:") 191 @field:FieldTarget2("field:") 192 @field:ValueParameterAndFieldTarget("valueParameterAndField") 193 @setparam:ValueParameterTarget("onConstructorParam") 194 @ValueParameterTarget("onConstructorParam") 195 var constructorParam : String = "" 196 ) 197 // FILE: main/JavaClassInModule2.java 198 pakage main; 199 import annotations.*; 200 @NoTargetAnnotation 201 class JavaClassInMain { 202 } 203