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

raphw / byte-buddy / #641

19 Aug 2024 10:38PM CUT coverage: 85.389% (-0.06%) from 85.448%
#641

push

raphw
Disable validation for minor breakage of protected API.

28759 of 33680 relevant lines covered (85.39%)

0.85 hits per line

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

50.0
/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/ClassWriterStrategy.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.dynamic.scaffold;
17

18
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
19
import net.bytebuddy.pool.TypePool;
20
import net.bytebuddy.utility.AsmClassReader;
21
import net.bytebuddy.utility.AsmClassWriter;
22
import org.objectweb.asm.ClassReader;
23
import org.objectweb.asm.ClassWriter;
24

25
/**
26
 * A class writer strategy is responsible for the creation of a {@link ClassWriter} when creating a type.
27
 *
28
 * @deprecated Use {@link AsmClassWriter.Factory}.
29
 */
30
@Deprecated
31
public interface ClassWriterStrategy {
32

33
    /**
34
     * Resolves a class writer.
35
     *
36
     * @param flags    The flags to set.
37
     * @param typePool A type pool for locating types.
38
     * @return The class writer to use.
39
     */
40
    ClassWriter resolve(int flags, TypePool typePool);
41

42
    /**
43
     * Resolves a class writer.
44
     *
45
     * @param flags       The flags to set.
46
     * @param typePool    A type pool for locating types.
47
     * @param classReader The class reader from which the original class is read.
48
     * @return The class writer to use.
49
     */
50
    ClassWriter resolve(int flags, TypePool typePool, ClassReader classReader);
51

52
    /**
53
     * Default implementations of class writer strategies.
54
     *
55
     * @deprecated Use {@link AsmClassWriter.Factory.Suppressing} or {@link net.bytebuddy.ByteBuddy#withIgnoredClassReader()}.
56
     */
57
    @Deprecated
1✔
58
    enum Default implements ClassWriterStrategy {
59

60
        /**
61
         * A class writer strategy that retains the original class's constant pool if applicable.
62
         */
63
        CONSTANT_POOL_RETAINING {
1✔
64
            /** {@inheritDoc} */
65
            public ClassWriter resolve(int flags, TypePool typePool, ClassReader classReader) {
66
                return new FrameComputingClassWriter(classReader, flags, typePool);
1✔
67
            }
68
        },
69

70
        /**
71
         * A class writer strategy that discards the original class's constant pool if applicable.
72
         */
73
        CONSTANT_POOL_DISCARDING {
1✔
74
            /** {@inheritDoc} */
75
            public ClassWriter resolve(int flags, TypePool typePool, ClassReader classReader) {
76
                return resolve(flags, typePool);
1✔
77
            }
78
        };
79

80
        /**
81
         * {@inheritDoc}
82
         */
83
        public ClassWriter resolve(int flags, TypePool typePool) {
84
            return new FrameComputingClassWriter(flags, typePool);
1✔
85
        }
86
    }
87

88
    /**
89
     * A class writer factory that delegates to a {@link ClassWriterStrategy}.
90
     */
91
    @HashCodeAndEqualsPlugin.Enhance
92
    class Delegating implements AsmClassWriter.Factory {
93

94
        /**
95
         * The class writer strategy to delegate to.
96
         */
97
        private final ClassWriterStrategy classWriterStrategy;
98

99
        /**
100
         * Creates a delegating class writer factory.
101
         *
102
         * @param classWriterStrategy The class writer strategy to delegate to.
103
         */
104
        public Delegating(ClassWriterStrategy classWriterStrategy) {
×
105
            this.classWriterStrategy = classWriterStrategy;
×
106
        }
×
107

108
        /**
109
         * {@inheritDoc}
110
         */
111
        public AsmClassWriter make(int flags) {
112
            return make(flags, TypePool.Empty.INSTANCE);
×
113
        }
114

115
        /**
116
         * {@inheritDoc}
117
         */
118
        public AsmClassWriter make(int flags, AsmClassReader classReader) {
119
            return make(flags, classReader, TypePool.Empty.INSTANCE);
×
120
        }
121

122
        /**
123
         * {@inheritDoc}
124
         */
125
        public AsmClassWriter make(int flags, TypePool typePool) {
126
            return new AsmClassWriter.Default(classWriterStrategy.resolve(flags, typePool));
×
127
        }
128

129
        /**
130
         * {@inheritDoc}
131
         */
132
        public AsmClassWriter make(int flags, AsmClassReader classReader, TypePool typePool) {
133
            ClassReader unwrapped = classReader.unwrap(ClassReader.class);
×
134
            return new AsmClassWriter.Default(unwrapped == null
×
135
                    ? classWriterStrategy.resolve(flags, typePool)
×
136
                    : classWriterStrategy.resolve(flags, typePool, unwrapped));
×
137
        }
138
    }
139

140
    /**
141
     * A class writer that piggy-backs on Byte Buddy's {@link TypePool} to avoid class loading or look-up errors when redefining a class.
142
     * This is not available when creating a new class where automatic frame computation is however not normally a requirement.
143
     *
144
     * @deprecated Use {@link AsmClassWriter.FrameComputingClassWriter}.
145
     */
146
    @Deprecated
147
    class FrameComputingClassWriter extends AsmClassWriter.FrameComputingClassWriter {
148

149
        /**
150
         * Creates a new frame computing class writer.
151
         *
152
         * @param flags    The flags to be handed to the writer.
153
         * @param typePool The type pool to use for computing stack map frames, if required.
154
         */
155
        public FrameComputingClassWriter(int flags, TypePool typePool) {
156
            super(flags, typePool);
1✔
157
        }
1✔
158

159
        /**
160
         * Creates a new frame computing class writer.
161
         *
162
         * @param classReader The class reader from which the original class is read.
163
         * @param flags       The flags to be handed to the writer.
164
         * @param typePool    The type pool to use for computing stack map frames, if required.
165
         */
166
        public FrameComputingClassWriter(ClassReader classReader, int flags, TypePool typePool) {
167
            super(classReader, flags, typePool);
1✔
168
        }
1✔
169
    }
170
}
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

© 2025 Coveralls, Inc