KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > tree > TreeCodeAdapter


1 /***
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000,2002,2003 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
31 package oracle.toplink.libraries.asm.tree;
32
33 import oracle.toplink.libraries.asm.CodeAdapter;
34 import oracle.toplink.libraries.asm.Label;
35 import oracle.toplink.libraries.asm.Attribute;
36
37 /**
38  * A {@link CodeAdapter CodeAdapter} that constructs a tree representation of
39  * the methods it vists. Each <tt>visit</tt><i>XXX</i> method of this class
40  * constructs an <i>XXX</i><tt>Node</tt> and adds it to the {@link #methodNode
41  * methodNode} node.
42  *
43  * @author Eric Bruneton
44  */

45
46 public class TreeCodeAdapter extends CodeAdapter {
47
48   /**
49    * A tree representation of the method that is being visited by this visitor.
50    */

51
52   public MethodNode methodNode;
53
54   /**
55    * Constructs a new {@link TreeCodeAdapter TreeCodeAdapter} object.
56    *
57    * @param methodNode the method node to be used to store the tree
58    * representation constructed by this code visitor.
59    */

60
61   public TreeCodeAdapter (final MethodNode methodNode) {
62     super(null);
63     this.methodNode = methodNode;
64   }
65
66   public void visitInsn (final int opcode) {
67     AbstractInsnNode n = new InsnNode(opcode);
68     methodNode.instructions.add(n);
69   }
70
71   public void visitIntInsn (final int opcode, final int operand) {
72     AbstractInsnNode n = new IntInsnNode(opcode, operand);
73     methodNode.instructions.add(n);
74   }
75
76   public void visitVarInsn (final int opcode, final int var) {
77     AbstractInsnNode n = new VarInsnNode(opcode, var);
78     methodNode.instructions.add(n);
79   }
80
81   public void visitTypeInsn (final int opcode, final String JavaDoc desc) {
82     AbstractInsnNode n = new TypeInsnNode(opcode, desc);
83     methodNode.instructions.add(n);
84   }
85
86   public void visitFieldInsn (
87     final int opcode,
88     final String JavaDoc owner,
89     final String JavaDoc name,
90     final String JavaDoc desc)
91   {
92     AbstractInsnNode n = new FieldInsnNode(opcode, owner, name, desc);
93     methodNode.instructions.add(n);
94   }
95
96   public void visitMethodInsn (
97     final int opcode,
98     final String JavaDoc owner,
99     final String JavaDoc name,
100     final String JavaDoc desc)
101   {
102     AbstractInsnNode n = new MethodInsnNode(opcode, owner, name, desc);
103     methodNode.instructions.add(n);
104   }
105
106   public void visitJumpInsn (final int opcode, final Label label) {
107     AbstractInsnNode n = new JumpInsnNode(opcode, label);
108     methodNode.instructions.add(n);
109   }
110
111   public void visitLabel (final Label label) {
112     methodNode.instructions.add(label);
113   }
114
115   public void visitLdcInsn (final Object JavaDoc cst) {
116     AbstractInsnNode n = new LdcInsnNode(cst);
117     methodNode.instructions.add(n);
118   }
119
120   public void visitIincInsn (final int var, final int increment) {
121     AbstractInsnNode n = new IincInsnNode(var, increment);
122     methodNode.instructions.add(n);
123   }
124
125   public void visitTableSwitchInsn (
126     final int min,
127     final int max,
128     final Label dflt,
129     final Label labels[])
130   {
131     AbstractInsnNode n = new TableSwitchInsnNode(min, max, dflt, labels);
132     methodNode.instructions.add(n);
133   }
134
135   public void visitLookupSwitchInsn (
136     final Label dflt,
137     final int keys[],
138     final Label labels[])
139   {
140     AbstractInsnNode n = new LookupSwitchInsnNode(dflt, keys, labels);
141     methodNode.instructions.add(n);
142   }
143
144   public void visitMultiANewArrayInsn (final String JavaDoc desc, final int dims) {
145     AbstractInsnNode n = new MultiANewArrayInsnNode(desc, dims);
146     methodNode.instructions.add(n);
147   }
148
149   public void visitTryCatchBlock (
150     final Label start,
151     final Label end,
152     final Label handler,
153     final String JavaDoc type)
154   {
155     TryCatchBlockNode n = new TryCatchBlockNode(start, end, handler, type);
156     methodNode.tryCatchBlocks.add(n);
157   }
158
159   public void visitMaxs (final int maxStack, final int maxLocals) {
160     methodNode.maxStack = maxStack;
161     methodNode.maxLocals = maxLocals;
162   }
163
164   public void visitLocalVariable (
165     final String JavaDoc name,
166     final String JavaDoc desc,
167     final Label start,
168     final Label end,
169     final int index)
170   {
171     LocalVariableNode n = new LocalVariableNode(name, desc, start, end, index);
172     methodNode.localVariables.add(n);
173   }
174
175   public void visitLineNumber (final int line, final Label start) {
176     LineNumberNode n = new LineNumberNode(line, start);
177     methodNode.lineNumbers.add(n);
178   }
179
180   public void visitAttribute (final Attribute attr) {
181     attr.next = methodNode.codeAttrs;
182     methodNode.codeAttrs = attr;
183   }
184 }
185
Popular Tags