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.dynamic.scaffold;
17
18 /**
19  * <p>
20  * If type validation is enabled, Byte Buddy performs several checks to ensure that a generated
21  * class file is specified in a valid manner. This involves checks of the generated instrumented
22  * type and checks of the generated byte code. Byte Buddy's {@link net.bytebuddy.implementation.Implementation}
23  * instances perform their own checks, independently of any type validation.
24  * </p>
25  * <p>
26  * The JVM's verifier performs its own checks; an illegal class file is never loaded. However, Byte Buddy's
27  * checks might be more expressive in the context of using the library. Also, Byte Buddy emits exceptions
28  * at class creation time while the JVM emits errors at class loading time.
29  * </p>
30  */

31 public enum TypeValidation {
32
33     /**
34      * Enables Byte Buddy's validation.
35      */

36     ENABLED(true),
37
38     /**
39      * Disables Byte Buddy's validation.
40      */

41     DISABLED(false);
42
43     /**
44      * {@code trueif type validation is enabled.
45      */

46     private final boolean enabled;
47
48     /**
49      * Creates a new type validation enumeration.
50      *
51      * @param enabled {@code trueif type validation is enabled.
52      */

53     TypeValidation(boolean enabled) {
54         this.enabled = enabled;
55     }
56
57     /**
58      * Returns {@link TypeValidation#ENABLED} if the supplied argument is {@code true}.
59      *
60      * @param enabled {@code trueif type validation should be enabled.
61      * @return A suitable type validation representation.
62      */

63     public static TypeValidation of(boolean enabled) {
64         return enabled
65                 ? ENABLED
66                 : DISABLED;
67     }
68
69     /**
70      * Returns {@code trueif type validation is enabled.
71      *
72      * @return {@code trueif type validation is enabled.
73      */

74     public boolean isEnabled() {
75         return enabled;
76     }
77 }
78