Source Code Cross Referenced for CheckPath.java in  » IDE » J » org » armedbear » j » 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 » J » org.armedbear.j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CheckPath.java
003:         *
004:         * Copyright (C) 2002 Peter Graves
005:         * $Id: CheckPath.java,v 1.1.1.1 2002/09/24 16:08:20 piso Exp $
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:
022:        package org.armedbear.j;
023:
024:        import java.io.BufferedReader;
025:        import java.io.IOException;
026:        import java.io.InputStreamReader;
027:        import java.util.HashSet;
028:        import java.util.Stack;
029:
030:        public final class CheckPath implements  Constants {
031:            private final Editor editor;
032:            private final boolean showAll;
033:            private final Buffer buffer;
034:            private FastStringBuffer sb = new FastStringBuffer(16384);
035:            private String path;
036:            private File currentDirectory;
037:            private HashSet checkedFiles = new HashSet(256);
038:            private Stack stack = new Stack();
039:            private int depthDisplayed;
040:
041:            private CheckPath(Editor editor, boolean showAll) {
042:                this .editor = editor;
043:                this .showAll = showAll;
044:                buffer = editor.getBuffer();
045:                path = buffer.getStringProperty(Property.INCLUDE_PATH);
046:                currentDirectory = editor.getCurrentDirectory();
047:            }
048:
049:            private String getOutput() {
050:                return sb.toString();
051:            }
052:
053:            private void run() {
054:                sb.append("File: ");
055:                sb.append(buffer.getFile().netPath());
056:                sb.append('\n');
057:                sb.append("Include path: ");
058:                sb.append(path);
059:                sb.append('\n');
060:                if (showAll)
061:                    sb.append("Included files:\n");
062:                else
063:                    sb.append("The following included files were not found:\n");
064:                checkBuffer(buffer, 0);
065:            }
066:
067:            private void checkBuffer(Buffer b, int depth) {
068:                for (Line line = b.getFirstLine(); line != null; line = line
069:                        .next()) {
070:                    String s = Utilities.extractInclude(line.getText());
071:                    if (s != null) {
072:                        int result = checkFile(s, depth);
073:                        if (showAll) {
074:                            if (result == NOT_FOUND)
075:                                sb.append("  NOT FOUND");
076:                            else if (result == ALREADY_LISTED)
077:                                sb.append("  (Already listed)");
078:                            if (sb.length() == 0
079:                                    || sb.charAt(sb.length() - 1) != '\n')
080:                                sb.append('\n');
081:                        } else if (result == NOT_FOUND) {
082:                            sb.append(s);
083:                            sb.append("  NOT FOUND\n");
084:                        }
085:                    }
086:                }
087:            }
088:
089:            private static final int NOT_FOUND = 0;
090:            private static final int FOUND = 1;
091:            private static final int ALREADY_LISTED = 2;
092:
093:            private int checkFile(final String s, final int depth) {
094:                if (showAll) {
095:                    sb.append(spaces(depth));
096:                    sb.append(s);
097:                } else if (depth < depthDisplayed)
098:                    depthDisplayed = depth;
099:                File file = Utilities.findInclude(s, path, currentDirectory);
100:                if (file == null)
101:                    return NOT_FOUND;
102:                if (checkedFiles.contains(file))
103:                    return ALREADY_LISTED;
104:                checkedFiles.add(file);
105:                int count = 0;
106:                try {
107:                    BufferedReader reader = new BufferedReader(
108:                            new InputStreamReader(file.getInputStream()));
109:                    String line;
110:                    while ((line = reader.readLine()) != null) {
111:                        String name = Utilities.extractInclude(line);
112:                        if (name != null) {
113:                            if (showAll && count == 0) {
114:                                sb.append('\n');
115:                                sb.append(spaces(depth));
116:                                sb.append(getDisplayName(file));
117:                                sb.append(" -->\n");
118:                            }
119:                            // Recurse!
120:                            stack.push(file);
121:                            int result = checkFile(name, depth + 1);
122:                            if (showAll) {
123:                                if (result == NOT_FOUND)
124:                                    sb.append("  NOT FOUND");
125:                                else if (result == ALREADY_LISTED)
126:                                    sb.append("  (Already listed)");
127:                                if (sb.length() == 0
128:                                        || sb.charAt(sb.length() - 1) != '\n')
129:                                    sb.append('\n');
130:                            } else if (result == NOT_FOUND) {
131:                                while (depthDisplayed < stack.size()) {
132:                                    sb.append(spaces(depthDisplayed));
133:                                    sb.append(getDisplayName((File) stack
134:                                            .get(depthDisplayed)));
135:                                    sb.append(" -->\n");
136:                                    ++depthDisplayed;
137:                                }
138:                                sb.append(spaces(depth + 1));
139:                                sb.append(name);
140:                                sb.append("  NOT FOUND\n");
141:                            }
142:                            stack.pop();
143:                            ++count;
144:                        }
145:                    }
146:                    reader.close();
147:                } catch (IOException e) {
148:                    Log.error(e);
149:                }
150:                return FOUND;
151:            }
152:
153:            private String getDisplayName(File file) {
154:                File dir = file.getParentFile();
155:                if (dir.equals(currentDirectory))
156:                    return file.getName();
157:                return file.canonicalPath();
158:            }
159:
160:            private static String spaces(int depth) {
161:                return Utilities.spaces(depth * 2);
162:            }
163:
164:            public static void checkPath() {
165:                checkPathInternal(false);
166:            }
167:
168:            public static void listIncludes() {
169:                checkPathInternal(true);
170:            }
171:
172:            private static void checkPathInternal(boolean showAll) {
173:                final Editor editor = Editor.currentEditor();
174:                final int modeId = editor.getModeId();
175:                if (modeId != C_MODE && modeId != CPP_MODE)
176:                    return;
177:                editor.setWaitCursor();
178:                CheckPath cp = new CheckPath(editor, showAll);
179:                cp.run();
180:                editor.setDefaultCursor();
181:                Buffer buf = OutputBuffer.getOutputBuffer(cp.getOutput());
182:                buf.setFormatter(new CheckPathFormatter(buf));
183:                FastStringBuffer sb = new FastStringBuffer();
184:                if (showAll)
185:                    sb.append("listIncludes ");
186:                else
187:                    sb.append("checkPath");
188:                sb.append(editor.getBuffer().getFile().getName());
189:                buf.setTitle(sb.toString());
190:                editor.makeNext(buf);
191:                editor.activateInOtherWindow(buf);
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.