PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package javainsight;
  22. import java.awt.Component;
  23. import java.io.File;
  24. import java.io.IOException;
  25. import java.util.ArrayList;
  26. import org.gjt.sp.jedit.io.VFS;
  27. import org.gjt.sp.jedit.io.VFSFile;
  28. import org.gjt.sp.jedit.io.VFSManager;
  29. import org.gjt.sp.util.Log;
  30. public abstract class ByteCodeVFS extends VFS
  31. {
  32. protected ByteCodeVFS(String name) {
  33. super(name, VFS.READ_CAP);
  34. }
  35. @Override
  36. public char getFileSeparator() {
  37. return File.separatorChar;
  38. }
  39. @Override
  40. public String getFileName(String path) {
  41. String protocol = this.getName();
  42. if (path.startsWith(protocol + ':')) {
  43. String clazzPath = path.substring((protocol + ':').length());
  44. VFS vfs = VFSManager.getVFSForPath(clazzPath);
  45. return vfs.getFileName(clazzPath);
  46. } else {
  47. VFS vfs = VFSManager.getVFSForPath(path);
  48. return vfs.getFileName(path);
  49. }
  50. }
  51. @Override
  52. public String getParentOfPath(String path) {
  53. String protocol = this.getName();
  54. if (path.startsWith(protocol + ':')) {
  55. String clazzPath = path.substring((protocol + ':').length());
  56. VFS vfs = VFSManager.getVFSForPath(clazzPath);
  57. return protocol + ':' + vfs.getParentOfPath(clazzPath);
  58. } else {
  59. VFS vfs = VFSManager.getVFSForPath(path);
  60. return vfs.getParentOfPath(path);
  61. }
  62. }
  63. @Override
  64. public String constructPath(String parent, String path) {
  65. String protocol = this.getName();
  66. if (parent.startsWith(protocol + ':')) {
  67. String clazzPath = parent.substring((protocol + ':').length());
  68. VFS vfs = VFSManager.getVFSForPath(clazzPath);
  69. return protocol + ':' + vfs.constructPath(clazzPath, path);
  70. } else {
  71. VFS vfs = VFSManager.getVFSForPath(parent);
  72. return vfs.constructPath(parent, path);
  73. }
  74. }
  75. @Override
  76. public VFSFile[] _listFiles(Object session, String path, Component comp) {
  77. String protocol = this.getName();
  78. String clazzPath = path;
  79. if (path.startsWith(protocol + ':')) {
  80. clazzPath = clazzPath.substring(protocol.length() + 1);
  81. }
  82. VFS vfs = VFSManager.getVFSForPath(clazzPath);
  83. try {
  84. VFSFile[] directoryEntries =
  85. vfs._listFiles(session, clazzPath, comp);
  86. if (directoryEntries == null) {
  87. return null;
  88. }
  89. ArrayList<VFSFile> result = new ArrayList<VFSFile>();
  90. for (int i = 0; i < directoryEntries.length; i++) {
  91. if ( directoryEntries[i].getPath().toLowerCase().endsWith(".class")
  92. || (directoryEntries[i].getType() == VFSFile.DIRECTORY)
  93. ) {
  94. result.add(
  95. new VFSFile(
  96. directoryEntries[i].getName(),
  97. protocol + ':' + directoryEntries[i].getPath(),
  98. protocol + ':' + directoryEntries[i].getDeletePath(),
  99. directoryEntries[i].getType(),
  100. directoryEntries[i].getLength(),
  101. directoryEntries[i].isHidden()
  102. )
  103. );
  104. }
  105. }
  106. return result.toArray(new VFSFile[result.size()]);
  107. } catch (IOException ioe) {
  108. Log.log(Log.ERROR, this, ioe);
  109. }
  110. return null;
  111. }
  112. @Override
  113. public VFSFile _getFile(Object session, String path, Component comp) {
  114. String protocol = this.getName();
  115. String clazzPath = path;
  116. if (path.startsWith(protocol + ':')) {
  117. clazzPath = clazzPath.substring(protocol.length() + 1);
  118. }
  119. VFS vfs = VFSManager.getVFSForPath(clazzPath);
  120. try {
  121. VFSFile file = vfs._getFile(session, clazzPath, comp);
  122. if (file == null) {
  123. return null;
  124. }
  125. return new VFSFile(
  126. file.getName(),
  127. protocol + ':' + file.getPath(),
  128. protocol + ':' + file.getDeletePath(),
  129. file.getType(),
  130. file.getLength(),
  131. file.isHidden()
  132. );
  133. } catch (IOException ioe) {
  134. Log.log(Log.ERROR, this, ioe);
  135. }
  136. return null;
  137. }
  138. }