• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

raphw / byte-buddy / #815

03 Nov 2025 02:07PM UTC coverage: 82.717% (-1.0%) from 83.677%
#815

push

raphw
Fix up test runs.

29472 of 35630 relevant lines covered (82.72%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/byte-buddy-dep/src/main/java/net/bytebuddy/description/enumeration/EnumerationDescription.java
1
/*
2
 * Copyright 2014 - Present 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.description.enumeration;
17

18
import net.bytebuddy.build.CachedReturnPlugin;
19
import net.bytebuddy.description.NamedElement;
20
import net.bytebuddy.description.type.TypeDescription;
21
import net.bytebuddy.utility.nullability.MaybeNull;
22

23
import java.util.ArrayList;
24
import java.util.List;
25

26
/**
27
 * Describes an enumeration value. Note that the {@link java.lang.Object#toString} method always returns the
28
 * value as if the method was not overridden, i.e. the name of the enumeration constant.
29
 */
30
public interface EnumerationDescription extends NamedElement {
31

32
    /**
33
     * Returns the name of this instance's enumeration value.
34
     *
35
     * @return The name of this enumeration constant.
36
     */
37
    String getValue();
38

39
    /**
40
     * Returns the type of this enumeration.
41
     *
42
     * @return The type of this enumeration.
43
     */
44
    TypeDescription getEnumerationType();
45

46
    /**
47
     * Prepares this enumeration value to be loaded.
48
     *
49
     * @param type A type constant representing the enumeration value.
50
     * @param <T>  The enumeration type.
51
     * @return The loaded enumeration constant corresponding to this value.
52
     */
53
    <T extends Enum<T>> T load(Class<T> type);
54

55
    /**
56
     * An adapter implementation of an enumeration description.
57
     */
58
    abstract class AbstractBase implements EnumerationDescription {
1✔
59

60
        /**
61
         * {@inheritDoc}
62
         */
63
        public String getActualName() {
64
            return getValue();
1✔
65
        }
66

67
        @Override
68
        @CachedReturnPlugin.Enhance("hashCode")
69
        public int hashCode() {
70
            return getValue().hashCode() + 31 * getEnumerationType().hashCode();
1✔
71
        }
72

73
        @Override
74
        public boolean equals(@MaybeNull Object other) {
75
            if (this == other) {
1✔
76
                return true;
1✔
77
            } else if (!(other instanceof EnumerationDescription)) {
1✔
78
                return false;
1✔
79
            }
80
            EnumerationDescription enumerationDescription = (EnumerationDescription) other;
1✔
81
            return getEnumerationType().equals(enumerationDescription.getEnumerationType()) && getValue().equals(enumerationDescription.getValue());
1✔
82
        }
83

84
        @Override
85
        public String toString() {
86
            return getValue();
1✔
87
        }
88
    }
89

90
    /**
91
     * An enumeration description representing a loaded enumeration.
92
     */
93
    class ForLoadedEnumeration extends AbstractBase {
94

95
        /**
96
         * The loaded enumeration value.
97
         */
98
        private final Enum<?> value;
99

100
        /**
101
         * Creates a new enumeration value representation for a loaded enumeration.
102
         *
103
         * @param value The value to represent.
104
         */
105
        public ForLoadedEnumeration(Enum<?> value) {
1✔
106
            this.value = value;
1✔
107
        }
1✔
108

109
        /**
110
         * Enlists a given array of loaded enumerations as enumeration values.
111
         *
112
         * @param enumerations The enumerations to represent.
113
         * @return A list of the given enumerations.
114
         */
115
        public static List<EnumerationDescription> asList(Enum<?>[] enumerations) {
116
            List<EnumerationDescription> result = new ArrayList<EnumerationDescription>(enumerations.length);
×
117
            for (Enum<?> enumeration : enumerations) {
×
118
                result.add(new ForLoadedEnumeration(enumeration));
×
119
            }
120
            return result;
×
121
        }
122

123
        /**
124
         * {@inheritDoc}
125
         */
126
        public String getValue() {
127
            return value.name();
1✔
128
        }
129

130
        /**
131
         * {@inheritDoc}
132
         */
133
        public TypeDescription getEnumerationType() {
134
            return TypeDescription.ForLoadedType.of(value.getDeclaringClass());
1✔
135
        }
136

137
        /**
138
         * {@inheritDoc}
139
         */
140
        @SuppressWarnings("unchecked")
141
        public <T extends Enum<T>> T load(Class<T> type) {
142
            return value.getDeclaringClass() == type
1✔
143
                    ? (T) value
144
                    : Enum.valueOf(type, value.name());
×
145
        }
146
    }
147

148
    /**
149
     * A latent description of an enumeration value.
150
     */
151
    class Latent extends AbstractBase {
152

153
        /**
154
         * The type of the enumeration.
155
         */
156
        private final TypeDescription enumerationType;
157

158
        /**
159
         * The value of the enumeration.
160
         */
161
        private final String value;
162

163
        /**
164
         * Creates a latent description of an enumeration value.
165
         *
166
         * @param enumerationType The enumeration type.
167
         * @param value           The value of the enumeration.
168
         */
169
        public Latent(TypeDescription enumerationType, String value) {
1✔
170
            this.enumerationType = enumerationType;
1✔
171
            this.value = value;
1✔
172
        }
1✔
173

174
        /**
175
         * {@inheritDoc}
176
         */
177
        public String getValue() {
178
            return value;
1✔
179
        }
180

181
        /**
182
         * {@inheritDoc}
183
         */
184
        public TypeDescription getEnumerationType() {
185
            return enumerationType;
1✔
186
        }
187

188
        /**
189
         * {@inheritDoc}
190
         */
191
        public <T extends Enum<T>> T load(Class<T> type) {
192
            if (!enumerationType.represents(type)) {
1✔
193
                throw new IllegalArgumentException(type + " does not represent " + enumerationType);
1✔
194
            }
195
            return Enum.valueOf(type, value);
1✔
196
        }
197
    }
198
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc