PageRenderTime 70ms CodeModel.GetById 55ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 179 lines | 118 code | 41 blank | 20 comment | 16 complexity | ce6d5195260f0e2f2943a127e995d217 MD5 | raw file
  1/*
  2 * ByteCodeVFS.java
  3 * Copyright (c) 2001 Andre Kaplan
  4 *
  5 * jEdit settings: :tabSize=4:indentSize=4:noTabs=true:
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License
  9 * as published by the Free Software Foundation; either version 2
 10 * of the License, or any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20*/
 21
 22package javainsight;
 23
 24
 25import java.awt.Component;
 26import java.io.File;
 27import java.io.IOException;
 28import java.util.ArrayList;
 29
 30import org.gjt.sp.jedit.io.VFS;
 31import org.gjt.sp.jedit.io.VFSFile;
 32import org.gjt.sp.jedit.io.VFSManager;
 33import org.gjt.sp.util.Log;
 34
 35
 36public abstract class ByteCodeVFS extends VFS
 37{
 38    protected ByteCodeVFS(String name) {
 39        super(name, VFS.READ_CAP);
 40    }
 41
 42
 43    @Override
 44    public char getFileSeparator() {
 45        return File.separatorChar;
 46    }
 47
 48
 49    @Override
 50    public String getFileName(String path) {
 51        String protocol = this.getName();
 52
 53        if (path.startsWith(protocol + ':')) {
 54            String clazzPath = path.substring((protocol + ':').length());
 55            VFS vfs = VFSManager.getVFSForPath(clazzPath);
 56
 57            return vfs.getFileName(clazzPath);
 58        } else {
 59            VFS vfs = VFSManager.getVFSForPath(path);
 60
 61            return vfs.getFileName(path);
 62        }
 63    }
 64
 65
 66    @Override
 67    public String getParentOfPath(String path) {
 68        String protocol = this.getName();
 69
 70        if (path.startsWith(protocol + ':')) {
 71            String clazzPath = path.substring((protocol + ':').length());
 72            VFS vfs = VFSManager.getVFSForPath(clazzPath);
 73
 74            return protocol + ':' + vfs.getParentOfPath(clazzPath);
 75        } else {
 76            VFS vfs = VFSManager.getVFSForPath(path);
 77
 78            return vfs.getParentOfPath(path);
 79        }
 80    }
 81
 82
 83    @Override
 84    public String constructPath(String parent, String path) {
 85        String protocol = this.getName();
 86
 87        if (parent.startsWith(protocol + ':')) {
 88            String clazzPath = parent.substring((protocol + ':').length());
 89            VFS vfs = VFSManager.getVFSForPath(clazzPath);
 90
 91            return protocol + ':' + vfs.constructPath(clazzPath, path);
 92        } else {
 93            VFS vfs = VFSManager.getVFSForPath(parent);
 94
 95            return vfs.constructPath(parent, path);
 96        }
 97    }
 98
 99
100    @Override
101    public VFSFile[] _listFiles(Object session, String path, Component comp) {
102        String protocol = this.getName();
103
104        String clazzPath = path;
105        if (path.startsWith(protocol + ':')) {
106            clazzPath = clazzPath.substring(protocol.length() + 1);
107        }
108
109        VFS vfs = VFSManager.getVFSForPath(clazzPath);
110
111        try {
112            VFSFile[] directoryEntries =
113                vfs._listFiles(session, clazzPath, comp);
114
115            if (directoryEntries == null) {
116                return null;
117            }
118
119            ArrayList<VFSFile> result = new ArrayList<VFSFile>();
120
121            for (int i = 0; i < directoryEntries.length; i++) {
122                if (   directoryEntries[i].getPath().toLowerCase().endsWith(".class")
123                    || (directoryEntries[i].getType() == VFSFile.DIRECTORY)
124                ) {
125                    result.add(
126                        new VFSFile(
127                            directoryEntries[i].getName(),
128                            protocol + ':' + directoryEntries[i].getPath(),
129                            protocol + ':' + directoryEntries[i].getDeletePath(),
130                            directoryEntries[i].getType(),
131                            directoryEntries[i].getLength(),
132                            directoryEntries[i].isHidden()
133                        )
134                    );
135                }
136            }
137            
138            return result.toArray(new VFSFile[result.size()]);
139        } catch (IOException ioe) {
140            Log.log(Log.ERROR, this, ioe);
141        }
142
143        return null;
144    }
145
146
147    @Override
148    public VFSFile _getFile(Object session, String path, Component comp) {
149        String protocol = this.getName();
150
151        String clazzPath = path;
152        if (path.startsWith(protocol + ':')) {
153            clazzPath = clazzPath.substring(protocol.length() + 1);
154        }
155
156        VFS vfs = VFSManager.getVFSForPath(clazzPath);
157
158        try {
159            VFSFile file = vfs._getFile(session, clazzPath, comp);
160
161            if (file == null) {
162                return null;
163            }
164
165            return new VFSFile(
166                file.getName(),
167                protocol + ':' + file.getPath(),
168                protocol + ':' + file.getDeletePath(),
169                file.getType(),
170                file.getLength(),
171                file.isHidden()
172            );
173        } catch (IOException ioe) {
174            Log.log(Log.ERROR, this, ioe);
175        }
176
177        return null;
178    }
179}