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.attribute;
17
18 /**
19  * An annotation retention strategy decides if annotations that are contained within a class file are preserved upon redefining
20  * or rebasing a method. When annotations are retained, it is important not to define annotations explicitly that are already
21  * defined. When annotations are retained, they are retained in their original format, i.e. default values that were not included
22  * in the class file are not added or skipped as determined by a {@link AnnotationValueFilter}.
23  */

24 public enum AnnotationRetention {
25
26     /**
27      * Enables annotation retention, i.e. annotations within an existing class files are preserved as they are.
28      */

29     ENABLED(true),
30
31     /**
32      * Disables annotation retention, i.e. annotations within an existing class files are discarded.
33      */

34     DISABLED(false);
35
36     /**
37      * {@code trueif annotation retention is enabled.
38      */

39     private final boolean enabled;
40
41     /**
42      * Creates an annotation retention strategy.
43      *
44      * @param enabled {@code trueif annotation retention is enabled.
45      */

46     AnnotationRetention(boolean enabled) {
47         this.enabled = enabled;
48     }
49
50     /**
51      * Resolves an annotation retention from a boolean value.
52      *
53      * @param enabled {@code trueif annotation retention is enabled.
54      * @return An enabled annotation retention if the value is {@code true}.
55      */

56     public static AnnotationRetention of(boolean enabled) {
57         return enabled
58                 ? ENABLED
59                 : DISABLED;
60     }
61
62     /**
63      * Returns {@code trueif annotation retention is enabled.
64      *
65      * @return {@code trueif annotation retention is enabled.
66      */

67     public boolean isEnabled() {
68         return enabled;
69     }
70 }
71