KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > loskutov > bco > asm > CommentedASMifierClassVisitor


1 /*******************************************************************************
2  * Copyright (c) 2004 Andrei Loskutov.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the BSD License
5  * which accompanies this distribution, and is available at
6  * http://www.opensource.org/licenses/bsd-license.php
7  * Contributor: Andrei Loskutov - initial API and implementation
8  *******************************************************************************/

9 package de.loskutov.bco.asm;
10
11 import java.util.BitSet JavaDoc;
12
13 import org.objectweb.asm.Label;
14 import org.objectweb.asm.util.ASMifierClassVisitor;
15 import org.objectweb.asm.util.ASMifierMethodVisitor;
16
17 import de.loskutov.bco.preferences.BCOConstants;
18
19 /**
20  * @author Andrei
21  */

22 public class CommentedASMifierClassVisitor extends ASMifierClassVisitor {
23
24     protected BitSet JavaDoc modes;
25     protected boolean raw;
26
27     protected ASMifierMethodVisitor createASMifierMethodVisitor() {
28         return new ASMifierMethodVisitor() {
29
30             public void visitFrame(final int type, final int nLocal,
31                 final Object JavaDoc[] local, final int nStack, final Object JavaDoc[] stack) {
32                 if (showStackMap) {
33                     super.visitFrame(type, nLocal, local, nStack, stack);
34                 }
35             }
36
37             public void visitLineNumber(int line, Label start) {
38                 if (showLines) {
39                     super.visitLineNumber(line, start);
40                 }
41             }
42
43             public void visitLocalVariable(String JavaDoc name, String JavaDoc desc,
44                 String JavaDoc signature, Label start, Label end, int index) {
45                 if (showLocals) {
46                     super.visitLocalVariable(
47                         name, desc, signature, start, end, index);
48                 }
49             }
50
51             public void visitMaxs(int maxStack, int maxLocals) {
52                 if (showLocals) {
53                     super.visitMaxs(maxStack, maxLocals);
54                 }
55             }
56
57         };
58     }
59
60     protected boolean showLines;
61     protected boolean showLocals;
62     protected boolean showStackMap;
63
64     public CommentedASMifierClassVisitor(final BitSet JavaDoc modes) {
65         super(null);
66         this.modes = modes;
67         raw = !modes.get(BCOConstants.F_SHOW_RAW_BYTECODE);
68         showLines = modes.get(BCOConstants.F_SHOW_LINE_INFO);
69         showLocals = modes.get(BCOConstants.F_SHOW_VARIABLES);
70         showStackMap = modes.get(BCOConstants.F_SHOW_STACKMAP);
71     }
72
73     public void visitEnd() {
74         text.add("cw.visitEnd();\n\n");
75         text.add("return cw.toByteArray();\n");
76         text.add("}\n");
77         text.add("}\n");
78     }
79 }
Popular Tags