~ubuntu-branches/ubuntu/trusty/cglib/trusty

« back to all changes in this revision

Viewing changes to src/test/net/sf/cglib/transform/DumpFieldsTask.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-10-08 21:23:45 UTC
  • Revision ID: james.westby@ubuntu.com-20091008212345-t2zy5hv2g8o4i40k
Tags: upstream-2.2+dfsg
ImportĀ upstreamĀ versionĀ 2.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2003 The Apache Software Foundation
 
3
 *
 
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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
 
 
19
import java.io.*;
 
20
 
 
21
import org.apache.tools.ant.BuildException;
 
22
import org.objectweb.asm.*;
 
23
import org.objectweb.asm.commons.EmptyVisitor;
 
24
 
 
25
public class DumpFieldsTask extends AbstractProcessTask {
 
26
    private File outfile;
 
27
    private PrintStream out;
 
28
 
 
29
    public void setOutputFile(File outfile) {
 
30
        this.outfile = outfile;
 
31
    }
 
32
    
 
33
    public void execute() throws BuildException {
 
34
        try {
 
35
            out = new PrintStream(new FileOutputStream(outfile));
 
36
            try{
 
37
                super.execute();
 
38
            }finally{ 
 
39
                out.close();
 
40
            }
 
41
        } catch (IOException e) {
 
42
            throw new BuildException(e);
 
43
        }
 
44
    }
 
45
 
 
46
    protected void processFile(File file) throws Exception {
 
47
        InputStream in = new BufferedInputStream(new FileInputStream(file));
 
48
        ClassReader r = new ClassReader(in);
 
49
        r.accept(new EmptyVisitor() {
 
50
            private String className;
 
51
 
 
52
            public void visit(int version,
 
53
                              int access,
 
54
                              String name,
 
55
                              String signature,
 
56
                              String superName,
 
57
                              String[] interfaces) {
 
58
                className = name.replace('/', '.');
 
59
            }
 
60
 
 
61
            public FieldVisitor visitField(int access,
 
62
                                           String name,
 
63
                                           String desc,
 
64
                                           String signature,
 
65
                                           Object value) {
 
66
                out.println("class=" + className + ", field=" + name);
 
67
                return null;
 
68
            }
 
69
        }, ClassReader.SKIP_DEBUG);
 
70
    }
 
71
}
 
72