PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/JavaInsight/javainsight/JasminVFS.java

#
Java | 90 lines | 42 code | 21 blank | 27 comment | 2 complexity | 32dd6b90efea814fb0d6805b753bd702 MD5 | raw file
 1/*
 2 * JasminVFS.java
 3 * Copyright (c) 2001, 2002 Andre Kaplan
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public License
 7 * as published by the Free Software Foundation; either version 2
 8 * of the License, or any later version.
 9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20
21package javainsight;
22
23import java.awt.Component;
24import java.io.*;
25
26import org.apache.bcel.classfile.ClassParser;
27import org.apache.bcel.classfile.JavaClass;
28
29import org.gjt.sp.jedit.io.VFS;
30import org.gjt.sp.jedit.io.VFSManager;
31
32import org.gjt.sp.util.Log;
33
34
35public class JasminVFS extends ByteCodeVFS
36{
37    public static final String PROTOCOL = "jasmin";
38
39
40    public JasminVFS() {
41        super(PROTOCOL);
42    }
43
44
45    /**
46     * Creates an input stream. This method is called from the I/O
47     * thread.
48     * @param session the VFS session
49     * @param path The path
50     * @param ignoreErrors If true, file not found errors should be
51     * ignored
52     * @param comp The component that will parent error dialog boxes
53     */
54    @Override
55    public InputStream _createInputStream(Object session,
56        String path, boolean ignoreErrors, Component comp)
57    {
58        String clazzPath = path;
59        if (path.startsWith(PROTOCOL + ':')) {
60            clazzPath = clazzPath.substring(PROTOCOL.length() + 1);
61        }
62
63        VFS vfs = VFSManager.getVFSForPath(clazzPath);
64
65        if (clazzPath.endsWith(".marks")) {
66            return null;
67        }
68
69        try {
70            InputStream in = vfs._createInputStream(session, clazzPath, ignoreErrors, comp);
71
72            JavaClass java_class = new ClassParser(in, clazzPath).parse();
73
74            StringWriter out = new StringWriter();
75
76            new JasminVisitor(java_class, out).disassemble();
77
78            out.close();
79
80            return new BufferedInputStream(new ByteArrayInputStream(
81                out.toString().replace("\r", "").getBytes()));
82        } catch (IOException ioe) {
83            Log.log(Log.ERROR, this, ioe);
84        } catch (Exception e) {
85            Log.log(Log.ERROR, this, e);
86        }
87
88        return null;
89    }
90}