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

raphw / byte-buddy / #759

24 Mar 2025 09:06AM UTC coverage: 85.202% (+0.03%) from 85.175%
#759

push

raphw
Add missing checksums

29340 of 34436 relevant lines covered (85.2%)

0.85 hits per line

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

76.19
/byte-buddy-dep/src/main/java/net/bytebuddy/build/EntryPoint.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.build;
17

18
import net.bytebuddy.ByteBuddy;
19
import net.bytebuddy.ClassFileVersion;
20
import net.bytebuddy.description.type.TypeDescription;
21
import net.bytebuddy.dynamic.ClassFileLocator;
22
import net.bytebuddy.dynamic.DynamicType;
23
import net.bytebuddy.dynamic.scaffold.MethodGraph;
24
import net.bytebuddy.dynamic.scaffold.TypeValidation;
25
import net.bytebuddy.dynamic.scaffold.inline.MethodNameTransformer;
26
import net.bytebuddy.implementation.Implementation;
27

28
import java.io.Serializable;
29

30
import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy;
31
import static net.bytebuddy.matcher.ElementMatchers.not;
32

33
/**
34
 * An entry point for a build tool which is responsible for the transformation's configuration.
35
 */
36
public interface EntryPoint extends Serializable {
37

38
    /**
39
     * Returns the Byte Buddy instance to use.
40
     *
41
     * @param classFileVersion The class file version in which to represent class files.
42
     * @return The Byte Buddy instance to use.
43
     */
44
    ByteBuddy byteBuddy(ClassFileVersion classFileVersion);
45

46
    /**
47
     * Applies a transformation.
48
     *
49
     * @param typeDescription       The type to transform.
50
     * @param byteBuddy             The Byte Buddy instance to use.
51
     * @param classFileLocator      The class file locator to use.
52
     * @param methodNameTransformer The Method name transformer to use.
53
     * @return A builder for the dynamic type to create.
54
     */
55
    DynamicType.Builder<?> transform(TypeDescription typeDescription,
56
                                     ByteBuddy byteBuddy,
57
                                     ClassFileLocator classFileLocator,
58
                                     MethodNameTransformer methodNameTransformer);
59

60
    /**
61
     * Default implementations for an entry point.
62
     */
63
    enum Default implements EntryPoint {
1✔
64

65
        /**
66
         * An entry point that rebases a type.
67
         */
68
        REBASE {
1✔
69
            /**
70
             * {@inheritDoc}
71
             * */
72
            public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
73
                return new ByteBuddy(classFileVersion);
1✔
74
            }
75

76
            /**
77
             * {@inheritDoc}
78
             * */
79
            public DynamicType.Builder<?> transform(TypeDescription typeDescription,
80
                                                    ByteBuddy byteBuddy,
81
                                                    ClassFileLocator classFileLocator,
82
                                                    MethodNameTransformer methodNameTransformer) {
83
                return byteBuddy.rebase(typeDescription, classFileLocator, methodNameTransformer);
1✔
84
            }
85
        },
86

87
        /**
88
         * An entry point that redefines a type.
89
         */
90
        REDEFINE {
1✔
91
            /**
92
             * {@inheritDoc}
93
             * */
94
            public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
95
                return new ByteBuddy(classFileVersion);
1✔
96
            }
97

98
            /**
99
             * {@inheritDoc}
100
             * */
101
            public DynamicType.Builder<?> transform(TypeDescription typeDescription,
102
                                                    ByteBuddy byteBuddy,
103
                                                    ClassFileLocator classFileLocator,
104
                                                    MethodNameTransformer methodNameTransformer) {
105
                return byteBuddy.redefine(typeDescription, classFileLocator);
1✔
106
            }
107
        },
108

109
        /**
110
         * An entry point that redefines a type and which does not change the dynamic type's shape, i.e. does
111
         * not add any methods or considers intercepting inherited methods.
112
         */
113
        REDEFINE_LOCAL {
1✔
114
            /**
115
             * {@inheritDoc}
116
             * */
117
            public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
118
                return new ByteBuddy(classFileVersion).with(Implementation.Context.Disabled.Factory.INSTANCE);
1✔
119
            }
120

121
            /**
122
             * {@inheritDoc}
123
             * */
124
            public DynamicType.Builder<?> transform(TypeDescription typeDescription,
125
                                                    ByteBuddy byteBuddy,
126
                                                    ClassFileLocator classFileLocator,
127
                                                    MethodNameTransformer methodNameTransformer) {
128
                return byteBuddy.redefine(typeDescription, classFileLocator).ignoreAlso(not(isDeclaredBy(typeDescription)));
1✔
129
            }
130
        },
131

132
        /**
133
         * An entry point that decorates a type and which only offers limited support for transformation by only allowing
134
         * for the application of {@link net.bytebuddy.asm.AsmVisitorWrapper}s while improving performance.
135
         */
136
        DECORATE {
1✔
137
            /**
138
             * {@inheritDoc}
139
             * */
140
            public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
141
                return new ByteBuddy(classFileVersion)
×
142
                        .with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE)
×
143
                        .with(Implementation.Context.Disabled.Factory.INSTANCE);
×
144
            }
145

146
            /**
147
             * {@inheritDoc}
148
             * */
149
            public DynamicType.Builder<?> transform(TypeDescription typeDescription,
150
                                                    ByteBuddy byteBuddy,
151
                                                    ClassFileLocator classFileLocator,
152
                                                    MethodNameTransformer methodNameTransformer) {
153
                return byteBuddy.decorate(typeDescription, classFileLocator);
×
154
            }
155
        }
156
    }
157

158
    /**
159
     * An entry point that wraps another entry point but disables validation.
160
     */
161
    @HashCodeAndEqualsPlugin.Enhance
162
    class Unvalidated implements EntryPoint {
163

164
        /**
165
         * The serial version UID.
166
         */
167
        private static final long serialVersionUID = 1L;
168

169
        /**
170
         * The entry point to use.
171
         */
172
        private final EntryPoint delegate;
173

174
        /**
175
         * Creates a new entry point with disabled validation.
176
         *
177
         * @param delegate The entry point to use.
178
         */
179
        public Unvalidated(EntryPoint delegate) {
1✔
180
            this.delegate = delegate;
1✔
181
        }
1✔
182

183
        /**
184
         * {@inheritDoc}
185
         */
186
        public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
187
            return delegate.byteBuddy(classFileVersion).with(TypeValidation.DISABLED);
1✔
188
        }
189

190
        /**
191
         * {@inheritDoc}
192
         */
193
        public DynamicType.Builder<?> transform(TypeDescription typeDescription,
194
                                                ByteBuddy byteBuddy,
195
                                                ClassFileLocator classFileLocator,
196
                                                MethodNameTransformer methodNameTransformer) {
197
            return delegate.transform(typeDescription, byteBuddy, classFileLocator, methodNameTransformer);
1✔
198
        }
199

200
        @Override
201
        public String toString() {
202
            return "Unvalidated:" + delegate;
×
203
        }
204
    }
205
}
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