Skip to content

Commit c8d3ef3

Browse files
puredangerstuarthalloway
authored andcommitted
CLJ-713 - upgrade ASM to 4.1.
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 6be0580 commit c8d3ef3

36 files changed

+18967
-17511
lines changed

src/clj/clojure/reflect/java.clj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
(require '[clojure.set :as set]
1313
'[clojure.string :as str])
14-
(import '[clojure.asm ClassReader ClassVisitor Type]
14+
(import '[clojure.asm ClassReader ClassVisitor Type Opcodes]
1515
'[java.lang.reflect Modifier]
1616
java.io.InputStream)
1717

@@ -202,9 +202,10 @@ the kinds of objects to which they can apply."}
202202
result (atom {:bases #{} :flags #{} :members #{}})]
203203
(.accept
204204
r
205-
(reify
206-
ClassVisitor
207-
(visit [_ version access name signature superName interfaces]
205+
(proxy
206+
[ClassVisitor]
207+
[Opcodes/ASM4]
208+
(visit [version access name signature superName interfaces]
208209
(let [flags (parse-flags access :class)
209210
;; ignore java.lang.Object on interfaces to match reflection
210211
superName (if (and (flags :interface)
@@ -219,17 +220,17 @@ the kinds of objects to which they can apply."}
219220
(not-empty))]
220221
(swap! result merge {:bases bases
221222
:flags flags})))
222-
(visitAnnotation [_ desc visible])
223-
(visitSource [_ name debug])
224-
(visitInnerClass [_ name outerName innerName access])
225-
(visitField [_ access name desc signature value]
223+
(visitAnnotation [desc visible])
224+
(visitSource [name debug])
225+
(visitInnerClass [name outerName innerName access])
226+
(visitField [access name desc signature value]
226227
(swap! result update-in [:members] (fnil conj #{})
227228
(Field. (symbol name)
228229
(field-descriptor->class-symbol desc)
229230
class-symbol
230231
(parse-flags access :field)))
231232
nil)
232-
(visitMethod [_ access name desc signature exceptions]
233+
(visitMethod [access name desc signature exceptions]
233234
(when-not (= name "<clinit>")
234235
(let [constructor? (= name "<init>")]
235236
(swap! result update-in [:members] (fnil conj #{})
@@ -248,7 +249,7 @@ the kinds of objects to which they can apply."}
248249
(vec (map internal-name->class-symbol exceptions))
249250
flags))))))
250251
nil)
251-
(visitEnd [_])
252+
(visitEnd [])
252253
) 0)
253254
@result))))
254255

Lines changed: 169 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,169 @@
1-
/***
2-
* ASM: a very small and fast Java bytecode manipulation framework
3-
* Copyright (c) 2000-2005 INRIA, France Telecom
4-
* All rights reserved.
5-
*
6-
* Redistribution and use in source and binary forms, with or without
7-
* modification, are permitted provided that the following conditions
8-
* are met:
9-
* 1. Redistributions of source code must retain the above copyright
10-
* notice, this list of conditions and the following disclaimer.
11-
* 2. Redistributions in binary form must reproduce the above copyright
12-
* notice, this list of conditions and the following disclaimer in the
13-
* documentation and/or other materials provided with the distribution.
14-
* 3. Neither the name of the copyright holders nor the names of its
15-
* contributors may be used to endorse or promote products derived from
16-
* this software without specific prior written permission.
17-
*
18-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28-
* THE POSSIBILITY OF SUCH DAMAGE.
29-
*/
30-
package clojure.asm;
31-
32-
/**
33-
* A visitor to visit a Java annotation. The methods of this interface must be
34-
* called in the following order: (<tt>visit<tt> | <tt>visitEnum<tt> |
35-
* <tt>visitAnnotation<tt> | <tt>visitArray<tt>)* <tt>visitEnd<tt>.
36-
*
37-
* @author Eric Bruneton
38-
* @author Eugene Kuleshov
39-
*/
40-
public interface AnnotationVisitor{
41-
42-
/**
43-
* Visits a primitive value of the annotation.
44-
*
45-
* @param name the value name.
46-
* @param value the actual value, whose type must be {@link Byte},
47-
* {@link Boolean}, {@link Character}, {@link Short},
48-
* {@link Integer}, {@link Long}, {@link Float}, {@link Double},
49-
* {@link String} or {@link Type}. This value can also be an array
50-
* of byte, boolean, short, char, int, long, float or double values
51-
* (this is equivalent to using {@link #visitArray visitArray} and
52-
* visiting each array element in turn, but is more convenient).
53-
*/
54-
void visit(String name, Object value);
55-
56-
/**
57-
* Visits an enumeration value of the annotation.
58-
*
59-
* @param name the value name.
60-
* @param desc the class descriptor of the enumeration class.
61-
* @param value the actual enumeration value.
62-
*/
63-
void visitEnum(String name, String desc, String value);
64-
65-
/**
66-
* Visits a nested annotation value of the annotation.
67-
*
68-
* @param name the value name.
69-
* @param desc the class descriptor of the nested annotation class.
70-
* @return a visitor to visit the actual nested annotation value, or
71-
* <tt>null</tt> if this visitor is not interested in visiting
72-
* this nested annotation. <i>The nested annotation value must be
73-
* fully visited before calling other methods on this annotation
74-
* visitor</i>.
75-
*/
76-
AnnotationVisitor visitAnnotation(String name, String desc);
77-
78-
/**
79-
* Visits an array value of the annotation. Note that arrays of primitive
80-
* types (such as byte, boolean, short, char, int, long, float or double)
81-
* can be passed as value to {@link #visit visit}. This is what
82-
* {@link ClassReader} does.
83-
*
84-
* @param name the value name.
85-
* @return a visitor to visit the actual array value elements, or
86-
* <tt>null</tt> if this visitor is not interested in visiting
87-
* these values. The 'name' parameters passed to the methods of this
88-
* visitor are ignored. <i>All the array values must be visited
89-
* before calling other methods on this annotation visitor</i>.
90-
*/
91-
AnnotationVisitor visitArray(String name);
92-
93-
/**
94-
* Visits the end of the annotation.
95-
*/
96-
void visitEnd();
97-
}
1+
/***
2+
* ASM: a very small and fast Java bytecode manipulation framework
3+
* Copyright (c) 2000-2011 INRIA, France Telecom
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* 3. Neither the name of the copyright holders nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28+
* THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package clojure.asm;
31+
32+
/**
33+
* A visitor to visit a Java annotation. The methods of this class must be
34+
* called in the following order: ( <tt>visit</tt> | <tt>visitEnum</tt> |
35+
* <tt>visitAnnotation</tt> | <tt>visitArray</tt> )* <tt>visitEnd</tt>.
36+
*
37+
* @author Eric Bruneton
38+
* @author Eugene Kuleshov
39+
*/
40+
public abstract class AnnotationVisitor {
41+
42+
/**
43+
* The ASM API version implemented by this visitor. The value of this field
44+
* must be one of {@link Opcodes#ASM4}.
45+
*/
46+
protected final int api;
47+
48+
/**
49+
* The annotation visitor to which this visitor must delegate method calls.
50+
* May be null.
51+
*/
52+
protected AnnotationVisitor av;
53+
54+
/**
55+
* Constructs a new {@link AnnotationVisitor}.
56+
*
57+
* @param api
58+
* the ASM API version implemented by this visitor. Must be one
59+
* of {@link Opcodes#ASM4}.
60+
*/
61+
public AnnotationVisitor(final int api) {
62+
this(api, null);
63+
}
64+
65+
/**
66+
* Constructs a new {@link AnnotationVisitor}.
67+
*
68+
* @param api
69+
* the ASM API version implemented by this visitor. Must be one
70+
* of {@link Opcodes#ASM4}.
71+
* @param av
72+
* the annotation visitor to which this visitor must delegate
73+
* method calls. May be null.
74+
*/
75+
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
76+
if (api != Opcodes.ASM4) {
77+
throw new IllegalArgumentException();
78+
}
79+
this.api = api;
80+
this.av = av;
81+
}
82+
83+
/**
84+
* Visits a primitive value of the annotation.
85+
*
86+
* @param name
87+
* the value name.
88+
* @param value
89+
* the actual value, whose type must be {@link Byte},
90+
* {@link Boolean}, {@link Character}, {@link Short},
91+
* {@link Integer} , {@link Long}, {@link Float}, {@link Double},
92+
* {@link String} or {@link Type} or OBJECT or ARRAY sort. This
93+
* value can also be an array of byte, boolean, short, char, int,
94+
* long, float or double values (this is equivalent to using
95+
* {@link #visitArray visitArray} and visiting each array element
96+
* in turn, but is more convenient).
97+
*/
98+
public void visit(String name, Object value) {
99+
if (av != null) {
100+
av.visit(name, value);
101+
}
102+
}
103+
104+
/**
105+
* Visits an enumeration value of the annotation.
106+
*
107+
* @param name
108+
* the value name.
109+
* @param desc
110+
* the class descriptor of the enumeration class.
111+
* @param value
112+
* the actual enumeration value.
113+
*/
114+
public void visitEnum(String name, String desc, String value) {
115+
if (av != null) {
116+
av.visitEnum(name, desc, value);
117+
}
118+
}
119+
120+
/**
121+
* Visits a nested annotation value of the annotation.
122+
*
123+
* @param name
124+
* the value name.
125+
* @param desc
126+
* the class descriptor of the nested annotation class.
127+
* @return a visitor to visit the actual nested annotation value, or
128+
* <tt>null</tt> if this visitor is not interested in visiting this
129+
* nested annotation. <i>The nested annotation value must be fully
130+
* visited before calling other methods on this annotation
131+
* visitor</i>.
132+
*/
133+
public AnnotationVisitor visitAnnotation(String name, String desc) {
134+
if (av != null) {
135+
return av.visitAnnotation(name, desc);
136+
}
137+
return null;
138+
}
139+
140+
/**
141+
* Visits an array value of the annotation. Note that arrays of primitive
142+
* types (such as byte, boolean, short, char, int, long, float or double)
143+
* can be passed as value to {@link #visit visit}. This is what
144+
* {@link ClassReader} does.
145+
*
146+
* @param name
147+
* the value name.
148+
* @return a visitor to visit the actual array value elements, or
149+
* <tt>null</tt> if this visitor is not interested in visiting these
150+
* values. The 'name' parameters passed to the methods of this
151+
* visitor are ignored. <i>All the array values must be visited
152+
* before calling other methods on this annotation visitor</i>.
153+
*/
154+
public AnnotationVisitor visitArray(String name) {
155+
if (av != null) {
156+
return av.visitArray(name);
157+
}
158+
return null;
159+
}
160+
161+
/**
162+
* Visits the end of the annotation.
163+
*/
164+
public void visitEnd() {
165+
if (av != null) {
166+
av.visitEnd();
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)