Source Code Cross Referenced for PrettyPrintFile.java in  » UML » jrefactory » org » acm » seguin » pretty » 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 » UML » jrefactory » org.acm.seguin.pretty 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *Author:  Chris Seguin
003:         *
004:         *This software has been developed under the copyleft
005:         *rules of the GNU General Public License.  Please
006:         *consult the GNU General Public License for more
007:         *details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.pretty;
010:
011:        import java.io.File;
012:        import java.io.IOException;
013:        import java.io.Writer;
014:        import java.io.OutputStreamWriter;
015:        import org.acm.seguin.awt.ExceptionPrinter;
016:        import org.acm.seguin.awt.Question;
017:        import org.acm.seguin.io.InplaceOutputStream;
018:        import net.sourceforge.jrefactory.ast.SimpleNode;
019:        import net.sourceforge.jrefactory.ast.ASTCompilationUnit;
020:        import org.acm.seguin.util.FileSettings;
021:        import net.sourceforge.jrefactory.factory.FileParserFactory;
022:        import net.sourceforge.jrefactory.factory.ParserFactory;
023:
024:        import java.util.*;
025:
026:        /**
027:         *  Holds a refactoring. Default version just pretty prints the file.
028:         *
029:         * @author   Chris Seguin
030:         * @author   <a href="JRefactory@ladyshot.demon.co.uk">Mike Atkinson</a>
031:         * @created  July 1, 1999
032:         * @version  $Id: PrettyPrintFile.java,v 1.12 2003/11/18 18:46:14 mikeatkinson Exp $
033:         */
034:        public class PrettyPrintFile {
035:            private ParserFactory factory;
036:            private boolean ask;
037:
038:            /**  Refactors java code. */
039:            public PrettyPrintFile() {
040:                ask = true;
041:            }
042:
043:            /**
044:             *  Sets whether we should ask the user
045:             *
046:             * @param way  the way to set the variable
047:             */
048:            public void setAsk(boolean way) {
049:                ask = way;
050:            }
051:
052:            /**
053:             *  Set the parser factory
054:             *
055:             * @param factory  Description of Parameter
056:             */
057:            public void setParserFactory(ParserFactory factory) {
058:                this .factory = factory;
059:            }
060:
061:            /**
062:             *  Returns true if this refactoring is applicable
063:             *
064:             * @param inputFile  the input file
065:             * @return          true if this refactoring is applicable
066:             */
067:            public boolean isApplicable(File inputFile) {
068:                if (!inputFile.canWrite()) {
069:                    return false;
070:                }
071:
072:                boolean result = true;
073:
074:                if (ask) {
075:                    result = Question.isYes("Pretty Printer",
076:                            "Do you want to pretty print the file\n"
077:                                    + inputFile.getPath() + "?");
078:                }
079:
080:                //  Create a factory if necessary
081:                if (result) {
082:                    setParserFactory(new FileParserFactory(inputFile));
083:                }
084:
085:                return result;
086:            }
087:
088:            /**
089:             *  Return the factory that gets the abstract syntax trees
090:             *
091:             * @return  the parser factory
092:             */
093:            public ParserFactory getParserFactory() {
094:                return factory;
095:            }
096:
097:            /**
098:             *  Apply the refactoring
099:             *
100:             * @param inputFile  the input file
101:             */
102:            public void apply(File inputFile) {
103:                SimpleNode root = factory.getAbstractSyntaxTree(true,
104:                        ExceptionPrinter.getInstance());
105:
106:                if (root != null) {
107:                    apply(inputFile, root);
108:                    postApply(inputFile, root);
109:                }
110:            }
111:
112:            /**
113:             *  Apply the refactoring
114:             *
115:             * @param inputFile  the input file
116:             * @param root       Description of Parameter
117:             */
118:            public void apply(File inputFile, SimpleNode root) {
119:                if (root != null) {
120:                    FileSettings pretty = FileSettings
121:                            .getRefactoryPrettySettings();
122:
123:                    pretty.setReloadNow(true);
124:
125:                    //  Create the visitor
126:                    PrettyPrintVisitor printer = new PrettyPrintVisitor();
127:
128:                    //  Create the appropriate print data
129:                    PrintData data = getPrintData(inputFile);
130:
131:                    if (root instanceof  ASTCompilationUnit) {
132:                        printer.visit((ASTCompilationUnit) root, data);
133:                    } else {
134:                        printer.visit(root, data);
135:                    }
136:
137:                    data.close(); //  Flush the output stream and close it
138:                }
139:            }
140:
141:            /**
142:             *  Create the output stream
143:             *
144:             * @param file  the name of the file
145:             * @return     the output stream
146:             */
147:            protected Writer getWriter(File file) {
148:                Writer out = null;
149:
150:                try {
151:                    out = new OutputStreamWriter(new InplaceOutputStream(file));
152:                } catch (IOException ioe) {
153:                    out = new OutputStreamWriter(System.out);
154:                }
155:
156:                return out; //  Return the output stream
157:            }
158:
159:            /**
160:             *  Return the appropriate print data
161:             *
162:             * @param input  Description of Parameter
163:             * @return      the print data
164:             */
165:            protected PrintData getPrintData(File input) {
166:                JavadocTags.get().reload();
167:
168:                //  Create the new stream
169:                return new PrintData(getWriter(input));
170:            }
171:
172:            /**
173:             *  Apply the refactoring
174:             *
175:             * @param inputFile  the input file
176:             * @param root       Description of Parameter
177:             */
178:            protected void postApply(File inputFile, SimpleNode root) {
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.