Source Code Cross Referenced for PrintSpecialMultiLineComment.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.util.StringTokenizer;
012:
013:        import net.sourceforge.jrefactory.ast.Node;
014:        import net.sourceforge.jrefactory.parser.JavaParserConstants;
015:        import net.sourceforge.jrefactory.parser.Token;
016:
017:        /**
018:         *  Consume a multi line comment
019:         *
020:         *@author     Chris Seguin
021:         *@created    October 14, 1999
022:         *@date       April 10, 1999
023:         */
024:        public class PrintSpecialMultiLineComment extends PrintSpecial {
025:            /**
026:             *  Determines if this print special can handle the current object
027:             *
028:             *@param  spec  Description of Parameter
029:             *@return       true if this one should process the input
030:             */
031:            public boolean isAcceptable(SpecialTokenData spec) {
032:                return (spec.getTokenType() == JavaParserConstants.MULTI_LINE_COMMENT);
033:            }
034:
035:            /**
036:             *  Processes the special token
037:             *
038:             *@param  node  the type of node this special is being processed for
039:             *@param  spec  the special token data
040:             *@return       Description of the Returned Value
041:             */
042:            public boolean process(Node node, SpecialTokenData spec) {
043:                //  Get the print data
044:                PrintData printData = spec.getPrintData();
045:                String image = spec.getTokenImage();
046:                int formatCode = printData.getCStyleFormatCode();
047:
048:                if (formatCode == PrintData.CSC_LEAVE_UNTOUCHED) {
049:                    transcribe(printData, image);
050:                } else {
051:                    cleanFormat(printData, image, formatCode, spec.isLast());
052:                }
053:
054:                //  Changed something
055:                return true;
056:            }
057:
058:            /**
059:             *  Cleanly format the code
060:             *
061:             *@param  printData   the print data
062:             *@param  image       the comment from the original file
063:             *@param  formatCode  the formatting style
064:             *@param  last        Description of Parameter
065:             */
066:            private void cleanFormat(PrintData printData, String image,
067:                    int formatCode, boolean last) {
068:                //  Make sure we are indented
069:                if ((formatCode != PrintData.CSC_MAINTAIN_STAR)
070:                        && !printData.isLineIndented()) {
071:                    printData.indent();
072:                }
073:
074:                if (formatCode == PrintData.CSC_MAINTAIN_STAR) {
075:                    if (!printData.isBufferEmpty()) {
076:                        printData.space();
077:                    } else if (!printData.isLineIndented()) {
078:                        printData.indent();
079:                    }
080:                }
081:
082:                //  Start the comment
083:                printData.appendComment("/*", PrintData.C_STYLE_COMMENT);
084:                if (formatCode == PrintData.CSC_MAINTAIN_STAR) {
085:                    //  Do nothing
086:                } else {
087:                    startNewline(printData, true, formatCode);
088:                }
089:
090:                //  Print the comment
091:                JavadocTokenizer tok = new JavadocTokenizer(image);
092:                tok.next();
093:                boolean lastWasNewline = false;
094:                boolean first = true;
095:
096:                while (tok.hasNext()) {
097:                    Token token = tok.next();
098:
099:                    if (first
100:                            && ((formatCode == PrintData.CSC_ALIGN_STAR) || (formatCode == PrintData.CSC_ALIGN_BLANK))) {
101:                        while (token.kind != JavadocTokenizer.WORD) {
102:                            if (tok.hasNext()) {
103:                                token = tok.next();
104:                            } else {
105:                                break;
106:                            }
107:                        }
108:
109:                        first = false;
110:                    }
111:
112:                    //  On a newline skip the space so that we realign things
113:                    if (lastWasNewline
114:                            && (token.kind == JavadocTokenizer.SPACE)
115:                            && (formatCode != PrintData.CSC_MAINTAIN_STAR)) {
116:                        token = tok.next();
117:                    }
118:
119:                    if (token.kind == JavadocTokenizer.NEWLINE) {
120:                        startNewline(printData, tok.hasNext(), formatCode);
121:                        lastWasNewline = true;
122:                    } else {
123:                        printData.appendComment(token.image,
124:                                PrintData.C_STYLE_COMMENT);
125:                        lastWasNewline = false;
126:                    }
127:                }
128:
129:                //  Finish the comment
130:                if (lastWasNewline) {
131:                    String rest = "/";
132:                    if (formatCode == PrintData.CSC_ALIGN_BLANK) {
133:                        rest = "*/";
134:                    }
135:                    printData.appendComment(rest, PrintData.C_STYLE_COMMENT);
136:                } else {
137:                    if ((formatCode != PrintData.CSC_MAINTAIN_STAR)
138:                            && !printData.isLineIndented()) {
139:                        printData.indent();
140:                    }
141:                    if (!printData.isStarsAlignedWithSlash())
142:                        printData.space();
143:                    printData.appendComment("*/", PrintData.C_STYLE_COMMENT);
144:                }
145:
146:                //  Newline
147:                if (((formatCode == PrintData.CSC_ALIGN_STAR) || (formatCode == PrintData.CSC_ALIGN_BLANK))
148:                        && last) {
149:                    printData.newline();
150:                    printData.surpriseIndent();
151:                }
152:            }
153:
154:            /**
155:             *  Starts a newline
156:             *
157:             *@param  printData   The print interface
158:             *@param  more        Are there more tokens
159:             *@param  formatCode  the formatting style
160:             */
161:            private void startNewline(PrintData printData, boolean more,
162:                    int formatCode) {
163:                printData.indent();
164:                if (formatCode == PrintData.CSC_ALIGN_BLANK) {
165:                    printData.appendComment("  ", PrintData.C_STYLE_COMMENT);
166:                } else {
167:                    if (!printData.isStarsAlignedWithSlash())
168:                        printData.space();
169:                    printData.appendComment("*", PrintData.C_STYLE_COMMENT);
170:                }
171:
172:                if ((formatCode == PrintData.CSC_MAINTAIN_STAR) || !more) {
173:                    //  Do nothing
174:                } else {
175:                    for (int ndx = 0; ndx < printData.getCStyleIndent(); ndx++) {
176:                        printData.appendComment(" ", PrintData.C_STYLE_COMMENT);
177:                    }
178:                }
179:            }
180:
181:            /**
182:             *  Simply copy the C style comment into the output file
183:             *
184:             *@param  printData  the print data
185:             *@param  image      the comment
186:             */
187:            private void transcribe(PrintData printData, String image) {
188:                StringTokenizer tok = new StringTokenizer(image, "\n\r");
189:                if (!printData.isBufferEmpty()) {
190:                    printData.space();
191:                } else if (!printData.isLineIndented()) {
192:                    printData.indent();
193:                }
194:
195:                while (tok.hasMoreTokens()) {
196:                    printData.appendComment(tok.nextToken(),
197:                            PrintData.C_STYLE_COMMENT);
198:                    if (tok.hasMoreTokens()) {
199:                        printData.newline();
200:                    }
201:                }
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.