Source Code Cross Referenced for SourceFileUtils.java in  » IDE » tIDE » tide » sources » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE » tIDE » tide.sources 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.sources;
002:
003:        import tide.editor.MainEditorFrame;
004:        import snow.texteditor.SimpleDocument;
005:        import java.util.*;
006:        import java.io.*;
007:        import javax.swing.tree.*;
008:
009:        public class SourceFileUtils {
010:            public SourceFileUtils() {
011:            }
012:
013:            /** All  name.class and name$*.class
014:             *  TODO: parse the source to look at private types !  " public class XXX {} private class A {} "
015:             */
016:            public static List<File> getClassFilesFor(SourceFile sf,
017:                    File classesBase) {
018:                List<File> cf = new ArrayList<File>();
019:
020:                String packagePath = getPackageName(sf).replace('.', '/');
021:                final String className = sf.javaPartName; // Hello
022:                File packageFile = new File(classesBase, packagePath);
023:
024:                if (!packageFile.exists()) {
025:                    //System.out.println("Package "+packageFile.getAbsolutePath()+" not found");
026:                    return cf;
027:                }
028:
029:                File[] cfs = packageFile.listFiles(new FilenameFilter() {
030:                    public boolean accept(File dir, String name) {
031:                        if (!name.endsWith(".class"))
032:                            return false;
033:                        if (name.startsWith(className + "."))
034:                            return true;
035:                        if (name.startsWith(className + "$"))
036:                            return true;
037:                        return false;
038:                    }
039:                });
040:
041:                for (File f : cfs) {
042:                    cf.add(f);
043:                }
044:
045:                return cf;
046:            }
047:
048:            public static String getPackageName(SourceFile sf) {
049:                if (sf.isDirectory)
050:                    return sf.getJavaName();
051:
052:                // just remove the last name
053:                String pn = sf.getJavaName();
054:                int pos = pn.lastIndexOf('.');
055:                if (pos == -1)
056:                    return ""; // base package (unnamed)
057:
058:                return pn.substring(0, pos);
059:            }
060:
061:            static FileItemNameComparator fileItemNameComparator = new FileItemNameComparator();
062:
063:            /**
064:             *  Should be called in the edt.
065:             */
066:            public static void insertSorted(final FileItem item,
067:                    final FileItem parent, final DefaultTreeModel tm) {
068:                // determine the insert position
069:                int pos = 0;
070:
071:                fl: for (pos = 0; pos < parent.getChildCount(); pos++) {
072:                    if (fileItemNameComparator.compare((FileItem) parent
073:                            .getChildAt(pos), item) > 0)
074:                        break fl;
075:                }
076:
077:                // bad if not edt call !(?)
078:                tm.insertNodeInto((DefaultMutableTreeNode) item,
079:                        (DefaultMutableTreeNode) parent, pos);
080:
081:            }
082:
083:            /*
084:             public static void main(String[] a)
085:             {
086:             System.out.println("a".compareTo("b"));
087:             }*/
088:
089:            /** Ordering according to
090:               1) directories first, alphabetically sorted
091:               2) sources files
092:               3) resource files
093:
094:               note: "a".compareTo("b") is -1
095:             */
096:            static class FileItemNameComparator implements  Comparator<FileItem> {
097:                public int compare(FileItem fi1, FileItem fi2) {
098:                    // treat the cases of different types,
099:                    if (fi1.isDirectory()) {
100:                        if (!fi2.isDirectory())
101:                            return -1;
102:                    } else {
103:                        // fi1 is a file
104:                        if (fi2.isDirectory())
105:                            return 1;
106:                    }
107:
108:                    // ok, they are of same type
109:                    return fi1.getJavaPartName().compareTo(
110:                            fi2.getJavaPartName());
111:                }
112:            }
113:
114:            /** null if not already existing.
115:             */
116:            public static SourceFile getDirectPackage(final SourceFile parent,
117:                    String name) {
118:                int pos = 0;
119:
120:                for (pos = 0; pos < parent.getChildCount(); pos++) {
121:                    SourceFile ci = parent.getChildFileAt(pos);
122:                    if (ci.isDirectory() && ci.getPackageName().equals(name)) {
123:                        return ci;
124:                    }
125:                }
126:
127:                return null;
128:            }
129:
130:            public static void writeDependencies(SourceFile src,
131:                    SimpleDocument doc) {
132:                if (src.isDirectory()) {
133:                    List<SourceFile> files = new ArrayList<SourceFile>();
134:                    MainEditorFrame.instance.sourcesTreePanel.getTreeModel()
135:                            .getAllSourceFilesRecurse(src, files, false, false);
136:                    for (SourceFile sfi : files) {
137:                        sfi.sourceFileDependencies.writeDependencies(doc);
138:                    }
139:                } else {
140:                    src.sourceFileDependencies.writeDependencies(doc);
141:                }
142:            }
143:            /*
144:             public static void writeDependenciesSrc(SourceFile src, SimpleDocument doc)
145:             {
146:             doc.append("=== Source "+src.getJavaName()+" ===\r\n");
147:             if(src.sourceFileDependencies.getClassesUsedBy_REF().isEmpty())
148:             {
149:             doc.appendLine("Uses no other classes in the project");
150:             }
151:             else
152:             {
153:             doc.appendLine("Uses "+src.sourceFileDependencies.getClassesUsedBy_REF().size()
154:             +" class"+(src.sourceFileDependencies.getClassesUsedBy_REF().size()==1?"":"es")+":");
155:             for(SourceFile sf: src.sourceFileDependencies.getClassesUsedBy_REF())
156:             {
157:             doc.appendLine("  "+sf.getJavaName()+".java:");
158:             }
159:             }
160:
161:             doc.appendLine("");
162:
163:             if(src.sourceFileDependencies.getClassesUsingThis_REF().isEmpty())
164:             {
165:             doc.appendLine("Is used by no other classes in the project");
166:             }
167:             else
168:             {
169:             doc.appendLine("Is used by "+src.sourceFileDependencies.getClassesUsingThis_REF().size()+" class"+(src.sourceFileDependencies.getClassesUsingThis_REF().size()==1?"":"es")+":");
170:             for(SourceFile sf: src.sourceFileDependencies.getClassesUsingThis_REF())
171:             {
172:             doc.appendLine("  "+sf.getJavaName()+".java:");
173:             }
174:             }
175:
176:             doc.appendLine("");
177:             }*/
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.