01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package net.sf.cglib.transform;
17:
18: import java.io.*;
19:
20: import org.apache.tools.ant.BuildException;
21: import org.objectweb.asm.*;
22: import org.objectweb.asm.commons.EmptyVisitor;
23:
24: public class DumpFieldsTask extends AbstractProcessTask {
25: private File outfile;
26: private PrintStream out;
27:
28: public void setOutputFile(File outfile) {
29: this .outfile = outfile;
30: }
31:
32: public void execute() throws BuildException {
33: try {
34: out = new PrintStream(new FileOutputStream(outfile));
35: try {
36: super .execute();
37: } finally {
38: out.close();
39: }
40: } catch (IOException e) {
41: throw new BuildException(e);
42: }
43: }
44:
45: protected void processFile(File file) throws Exception {
46: InputStream in = new BufferedInputStream(new FileInputStream(
47: file));
48: ClassReader r = new ClassReader(in);
49: r.accept(new EmptyVisitor() {
50: private String className;
51:
52: public void visit(int version, int access, String name,
53: String signature, String super Name,
54: String[] interfaces) {
55: className = name.replace('/', '.');
56: }
57:
58: public FieldVisitor visitField(int access, String name,
59: String desc, String signature, Object value) {
60: out.println("class=" + className + ", field=" + name);
61: return null;
62: }
63: }, true);
64: }
65: }
|