001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.transform.inlining;
005:
006: import com.tc.asm.AnnotationVisitor;
007: import com.tc.asm.Attribute;
008: import com.tc.asm.ClassVisitor;
009: import com.tc.asm.FieldVisitor;
010: import com.tc.asm.Label;
011: import com.tc.asm.MethodVisitor;
012:
013: /**
014: * Visitors that are not writing any bytecode and using a Null ClassVisitor / Code Visitor as a target instead.
015: *
016: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
017: */
018: public class AsmNullAdapter {
019:
020: /**
021: * A NullClassAdapter that does nothing.
022: * Can be used to speed up ASM and avoid unecessary bytecode writing thru a regular ClassWriter when this is not
023: * needed (read only purpose).
024: */
025: public static class NullClassAdapter implements ClassVisitor {
026:
027: public final static ClassVisitor NULL_CLASS_ADAPTER = new NullClassAdapter();
028:
029: public void visit(int version, int access, String name,
030: String signature, String super Name, String[] interfaces) {
031: }
032:
033: public void visitInnerClass(String name, String outerName,
034: String innerName, int access) {
035: }
036:
037: public FieldVisitor visitField(int access, String name,
038: String desc, String signature, Object value) {
039: return NullFieldAdapter.NULL_FIELD_ADAPTER;
040: }
041:
042: public MethodVisitor visitMethod(int access, String name,
043: String desc, String signature, String[] exceptions) {
044: return NullMethodAdapter.NULL_METHOD_ADAPTER;
045: }
046:
047: public void visitSource(String source, String debug) {
048: }
049:
050: public void visitOuterClass(String owner, String name,
051: String desc) {
052: }
053:
054: public AnnotationVisitor visitAnnotation(String desc,
055: boolean visible) {
056: return NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER;
057: }
058:
059: public void visitAttribute(Attribute attribute) {
060: }
061:
062: public void visitEnd() {
063: }
064: }
065:
066: /**
067: * A NullMethodAdapter that does nothing.
068: * Can be used to speed up ASM and avoid unecessary bytecode writing thru a regular CodeWriter when this is not
069: * needed (read only purpose)
070: */
071: public static class NullMethodAdapter implements MethodVisitor {
072:
073: public final static MethodVisitor NULL_METHOD_ADAPTER = new NullMethodAdapter();
074:
075: public void visitInsn(int opcode) {
076: }
077:
078: public void visitIntInsn(int opcode, int operand) {
079: }
080:
081: public void visitVarInsn(int opcode, int var) {
082: }
083:
084: public void visitTypeInsn(int opcode, String desc) {
085: }
086:
087: public void visitFieldInsn(int opcode, String owner,
088: String name, String desc) {
089: }
090:
091: public void visitMethodInsn(int opcode, String owner,
092: String name, String desc) {
093: }
094:
095: public void visitJumpInsn(int opcode, Label label) {
096: }
097:
098: public void visitLabel(Label label) {
099: }
100:
101: public void visitLdcInsn(Object cst) {
102: }
103:
104: public void visitIincInsn(int var, int increment) {
105: }
106:
107: public void visitTableSwitchInsn(int min, int max, Label dflt,
108: Label labels[]) {
109: }
110:
111: public void visitLookupSwitchInsn(Label dflt, int keys[],
112: Label labels[]) {
113: }
114:
115: public void visitMultiANewArrayInsn(String desc, int dims) {
116: }
117:
118: public void visitTryCatchBlock(Label start, Label end,
119: Label handler, String type) {
120: }
121:
122: public void visitMaxs(int maxStack, int maxLocals) {
123: }
124:
125: public void visitLocalVariable(String name, String desc,
126: String sig, Label start, Label end, int index) {
127: }
128:
129: public void visitLineNumber(int line, Label start) {
130: }
131:
132: public void visitAttribute(Attribute attr) {
133: }
134:
135: public AnnotationVisitor visitAnnotationDefault() {
136: return NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER;
137: }
138:
139: public AnnotationVisitor visitAnnotation(String desc,
140: boolean visible) {
141: return NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER;
142: }
143:
144: public AnnotationVisitor visitParameterAnnotation(
145: int parameter, String desc, boolean visible) {
146: return NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER;
147: }
148:
149: public void visitCode() {
150: }
151:
152: public void visitEnd() {
153: }
154:
155: public void visitFrame(int type, int local, Object[] local2,
156: int stack, Object[] stack2) {
157: }
158: }
159:
160: /**
161: * A NullFieldAdapter
162: */
163: public static class NullFieldAdapter implements FieldVisitor {
164:
165: public final static FieldVisitor NULL_FIELD_ADAPTER = new NullFieldAdapter();
166:
167: public AnnotationVisitor visitAnnotation(String desc,
168: boolean visible) {
169: return NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER;
170: }
171:
172: public void visitAttribute(Attribute attr) {
173: }
174:
175: public void visitEnd() {
176: }
177: }
178:
179: /**
180: * A NullAnnotationVisitor
181: */
182: public static class NullAnnotationVisitor implements
183: AnnotationVisitor {
184:
185: public final static AnnotationVisitor NULL_ANNOTATION_ADAPTER = new NullAnnotationVisitor();
186:
187: public void visit(String name, Object value) {
188: }
189:
190: public void visitEnum(String name, String desc, String value) {
191: }
192:
193: public AnnotationVisitor visitAnnotation(String name,
194: String desc) {
195: return NULL_ANNOTATION_ADAPTER;
196: }
197:
198: public AnnotationVisitor visitArray(String name) {
199: return NULL_ANNOTATION_ADAPTER;
200: }
201:
202: public void visitEnd() {
203: }
204: }
205: }
|