Skip to content

Commit df4df0a

Browse files
committed
subset of the ASM framework, re-namespaced as scala.tools.asm
1 parent 07546bd commit df4df0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+27954
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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 scala.tools.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 the ASM API version implemented by this visitor. Must be one
58+
* of {@link Opcodes#ASM4}.
59+
*/
60+
public AnnotationVisitor(final int api) {
61+
this(api, null);
62+
}
63+
64+
/**
65+
* Constructs a new {@link AnnotationVisitor}.
66+
*
67+
* @param api the ASM API version implemented by this visitor. Must be one
68+
* of {@link Opcodes#ASM4}.
69+
* @param av the annotation visitor to which this visitor must delegate
70+
* method calls. May be null.
71+
*/
72+
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
73+
/*if (api != Opcodes.ASM4) {
74+
throw new IllegalArgumentException();
75+
}*/
76+
this.api = api;
77+
this.av = av;
78+
}
79+
80+
/**
81+
* Visits a primitive value of the annotation.
82+
*
83+
* @param name the value name.
84+
* @param value the actual value, whose type must be {@link Byte},
85+
* {@link Boolean}, {@link Character}, {@link Short}, {@link Integer}
86+
* , {@link Long}, {@link Float}, {@link Double}, {@link String} or
87+
* {@link Type} or OBJECT or ARRAY sort. This value can also be an
88+
* array of byte, boolean, short, char, int, long, float or double
89+
* values (this is equivalent to using {@link #visitArray visitArray}
90+
* and visiting each array element in turn, but is more convenient).
91+
*/
92+
public void visit(String name, Object value) {
93+
if (av != null) {
94+
av.visit(name, value);
95+
}
96+
}
97+
98+
/**
99+
* Visits an enumeration value of the annotation.
100+
*
101+
* @param name the value name.
102+
* @param desc the class descriptor of the enumeration class.
103+
* @param value the actual enumeration value.
104+
*/
105+
public void visitEnum(String name, String desc, String value) {
106+
if (av != null) {
107+
av.visitEnum(name, desc, value);
108+
}
109+
}
110+
111+
/**
112+
* Visits a nested annotation value of the annotation.
113+
*
114+
* @param name the value name.
115+
* @param desc the class descriptor of the nested annotation class.
116+
* @return a visitor to visit the actual nested annotation value, or
117+
* <tt>null</tt> if this visitor is not interested in visiting
118+
* this nested annotation. <i>The nested annotation value must be
119+
* fully visited before calling other methods on this annotation
120+
* visitor</i>.
121+
*/
122+
public AnnotationVisitor visitAnnotation(String name, String desc) {
123+
if (av != null) {
124+
return av.visitAnnotation(name, desc);
125+
}
126+
return null;
127+
}
128+
129+
/**
130+
* Visits an array value of the annotation. Note that arrays of primitive
131+
* types (such as byte, boolean, short, char, int, long, float or double)
132+
* can be passed as value to {@link #visit visit}. This is what
133+
* {@link ClassReader} does.
134+
*
135+
* @param name the value name.
136+
* @return a visitor to visit the actual array value elements, or
137+
* <tt>null</tt> if this visitor is not interested in visiting
138+
* these values. The 'name' parameters passed to the methods of this
139+
* visitor are ignored. <i>All the array values must be visited
140+
* before calling other methods on this annotation visitor</i>.
141+
*/
142+
public AnnotationVisitor visitArray(String name) {
143+
if (av != null) {
144+
return av.visitArray(name);
145+
}
146+
return null;
147+
}
148+
149+
/**
150+
* Visits the end of the annotation.
151+
*/
152+
public void visitEnd() {
153+
if (av != null) {
154+
av.visitEnd();
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)