1 /*
2  * Copyright 2014 - 2020 Rafael Winterhalter
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.bytebuddy.implementation.bind.annotation;
17
18 import net.bytebuddy.description.annotation.AnnotationDescription;
19 import net.bytebuddy.description.method.MethodDescription;
20 import net.bytebuddy.description.method.ParameterDescription;
21 import net.bytebuddy.implementation.Implementation;
22 import net.bytebuddy.implementation.bind.MethodDelegationBinder;
23 import net.bytebuddy.implementation.bytecode.assign.Assigner;
24 import net.bytebuddy.implementation.bytecode.constant.DefaultValue;
25
26 import java.lang.annotation.*;
27
28 /**
29  * Binds the parameter type's default value to the annotated parameter, i.e. {@code null} or a numeric value
30  * representing zero.
31  *
32  * @see net.bytebuddy.implementation.MethodDelegation
33  * @see net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder
34  */

35 @Documented
36 @Retention(RetentionPolicy.RUNTIME)
37 @Target(ElementType.PARAMETER)
38 public @interface Empty {
39
40     /**
41      * A binder for the {@link net.bytebuddy.implementation.bind.annotation.Empty} annotation.
42      */

43     enum Binder implements TargetMethodAnnotationDrivenBinder.ParameterBinder<Empty> {
44
45         /**
46          * The singleton instance.
47          */

48         INSTANCE;
49
50         /**
51          * {@inheritDoc}
52          */

53         public Class<Empty> getHandledType() {
54             return Empty.class;
55         }
56
57         /**
58          * {@inheritDoc}
59          */

60         public MethodDelegationBinder.ParameterBinding<?> bind(AnnotationDescription.Loadable<Empty> annotation,
61                                                                MethodDescription source,
62                                                                ParameterDescription target,
63                                                                Implementation.Target implementationTarget,
64                                                                Assigner assigner,
65                                                                Assigner.Typing typing) {
66             return new MethodDelegationBinder.ParameterBinding.Anonymous(DefaultValue.of(target.getType().asErasure()));
67         }
68     }
69 }
70