Source Code Cross Referenced for PrettyPrintVisitor.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) 


0001:        /*
0002:         *  Author:  Chris Seguin
0003:         *
0004:         *  This software has been developed under the copyleft
0005:         *  rules of the GNU General Public License.  Please
0006:         *  consult the GNU General Public License for more
0007:         *  details about use and distribution of this software.
0008:         */
0009:        package org.acm.seguin.pretty;
0010:
0011:        import java.util.Enumeration;
0012:        import net.sourceforge.jrefactory.parser.JavaParserVisitor;
0013:        import net.sourceforge.jrefactory.parser.Token;
0014:        import net.sourceforge.jrefactory.ast.Node;
0015:        import net.sourceforge.jrefactory.ast.ASTActualTypeArgument;
0016:        import net.sourceforge.jrefactory.ast.ASTAdditiveExpression;
0017:        import net.sourceforge.jrefactory.ast.ASTAllocationExpression;
0018:        import net.sourceforge.jrefactory.ast.ASTAndExpression;
0019:        import net.sourceforge.jrefactory.ast.ASTArgumentList;
0020:        import net.sourceforge.jrefactory.ast.ASTArguments;
0021:        import net.sourceforge.jrefactory.ast.ASTArrayDimsAndInits;
0022:        import net.sourceforge.jrefactory.ast.ASTArrayInitializer;
0023:        import net.sourceforge.jrefactory.ast.ASTAssertionStatement;
0024:        import net.sourceforge.jrefactory.ast.ASTAssignmentOperator;
0025:        import net.sourceforge.jrefactory.ast.ASTAnnotationTypeDeclaration;
0026:        import net.sourceforge.jrefactory.ast.ASTAnnotationTypeMemberDeclaration;
0027:        import net.sourceforge.jrefactory.ast.ASTAnnotation;
0028:        import net.sourceforge.jrefactory.ast.ASTMemberValuePairs;
0029:        import net.sourceforge.jrefactory.ast.ASTMemberValuePair;
0030:        import net.sourceforge.jrefactory.ast.ASTMemberValue;
0031:        import net.sourceforge.jrefactory.ast.ASTMemberValueArrayInitializer;
0032:        import net.sourceforge.jrefactory.ast.ASTAnnotationMethodDeclaration;
0033:        import net.sourceforge.jrefactory.ast.ASTConstantDeclaration;
0034:
0035:        import net.sourceforge.jrefactory.ast.ASTBlock;
0036:        import net.sourceforge.jrefactory.ast.ASTBlockStatement;
0037:        import net.sourceforge.jrefactory.ast.ASTBooleanLiteral;
0038:        import net.sourceforge.jrefactory.ast.ASTBreakStatement;
0039:        import net.sourceforge.jrefactory.ast.ASTCastExpression;
0040:        import net.sourceforge.jrefactory.ast.ASTClassBody;
0041:        import net.sourceforge.jrefactory.ast.ASTClassBodyDeclaration;
0042:        import net.sourceforge.jrefactory.ast.ASTClassDeclaration;
0043:        import net.sourceforge.jrefactory.ast.ASTClassOrInterfaceType;
0044:
0045:        import net.sourceforge.jrefactory.ast.ASTClassOrInterfaceType;
0046:        import net.sourceforge.jrefactory.ast.ASTCompilationUnit;
0047:        import net.sourceforge.jrefactory.ast.ASTConditionalAndExpression;
0048:        import net.sourceforge.jrefactory.ast.ASTConditionalExpression;
0049:        import net.sourceforge.jrefactory.ast.ASTConditionalOrExpression;
0050:        import net.sourceforge.jrefactory.ast.ASTConstructorDeclaration;
0051:        import net.sourceforge.jrefactory.ast.ASTContinueStatement;
0052:        import net.sourceforge.jrefactory.ast.ASTDoStatement;
0053:        import net.sourceforge.jrefactory.ast.ASTEmptyStatement;
0054:        import net.sourceforge.jrefactory.ast.ASTEnumDeclaration;
0055:        import net.sourceforge.jrefactory.ast.ASTEnumElement;
0056:        import net.sourceforge.jrefactory.ast.ASTEqualityExpression;
0057:        import net.sourceforge.jrefactory.ast.ASTExclusiveOrExpression;
0058:        import net.sourceforge.jrefactory.ast.ASTExplicitConstructorInvocation;
0059:        import net.sourceforge.jrefactory.ast.ASTExpression;
0060:        import net.sourceforge.jrefactory.ast.ASTFieldDeclaration;
0061:        import net.sourceforge.jrefactory.ast.ASTForInit;
0062:        import net.sourceforge.jrefactory.ast.ASTForStatement;
0063:        import net.sourceforge.jrefactory.ast.ASTForUpdate;
0064:        import net.sourceforge.jrefactory.ast.ASTFormalParameter;
0065:        import net.sourceforge.jrefactory.ast.ASTFormalParameters;
0066:        import net.sourceforge.jrefactory.ast.ASTGenericNameList;
0067:        import net.sourceforge.jrefactory.ast.ASTIdentifier;
0068:        import net.sourceforge.jrefactory.ast.ASTIfStatement;
0069:        import net.sourceforge.jrefactory.ast.ASTImportDeclaration;
0070:        import net.sourceforge.jrefactory.ast.ASTInclusiveOrExpression;
0071:        import net.sourceforge.jrefactory.ast.ASTInitializer;
0072:        import net.sourceforge.jrefactory.ast.ASTInstanceOfExpression;
0073:        import net.sourceforge.jrefactory.ast.ASTInterfaceBody;
0074:        import net.sourceforge.jrefactory.ast.ASTInterfaceDeclaration;
0075:        import net.sourceforge.jrefactory.ast.ASTInterfaceMemberDeclaration;
0076:        import net.sourceforge.jrefactory.ast.ASTLabeledStatement;
0077:        import net.sourceforge.jrefactory.ast.ASTLiteral;
0078:        import net.sourceforge.jrefactory.ast.ASTLocalVariableDeclaration;
0079:        import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
0080:        import net.sourceforge.jrefactory.ast.ASTMethodDeclarator;
0081:        import net.sourceforge.jrefactory.ast.ASTMultiplicativeExpression;
0082:        import net.sourceforge.jrefactory.ast.ASTName;
0083:        import net.sourceforge.jrefactory.ast.ASTNameList;
0084:        import net.sourceforge.jrefactory.ast.ASTNestedClassDeclaration;
0085:        import net.sourceforge.jrefactory.ast.ASTNestedInterfaceDeclaration;
0086:        import net.sourceforge.jrefactory.ast.ASTNullLiteral;
0087:        import net.sourceforge.jrefactory.ast.ASTPackageDeclaration;
0088:        import net.sourceforge.jrefactory.ast.ASTPostfixExpression;
0089:        import net.sourceforge.jrefactory.ast.ASTPreDecrementExpression;
0090:        import net.sourceforge.jrefactory.ast.ASTPreIncrementExpression;
0091:        import net.sourceforge.jrefactory.ast.ASTPrimaryExpression;
0092:        import net.sourceforge.jrefactory.ast.ASTPrimaryPrefix;
0093:        import net.sourceforge.jrefactory.ast.ASTPrimarySuffix;
0094:        import net.sourceforge.jrefactory.ast.ASTPrimitiveType;
0095:        import net.sourceforge.jrefactory.ast.ASTReferenceType;
0096:        import net.sourceforge.jrefactory.ast.ASTReferenceTypeList;
0097:        import net.sourceforge.jrefactory.ast.ASTRelationalExpression;
0098:        import net.sourceforge.jrefactory.ast.ASTResultType;
0099:        import net.sourceforge.jrefactory.ast.ASTReturnStatement;
0100:        import net.sourceforge.jrefactory.ast.ASTShiftExpression;
0101:        import net.sourceforge.jrefactory.ast.ASTStatement;
0102:        import net.sourceforge.jrefactory.ast.ASTStatementExpression;
0103:        import net.sourceforge.jrefactory.ast.ASTStatementExpressionList;
0104:        import net.sourceforge.jrefactory.ast.ASTSwitchLabel;
0105:        import net.sourceforge.jrefactory.ast.ASTSwitchStatement;
0106:        import net.sourceforge.jrefactory.ast.ASTSynchronizedStatement;
0107:        import net.sourceforge.jrefactory.ast.ASTThrowStatement;
0108:        import net.sourceforge.jrefactory.ast.ASTTryStatement;
0109:        import net.sourceforge.jrefactory.ast.ASTType;
0110:        import net.sourceforge.jrefactory.ast.ASTTypeArguments;
0111:        import net.sourceforge.jrefactory.ast.ASTTypeDeclaration;
0112:        import net.sourceforge.jrefactory.ast.ASTTypeParameter;
0113:        import net.sourceforge.jrefactory.ast.ASTTypeParameterList;
0114:        import net.sourceforge.jrefactory.ast.ASTTypeParameters;
0115:        import net.sourceforge.jrefactory.ast.ASTUnaryExpression;
0116:        import net.sourceforge.jrefactory.ast.ASTUnaryExpressionNotPlusMinus;
0117:        import net.sourceforge.jrefactory.ast.ASTUnmodifiedClassDeclaration;
0118:        import net.sourceforge.jrefactory.ast.ASTUnmodifiedInterfaceDeclaration;
0119:        import net.sourceforge.jrefactory.ast.ASTVariableDeclarator;
0120:        import net.sourceforge.jrefactory.ast.ASTVariableDeclaratorId;
0121:        import net.sourceforge.jrefactory.ast.ASTVariableInitializer;
0122:        import net.sourceforge.jrefactory.ast.ASTWhileStatement;
0123:        import net.sourceforge.jrefactory.ast.ASTJSPBody;
0124:
0125:        import net.sourceforge.jrefactory.ast.SimpleNode;
0126:        import org.acm.seguin.util.FileSettings;
0127:        import org.acm.seguin.util.MissingSettingsException;
0128:
0129:        import org.acm.seguin.pretty.sort.FixupFinalStaticOrder;
0130:        import org.acm.seguin.pretty.jdi.*;
0131:
0132:        import net.sourceforge.jrefactory.parser.NamedToken;
0133:
0134:        /**
0135:         *  This object simply reflects all the processing back to the individual nodes.
0136:         *
0137:         * @author     Chris Seguin
0138:         * @author     Mike Atkinson
0139:         * @created    March 4, 1999
0140:         */
0141:        public class PrettyPrintVisitor implements  JavaParserVisitor {
0142:            //  Instance Variables
0143:            SpecialTokenVisitor specialTokenVisitor;
0144:            private boolean enclosingIfStatement = false;
0145:            private boolean withinArguments = false;
0146:            // when true we are within an IfStatement
0147:            private FieldSizeLookAhead fsla;
0148:            private LocalVariableLookAhead lvla;
0149:
0150:            private final static String[] ENUM_MODIFIERS = new String[] {
0151:                    "static", "transient", "volatile", "final", "public",
0152:                    "protected", "private" };
0153:
0154:            private final static String[] CLASS_DECLARATION_MODIFIERS = new String[] {
0155:                    "final", "public", "abstract", "strictfp" };
0156:
0157:            private final static String[] NESTED_CLASS_MODIFIERS = new String[] {
0158:                    "static", "abstract", "strictfp", "final", "public",
0159:                    "protected", "private" };
0160:
0161:            private final static String[] INTERFACE_MODIFIERS = new String[] {
0162:                    "strictfp", "abstract", "public" };
0163:
0164:            private final static String[] NESTED_INTERFACE_MODIFIERS = new String[] {
0165:                    "static", "strictfp", "abstract", "final", "public",
0166:                    "protected", "private" };
0167:
0168:            private final static String[] FIELD_MODIFIERS = new String[] {
0169:                    "static", "transient", "volatile", "final", "public",
0170:                    "protected", "private" };
0171:
0172:            private final static String[] METHOD_MODIFIERS = new String[] {
0173:                    "synchronized", "static", "native", "volatile", "final",
0174:                    "public", "protected", "private" };
0175:
0176:            private final static String[] CONSTRUCTOR_MODIFIERS = new String[] {
0177:                    "public", "protected", "private", "id" };
0178:
0179:            /**  Constructor for the PrettyPrintVisitor object */
0180:            public PrettyPrintVisitor() {
0181:                specialTokenVisitor = new SpecialTokenVisitor();
0182:
0183:                fsla = new FieldSizeLookAhead(PrintData.DFS_ALIGN_EQUALS);
0184:                lvla = new LocalVariableLookAhead();
0185:            }
0186:
0187:            /**
0188:             *  Description of the Method
0189:             *
0190:             * @param  node  Description of Parameter
0191:             * @param  data  Description of Parameter
0192:             * @return       Description of the Returned Value
0193:             * @since        JRefactory 2.7.00
0194:             */
0195:            public Object visit(SimpleNode node, Object data) {
0196:                node.childrenAccept(this , data);
0197:                return data;
0198:            }
0199:
0200:            /**
0201:             *  Description of the Method
0202:             *
0203:             * @param  node  Description of Parameter
0204:             * @param  data  Description of Parameter
0205:             * @return       Description of the Returned Value
0206:             * @since        JRefactory 2.7.00
0207:             */
0208:            public Object visit(ASTJSPBody node, Object data) {
0209:                node.childrenAccept(this , data);
0210:                return data;
0211:            }
0212:
0213:            /**
0214:             *  Description of the Method
0215:             *
0216:             * @param  node  Description of Parameter
0217:             * @param  data  Description of Parameter
0218:             * @return       Description of the Returned Value
0219:             * @since        JRefactory 2.7.00
0220:             */
0221:            public Object visit(ASTTypeParameterList node, Object data) {
0222:                PrintData printData = (PrintData) data;
0223:                //  Get the data
0224:
0225:                //  Traverse the children
0226:                int countChildren = node.jjtGetNumChildren();
0227:                for (int ndx = 0; ndx < countChildren; ndx++) {
0228:                    if (ndx > 0) {
0229:                        jjtAcceptSpecial(node, printData,
0230:                                ("comma." + (ndx - 1)));
0231:                        printData.appendText(", ");
0232:                    }
0233:                    Node child = node.jjtGetChild(ndx);
0234:                    child.jjtAccept(this , data);
0235:                }
0236:
0237:                return data;
0238:                //  Return the data
0239:            }
0240:
0241:            /**
0242:             *  Description of the Method
0243:             *
0244:             * @param  node  Description of Parameter
0245:             * @param  data  Description of Parameter
0246:             * @return       Description of the Returned Value
0247:             * @since        JRefactory 2.7.00
0248:             */
0249:            public Object visit(ASTTypeParameter node, Object data) {
0250:                PrintData printData = (PrintData) data;
0251:                //  Get the data
0252:
0253:                //  Print the name of the node
0254:                int countChildren = node.jjtGetNumChildren();
0255:                for (int ndx = 0; ndx < countChildren; ndx++) {
0256:                    if (ndx == 1) {
0257:                        jjtAcceptSpecial(node, printData, "extends.");
0258:                        printData.appendText(" extends ");
0259:                    } else if (ndx > 1) {
0260:                        jjtAcceptSpecial(node, printData, "and.");
0261:                        printData.appendText(" & ");
0262:                    }
0263:                    Node child = node.jjtGetChild(ndx);
0264:                    child.jjtAccept(this , data);
0265:                }
0266:
0267:                return data;
0268:                //  Return the data
0269:            }
0270:
0271:            /**
0272:             *  Description of the Method
0273:             *
0274:             * @param  node  Description of Parameter
0275:             * @param  data  Description of Parameter
0276:             * @return       Description of the Returned Value
0277:             * @since        JRefactory 2.7.00
0278:             */
0279:            public Object visit(ASTTypeParameters node, Object data) {
0280:                PrintData printData = (PrintData) data;
0281:                //  Get the data
0282:
0283:                jjtAcceptSpecial(node, printData, "<.");
0284:                printData.appendText("<");
0285:
0286:                node.childrenAccept(this , data);
0287:                //  Traverse the children
0288:
0289:                printData.appendText(">");
0290:                jjtAcceptSpecial(node, printData, ">.");
0291:
0292:                return data;
0293:                //  Return the data
0294:            }
0295:
0296:            /**
0297:             *  Description of the Method
0298:             *
0299:             * @param  node  Description of Parameter
0300:             * @param  data  Description of Parameter
0301:             * @return       Description of the Returned Value
0302:             * @since        JRefactory 2.7.00
0303:             */
0304:            public Object visit(ASTTypeArguments node, Object data) {
0305:                PrintData printData = (PrintData) data;
0306:                //  Get the data
0307:
0308:                //  Print the name of the node
0309:                jjtAcceptSpecial(node, printData, "<.");
0310:                printData.appendText("<");
0311:
0312:                int countChildren = node.jjtGetNumChildren();
0313:                for (int ndx = 0; ndx < countChildren; ndx++) {
0314:                    if (ndx > 0) {
0315:                        jjtAcceptSpecial(node, printData,
0316:                                ("comma." + (ndx - 1)));
0317:                        printData.appendText(", ");
0318:                    }
0319:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0320:                }
0321:
0322:                jjtAcceptSpecial(node, printData, ">.");
0323:                printData.appendText(">");
0324:
0325:                return data;
0326:                //  Return the data
0327:            }
0328:
0329:            /**
0330:             *  Description of the Method
0331:             *
0332:             * @param  node  Description of Parameter
0333:             * @param  data  Description of Parameter
0334:             * @return       Description of the Returned Value
0335:             * @since        JRefactory 2.7.00
0336:             */
0337:            public Object visit(ASTReferenceTypeList node, Object data) {
0338:                PrintData printData = (PrintData) data;
0339:                //  Get the data
0340:
0341:                int countChildren = node.jjtGetNumChildren();
0342:                if (countChildren > 0) {
0343:                    for (int ndx = 0; ndx < countChildren; ndx++) {
0344:                        if (ndx > 0) {
0345:                            jjtAcceptSpecial(node, printData,
0346:                                    ("comma." + (ndx - 1)));
0347:                            printData.appendText(", ");
0348:                        }
0349:                        node.jjtGetChild(ndx).jjtAccept(this , data);
0350:                    }
0351:                }
0352:
0353:                return data;
0354:                //  Return the data
0355:            }
0356:
0357:            /**
0358:             *  Description of the Method
0359:             *
0360:             * @param  node  Description of Parameter
0361:             * @param  data  Description of Parameter
0362:             * @return       Description of the Returned Value
0363:             * @since        JRefactory 2.7.00
0364:             */
0365:            public Object visit(ASTReferenceType node, Object data) {
0366:                PrintData printData = (PrintData) data;
0367:                //  Get the data
0368:
0369:                //  Traverse the children
0370:                int childrenCount = node.jjtGetNumChildren();
0371:                for (int ndx = 0; ndx < childrenCount; ndx++) {
0372:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0373:                }
0374:
0375:                //  Add the array
0376:                int count = node.getArrayCount();
0377:                for (int ndx = 0; ndx < count; ndx++) {
0378:                    jjtAcceptSpecial(node, printData, "[." + ndx);
0379:                    printData.appendText("[");
0380:                    jjtAcceptSpecial(node, printData, "]." + ndx);
0381:                    printData.appendText("]");
0382:                }
0383:
0384:                return data;
0385:                //  Return the data
0386:            }
0387:
0388:            /**
0389:             *  Description of the Method
0390:             *
0391:             * @param  node  Description of Parameter
0392:             * @param  data  Description of Parameter
0393:             * @return       Description of the Returned Value
0394:             * @since        JRefactory 2.7.00
0395:             */
0396:            public Object visit(ASTClassOrInterfaceType node, Object data) {
0397:                PrintData printData = (PrintData) data;
0398:                //  Get the data
0399:
0400:                //  Traverse the children
0401:                boolean first = true;
0402:                int childrenCount = node.jjtGetNumChildren();
0403:                int count = 0;
0404:                for (int ndx = 0; ndx < childrenCount; ndx++) {
0405:                    Node child = node.jjtGetChild(ndx);
0406:                    if (child instanceof  ASTIdentifier) {
0407:                        if (!first) {
0408:                            jjtAcceptSpecial(node, printData, "period." + count);
0409:                            printData.appendText(".");
0410:                            count++;
0411:                        }
0412:                        first = false;
0413:                    }
0414:                    child.jjtAccept(this , data);
0415:                }
0416:
0417:                return data;
0418:                //  Return the data
0419:            }
0420:
0421:            /**
0422:             *  Description of the Method
0423:             *
0424:             * @param  node  Description of Parameter
0425:             * @param  data  Description of Parameter
0426:             * @return       Description of the Returned Value
0427:             * @since        JRefactory 2.7.00
0428:             */
0429:            public Object visit(ASTActualTypeArgument node, Object data) {
0430:                PrintData printData = (PrintData) data;
0431:                //  Get the data
0432:
0433:                if (node.hasWildcard()) {
0434:                    jjtAcceptSpecial(node, printData, "?");
0435:                    printData.appendText("?");
0436:                }
0437:
0438:                if (node.hasExtends()) {
0439:                    jjtAcceptSpecial(node, printData, "extends");
0440:                    printData.appendText(" extends ");
0441:                }
0442:                if (node.hasSuper()) {
0443:                    jjtAcceptSpecial(node, printData, "super");
0444:                    printData.appendText(" super ");
0445:                }
0446:
0447:                //  Traverse the children
0448:                int childrenCount = node.jjtGetNumChildren();
0449:                for (int ndx = 0; ndx < childrenCount; ndx++) {
0450:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0451:                }
0452:
0453:                return data;
0454:                //  Return the data
0455:            }
0456:
0457:            /**
0458:             *  Description of the Method
0459:             *
0460:             * @param  node  Description of Parameter
0461:             * @param  data  Description of Parameter
0462:             * @return       Description of the Returned Value
0463:             * @since        JRefactory 2.7.00
0464:             */
0465:            public Object visit(ASTGenericNameList node, Object data) {
0466:                PrintData printData = (PrintData) data;
0467:                //  Get the data
0468:
0469:                //  Traverse the children
0470:                int countChildren = node.jjtGetNumChildren();
0471:                for (int ndx = 0; ndx < countChildren; ndx++) {
0472:                    Node child = node.jjtGetChild(ndx);
0473:                    if (ndx > 0 && child instanceof  ASTName) {
0474:                        // ASTClassOrInterfaceType
0475:                        jjtAcceptSpecial(node, printData,
0476:                                ("comma." + (ndx - 1)));
0477:                        printData.appendText(", ");
0478:                    }
0479:                    child.jjtAccept(this , data);
0480:                }
0481:
0482:                return data;
0483:                //  Return the data
0484:            }
0485:
0486:            /**
0487:             *  Description of the Method
0488:             *
0489:             * @param  node  Description of Parameter
0490:             * @param  data  Description of Parameter
0491:             * @return       Description of the Returned Value
0492:             * @since        JRefactory 2.7.00
0493:             */
0494:            public Object visit(ASTEnumDeclaration node, Object data) {
0495:                PrintData printData = (PrintData) data;
0496:                //  Get the data
0497:
0498:                //  Print any tokens
0499:                EnumDeclaration enumJDI = new EnumDeclaration(node);
0500:                printData.beginEnum();
0501:                //jjtAcceptSpecials(enumJDI, node, printData, ENUM_MODIFIERS);
0502:
0503:                //  Print the annotation and class special tokens
0504:                int childNo = 0;
0505:                SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
0506:                while (child instanceof  ASTAnnotation) {
0507:                    if (childNo == 0) {
0508:                        printData.indent();
0509:                        node.jjtAccept(specialTokenVisitor,
0510:                                new SpecialTokenData(enumJDI, node
0511:                                        .getSpecial("@.0"), printData));
0512:                    }
0513:                    child = (SimpleNode) node.jjtGetChild(++childNo);
0514:                }
0515:                if (childNo == 0) {
0516:                    jjtAcceptSpecials(enumJDI, node, printData,
0517:                            CLASS_DECLARATION_MODIFIERS);
0518:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
0519:                            enumJDI, child.getSpecial("enum"), printData));
0520:                }
0521:
0522:                //  Make sure that the javadoc stuff is there
0523:                if (isJavadocRequired(enumJDI, node, printData)) {
0524:                    enumJDI.finish();
0525:                    enumJDI.printJavaDocComponents(printData);
0526:                }
0527:
0528:                //  Indent and include the modifiers
0529:                childNo = 0;
0530:                child = (SimpleNode) node.jjtGetChild(childNo);
0531:                while (child instanceof  ASTAnnotation) {
0532:                    printData.indent();
0533:                    if (childNo > 0) {
0534:                        jjtAcceptSpecial(node, printData, "@." + childNo);
0535:                    }
0536:                    child.jjtAccept(this , data);
0537:                    child = (SimpleNode) node.jjtGetChild(++childNo);
0538:                }
0539:                if (childNo > 0) {
0540:                    printData.indent();
0541:                    jjtAcceptSpecials(node, printData,
0542:                            CLASS_DECLARATION_MODIFIERS);
0543:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
0544:                            enumJDI, child.getSpecial("enum"), printData));
0545:                }
0546:
0547:                // print the modifiers
0548:                printData.indent();
0549:                String modifiers = node.getModifiersString(printData
0550:                        .getModifierOrder());
0551:                printData.appendKeyword(modifiers);
0552:
0553:                printData.appendText("enum ");
0554:
0555:                // print the enum name (an Identifier).
0556:                node.jjtGetChild(childNo++).jjtAccept(this , data);
0557:
0558:                printData.appendText(" { ");
0559:
0560:                //  Traverse the children
0561:                boolean printingElements = true;
0562:                int countChildren = node.jjtGetNumChildren();
0563:                for (int ndx = childNo; ndx < countChildren; ndx++) {
0564:                    child = (SimpleNode) node.jjtGetChild(ndx);
0565:                    if (!(child instanceof  ASTEnumElement)) {
0566:                        if (printingElements) {
0567:                            jjtAcceptSpecial(node, printData, "semicolon");
0568:                            printData.appendText(";");
0569:                            printingElements = false;
0570:                            printData.incrIndent();
0571:                            printData.newline();
0572:                        }
0573:                    }
0574:                    if (ndx > 1 && printingElements) {
0575:                        jjtAcceptSpecial(node, printData,
0576:                                ("comma." + (ndx - 1)));
0577:                        printData.appendText(", ");
0578:                    }
0579:                    child.jjtAccept(this , data);
0580:                }
0581:                jjtAcceptSpecial(node, printData, "end");
0582:                if (!printingElements) {
0583:                    printData.decrIndent();
0584:                    printData.indent();
0585:                    printData.appendText("}");
0586:                } else {
0587:                    printData.appendText(" }");
0588:                }
0589:                //  Finish the entry
0590:                printData.newline();
0591:                printData.endEnum();
0592:
0593:                return data;
0594:                //  Return the data
0595:            }
0596:
0597:            /**
0598:             *  Description of the Method
0599:             *
0600:             * @param  node  Description of Parameter
0601:             * @param  data  Description of Parameter
0602:             * @return       Description of the Returned Value
0603:             * @since        JRefactory 2.7.00
0604:             */
0605:            public Object visit(ASTIdentifier node, Object data) {
0606:                PrintData printData = (PrintData) data;
0607:                //  Get the data
0608:
0609:                jjtAcceptSpecial(node, printData, "id");
0610:                printData.appendText(node.getName());
0611:
0612:                return data;
0613:                //  Return the data
0614:            }
0615:
0616:            /**
0617:             *  Description of the Method
0618:             *
0619:             * @param  node  Description of Parameter
0620:             * @param  data  Description of Parameter
0621:             * @return       Description of the Returned Value
0622:             * @since        JRefactory 2.7.00
0623:             */
0624:            public Object visit(ASTEnumElement node, Object data) {
0625:                PrintData printData = (PrintData) data; //  Get the data
0626:
0627:                printData.appendText(node.getName());
0628:                for (int ndx = 1; ndx < node.jjtGetNumChildren(); ndx++) {
0629:                    Node child = node.jjtGetChild(ndx);
0630:                    child.jjtAccept(this , data);
0631:                }
0632:
0633:                return data; //  Return the data
0634:            }
0635:
0636:            /**
0637:             *  Description of the Method
0638:             *
0639:             * @param  node  Description of Parameter
0640:             * @param  data  Description of Parameter
0641:             * @return       Description of the Returned Value
0642:             * @since        JRefactory 2.9.04
0643:             */
0644:            public Object visit(ASTAnnotationTypeDeclaration node, Object data) {
0645:                PrintData printData = (PrintData) data; //  Get the data
0646:                AnnotationTypeDeclaration typeJDI = new AnnotationTypeDeclaration(
0647:                        node);
0648:
0649:                printData.beginInterface();
0650:
0651:                int childNo = 0;
0652:                if (node.hasAnyChildren()) {
0653:                    //  Print the annotation and class special tokens
0654:                    SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
0655:                    while (child instanceof  ASTAnnotation) {
0656:                        if (childNo == 0) {
0657:                            printData.indent();
0658:                            node.jjtAccept(specialTokenVisitor,
0659:                                    new SpecialTokenData(typeJDI, node
0660:                                            .getSpecial("@.0"), printData));
0661:                        }
0662:                        child = (SimpleNode) node.jjtGetChild(++childNo);
0663:                    }
0664:                    if (childNo == 0) {
0665:                        jjtAcceptSpecials(
0666:                                typeJDI,
0667:                                node,
0668:                                printData,
0669:                                new String[] { "abstract", "public", "strictfp" });
0670:                        child.jjtAccept(specialTokenVisitor,
0671:                                new SpecialTokenData(typeJDI, child
0672:                                        .getSpecial("enum"), printData));
0673:                    }
0674:
0675:                    //  Make sure that the javadoc stuff is there
0676:                    if (isJavadocRequired(typeJDI, node, printData)) {
0677:                        typeJDI.finish(printData.getCurrentClassName());
0678:                        typeJDI.printJavaDocComponents(printData);
0679:                    }
0680:
0681:                    //  Indent and include the modifiers
0682:                    childNo = 0;
0683:                    child = (SimpleNode) node.jjtGetChild(childNo);
0684:                    while (child instanceof  ASTAnnotation) {
0685:                        printData.indent();
0686:                        if (childNo > 0) {
0687:                            jjtAcceptSpecial(node, printData, "@." + childNo);
0688:                        }
0689:                        child.jjtAccept(this , data);
0690:                        child = (SimpleNode) node.jjtGetChild(++childNo);
0691:                    }
0692:                    if (childNo > 0) {
0693:                        printData.indent();
0694:                        child.jjtAccept(specialTokenVisitor,
0695:                                new SpecialTokenData(typeJDI, child
0696:                                        .getSpecial("enum"), printData));
0697:                    }
0698:                } else {
0699:                    jjtAcceptSpecials(typeJDI, node, printData, new String[] {
0700:                            "abstract", "public", "strictfp" });
0701:                    //  Make sure that the javadoc stuff is there
0702:                    if (typeJDI.isRequired()) {
0703:                        typeJDI.finish(node.getName());
0704:                        typeJDI.printJavaDocComponents(printData);
0705:                    }
0706:                }
0707:
0708:                printData.indent();
0709:                printData.appendKeyword(node.getModifiersString(printData
0710:                        .getModifierOrder()));
0711:
0712:                // Handle return param
0713:                jjtAcceptSpecials(node, printData, new String[] { "@",
0714:                        "@interface", "id", "{" });
0715:                printData.appendText("@interface ");
0716:                printData.appendText(node.getName());
0717:                printData.classBrace();
0718:                printData.beginBlock();
0719:                for (int ndx = childNo; ndx < node.jjtGetNumChildren(); ndx++) {
0720:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0721:                }
0722:                printData.classBrace();
0723:                printData.endBlock();
0724:                jjtAcceptSpecial(node, printData, "}");
0725:                printData.newline();
0726:                printData.endInterface();
0727:                return data; //  Return the data
0728:            }
0729:
0730:            /**
0731:             *  Description of the Method
0732:             *
0733:             * @param  node  Description of Parameter
0734:             * @param  data  Description of Parameter
0735:             * @return       Description of the Returned Value
0736:             * @since        JRefactory 2.9.04
0737:             */
0738:            public Object visit(ASTAnnotationTypeMemberDeclaration node,
0739:                    Object data) {
0740:                PrintData printData = (PrintData) data; //  Get the data
0741:                for (int ndx = 0; ndx < node.jjtGetNumChildren(); ndx++) {
0742:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0743:                }
0744:                return data; //  Return the data
0745:            }
0746:
0747:            /**
0748:             *  Description of the Method
0749:             *
0750:             * @param  node  Description of Parameter
0751:             * @param  data  Description of Parameter
0752:             * @return       Description of the Returned Value
0753:             * @since        JRefactory 2.9.04
0754:             */
0755:            public Object visit(ASTAnnotationMethodDeclaration node, Object data) {
0756:                PrintData printData = (PrintData) data; //  Get the data
0757:                AnnotationMethodDeclaration methodJDI = new AnnotationMethodDeclaration(
0758:                        node);
0759:
0760:                printData.beginMethod();
0761:
0762:                //  Print the annotation method special tokens
0763:                jjtAcceptSpecials(methodJDI, node, printData, new String[] {
0764:                        "public", "abstract" });
0765:                if (isJavadocRequired(methodJDI, node, printData)) {
0766:                    methodJDI.finish(printData.getCurrentClassName());
0767:                    methodJDI.printJavaDocComponents(printData);
0768:                }
0769:                printData.indent();
0770:                printData.appendKeyword(node.getModifiersString(printData
0771:                        .getModifierOrder()));
0772:
0773:                // Handle return param
0774:                node.jjtGetChild(0).jjtAccept(this , data);
0775:                printData.space();
0776:                // Handle the method name
0777:                node.jjtGetChild(1).jjtAccept(this , data);
0778:                jjtAcceptSpecials(methodJDI, node, printData, new String[] {
0779:                        "(", ")" });
0780:                printData.appendText("()");
0781:                if (node.jjtGetNumChildren() > 2) {
0782:                    jjtAcceptSpecial(node, printData, "default");
0783:                    printData.appendText(" default ");
0784:                    node.jjtGetChild(2).jjtAccept(this , data);
0785:                }
0786:
0787:                jjtAcceptSpecial(node, printData, ";");
0788:                printData.appendText(";");
0789:                printData.endMethod();
0790:                return data; //  Return the data
0791:            }
0792:
0793:            /**
0794:             *  Description of the Method
0795:             *
0796:             * @param  node  Description of Parameter
0797:             * @param  data  Description of Parameter
0798:             * @return       Description of the Returned Value
0799:             * @since        JRefactory 2.9.04
0800:             */
0801:            public Object visit(ASTConstantDeclaration node, Object data) {
0802:                PrintData printData = (PrintData) data; //  Get the data
0803:                ConstantDeclaration constJDI = new ConstantDeclaration(node);
0804:
0805:                printData.beginField();
0806:
0807:                //  Print the annotation method special tokens
0808:                jjtAcceptSpecials(constJDI, node, printData, new String[] {
0809:                        "public", "static", "final" });
0810:                if (isJavadocRequired(constJDI, node, printData)) {
0811:                    constJDI.finish();
0812:                    constJDI.printJavaDocComponents(printData);
0813:                }
0814:                printData.indent();
0815:                printData.appendKeyword(node.getModifiersString(printData
0816:                        .getModifierOrder()));
0817:
0818:                // Handle the type
0819:                node.jjtGetChild(0).jjtAccept(this , data);
0820:                printData.space();
0821:                // Handle the method name
0822:                for (int ndx = 1; ndx < node.jjtGetNumChildren(); ndx++) {
0823:                    if (ndx > 1) {
0824:                        jjtAcceptSpecial(node, printData,
0825:                                ("comma." + (ndx - 2)));
0826:                        printData.appendText(",");
0827:                    }
0828:                    node.jjtGetChild(ndx).jjtAccept(this , data);
0829:                }
0830:
0831:                jjtAcceptSpecial(node, printData, ";");
0832:                printData.appendText(";");
0833:                printData.newline();
0834:                printData.endField();
0835:
0836:                return data; //  Return the data
0837:            }
0838:
0839:            /**
0840:             *  Description of the Method
0841:             *
0842:             * @param  node  Description of Parameter
0843:             * @param  data  Description of Parameter
0844:             * @return       Description of the Returned Value
0845:             * @since        JRefactory 2.9.04
0846:             */
0847:            public Object visit(ASTAnnotation node, Object data) {
0848:                PrintData printData = (PrintData) data; //  Get the data
0849:
0850:                if (!(node.jjtGetParent() instanceof  ASTFormalParameter || node
0851:                        .jjtGetParent() instanceof  ASTMemberValue)) {
0852:                    printData.indent();
0853:                }
0854:                printData.appendText("@");
0855:                node.jjtGetChild(0).jjtAccept(this , data);
0856:                if (!node.isMarkerAnnotation()) {
0857:                    printData.appendText("(");
0858:                    printData.incrIndent();
0859:                }
0860:                for (int ndx = 1; ndx < node.jjtGetNumChildren(); ndx++) {
0861:                    Node child = node.jjtGetChild(ndx);
0862:                    child.jjtAccept(this , data);
0863:                }
0864:                if (!node.isMarkerAnnotation()) {
0865:                    printData.decrIndent();
0866:                    printData.appendText(")");
0867:                }
0868:                printData.space();
0869:
0870:                return data; //  Return the data
0871:            }
0872:
0873:            /**
0874:             *  Description of the Method
0875:             *
0876:             * @param  node  Description of Parameter
0877:             * @param  data  Description of Parameter
0878:             * @return       Description of the Returned Value
0879:             * @since        JRefactory 2.9.04
0880:             */
0881:            public Object visit(ASTMemberValuePairs node, Object data) {
0882:                PrintData printData = (PrintData) data;
0883:                if (node.jjtGetNumChildren() > 2) {
0884:                    printData.indent();
0885:                }
0886:                for (int ndx = 0; ndx < node.jjtGetNumChildren(); ndx++) {
0887:                    Node child = node.jjtGetChild(ndx);
0888:                    if (ndx > 0) {
0889:                        jjtAcceptSpecial(node, printData,
0890:                                ("comma." + (ndx - 1)));
0891:                        printData.appendText(", ");
0892:                    }
0893:                    if (node.jjtGetNumChildren() > 2) {
0894:                        printData.indent();
0895:                    }
0896:                    child.jjtAccept(this , data);
0897:                }
0898:                return data; //  Return the data
0899:            }
0900:
0901:            /**
0902:             *  Description of the Method
0903:             *
0904:             * @param  node  Description of Parameter
0905:             * @param  data  Description of Parameter
0906:             * @return       Description of the Returned Value
0907:             * @since        JRefactory 2.9.04
0908:             */
0909:            public Object visit(ASTMemberValuePair node, Object data) {
0910:                PrintData printData = (PrintData) data;
0911:                node.jjtGetChild(0).jjtAccept(this , data);
0912:                jjtAcceptSpecial(node, printData, "=");
0913:                printData.appendText("=");
0914:                node.jjtGetChild(1).jjtAccept(this , data);
0915:                return data; //  Return the data
0916:            }
0917:
0918:            /**
0919:             *  Description of the Method
0920:             *
0921:             * @param  node  Description of Parameter
0922:             * @param  data  Description of Parameter
0923:             * @return       Description of the Returned Value
0924:             * @since        JRefactory 2.9.04
0925:             */
0926:            public Object visit(ASTMemberValue node, Object data) {
0927:                PrintData printData = (PrintData) data;
0928:                jjtAcceptSpecial(node, printData, "@");
0929:                node.jjtGetChild(0).jjtAccept(this , data);
0930:                return data; //  Return the data
0931:            }
0932:
0933:            /**
0934:             *  Description of the Method
0935:             *
0936:             * @param  node  Description of Parameter
0937:             * @param  data  Description of Parameter
0938:             * @return       Description of the Returned Value
0939:             * @since        JRefactory 2.9.04
0940:             */
0941:            public Object visit(ASTMemberValueArrayInitializer node, Object data) {
0942:                PrintData printData = (PrintData) data;
0943:                jjtAcceptSpecial(node, printData, "{");
0944:                printData.appendText("{");
0945:                for (int ndx = 0; ndx < node.jjtGetNumChildren(); ndx++) {
0946:                    Node child = node.jjtGetChild(ndx);
0947:                    if (ndx > 0) {
0948:                        jjtAcceptSpecial(node, printData,
0949:                                ("comma." + (ndx - 1)));
0950:                        printData.appendText(", ");
0951:                    }
0952:                    child.jjtAccept(this , data);
0953:                }
0954:                jjtAcceptSpecial(node, printData, "}");
0955:                printData.appendText("}");
0956:                return data; //  Return the data
0957:            }
0958:
0959:            /**
0960:             *  Description of the Method
0961:             *
0962:             * @param  node  Description of Parameter
0963:             * @param  data  Description of Parameter
0964:             * @return       Description of the Returned Value
0965:             */
0966:            public Object visit(ASTCompilationUnit node, Object data) {
0967:                PrintData printData = (PrintData) data;
0968:
0969:                // This whole section is to enable sorting of imports while keeping
0970:                // the single line comments on the same line as the import declaration
0971:                // with it, and not the subsequent AST node where the line comment is
0972:                // stored by the parser.
0973:                if (printData.isSortTop()) {
0974:                    //System.out.println("BEFORE");
0975:                    //for (int i=0; i<node.jjtGetNumChildren(); i++) {
0976:                    //   SimpleNode child = (SimpleNode)node.jjtGetChild(i);
0977:                    //   if (child instanceof ASTImportDeclaration) {
0978:                    //      ASTImportDeclaration is = (ASTImportDeclaration)child;
0979:                    //      System.out.println("is="+is.getImage());
0980:                    //      Token token = is.getSpecial("import");
0981:                    //      while (token!=null) {
0982:                    //         System.out.println("  token="+token);
0983:                    //         token = token.specialToken;
0984:                    //      }
0985:                    //   }
0986:                    //}
0987:
0988:                    //System.out.println("MUNGING");
0989:                    java.util.Map isMap = new java.util.HashMap();
0990:                    Object firstComment = new Object();
0991:                    ASTImportDeclaration previs = null;
0992:                    SimpleNode lastToReplace = null;
0993:                    NamedToken lastToReplaceNamed = null;
0994:
0995:                    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
0996:                        SimpleNode child = (SimpleNode) node.jjtGetChild(i);
0997:                        if (child instanceof  ASTImportDeclaration) {
0998:                            ASTImportDeclaration is = (ASTImportDeclaration) child;
0999:                            removeLastToken(isMap, is, previs, "import",
1000:                                    firstComment);
1001:                            previs = is;
1002:                        } else if (previs != null
1003:                                && child instanceof  ASTTypeDeclaration) {
1004:                            SimpleNode grandChild = (SimpleNode) child
1005:                                    .jjtGetChild(0);
1006:                            //System.out.println("  grandChild="+child.getImage()+", grandChild.specials="+grandChild.specials);
1007:                            if (grandChild.specials != null) {
1008:                                for (Enumeration e = grandChild.specials
1009:                                        .elements(); e.hasMoreElements();) {
1010:                                    Object obj = e.nextElement();
1011:                                    //System.out.println("obj.class = "+obj.getClass());
1012:                                    if (obj instanceof  NamedToken) {
1013:                                        NamedToken namedToken = (NamedToken) obj;
1014:                                        //System.out.println("namedToken="+namedToken.getID());
1015:                                        removeLastToken(isMap, grandChild,
1016:                                                previs, namedToken.getID(),
1017:                                                firstComment);
1018:                                        lastToReplace = grandChild;
1019:                                        lastToReplaceNamed = namedToken;
1020:                                    }
1021:                                }
1022:                            }
1023:                            previs = null;
1024:                            child.specials = null;
1025:                        }
1026:                    }
1027:                    Token firstToken = null;
1028:                    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
1029:                        SimpleNode child = (SimpleNode) node.jjtGetChild(i);
1030:                        if (child instanceof  ASTImportDeclaration) {
1031:                            firstToken = child.getSpecial("import");
1032:                            child.specials = new java.util.Vector();
1033:                            break;
1034:                        }
1035:                    }
1036:
1037:                    //System.out.println("MUNGED");
1038:                    //for (int i=0; i<node.jjtGetNumChildren(); i++) {
1039:                    //   SimpleNode child = (SimpleNode)node.jjtGetChild(i);
1040:                    //   if (child instanceof ASTImportDeclaration) {
1041:                    //      ASTImportDeclaration is = (ASTImportDeclaration)child;
1042:                    //      System.out.println("is="+is.getImage());
1043:                    //      Token token = is.getSpecial("import");
1044:                    //      while (token!=null) {
1045:                    //         System.out.println("  token="+token);
1046:                    //         token = token.specialToken;
1047:                    //      }
1048:                    //   }
1049:                    //}
1050:
1051:                    //  Sort it
1052:                    node.sort(printData.getTopOrder(node));
1053:
1054:                    //System.out.println("SORTED");
1055:                    //for (int i=0; i<node.jjtGetNumChildren(); i++) {
1056:                    //   SimpleNode child = (SimpleNode)node.jjtGetChild(i);
1057:                    //   if (child instanceof ASTImportDeclaration) {
1058:                    //      ASTImportDeclaration is = (ASTImportDeclaration)child;
1059:                    //      System.out.println("is="+is.getImage());
1060:                    //      Token token = is.getSpecial("import");
1061:                    //      while (token!=null) {
1062:                    //         System.out.println("  token="+token);
1063:                    //         token = token.specialToken;
1064:                    //      }
1065:                    //   }
1066:                    //}
1067:
1068:                    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
1069:                        SimpleNode child = (SimpleNode) node.jjtGetChild(i);
1070:                        if (child instanceof  ASTImportDeclaration) {
1071:                            Token token = child.getSpecial("import");
1072:                            while (token != null) {
1073:                                if (token.specialToken == null) {
1074:                                    token.specialToken = firstToken;
1075:                                    break;
1076:                                }
1077:                                token = token.specialToken;
1078:                            }
1079:                            break;
1080:                        }
1081:                    }
1082:
1083:                    //System.out.println("DEMUNGING");
1084:                    previs = null;
1085:                    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
1086:                        SimpleNode child = (SimpleNode) node.jjtGetChild(i);
1087:                        if (child instanceof  ASTImportDeclaration) {
1088:                            ASTImportDeclaration is = (ASTImportDeclaration) child;
1089:                            Token tok = (Token) isMap
1090:                                    .get(((previs == null) ? firstComment
1091:                                            : previs));
1092:                            if (tok != null) {
1093:                                tok.specialToken = null;
1094:                                //System.out.println("  replacing "+tok);
1095:
1096:                                Token token = is.getSpecial("import");
1097:                                if (token == null) {
1098:                                    replaceNamedToken(is, "import",
1099:                                            new NamedToken("import", tok));
1100:                                } else {
1101:                                    while (token != null) {
1102:                                        //System.out.println("  token="+token);
1103:                                        if (token.specialToken == null) {
1104:                                            token.specialToken = tok;
1105:                                            break;
1106:                                        }
1107:                                        token = token.specialToken;
1108:                                    }
1109:                                }
1110:                            }
1111:
1112:                            previs = is;
1113:                        } else if (previs != null
1114:                                && child instanceof  ASTTypeDeclaration) {
1115:                            Token tok = (Token) isMap
1116:                                    .get(((previs == null) ? firstComment
1117:                                            : previs));
1118:                            if (tok != null) {
1119:                                tok.specialToken = null;
1120:                                //System.out.println("  replacing "+tok);
1121:                                Token token = lastToReplace
1122:                                        .getSpecial(lastToReplaceNamed.getID());
1123:                                if (token == null) {
1124:                                    replaceNamedToken(lastToReplace,
1125:                                            lastToReplaceNamed.getID(),
1126:                                            new NamedToken(lastToReplaceNamed
1127:                                                    .getID(), tok));
1128:                                } else {
1129:                                    while (token != null) {
1130:                                        //System.out.println("  token="+token);
1131:                                        if (token.specialToken == null) {
1132:                                            token.specialToken = tok;
1133:                                            break;
1134:                                        }
1135:                                        token = token.specialToken;
1136:                                    }
1137:                                }
1138:                            }
1139:
1140:                            previs = null;
1141:                            lastToReplace = null;
1142:                        }
1143:                    }
1144:
1145:                    //System.out.println("AFTER");
1146:                    //for (int i=0; i<node.jjtGetNumChildren(); i++) {
1147:                    //   SimpleNode child = (SimpleNode)node.jjtGetChild(i);
1148:                    //   System.out.println("child="+child);
1149:                    //   if (child instanceof ASTImportDeclaration) {
1150:                    //      ASTImportDeclaration is = (ASTImportDeclaration)child;
1151:                    //      System.out.println("is="+is.getImage());
1152:                    //      Token token = is.getSpecial("import");
1153:                    //      while (token!=null) {
1154:                    //         System.out.println("  token="+token);
1155:                    //         token = token.specialToken;
1156:                    //      }
1157:                    //   }
1158:                    //}
1159:                    //System.out.println("COMPLETE");
1160:                }
1161:
1162:                //  Check if we have a header
1163:                loadHeader(node, printData);
1164:
1165:                //  Accept the children
1166:                node.childrenAccept(this , data);
1167:
1168:                //  Visit EOF special token
1169:                if (!loadFooter(printData)) {
1170:                    jjtAcceptSpecial(node, printData, "EOF");
1171:                }
1172:
1173:                //  Flush the buffer
1174:                printData.flush();
1175:
1176:                //  Return the data
1177:                return data;
1178:            }
1179:
1180:            /**
1181:             *  Gets the special associated with a particular key
1182:             *
1183:             * @param  key  the key
1184:             * @return      the value
1185:             */
1186:            private void replaceNamedToken(SimpleNode node, String key,
1187:                    NamedToken newToken) {
1188:                if ((node.specials == null) || (key == null)) {
1189:                    return;
1190:                }
1191:
1192:                //System.out.println("replaceNamedToken("+node+", "+key+", "+newToken+")");
1193:                int last = node.specials.size();
1194:                for (int ndx = 0; ndx < last; ndx++) {
1195:                    NamedToken named = (NamedToken) node.specials
1196:                            .elementAt(ndx);
1197:                    if (named.check(key)) {
1198:                        System.out.println("  - setting");
1199:                        node.specials.setElementAt(newToken, ndx);
1200:                    }
1201:                }
1202:
1203:                return;
1204:            }
1205:
1206:            private void removeLastToken(java.util.Map isMap, SimpleNode node,
1207:                    SimpleNode prevNode, String specialName, Object firstComment) {
1208:                Token token = node.getSpecial(specialName);
1209:                //System.out.println("  token="+token);
1210:                Token prevToken = null;
1211:                Token lastToken = null;
1212:                while (token != null) {
1213:                    prevToken = lastToken;
1214:                    lastToken = token;
1215:                    //System.out.println("  lastToken="+lastToken);
1216:                    token = token.specialToken;
1217:                }
1218:                if (lastToken.kind == net.sourceforge.jrefactory.parser.JavaParserConstants.SINGLE_LINE_COMMENT) {
1219:                    //System.out.println("removing single line comment "+lastToken);
1220:                    token = node.getSpecial(specialName);
1221:                    if (prevNode == null) {
1222:                        isMap.put(firstComment, lastToken);
1223:                    } else {
1224:                        isMap.put(prevNode, lastToken);
1225:                    }
1226:                    if (token == lastToken) {
1227:                        replaceNamedToken(node, specialName, new NamedToken(
1228:                                specialName, null));
1229:                    } else {
1230:                        prevToken.specialToken = null;
1231:                    }
1232:                }
1233:            }
1234:
1235:            /**
1236:             *  Description of the Method
1237:             *
1238:             * @param  node  Description of Parameter
1239:             * @param  data  Description of Parameter
1240:             * @return       Description of the Returned Value
1241:             */
1242:            public Object visit(ASTPackageDeclaration node, Object data) {
1243:                PrintData printData = (PrintData) data;
1244:                PackageDeclaration packageJDI = new PackageDeclaration(node);
1245:
1246:                //  Print any tokens
1247:                //jjtAcceptSpecial(node, printData, "package");
1248:                node.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1249:                        packageJDI, node.getSpecial("package"), printData));
1250:                printData.appendKeyword("package");
1251:                printData.space();
1252:
1253:                //  Traverse the children
1254:                node.childrenAccept(this , data);
1255:
1256:                //  Print any final tokens
1257:                //jjtAcceptSpecial(node, printData, "semicolon");
1258:                node.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1259:                        packageJDI, node.getSpecial("semicolon"), printData));
1260:                printData.appendText(";");
1261:
1262:                for (int ndx = 0; ndx <= printData.getLinesAfterPackage(); ndx++) {
1263:                    printData.newline();
1264:                }
1265:
1266:                return data; //  Return the data
1267:            }
1268:
1269:            /**
1270:             *  Description of the Method
1271:             *
1272:             * @param  node  Description of Parameter
1273:             * @param  data  Description of Parameter
1274:             * @return       Description of the Returned Value
1275:             */
1276:            public Object visit(ASTImportDeclaration node, Object data) {
1277:                //  Get the data
1278:                PrintData printData = (PrintData) data;
1279:
1280:                //  Print any tokens
1281:                jjtAcceptSpecial(node, printData, "import", printData
1282:                        .isMaintainNewlinesAroundImports());
1283:                printData.appendKeyword("import");
1284:
1285:                // handle static imports for JDK 1.5
1286:                if (node.isStaticImport()) {
1287:                    jjtAcceptSpecial(node, printData, "static");
1288:                    printData.appendKeyword(" static");
1289:                }
1290:
1291:                printData.space();
1292:
1293:                //  Traverse the children
1294:                node.childrenAccept(this , data);
1295:
1296:                //  Print any final tokens
1297:                if (node.isImportingPackage()) {
1298:                    jjtAcceptSpecial(node, printData, "period");
1299:                    printData.appendText(".");
1300:                    jjtAcceptSpecial(node, printData, "star");
1301:                    printData.appendText("*");
1302:                    jjtAcceptSpecial(node, printData, "semicolon");
1303:                    printData.appendText(";");
1304:                    printData.newline();
1305:                } else {
1306:                    jjtAcceptSpecial(node, printData, "semicolon");
1307:                    printData.appendText(";");
1308:                    printData.newline();
1309:                }
1310:
1311:                //  Return the data
1312:                return data;
1313:            }
1314:
1315:            /**
1316:             *  Description of the Method
1317:             *
1318:             * @param  node  Description of Parameter
1319:             * @param  data  Description of Parameter
1320:             * @return       Description of the Returned Value
1321:             */
1322:            public Object visit(ASTTypeDeclaration node, Object data) {
1323:                if (node.hasAnyChildren()) {
1324:                    node.childrenAccept(this , data);
1325:                } else {
1326:                    //  Get the data
1327:                    PrintData printData = (PrintData) data;
1328:                    jjtAcceptSpecial(node, printData, "semicolon");
1329:                    printData.appendText(";");
1330:                    printData.newline();
1331:                }
1332:                return data;
1333:            }
1334:
1335:            /**
1336:             *  Visit a class declaration
1337:             *
1338:             * @param  node  the class declaration
1339:             * @param  data  the print data
1340:             * @return       the result of visiting this node
1341:             */
1342:            public Object visit(ASTClassDeclaration node, Object data) {
1343:                //  Get the data
1344:                PrintData printData = (PrintData) data;
1345:                ClassDeclaration classJDI = new ClassDeclaration(node);
1346:
1347:                //  Add blank lines before the class
1348:                for (int ndx = 0; ndx < printData.getLinesBeforeClass(); ndx++) {
1349:                    printData.newline();
1350:                }
1351:
1352:                //  Print any tokens
1353:                //jjtAcceptSpecials(classJDI, node, printData, CLASS_DECLARATION_MODIFIERS);
1354:
1355:                //  Print the annotation and class special tokens
1356:                int childNo = 0;
1357:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
1358:                while (child instanceof  ASTAnnotation) {
1359:                    if (childNo == 0) {
1360:                        printData.indent();
1361:                        node.jjtAccept(specialTokenVisitor,
1362:                                new SpecialTokenData(classJDI, node
1363:                                        .getSpecial("@.0"), printData));
1364:                    }
1365:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1366:                }
1367:                if (childNo == 0) {
1368:                    jjtAcceptSpecials(classJDI, node, printData,
1369:                            CLASS_DECLARATION_MODIFIERS);
1370:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1371:                            classJDI, child.getSpecial("class"), printData));
1372:                }
1373:                //child = (SimpleNode)node.jjtGetChild(childNo);
1374:                //child.jjtAccept(specialTokenVisitor, new SpecialTokenData(classJDI, child.getSpecial("class"), printData));
1375:
1376:                //  Make sure that the javadoc stuff is there
1377:                if (classJDI.isRequired()) {
1378:                    classJDI.finish();
1379:                    classJDI.printJavaDocComponents(printData);
1380:                }
1381:
1382:                //  Indent and include the modifiers
1383:                childNo = 0;
1384:                child = (SimpleNode) node.jjtGetChild(childNo);
1385:                while (child instanceof  ASTAnnotation) {
1386:                    printData.indent();
1387:                    if (childNo > 0) {
1388:                        jjtAcceptSpecial(node, printData, "@." + childNo);
1389:                    }
1390:                    child.jjtAccept(this , data);
1391:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1392:                }
1393:                if (childNo > 0) {
1394:                    printData.indent();
1395:                    jjtAcceptSpecials(node, printData,
1396:                            CLASS_DECLARATION_MODIFIERS);
1397:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1398:                            classJDI, child.getSpecial("class"), printData));
1399:                }
1400:
1401:                printData.indent();
1402:                printData.appendKeyword(node.getModifiersString(printData
1403:                        .getModifierOrder()));
1404:
1405:                //  Traverse the children
1406:                for (int i = childNo; i < node.jjtGetNumChildren(); i++) {
1407:                    node.jjtGetChild(i).jjtAccept(this , data);
1408:                }
1409:
1410:                //  Return the data
1411:                return data;
1412:            }
1413:
1414:            /**
1415:             *  Description of the Method
1416:             *
1417:             * @param  node  Description of Parameter
1418:             * @param  data  Description of Parameter
1419:             * @return       Description of the Returned Value
1420:             */
1421:            public Object visit(ASTUnmodifiedClassDeclaration node, Object data) {
1422:                //  Get the data
1423:                PrintData printData = (PrintData) data;
1424:
1425:                //  Print any tokens
1426:                printData.appendKeyword("class");
1427:                printData.space();
1428:                jjtAcceptSpecial(node, printData, "id");
1429:                printData.appendText(node.getName());
1430:                printData.pushCurrentClassName(node.getName());
1431:
1432:                //  Traverse the children
1433:                int lastIndex = node.jjtGetNumChildren();
1434:                for (int ndx = 0; ndx < lastIndex; ndx++) {
1435:                    Node next = node.jjtGetChild(ndx);
1436:                    //if (next instanceof ASTTypeParameterList) {
1437:                    //    jjtAcceptSpecial(node, printData, "extends");
1438:                    //    printData.space();
1439:                    //    next.jjtAccept(this, data);
1440:                    //}
1441:                    //else
1442:                    if (next instanceof  ASTName) {
1443:                        // ASTClassOrInterfaceType
1444:                        jjtAcceptSpecial(node, printData, "extends");
1445:                        //  Add blank line before extends
1446:                        if (printData.isLineBeforeExtends()) {
1447:                            int indentation = printData.getExtendsIndentation();
1448:                            printData.incrIndent(indentation);
1449:                            printData.indent();
1450:                            printData.incrIndent(-indentation);
1451:                        } else {
1452:                            printData.space();
1453:                        }
1454:                        printData.appendKeyword("extends");
1455:                        printData.space();
1456:                        next.jjtAccept(this , data);
1457:                    } else if (next instanceof  ASTNameList) {
1458:                        jjtAcceptSpecial(node, printData, "implements");
1459:                        //  Add blank line before implements
1460:                        if (printData.isLineBeforeImplements()) {
1461:                            int indentation = printData
1462:                                    .getImplementsIndentation();
1463:                            printData.incrIndent(indentation);
1464:                            printData.indent();
1465:                            printData.incrIndent(-indentation);
1466:                        } else {
1467:                            printData.space();
1468:                        }
1469:                        printData.appendKeyword("implements");
1470:                        printData.space();
1471:                        printData.sortImplements((ASTNameList) next); //  Sort the thrown exceptions
1472:                        next.jjtAccept(this , data);
1473:                    } else {
1474:                        next.jjtAccept(this , data);
1475:                    }
1476:                }
1477:
1478:                //  Finish the class
1479:                printData.popCurrentClassName();
1480:
1481:                //  Return the data
1482:                return data;
1483:            }
1484:
1485:            /**
1486:             *  Visits a class body node
1487:             *
1488:             * @param  node  The node we are visiting
1489:             * @param  data  the print data
1490:             * @return       the print data
1491:             */
1492:            public Object visit(ASTClassBody node, Object data) {
1493:                return visit(node, data, true);
1494:            }
1495:
1496:            /**
1497:             *  Visits a class body node
1498:             *
1499:             * @param  node     The node we are visiting
1500:             * @param  data     The print data
1501:             * @param  newline  Whether there should be a new line
1502:             * @return          the print data
1503:             */
1504:            public Object visit(ASTClassBody node, Object data, boolean newline) {
1505:                //  Get the data
1506:                PrintData printData = (PrintData) data;
1507:
1508:                //  Sort it
1509:                node.sort(printData.getOrder(), new FixupFinalStaticOrder());
1510:
1511:                FieldSizeLookAhead fsla = new FieldSizeLookAhead(printData
1512:                        .getFieldSpaceCode());
1513:                FieldSize size = fsla.run(node);
1514:                size.update(printData.getDynamicFieldSpaces());
1515:                printData.pushFieldSize(size);
1516:
1517:                //  Print any tokens
1518:                printData.classBrace();
1519:                printData.beginBlock();
1520:                jjtAcceptSpecial(node, printData, "begin", false);
1521:
1522:                //  Traverse the children
1523:                node.childrenAccept(this , data);
1524:
1525:                //  Print any tokens
1526:                jjtAcceptSpecial(node, printData, "end");
1527:
1528:                printData.classBrace();
1529:                printData.endBlock(newline, true);
1530:
1531:                printData.popFieldSize();
1532:
1533:                //  Return the data
1534:                return data;
1535:            }
1536:
1537:            /**
1538:             *  Description of the Method
1539:             *
1540:             * @param  node  Description of Parameter
1541:             * @param  data  Description of Parameter
1542:             * @return       Description of the Returned Value
1543:             */
1544:            public Object visit(ASTNestedClassDeclaration node, Object data) {
1545:                //  Get the data
1546:                PrintData printData = (PrintData) data;
1547:                NestedClassDeclaration clazzJDI = new NestedClassDeclaration(
1548:                        node);
1549:
1550:                //  Print any tokens
1551:                printData.beginClass();
1552:                int childNo = 0;
1553:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
1554:                while (child instanceof  ASTAnnotation) {
1555:                    if (childNo == 0) {
1556:                        printData.indent();
1557:                        node.jjtAccept(specialTokenVisitor,
1558:                                new SpecialTokenData(clazzJDI, node
1559:                                        .getSpecial("@.0"), printData));
1560:                    }
1561:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1562:                }
1563:                if (childNo == 0) {
1564:                    jjtAcceptSpecials(clazzJDI, node, printData,
1565:                            NESTED_CLASS_MODIFIERS);
1566:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1567:                            clazzJDI, child.getSpecial("class"), printData));
1568:                }
1569:
1570:                //  Make sure the java doc is there
1571:                if (isJavadocRequired(clazzJDI, node, printData)) {
1572:                    clazzJDI.finish();
1573:                    clazzJDI.printJavaDocComponents(printData);
1574:                }
1575:
1576:                //  Indent and include the modifiers
1577:                childNo = 0;
1578:                child = (SimpleNode) node.jjtGetChild(childNo);
1579:                while (child instanceof  ASTAnnotation) {
1580:                    printData.indent();
1581:                    if (childNo > 0) {
1582:                        jjtAcceptSpecial(node, printData, "@." + childNo);
1583:                    }
1584:                    child.jjtAccept(this , data);
1585:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1586:                }
1587:                if (childNo > 0) {
1588:                    printData.indent();
1589:                    jjtAcceptSpecials(node, printData, NESTED_CLASS_MODIFIERS);
1590:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1591:                            clazzJDI, child.getSpecial("class"), printData));
1592:                }
1593:
1594:                printData.indent();
1595:                printData.appendKeyword(node.getModifiersString(printData
1596:                        .getModifierOrder()));
1597:
1598:                //  Traverse the children
1599:                for (int i = childNo; i < node.jjtGetNumChildren(); i++) {
1600:                    node.jjtGetChild(i).jjtAccept(this , data);
1601:                }
1602:                printData.endClass();
1603:
1604:                //  Return the data
1605:                return data;
1606:            }
1607:
1608:            /**
1609:             *  Description of the Method
1610:             *
1611:             * @param  node  Description of Parameter
1612:             * @param  data  Description of Parameter
1613:             * @return       Description of the Returned Value
1614:             */
1615:            public Object visit(ASTClassBodyDeclaration node, Object data) {
1616:                node.childrenAccept(this , data);
1617:                return data;
1618:            }
1619:
1620:            /**
1621:             *  Description of the Method
1622:             *
1623:             * @param  node  Description of Parameter
1624:             * @param  data  Description of Parameter
1625:             * @return       Description of the Returned Value
1626:             */
1627:            public Object visit(ASTInterfaceDeclaration node, Object data) {
1628:                //  Get the data
1629:                PrintData printData = (PrintData) data;
1630:                InterfaceDeclaration intfJDI = new InterfaceDeclaration(node);
1631:
1632:                //  Add blank lines before the interface
1633:                for (int ndx = 0; ndx < printData.getLinesBeforeClass(); ndx++) {
1634:                    printData.newline();
1635:                }
1636:
1637:                //  Print any special tokens
1638:                //jjtAcceptSpecials(intfJDI, node, printData, INTERFACE_MODIFIERS);
1639:
1640:                //  Print the annotation and interface special tokens
1641:                int childNo = 0;
1642:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
1643:                while (child instanceof  ASTAnnotation) {
1644:                    if (childNo == 0) {
1645:                        printData.indent();
1646:                        node.jjtAccept(specialTokenVisitor,
1647:                                new SpecialTokenData(intfJDI, node
1648:                                        .getSpecial("@.0"), printData));
1649:                    }
1650:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1651:                }
1652:                if (childNo == 0) {
1653:                    jjtAcceptSpecials(intfJDI, node, printData,
1654:                            INTERFACE_MODIFIERS);
1655:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1656:                            intfJDI, child.getSpecial("interface"), printData));
1657:                }
1658:
1659:                //  Include the java doc comments
1660:                if (intfJDI.isRequired()) {
1661:                    intfJDI.finish();
1662:                    intfJDI.printJavaDocComponents(printData);
1663:                }
1664:
1665:                //  Print the Annotations
1666:                childNo = 0;
1667:                child = (SimpleNode) node.jjtGetChild(childNo);
1668:                while (child instanceof  ASTAnnotation) {
1669:                    printData.indent();
1670:                    if (childNo > 0) {
1671:                        jjtAcceptSpecial(node, printData, "@." + childNo);
1672:                    }
1673:                    child.jjtAccept(this , data);
1674:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1675:                }
1676:                if (childNo > 0) {
1677:                    printData.indent();
1678:                    jjtAcceptSpecials(node, printData, INTERFACE_MODIFIERS);
1679:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1680:                            child.getSpecial("interface"), printData));
1681:                }
1682:
1683:                //  Indent and add the modifiers
1684:                printData.indent();
1685:                printData.appendKeyword(node.getModifiersString(printData
1686:                        .getModifierOrder()));
1687:
1688:                //  Traverse the non-annotation children (there is only one)
1689:                child = (SimpleNode) node.jjtGetChild(childNo);
1690:                child.jjtAccept(this , data);
1691:
1692:                //  Return the data
1693:                return data;
1694:            }
1695:
1696:            /**
1697:             *  Description of the Method
1698:             *
1699:             * @param  node  Description of Parameter
1700:             * @param  data  Description of Parameter
1701:             * @return       Description of the Returned Value
1702:             */
1703:            public Object visit(ASTNestedInterfaceDeclaration node, Object data) {
1704:                //  Get the data
1705:                PrintData printData = (PrintData) data;
1706:                NestedInterfaceDeclaration intfJDI = new NestedInterfaceDeclaration(
1707:                        node);
1708:
1709:                //  Print any tokens
1710:                printData.beginInterface();
1711:                //jjtAcceptSpecials(intfJDI, node, printData, NESTED_INTERFACE_MODIFIERS);
1712:
1713:                //  Print the annotation and interface special tokens
1714:                int childNo = 0;
1715:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
1716:                while (child instanceof  ASTAnnotation) {
1717:                    if (childNo == 0) {
1718:                        printData.indent();
1719:                        node.jjtAccept(specialTokenVisitor,
1720:                                new SpecialTokenData(intfJDI, node
1721:                                        .getSpecial("@.0"), printData));
1722:                    }
1723:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1724:                }
1725:                if (childNo == 0) {
1726:                    jjtAcceptSpecials(intfJDI, node, printData,
1727:                            NESTED_INTERFACE_MODIFIERS);
1728:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1729:                            intfJDI, child.getSpecial("interface"), printData));
1730:                }
1731:
1732:                //  Force the Javadoc to be included
1733:                if (isJavadocRequired(intfJDI, node, printData)) {
1734:                    intfJDI.finish();
1735:                    intfJDI.printJavaDocComponents(printData);
1736:                }
1737:
1738:                //  Print the Annotations
1739:                childNo = 0;
1740:                child = (SimpleNode) node.jjtGetChild(childNo);
1741:                while (child instanceof  ASTAnnotation) {
1742:                    printData.indent();
1743:                    if (childNo > 0) {
1744:                        jjtAcceptSpecial(node, printData, "@." + childNo);
1745:                    }
1746:                    child.jjtAccept(this , data);
1747:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1748:                }
1749:                if (childNo > 0) {
1750:                    printData.indent();
1751:                    jjtAcceptSpecials(node, printData,
1752:                            NESTED_INTERFACE_MODIFIERS);
1753:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1754:                            intfJDI, child.getSpecial("interface"), printData));
1755:                }
1756:
1757:                //  Indent and include the modifiers
1758:                printData.indent();
1759:                printData.appendKeyword(node.getModifiersString(printData
1760:                        .getModifierOrder()));
1761:
1762:                //  Traverse the children (except the Annotations) there is only one
1763:                child = (SimpleNode) node.jjtGetChild(childNo);
1764:                child.jjtAccept(this , data);
1765:
1766:                //  Finish this interface
1767:                printData.endInterface();
1768:
1769:                //  Return the data
1770:                return data;
1771:            }
1772:
1773:            /**
1774:             *  Description of the Method
1775:             *
1776:             * @param  node  Description of Parameter
1777:             * @param  data  Description of Parameter
1778:             * @return       Description of the Returned Value
1779:             */
1780:            public Object visit(ASTUnmodifiedInterfaceDeclaration node,
1781:                    Object data) {
1782:                //  Local Variables
1783:                boolean first = true;
1784:
1785:                //  Get the data
1786:                PrintData printData = (PrintData) data;
1787:
1788:                //  Print any tokens
1789:                printData.appendKeyword("interface");
1790:                printData.space();
1791:                jjtAcceptSpecial(node, printData, "id");
1792:                printData.appendText(node.getName());
1793:                printData.pushCurrentClassName(node.getName());
1794:
1795:                //  Traverse the children
1796:                int child = 0;
1797:                Node next = node.jjtGetChild(child++);
1798:                if (next instanceof  ASTNameList) {
1799:                    jjtAcceptSpecial(node, printData, "extends");
1800:                    //  Add blank line before extends
1801:                    if (printData.isLineBeforeExtends()) {
1802:                        int indentation = printData.getExtendsIndentation();
1803:                        printData.incrIndent(indentation);
1804:                        printData.indent();
1805:                        printData.incrIndent(-indentation);
1806:                    } else {
1807:                        printData.space();
1808:                    }
1809:                    printData.appendKeyword("extends");
1810:                    printData.space();
1811:                    printData.sortExtends((ASTNameList) next); //  Sort the thrown exceptions
1812:                    next.jjtAccept(this , data);
1813:
1814:                    //  Get the next node
1815:                    next = node.jjtGetChild(child++);
1816:                }
1817:
1818:                //  Handle the interface body
1819:                next.jjtAccept(this , data);
1820:
1821:                //  Finish
1822:                printData.popCurrentClassName();
1823:
1824:                //  Return the data
1825:                return data;
1826:            }
1827:
1828:            /**
1829:             *  Description of the Method
1830:             *
1831:             * @param  node  Description of Parameter
1832:             * @param  data  Description of Parameter
1833:             * @return       Description of the Returned Value
1834:             */
1835:            public Object visit(ASTInterfaceBody node, Object data) {
1836:                //  Get the data
1837:                PrintData printData = (PrintData) data;
1838:
1839:                FieldSizeLookAhead fsla = new FieldSizeLookAhead(printData
1840:                        .getFieldSpaceCode());
1841:                FieldSize size = fsla.run(node);
1842:                size.update(printData.getDynamicFieldSpaces());
1843:                printData.pushFieldSize(size);
1844:
1845:                //  Begin the block
1846:                printData.classBrace();
1847:                printData.beginBlock();
1848:                jjtAcceptSpecial(node, printData, "begin", false);
1849:
1850:                //  Travers the children
1851:                node.childrenAccept(this , data);
1852:
1853:                //  End the block
1854:                jjtAcceptSpecial(node, printData, "end");
1855:
1856:                printData.classBrace();
1857:                printData.endBlock();
1858:
1859:                printData.popFieldSize();
1860:
1861:                //  Return the data
1862:                return data;
1863:            }
1864:
1865:            /**
1866:             *  Description of the Method
1867:             *
1868:             * @param  node  Description of Parameter
1869:             * @param  data  Description of Parameter
1870:             * @return       Description of the Returned Value
1871:             */
1872:            public Object visit(ASTInterfaceMemberDeclaration node, Object data) {
1873:                node.childrenAccept(this , data);
1874:                return data;
1875:            }
1876:
1877:            /**
1878:             *  Description of the Method
1879:             *
1880:             * @param  node  Description of Parameter
1881:             * @param  data  Description of Parameter
1882:             * @return       Description of the Returned Value
1883:             */
1884:            public Object visit(ASTFieldDeclaration node, Object data) {
1885:                //  Get the data
1886:                PrintData printData = (PrintData) data;
1887:                FieldDeclaration fieldJDI = new FieldDeclaration(node);
1888:
1889:                //  Print any special tokens
1890:                printData.beginField();
1891:                //jjtAcceptSpecials(fieldJDI, node, printData, FIELD_MODIFIERS);
1892:
1893:                //  Print the annotation and field special tokens
1894:                int childNo = 0;
1895:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
1896:                while (child instanceof  ASTAnnotation) {
1897:                    if (childNo == 0) {
1898:                        printData.indent();
1899:                        node.jjtAccept(specialTokenVisitor,
1900:                                new SpecialTokenData(fieldJDI, node
1901:                                        .getSpecial("@.0"), printData));
1902:                    }
1903:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1904:                }
1905:                if (childNo == 0) {
1906:                    jjtAcceptSpecials(fieldJDI, node, printData,
1907:                            FIELD_MODIFIERS);
1908:                    ASTType type = (ASTType) child;
1909:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1910:                            fieldJDI, getInitialToken(type), printData));
1911:                }
1912:
1913:                // Include the JavaDoc comments
1914:                if (isJavadocRequired(fieldJDI, node, printData)) {
1915:                    fieldJDI.finish();
1916:                    fieldJDI.printJavaDocComponents(printData);
1917:                }
1918:
1919:                //  Print the Annotations
1920:                childNo = 0;
1921:                child = (SimpleNode) node.jjtGetChild(childNo);
1922:                while (child instanceof  ASTAnnotation) {
1923:                    printData.indent();
1924:                    if (childNo > 0) {
1925:                        jjtAcceptSpecial(node, printData, "@." + childNo);
1926:                    }
1927:                    child.jjtAccept(this , data);
1928:                    child = (SimpleNode) node.jjtGetChild(++childNo);
1929:                }
1930:                if (childNo > 0) {
1931:                    printData.indent();
1932:                    jjtAcceptSpecials(node, printData, FIELD_MODIFIERS);
1933:                    ASTType type = (ASTType) child;
1934:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
1935:                            fieldJDI, getInitialToken(type), printData));
1936:                }
1937:
1938:                //  Indent and include the modifiers
1939:                printData.indent();
1940:                String modifiers = node.getModifiersString(printData
1941:                        .getModifierOrder());
1942:                printData.appendKeyword(modifiers);
1943:                if (printData
1944:                        .isDynamicFieldSpacing(fieldJDI.isJavadocPrinted())) {
1945:                    FieldSize size = printData.topFieldSize();
1946:                    int maxModifier = size.getModifierLength();
1947:                    for (int ndx = modifiers.length(); ndx < maxModifier; ndx++) {
1948:                        printData.space();
1949:                    }
1950:                }
1951:
1952:                //  Handle the first two/three children (which are required)
1953:                Node next = node.jjtGetChild(childNo);
1954:                next.jjtAccept(this , data);
1955:                if (printData
1956:                        .isDynamicFieldSpacing(fieldJDI.isJavadocPrinted())) {
1957:                    int current = fsla.computeTypeLength(node);
1958:
1959:                    FieldSize size = printData.topFieldSize();
1960:                    int maxType = size.getTypeLength();
1961:                    for (int ndx = current; ndx < maxType; ndx++) {
1962:                        printData.space();
1963:                    }
1964:                }
1965:
1966:                if (printData.getFieldSpaceCode() == PrintData.DFS_ALIGN_EQUALS) {
1967:                    printData.setTempEqualsLength(fsla
1968:                            .computeEqualsLength(node));
1969:                }
1970:
1971:                standardFieldIndent(printData);
1972:                next = node.jjtGetChild(childNo + 1);
1973:                printData.setStoreJavadocPrinted(fieldJDI.isJavadocPrinted());
1974:                next.jjtAccept(this , data);
1975:                printData.setStoreJavadocPrinted(false);
1976:
1977:                //  Traverse the rest of the children
1978:                int lastIndex = node.jjtGetNumChildren();
1979:                for (int ndx = childNo + 2; ndx < lastIndex; ndx++) {
1980:                    jjtAcceptSpecial(node, printData, "comma."
1981:                            + (ndx - (childNo + 2)));
1982:                    printData.appendText(", ");
1983:                    next = node.jjtGetChild(ndx);
1984:                    next.jjtAccept(this , data);
1985:                }
1986:
1987:                //  Finish the entry
1988:                jjtAcceptSpecial(node, printData, "semicolon");
1989:                printData.appendText(";");
1990:                printData.newline();
1991:                printData.endField();
1992:
1993:                //  Return the data
1994:                return data;
1995:            }
1996:
1997:            /**
1998:             *  Description of the Method
1999:             *
2000:             * @param  node  Description of Parameter
2001:             * @param  data  Description of Parameter
2002:             * @return       Description of the Returned Value
2003:             */
2004:            public Object visit(ASTVariableDeclarator node, Object data) {
2005:                //  Get the data
2006:                PrintData printData = (PrintData) data;
2007:
2008:                //  Handle the first child (which is required)
2009:                Node next = node.jjtGetFirstChild();
2010:                next.jjtAccept(this , data);
2011:
2012:                if ((printData.isDynamicFieldSpacing(printData
2013:                        .isStoreJavadocPrinted()))
2014:                        && (node.jjtGetNumChildren() > 1)) {
2015:                    int current = ((ASTVariableDeclaratorId) next).getName()
2016:                            .length();
2017:                    current += ((ASTVariableDeclaratorId) next).getArrayCount() * 2;
2018:
2019:                    FieldSize size = printData.topFieldSize();
2020:                    int maxName = size.getNameLength();
2021:                    for (int ndx = current; ndx < maxName; ndx++) {
2022:                        printData.space();
2023:                    }
2024:                }
2025:                if ((printData.getFieldSpaceCode() == PrintData.DFS_ALIGN_EQUALS)
2026:                        && (node.jjtGetNumChildren() > 1)
2027:                        && !printData.getSkipNameSpacing()) {
2028:                    int current = printData.getTempEqualsLength();
2029:
2030:                    FieldSize size = printData.topFieldSize();
2031:                    int maxName = size.getEqualsLength();
2032:                    for (int ndx = current; ndx < maxName; ndx++) {
2033:                        printData.space();
2034:                    }
2035:                }
2036:                printData.setStoreJavadocPrinted(false);
2037:
2038:                //  Traverse the rest of the children
2039:                if (node.jjtGetNumChildren() > 1) {
2040:                    jjtAcceptSpecial(node, printData, "equals");
2041:                    if (printData.isSpaceAroundOperators()) {
2042:                        printData.space();
2043:                    }
2044:                    printData.appendText("=");
2045:                    if (printData.isSpaceAroundOperators()) {
2046:                        printData.space();
2047:                    }
2048:                    next = node.jjtGetChild(1);
2049:                    next.jjtAccept(this , data);
2050:                }
2051:
2052:                //  Return the data
2053:                return data;
2054:            }
2055:
2056:            /**
2057:             *  Description of the Method
2058:             *
2059:             * @param  node  Description of Parameter
2060:             * @param  data  Description of Parameter
2061:             * @return       Description of the Returned Value
2062:             */
2063:            public Object visit(ASTVariableDeclaratorId node, Object data) {
2064:                //  Get the data
2065:                PrintData printData = (PrintData) data;
2066:
2067:                //  Handle the first child (which is required)
2068:                jjtAcceptSpecial(node, printData, "id");
2069:                printData.appendText(node.getName());
2070:                int last = node.getArrayCount();
2071:                for (int ndx = 0; ndx < last; ndx++) {
2072:                    jjtAcceptSpecial(node, printData, "[." + ndx);
2073:                    printData.appendText("[");
2074:                    jjtAcceptSpecial(node, printData, "]." + ndx);
2075:                    printData.appendText("]");
2076:                }
2077:
2078:                //  Return the data
2079:                return data;
2080:            }
2081:
2082:            /**
2083:             *  Description of the Method
2084:             *
2085:             * @param  node  Description of Parameter
2086:             * @param  data  Description of Parameter
2087:             * @return       Description of the Returned Value
2088:             */
2089:            public Object visit(ASTVariableInitializer node, Object data) {
2090:                node.childrenAccept(this , data);
2091:                return data;
2092:            }
2093:
2094:            /**
2095:             *  Description of the Method
2096:             *
2097:             * @param  node  Description of Parameter
2098:             * @param  data  Description of Parameter
2099:             * @return       Description of the Returned Value
2100:             */
2101:            public Object visit(ASTArrayInitializer node, Object data) {
2102:                //  Get the data
2103:                PrintData printData = (PrintData) data;
2104:
2105:                int incrBy = 3;
2106:                //  Handle the first child (which is required)
2107:                if (!printData.isArrayInitializerIndented()) {
2108:                    incrBy = (printData.getIndent() <= 1) ? 1 : 0;
2109:                    if (incrBy == 1) {
2110:                        printData.decrIndent();
2111:                    } else if (printData.getSurpriseReturn() == PrintData.SINGLE_INDENT) {
2112:                        printData.decrIndent();
2113:                    } else if (printData.getSurpriseReturn() == PrintData.DOUBLE_INDENT) {
2114:                        printData.decrIndent();
2115:                        printData.decrIndent();
2116:                    } else if (printData.getSurpriseReturn() == printData.PARAM_INDENT) {
2117:                        printData.decrIndent();
2118:                    }
2119:                }
2120:                jjtAcceptSpecial(node, printData, "begin");
2121:                printData.appendText("{");
2122:                if (printData.isIndentInInitailzer()) {
2123:                    printData.incrIndent();
2124:                }
2125:
2126:                int last = node.jjtGetNumChildren();
2127:                for (int ndx = 0; ndx < last; ndx++) {
2128:                    if (ndx > 0) {
2129:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
2130:                        printData.appendText(", ");
2131:                    }
2132:                    Node child = node.jjtGetChild(ndx);
2133:                    child.jjtAccept(this , data);
2134:                }
2135:                if (node.isFinalComma()) {
2136:                    jjtAcceptSpecial(node, printData, "comma." + (last - 1));
2137:                    printData.appendText(",");
2138:                }
2139:
2140:                if (printData.isIndentInInitailzer()) {
2141:                    printData.decrIndent();
2142:                }
2143:
2144:                jjtAcceptSpecial(node, printData, "end");
2145:                printData.appendText("}");
2146:                if (!printData.isArrayInitializerIndented()) {
2147:                    if (incrBy == 1) {
2148:                        printData.incrIndent();
2149:                    } else if (printData.getSurpriseReturn() == PrintData.SINGLE_INDENT) {
2150:                        printData.incrIndent();
2151:                    } else if (printData.getSurpriseReturn() == PrintData.DOUBLE_INDENT) {
2152:                        printData.incrIndent();
2153:                        printData.incrIndent();
2154:                    } else if (printData.getSurpriseReturn() == printData.PARAM_INDENT) {
2155:                        printData.incrIndent();
2156:                    }
2157:                }
2158:
2159:                //  Return the data
2160:                return data;
2161:            }
2162:
2163:            /**
2164:             *  Pretty prints the method declaration
2165:             *
2166:             * @param  node  the node in the parse tree
2167:             * @param  data  the print data
2168:             * @return       the print data
2169:             */
2170:            public Object visit(ASTMethodDeclaration node, Object data) {
2171:                PrintData printData = (PrintData) data;
2172:                MethodDeclaration methodJDI = new MethodDeclaration(node);
2173:
2174:                //  Print any tokens
2175:                printData.beginMethod();
2176:
2177:                //  Print the annotation and method special tokens
2178:                int childNo = 0;
2179:                SimpleNode child = (SimpleNode) node.jjtGetChild(childNo);
2180:                while (child instanceof  ASTAnnotation) {
2181:                    if (childNo == 0) {
2182:                        printData.indent();
2183:                        node.jjtAccept(specialTokenVisitor,
2184:                                new SpecialTokenData(methodJDI, node
2185:                                        .getSpecial("@.0"), printData));
2186:                    }
2187:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2188:                }
2189:                if (childNo == 0) {
2190:                    jjtAcceptSpecials(methodJDI, node, printData,
2191:                            METHOD_MODIFIERS);
2192:                    child.jjtAccept(specialTokenVisitor,
2193:                            new SpecialTokenData(methodJDI, child
2194:                                    .getSpecial("interface"), printData));
2195:                }
2196:                if (child instanceof  ASTTypeParameters) {
2197:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2198:                }
2199:                node.jjtAccept(specialTokenVisitor, new SpecialTokenData(
2200:                        methodJDI, getInitialToken((ASTResultType) child),
2201:                        printData));
2202:
2203:                //  Include the java doc comments
2204:                if (isJavadocRequired(methodJDI, node, printData)) {
2205:                    try {
2206:                        methodJDI.finish(printData.getCurrentClassName());
2207:                    } catch (Exception e) {
2208:                        methodJDI.finish("<none>");
2209:                    }
2210:                    methodJDI.printJavaDocComponents(printData);
2211:                }
2212:
2213:                //  Print the Annotations
2214:                childNo = 0;
2215:                child = (SimpleNode) node.jjtGetChild(childNo);
2216:                while (child instanceof  ASTAnnotation) {
2217:                    printData.indent();
2218:                    if (childNo > 0) {
2219:                        jjtAcceptSpecial(node, printData, "@." + childNo);
2220:                    }
2221:                    child.jjtAccept(this , data);
2222:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2223:                }
2224:                if (childNo > 0) {
2225:                    printData.indent();
2226:                    jjtAcceptSpecials(node, printData, METHOD_MODIFIERS);
2227:                    child.jjtAccept(specialTokenVisitor, new SpecialTokenData(
2228:                            child.getSpecial("class"), printData));
2229:                }
2230:
2231:                //  Indent and add the modifiers
2232:                printData.indent();
2233:                printData.appendKeyword(node.getModifiersString(printData
2234:                        .getModifierOrder()));
2235:
2236:                //  Handle the TypeParameter declaration (if present)
2237:                while (child instanceof  ASTTypeParameters) {
2238:                    child.jjtAccept(this , data);
2239:                    printData.space();
2240:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2241:                }
2242:
2243:                // Handle return param
2244:                child.jjtAccept(this , data);
2245:                printData.space();
2246:                // Handle the method name
2247:                child = (SimpleNode) node.jjtGetChild(++childNo);
2248:                child.jjtAccept(this , data);
2249:
2250:                //  Traverse the rest of the children
2251:                int lastIndex = node.jjtGetNumChildren();
2252:                boolean foundBlock = false;
2253:                for (int ndx = childNo + 1; ndx < lastIndex; ndx++) {
2254:                    Node next = node.jjtGetChild(ndx);
2255:                    if (next instanceof  ASTNameList) {
2256:                        jjtAcceptSpecial(node, printData, "throws");
2257:                        printData.space();
2258:                        if (printData.isThrowsOnNewline()) {
2259:                            printData.incrIndent();
2260:                            printData.indent();
2261:                            printData.decrIndent();
2262:                        }
2263:                        printData.appendKeyword("throws");
2264:                        printData.space();
2265:                        printData.sortThrows((ASTNameList) next); //  Sort the thrown exceptions
2266:                        next.jjtAccept(this , data);
2267:                    } else if (next instanceof  ASTBlock) {
2268:                        foundBlock = true;
2269:                        if ((next.jjtGetNumChildren() == 0)
2270:                                && printData.isEmptyBlockOnSingleLine()
2271:                                && !isCommentsPresent((ASTBlock) next)) {
2272:                            printData.appendText(" { }");
2273:                            printData.newline();
2274:                        } else {
2275:                            printData.methodBrace();
2276:                            next.jjtAccept(this , data);
2277:                        }
2278:                    }
2279:                }
2280:
2281:                //  Finish if it is abstract
2282:                if (!foundBlock) {
2283:                    jjtAcceptSpecial(node, printData, "semicolon");
2284:                    printData.appendText(";");
2285:                    printData.newline();
2286:                }
2287:
2288:                //  Note the end of the method
2289:                printData.endMethod();
2290:
2291:                return data;
2292:                //  Return the data
2293:            }
2294:
2295:            /**
2296:             *  Description of the Method
2297:             *
2298:             * @param  node  Description of Parameter
2299:             * @param  data  Description of Parameter
2300:             * @return       Description of the Returned Value
2301:             */
2302:            public Object visit(ASTMethodDeclarator node, Object data) {
2303:                //  Get the data
2304:                PrintData printData = (PrintData) data;
2305:
2306:                //  Handle the first child (which is required)
2307:                jjtAcceptSpecial(node, printData, "id");
2308:                printData.appendText(node.getName());
2309:                node.childrenAccept(this , data);
2310:
2311:                //  Add the array
2312:                int count = node.getArrayCount();
2313:                for (int ndx = 0; ndx < count; ndx++) {
2314:                    jjtAcceptSpecial(node, printData, "[." + ndx);
2315:                    printData.appendText("[");
2316:                    jjtAcceptSpecial(node, printData, "]." + ndx);
2317:                    printData.appendText("]");
2318:                }
2319:
2320:                //  Return the data
2321:                return data;
2322:            }
2323:
2324:            /**
2325:             *  Description of the Method
2326:             *
2327:             * @param  node  Description of Parameter
2328:             * @param  data  Description of Parameter
2329:             * @return       Description of the Returned Value
2330:             */
2331:            public Object visit(ASTFormalParameters node, Object data) {
2332:                PrintData printData = (PrintData) data;
2333:                //  Get the data
2334:
2335:                //  Print any tokens
2336:                jjtAcceptSpecial(node, printData, "begin");
2337:                if (printData.isSpaceAfterMethod() && node.hasAnyChildren()) {
2338:                    printData.space();
2339:                }
2340:                printData.beginExpression(node.hasAnyChildren());
2341:                printData.enterMethodDecl();
2342:                printData.setParamIndent();
2343:
2344:                //  Traverse the children
2345:                Node next;
2346:                int lastIndex = node.jjtGetNumChildren();
2347:                for (int ndx = 0; ndx < lastIndex; ndx++) {
2348:                    if (ndx > 0) {
2349:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
2350:                        printData.appendText(", ");
2351:                    }
2352:                    next = node.jjtGetChild(ndx);
2353:                    next.jjtAccept(this , data);
2354:                }
2355:
2356:                //  Finish it
2357:                jjtAcceptSpecial(node, printData, "end");
2358:                printData.endExpression(node.hasAnyChildren());
2359:
2360:                printData.exitMethodDecl();
2361:
2362:                return data;
2363:                //  Return the data
2364:            }
2365:
2366:            /**
2367:             *  Description of the Method
2368:             *
2369:             * @param  node  Description of Parameter
2370:             * @param  data  Description of Parameter
2371:             * @return       Description of the Returned Value
2372:             */
2373:            public Object visit(ASTFormalParameter node, Object data) {
2374:                PrintData printData = (PrintData) data;
2375:                //  Get the data
2376:
2377:                //  Print the annotation and method special tokens
2378:                int childNo = 0;
2379:                SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
2380:                while (child instanceof  ASTAnnotation) {
2381:                    jjtAcceptSpecial(node, printData, "@." + childNo);
2382:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2383:                }
2384:                //  Print any tokens
2385:                if (node.isUsingFinal()) {
2386:                    jjtAcceptSpecial(node, printData, "final");
2387:                    printData.appendKeyword("final");
2388:                    printData.space();
2389:                }
2390:
2391:                printData.setParamIndent();
2392:
2393:                //  Traverse the children
2394:                childNo = 0;
2395:                child = (SimpleNode) node.jjtGetChild(childNo);
2396:                while (child instanceof  ASTAnnotation) {
2397:                    child.jjtAccept(this , data);
2398:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2399:                }
2400:                child.jjtAccept(this , data);
2401:                printData.space();
2402:                child = (SimpleNode) node.jjtGetChild(++childNo);
2403:                child.jjtAccept(this , data);
2404:
2405:                return data;
2406:                //  Return the data
2407:            }
2408:
2409:            /**
2410:             *  Description of the Method
2411:             *
2412:             * @param  node  Description of Parameter
2413:             * @param  data  Description of Parameter
2414:             * @return       Description of the Returned Value
2415:             */
2416:            public Object visit(ASTConstructorDeclaration node, Object data) {
2417:                PrintData printData = (PrintData) data;
2418:                ConstructorDeclaration constructorJDI = new ConstructorDeclaration(
2419:                        node);
2420:
2421:                printData.beginMethod();
2422:
2423:                //  Print the annotation and method special tokens
2424:                int childNo = 0;
2425:                SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
2426:                while (child instanceof  ASTAnnotation) {
2427:                    jjtAcceptSpecial(node, printData, "@." + childNo);
2428:                    child = (SimpleNode) node.jjtGetChild(++childNo);
2429:                }
2430:                jjtAcceptSpecials(constructorJDI, node, printData,
2431:                        CONSTRUCTOR_MODIFIERS);
2432:
2433:                if (constructorJDI.isRequired()) {
2434:                    constructorJDI.finish();
2435:                    constructorJDI.printJavaDocComponents(printData);
2436:                }
2437:
2438:                printData.indent();
2439:                printData.appendKeyword(node.getModifiersString(printData
2440:                        .getModifierOrder()));
2441:                for (int i = 0; i < childNo; i++) {
2442:                    Node next = node.jjtGetChild(i);
2443:                    next.jjtAccept(this , data);
2444:                }
2445:
2446:                printData.appendText(node.getName());
2447:
2448:                //  Handle the return type (which is required)
2449:                Node next = node.jjtGetChild(childNo);
2450:                next.jjtAccept(this , data);
2451:
2452:                //  Get the last index
2453:                int lastIndex = node.jjtGetNumChildren();
2454:                childNo++;
2455:
2456:                //  Handle the name list if it is present
2457:                if (childNo < lastIndex) {
2458:                    next = node.jjtGetChild(childNo);
2459:                    if (next instanceof  ASTNameList) {
2460:                        jjtAcceptSpecial(node, printData, "throws");
2461:                        printData.space();
2462:                        if (printData.isThrowsOnNewline()) {
2463:                            printData.incrIndent();
2464:                            printData.indent();
2465:                            printData.decrIndent();
2466:                        }
2467:                        printData.appendKeyword("throws");
2468:                        printData.space();
2469:                        printData.sortThrows((ASTNameList) next); //  Sort the thrown exceptions
2470:                        next.jjtAccept(this , data);
2471:                        childNo++;
2472:                    }
2473:                }
2474:
2475:                //  Print the starting block
2476:                if ((lastIndex == childNo)
2477:                        && printData.isEmptyBlockOnSingleLine()) {
2478:                    printData.appendText(" { }");
2479:                    printData.newline();
2480:                } else {
2481:                    LocalVariableLookAhead lvla = new LocalVariableLookAhead();
2482:                    FieldSize size = lvla.run(node);
2483:                    size.update(printData.getDynamicFieldSpaces());
2484:                    printData.pushFieldSize(size);
2485:
2486:                    printData.methodBrace();
2487:                    printData.beginBlock();
2488:                    jjtAcceptSpecial(node, printData, "begin", false);
2489:
2490:                    if (printData.isLineBeforeMultistatementMethodBody()
2491:                            && (lastIndex - childNo > 1)
2492:                            && (printData.getMethodBlockStyle() == PrintData.BLOCK_STYLE_C)) {
2493:                        printData.newline();
2494:                    }
2495:
2496:                    //  Traverse the rest of the children
2497:                    boolean foundBlock = false;
2498:                    for (int ndx = childNo; ndx < lastIndex; ndx++) {
2499:                        next = node.jjtGetChild(ndx);
2500:                        next.jjtAccept(this , data);
2501:                    }
2502:
2503:                    //  Print the end block
2504:                    jjtAcceptSpecial(node, printData, "end");
2505:
2506:                    printData.methodBrace();
2507:                    printData.endBlock();
2508:                }
2509:                printData.endMethod();
2510:
2511:                return data; //  Return the data
2512:            }
2513:
2514:            /**
2515:             *  Description of the Method
2516:             *
2517:             * @param  node  Description of Parameter
2518:             * @param  data  Description of Parameter
2519:             * @return       Description of the Returned Value
2520:             */
2521:            public Object visit(ASTExplicitConstructorInvocation node,
2522:                    Object data) {
2523:                PrintData printData = (PrintData) data; //  Get the data
2524:
2525:                //  Print the name of the node
2526:                int startWith = 0;
2527:                printData.indent();
2528:                if (node.jjtGetFirstChild() instanceof  ASTPrimaryExpression) {
2529:                    node.jjtGetFirstChild().jjtAccept(this , data);
2530:                    startWith++;
2531:                    jjtAcceptSpecial(node, printData, ".");
2532:                    printData.appendText(".");
2533:                }
2534:                if (node.jjtGetChild(startWith) instanceof  ASTIdentifier) {
2535:                    node.jjtGetChild(startWith).jjtAccept(this , data);
2536:                    startWith++;
2537:                    jjtAcceptSpecial(node, printData, ".2");
2538:                    printData.appendText(".");
2539:                }
2540:                jjtAcceptSpecial(node, printData, "explicit");
2541:                printData.appendText(node.getName());
2542:
2543:                //  Traverse the children
2544:                int last = node.jjtGetNumChildren();
2545:                for (int ndx = startWith; ndx < last; ndx++) {
2546:                    node.jjtGetChild(ndx).jjtAccept(this , data);
2547:                }
2548:
2549:                //  End of the line
2550:                printData.appendText(";");
2551:                jjtAcceptSpecial(node, printData, "semicolon");
2552:                printData.newline();
2553:
2554:                return data; //  Return the data
2555:            }
2556:
2557:            /**
2558:             *  Formats the initializer
2559:             *
2560:             * @param  node  The initializer node
2561:             * @param  data  The print data
2562:             * @return       Nothing interesting
2563:             */
2564:            public Object visit(ASTInitializer node, Object data) {
2565:                //  Get the data
2566:                PrintData printData = (PrintData) data;
2567:
2568:                //  Print the name of the node
2569:                printData.indent();
2570:                if (node.isUsingStatic()) {
2571:                    jjtAcceptSpecial(node, printData, "static");
2572:                    printData.appendKeyword("static");
2573:                }
2574:
2575:                //  Traverse the children
2576:                ASTBlock block = (ASTBlock) node.jjtGetFirstChild();
2577:                blockProcess(block, printData, true, node.isUsingStatic());
2578:
2579:                //  Return the data
2580:                return data;
2581:            }
2582:
2583:            /**
2584:             *  Description of the Method
2585:             *
2586:             * @param  node  Description of Parameter
2587:             * @param  data  Description of Parameter
2588:             * @return       Description of the Returned Value
2589:             */
2590:            public Object visit(ASTType node, Object data) {
2591:                //  Get the data
2592:                PrintData printData = (PrintData) data;
2593:
2594:                //  Traverse the children
2595:                node.childrenAccept(this , data);
2596:                //if (node.jjtGetFirstChild() != null) {
2597:                //    node.jjtGetFirstChild().jjtAccept(this, data);
2598:                //}
2599:
2600:                //  Return the data
2601:                return data;
2602:            }
2603:
2604:            /**
2605:             *  Description of the Method
2606:             *
2607:             * @param  node  Description of Parameter
2608:             * @param  data  Description of Parameter
2609:             * @return       Description of the Returned Value
2610:             */
2611:            public Object visit(ASTPrimitiveType node, Object data) {
2612:                //  Get the data
2613:                PrintData printData = (PrintData) data;
2614:
2615:                //  Print the name of the node
2616:                jjtAcceptSpecial(node, printData, "primitive");
2617:                printData.appendKeyword(node.getName());
2618:
2619:                //  Return the data
2620:                return data;
2621:            }
2622:
2623:            /**
2624:             *  Description of the Method
2625:             *
2626:             * @param  node  Description of Parameter
2627:             * @param  data  Description of Parameter
2628:             * @return       Description of the Returned Value
2629:             */
2630:            public Object visit(ASTResultType node, Object data) {
2631:                //  Get the data
2632:                PrintData printData = (PrintData) data;
2633:
2634:                //  Traverse the children
2635:                if (node.hasAnyChildren()) {
2636:                    node.childrenAccept(this , data);
2637:                } else {
2638:                    jjtAcceptSpecial(node, printData, "primitive");
2639:                    printData.appendKeyword("void");
2640:                }
2641:
2642:                //  Return the data
2643:                return data;
2644:            }
2645:
2646:            /**
2647:             *  Description of the Method
2648:             *
2649:             * @param  node  Description of Parameter
2650:             * @param  data  Description of Parameter
2651:             * @return       Description of the Returned Value
2652:             */
2653:            public Object visit(ASTName node, Object data) {
2654:                //  Get the data
2655:                PrintData printData = (PrintData) data;
2656:
2657:                //  Print the name of the node
2658:                int size = node.getNameSize();
2659:                for (int ndx = 0; ndx < size; ndx++) {
2660:                    jjtAcceptSpecial(node, printData, "id" + ndx);
2661:                    jjtAcceptSpecial(node, printData, "period" + ndx);
2662:                }
2663:                printData.appendText(node.getName());
2664:
2665:                //  Return the data
2666:                return data;
2667:            }
2668:
2669:            /**
2670:             *  Description of the Method
2671:             *
2672:             * @param  node  Description of Parameter
2673:             * @param  data  Description of Parameter
2674:             * @return       Description of the Returned Value
2675:             */
2676:            public Object visit(ASTNameList node, Object data) {
2677:                //  Get the data
2678:                PrintData printData = (PrintData) data;
2679:
2680:                //  Traverse the children
2681:                int countChildren = node.jjtGetNumChildren();
2682:                for (int ndx = 0; ndx < countChildren; ndx++) {
2683:                    if (ndx > 0) {
2684:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
2685:                        printData.appendText(", ");
2686:                    }
2687:                    Node child = node.jjtGetChild(ndx);
2688:                    child.jjtAccept(this , data);
2689:                }
2690:
2691:                //  Return the data
2692:                return data;
2693:            }
2694:
2695:            /**
2696:             *  Description of the Method
2697:             *
2698:             * @param  node  Description of Parameter
2699:             * @param  data  Description of Parameter
2700:             * @return       Description of the Returned Value
2701:             */
2702:            public Object visit(ASTExpression node, Object data) {
2703:                node.childrenAccept(this , data);
2704:                return data;
2705:            }
2706:
2707:            /**
2708:             *  Description of the Method
2709:             *
2710:             * @param  node  Description of Parameter
2711:             * @param  data  Description of Parameter
2712:             * @return       Description of the Returned Value
2713:             */
2714:            public Object visit(ASTAssignmentOperator node, Object data) {
2715:                //  Get the data
2716:                PrintData printData = (PrintData) data;
2717:
2718:                //  Print the name of the node
2719:                if (printData.isSpaceAroundOperators()) {
2720:                    printData.space();
2721:                }
2722:                jjtAcceptSpecial(node, printData, "operator");
2723:                printData.appendText(node.getName());
2724:                if (printData.isSpaceAroundOperators()) {
2725:                    printData.space();
2726:                }
2727:
2728:                //  Return the data
2729:                return data;
2730:            }
2731:
2732:            /**
2733:             *  Description of the Method
2734:             *
2735:             * @param  node  Description of Parameter
2736:             * @param  data  Description of Parameter
2737:             * @return       Description of the Returned Value
2738:             */
2739:            public Object visit(ASTConditionalExpression node, Object data) {
2740:                //  Get the data
2741:                PrintData printData = (PrintData) data;
2742:
2743:                //  Traverse the children
2744:                int childCount = node.jjtGetNumChildren();
2745:                if (childCount == 1) {
2746:                    node.jjtGetFirstChild().jjtAccept(this , data);
2747:                } else {
2748:                    node.jjtGetFirstChild().jjtAccept(this , data);
2749:                    if (printData.isSpaceAroundOperators()) {
2750:                        printData.space();
2751:                    }
2752:                    jjtAcceptSpecial(node, printData, "?");
2753:                    printData.appendText("?");
2754:                    if (printData.isSpaceAroundOperators()) {
2755:                        printData.space();
2756:                    }
2757:                    node.jjtGetChild(1).jjtAccept(this , data);
2758:                    if (printData.isSpaceAroundOperators()) {
2759:                        printData.space();
2760:                    }
2761:                    jjtAcceptSpecial(node, printData, ":");
2762:                    printData.appendText(":");
2763:                    if (printData.isSpaceAroundOperators()) {
2764:                        printData.space();
2765:                    }
2766:                    node.jjtGetChild(2).jjtAccept(this , data);
2767:                }
2768:
2769:                //  Return the data
2770:                return data;
2771:            }
2772:
2773:            /**
2774:             *  Description of the Method
2775:             *
2776:             * @param  node  Description of Parameter
2777:             * @param  data  Description of Parameter
2778:             * @return       Description of the Returned Value
2779:             */
2780:            public Object visit(ASTConditionalOrExpression node, Object data) {
2781:                return binaryExpression(node, "||", data);
2782:            }
2783:
2784:            /**
2785:             *  Description of the Method
2786:             *
2787:             * @param  node  Description of Parameter
2788:             * @param  data  Description of Parameter
2789:             * @return       Description of the Returned Value
2790:             */
2791:            public Object visit(ASTConditionalAndExpression node, Object data) {
2792:                return binaryExpression(node, "&&", data);
2793:            }
2794:
2795:            /**
2796:             *  Description of the Method
2797:             *
2798:             * @param  node  Description of Parameter
2799:             * @param  data  Description of Parameter
2800:             * @return       Description of the Returned Value
2801:             */
2802:            public Object visit(ASTInclusiveOrExpression node, Object data) {
2803:                return binaryExpression(node, "|", data);
2804:            }
2805:
2806:            /**
2807:             *  Description of the Method
2808:             *
2809:             * @param  node  Description of Parameter
2810:             * @param  data  Description of Parameter
2811:             * @return       Description of the Returned Value
2812:             */
2813:            public Object visit(ASTExclusiveOrExpression node, Object data) {
2814:                return binaryExpression(node, "^", data);
2815:            }
2816:
2817:            /**
2818:             *  Description of the Method
2819:             *
2820:             * @param  node  Description of Parameter
2821:             * @param  data  Description of Parameter
2822:             * @return       Description of the Returned Value
2823:             */
2824:            public Object visit(ASTAndExpression node, Object data) {
2825:                return binaryExpression(node, "&", data);
2826:            }
2827:
2828:            /**
2829:             *  Description of the Method
2830:             *
2831:             * @param  node  Description of Parameter
2832:             * @param  data  Description of Parameter
2833:             * @return       Description of the Returned Value
2834:             */
2835:            public Object visit(ASTEqualityExpression node, Object data) {
2836:                return binaryExpression(node, node.getNames(), data);
2837:            }
2838:
2839:            /**
2840:             *  Description of the Method
2841:             *
2842:             * @param  node  Description of Parameter
2843:             * @param  data  Description of Parameter
2844:             * @return       Description of the Returned Value
2845:             */
2846:            public Object visit(ASTInstanceOfExpression node, Object data) {
2847:                return binaryExpression(node, "instanceof", data);
2848:            }
2849:
2850:            /**
2851:             *  Description of the Method
2852:             *
2853:             * @param  node  Description of Parameter
2854:             * @param  data  Description of Parameter
2855:             * @return       Description of the Returned Value
2856:             */
2857:            public Object visit(ASTRelationalExpression node, Object data) {
2858:                return binaryExpression(node, node.getNames(), data);
2859:            }
2860:
2861:            /**
2862:             *  Description of the Method
2863:             *
2864:             * @param  node  Description of Parameter
2865:             * @param  data  Description of Parameter
2866:             * @return       Description of the Returned Value
2867:             */
2868:            public Object visit(ASTShiftExpression node, Object data) {
2869:                return binaryExpression(node, node.getNames(), data);
2870:            }
2871:
2872:            /**
2873:             *  Description of the Method
2874:             *
2875:             * @param  node  Description of Parameter
2876:             * @param  data  Description of Parameter
2877:             * @return       Description of the Returned Value
2878:             */
2879:            public Object visit(ASTAdditiveExpression node, Object data) {
2880:                return binaryExpression(node, node.getNames(), data);
2881:            }
2882:
2883:            /**
2884:             *  Description of the Method
2885:             *
2886:             * @param  node  Description of Parameter
2887:             * @param  data  Description of Parameter
2888:             * @return       Description of the Returned Value
2889:             */
2890:            public Object visit(ASTMultiplicativeExpression node, Object data) {
2891:                return binaryExpression(node, node.getNames(), data);
2892:            }
2893:
2894:            /**
2895:             *  Description of the Method
2896:             *
2897:             * @param  node  Description of Parameter
2898:             * @param  data  Description of Parameter
2899:             * @return       Description of the Returned Value
2900:             */
2901:            public Object visit(ASTUnaryExpression node, Object data) {
2902:                //  Get the data
2903:                PrintData printData = (PrintData) data;
2904:
2905:                //  Traverse the children
2906:                Node child = node.jjtGetFirstChild();
2907:                if (child instanceof  ASTUnaryExpression) {
2908:                    jjtAcceptSpecial(node, printData, "operator");
2909:                    printData.appendText(node.getName());
2910:                }
2911:                child.jjtAccept(this , data);
2912:
2913:                //  Return the data
2914:                return data;
2915:            }
2916:
2917:            /**
2918:             *  Description of the Method
2919:             *
2920:             * @param  node  Description of Parameter
2921:             * @param  data  Description of Parameter
2922:             * @return       Description of the Returned Value
2923:             */
2924:            public Object visit(ASTPreIncrementExpression node, Object data) {
2925:                //  Get the data
2926:                PrintData printData = (PrintData) data;
2927:
2928:                //  Include the preincrement
2929:                jjtAcceptSpecial(node, printData, "operator");
2930:                printData.appendText("++");
2931:
2932:                //  Traverse the children
2933:                node.childrenAccept(this , data);
2934:
2935:                //  Return the data
2936:                return data;
2937:            }
2938:
2939:            /**
2940:             *  Description of the Method
2941:             *
2942:             * @param  node  Description of Parameter
2943:             * @param  data  Description of Parameter
2944:             * @return       Description of the Returned Value
2945:             */
2946:            public Object visit(ASTPreDecrementExpression node, Object data) {
2947:                //  Get the data
2948:                PrintData printData = (PrintData) data;
2949:
2950:                //  Include the preincrement
2951:                jjtAcceptSpecial(node, printData, "operator");
2952:                printData.appendText("--");
2953:
2954:                //  Traverse the children
2955:                node.childrenAccept(this , data);
2956:
2957:                //  Return the data
2958:                return data;
2959:            }
2960:
2961:            /**
2962:             *  Description of the Method
2963:             *
2964:             * @param  node  Description of Parameter
2965:             * @param  data  Description of Parameter
2966:             * @return       Description of the Returned Value
2967:             */
2968:            public Object visit(ASTUnaryExpressionNotPlusMinus node, Object data) {
2969:                //  Get the data
2970:                PrintData printData = (PrintData) data;
2971:
2972:                //  Traverse the children
2973:                Node child = node.jjtGetFirstChild();
2974:                if (child instanceof  ASTUnaryExpression) {
2975:                    jjtAcceptSpecial(node, printData, "operator");
2976:                    printData.appendText(node.getName());
2977:                    if (node.getName().equals("!") && printData.isBangSpace()) {
2978:                        printData.space();
2979:                    }
2980:                }
2981:                child.jjtAccept(this , data);
2982:
2983:                //  Return the data
2984:                return data;
2985:            }
2986:
2987:            /**
2988:             *  Description of the Method
2989:             *
2990:             * @param  node  Description of Parameter
2991:             * @param  data  Description of Parameter
2992:             * @return       Description of the Returned Value
2993:             */
2994:            public Object visit(ASTPostfixExpression node, Object data) {
2995:                //  Get the data
2996:                PrintData printData = (PrintData) data;
2997:
2998:                //  Traverse the children
2999:                node.childrenAccept(this , data);
3000:
3001:                //  Include the increment
3002:                jjtAcceptSpecial(node, printData, "operator");
3003:                printData.appendText(node.getName());
3004:
3005:                //  Return the data
3006:                return data;
3007:            }
3008:
3009:            /**
3010:             *  Description of the Method
3011:             *
3012:             * @param  node  Description of Parameter
3013:             * @param  data  Description of Parameter
3014:             * @return       Description of the Returned Value
3015:             */
3016:            public Object visit(ASTCastExpression node, Object data) {
3017:                //  Get the data
3018:                PrintData printData = (PrintData) data;
3019:
3020:                //  Cast portion
3021:                jjtAcceptSpecial(node, printData, "begin");
3022:                printData.beginExpression(printData.isCastSpace());
3023:                if (printData.isSpaceInsideCast()) {
3024:                    printData.space();
3025:                }
3026:                node.jjtGetFirstChild().jjtAccept(this , data);
3027:                if (printData.isSpaceInsideCast()) {
3028:                    printData.space();
3029:                }
3030:                jjtAcceptSpecial(node, printData, "end");
3031:                printData.endExpression(printData.isCastSpace());
3032:                if (printData.isSpaceAfterCast()) {
3033:                    printData.space();
3034:                }
3035:
3036:                //  Expression
3037:                node.jjtGetChild(1).jjtAccept(this , data);
3038:
3039:                //  Return the data
3040:                return data;
3041:            }
3042:
3043:            /**
3044:             *  Description of the Method
3045:             *
3046:             * @param  node  Description of Parameter
3047:             * @param  data  Description of Parameter
3048:             * @return       Description of the Returned Value
3049:             */
3050:            public Object visit(ASTPrimaryExpression node, Object data) {
3051:                node.childrenAccept(this , data);
3052:                return data;
3053:            }
3054:
3055:            /**
3056:             *  Description of the Method
3057:             *
3058:             * @param  node  Description of Parameter
3059:             * @param  data  Description of Parameter
3060:             * @return       Description of the Returned Value
3061:             */
3062:            public Object visit(ASTPrimaryPrefix node, Object data) {
3063:                //  Get the data
3064:                PrintData printData = (PrintData) data;
3065:
3066:                for (int ndx = 0; ndx < node.getCount(); ndx++) {
3067:                    jjtAcceptSpecial(node, printData, "this." + ndx);
3068:                }
3069:
3070:                //  Traverse the children
3071:                if (node.jjtGetNumChildren() == 0) {
3072:                    jjtAcceptSpecial(node, printData, "this");
3073:                    jjtAcceptSpecial(node, printData, "id");
3074:                    printData.appendText(node.getName());
3075:                } else {
3076:                    Node child = node.jjtGetFirstChild();
3077:                    if ((child instanceof  ASTLiteral)
3078:                            || (child instanceof  ASTName)
3079:                            || (child instanceof  ASTAllocationExpression)) {
3080:                        java.util.List anonInnerClasses = node
3081:                                .findChildrenOfType(ASTClassBody.class);
3082:                        boolean indent = withinArguments
3083:                                && (anonInnerClasses.size() > 0);
3084:                        if (indent) {
3085:                            printData.incrIndent();
3086:                            printData.incrIndent();
3087:                        }
3088:                        child.jjtAccept(this , data);
3089:                        if (indent) {
3090:                            printData.decrIndent();
3091:                            printData.decrIndent();
3092:                        }
3093:                    } else if (child instanceof  ASTExpression) {
3094:                        jjtAcceptSpecial(node, printData, "begin");
3095:                        if (printData.isSpaceAfterMethod()
3096:                                && node.hasAnyChildren()
3097:                                && printData.isSpaceAroundOperators()) {
3098:                            printData.space();
3099:                        }
3100:                        printData.beginExpression(node.hasAnyChildren());
3101:                        child.jjtAccept(this , data);
3102:                        jjtAcceptSpecial(node, printData, "end");
3103:                        printData.endExpression(node.hasAnyChildren());
3104:                    } else if (child instanceof  ASTResultType) {
3105:                        child.jjtAccept(this , data);
3106:                        printData.appendText(".class");
3107:                    }
3108:                }
3109:
3110:                //  Return the data
3111:                return data;
3112:            }
3113:
3114:            /**
3115:             *  Description of the Method
3116:             *
3117:             * @param  node  Description of Parameter
3118:             * @param  data  Description of Parameter
3119:             * @return       Description of the Returned Value
3120:             */
3121:            public Object visit(ASTPrimarySuffix node, Object data) {
3122:                PrintData printData = (PrintData) data;
3123:                //  Get the data
3124:
3125:                //  Traverse the children
3126:                if (node.jjtGetNumChildren() == 0) {
3127:                    jjtAcceptSpecial(node, printData, "dot");
3128:                    printData.appendText(".");
3129:                    jjtAcceptSpecial(node, printData, "id");
3130:                    printData.appendText(node.getName());
3131:                } else {
3132:                    Node child = node.jjtGetFirstChild();
3133:                    if (child instanceof  ASTArguments) {
3134:                        child.jjtAccept(this , data);
3135:                    } else if (child instanceof  ASTExpression) {
3136:                        jjtAcceptSpecial(node, printData, "[");
3137:                        printData.appendText("[");
3138:                        child.jjtAccept(this , data);
3139:                        jjtAcceptSpecial(node, printData, "]");
3140:                        printData.appendText("]");
3141:                    } else if (child instanceof  ASTAllocationExpression) {
3142:                        jjtAcceptSpecial(node, printData, "dot");
3143:                        printData.appendText(".");
3144:                        child.jjtAccept(this , data);
3145:                    } else if (child instanceof  ASTReferenceTypeList) {
3146:                        jjtAcceptSpecial(node, printData, "dot");
3147:                        printData.appendText(".");
3148:                        printData.appendText("<");
3149:                        child.jjtAccept(this , data);
3150:                        printData.appendText(">");
3151:                        jjtAcceptSpecial(node, printData, "id");
3152:                        printData.appendText(node.getName());
3153:                    }
3154:                }
3155:
3156:                return data;
3157:                //  Return the data
3158:            }
3159:
3160:            /**
3161:             *  Description of the Method
3162:             *
3163:             * @param  node  Description of Parameter
3164:             * @param  data  Description of Parameter
3165:             * @return       Description of the Returned Value
3166:             */
3167:            public Object visit(ASTLiteral node, Object data) {
3168:                //  Get the data
3169:                PrintData printData = (PrintData) data;
3170:
3171:                //  Traverse the children
3172:                if (node.hasAnyChildren()) {
3173:                    node.childrenAccept(this , data);
3174:                } else {
3175:                    jjtAcceptSpecial(node, printData, "id");
3176:                    printData.appendConstant(node.getName());
3177:                }
3178:
3179:                //  Return the data
3180:                return data;
3181:            }
3182:
3183:            /**
3184:             *  Description of the Method
3185:             *
3186:             * @param  node  Description of Parameter
3187:             * @param  data  Description of Parameter
3188:             * @return       Description of the Returned Value
3189:             */
3190:            public Object visit(ASTBooleanLiteral node, Object data) {
3191:                //  Get the data
3192:                PrintData printData = (PrintData) data;
3193:
3194:                //  Print the data
3195:                jjtAcceptSpecial(node, printData, "id");
3196:                printData.appendConstant(node.getName());
3197:
3198:                //  Return the data
3199:                return data;
3200:            }
3201:
3202:            /**
3203:             *  Description of the Method
3204:             *
3205:             * @param  node  Description of Parameter
3206:             * @param  data  Description of Parameter
3207:             * @return       Description of the Returned Value
3208:             */
3209:            public Object visit(ASTNullLiteral node, Object data) {
3210:                //  Get the data
3211:                PrintData printData = (PrintData) data;
3212:
3213:                //  Print the data
3214:                jjtAcceptSpecial(node, printData, "id");
3215:                printData.appendConstant("null");
3216:
3217:                //  Return the data
3218:                return data;
3219:            }
3220:
3221:            /**
3222:             *  Description of the Method
3223:             *
3224:             * @param  node  Description of Parameter
3225:             * @param  data  Description of Parameter
3226:             * @return       Description of the Returned Value
3227:             */
3228:            public Object visit(ASTArguments node, Object data) {
3229:                //  Get the data
3230:                PrintData printData = (PrintData) data;
3231:
3232:                //  Start the parens
3233:                jjtAcceptSpecial(node, printData, "begin");
3234:                if (printData.isSpaceAfterMethod() && node.hasAnyChildren()) {
3235:                    printData.space();
3236:                }
3237:                printData.beginExpression(node.hasAnyChildren());
3238:
3239:                withinArguments = true;
3240:                //  Traverse the children
3241:                node.childrenAccept(this , data);
3242:                withinArguments = false;
3243:
3244:                //  Finish the parens
3245:                jjtAcceptSpecial(node, printData, "end");
3246:                printData.endExpression(node.hasAnyChildren());
3247:
3248:                //  Return the data
3249:                return data;
3250:            }
3251:
3252:            /**
3253:             *  Description of the Method
3254:             *
3255:             * @param  node  Description of Parameter
3256:             * @param  data  Description of Parameter
3257:             * @return       Description of the Returned Value
3258:             */
3259:            public Object visit(ASTArgumentList node, Object data) {
3260:                //  Get the data
3261:                PrintData printData = (PrintData) data;
3262:
3263:                //  Traverse the children
3264:                int count = node.jjtGetNumChildren();
3265:                for (int ndx = 0; ndx < count; ndx++) {
3266:                    if (ndx > 0) {
3267:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
3268:                        printData.appendText(", ");
3269:                    }
3270:                    node.jjtGetChild(ndx).jjtAccept(this , data);
3271:                }
3272:
3273:                //  Return the data
3274:                return data;
3275:            }
3276:
3277:            /**
3278:             *  Description of the Method
3279:             *
3280:             * @param  node  Description of Parameter
3281:             * @param  data  Description of Parameter
3282:             * @return       Description of the Returned Value
3283:             */
3284:            public Object visit(ASTAllocationExpression node, Object data) {
3285:                //  Get the data
3286:                PrintData printData = (PrintData) data;
3287:
3288:                //  Traverse the children
3289:                if (node.jjtGetChild(node.jjtGetNumChildren() - 1) instanceof  ASTClassBody) {
3290:                    //  Indenting
3291:                    int lastType = printData.getState();
3292:                    printData.setState(PrintData.EMPTY);
3293:                    printData.incrIndent();
3294:
3295:                    //  Print the name of the node
3296:                    jjtAcceptSpecial(node, printData, "id");
3297:                    printData.indent();
3298:                    printData.appendKeyword("new");
3299:                    printData.space();
3300:
3301:                    //  Traverse the children
3302:                    SimpleNode nameNode = (SimpleNode) node.jjtGetFirstChild();
3303:                    nameNode.jjtAccept(this , data);
3304:                    int x = 0;
3305:                    if (node.jjtGetChild(1) instanceof  ASTTypeArguments) {
3306:                        x++;
3307:                        ASTTypeArguments typeArguments = (ASTTypeArguments) node
3308:                                .jjtGetChild(1);
3309:                        typeArguments.jjtAccept(this , data);
3310:                    }
3311:
3312:                    SimpleNode arguments = (SimpleNode) node.jjtGetChild(1 + x);
3313:                    arguments.jjtAccept(this , data);
3314:
3315:                    ASTClassBody classBody = (ASTClassBody) node
3316:                            .jjtGetChild(2 + x);
3317:                    visit(classBody, data, false);
3318:
3319:                    //  Cleanup
3320:                    printData.decrIndent();
3321:                    //printData.indent();
3322:                    printData.setState(lastType);
3323:                } else {
3324:                    //  Print the name of the node
3325:                    jjtAcceptSpecial(node, printData, "id");
3326:                    printData.appendKeyword("new");
3327:                    printData.space();
3328:
3329:                    //  Traverse the children
3330:                    node.childrenAccept(this , data);
3331:                }
3332:
3333:                //  Return the data
3334:                return data;
3335:            }
3336:
3337:            /**
3338:             *  Description of the Method
3339:             *
3340:             * @param  node  Description of Parameter
3341:             * @param  data  Description of Parameter
3342:             * @return       Description of the Returned Value
3343:             */
3344:            public Object visit(ASTArrayDimsAndInits node, Object data) {
3345:                //  Get the data
3346:                PrintData printData = (PrintData) data;
3347:
3348:                //  Traverse the children
3349:                boolean foundInitializer = false;
3350:                int last = node.jjtGetNumChildren();
3351:                for (int ndx = 0; ndx < last; ndx++) {
3352:                    if (node.jjtGetChild(ndx) instanceof  ASTExpression) {
3353:                        jjtAcceptSpecial(node, printData, "[." + ndx);
3354:                        printData.appendText("[");
3355:                        node.jjtGetChild(ndx).jjtAccept(this , data);
3356:                        jjtAcceptSpecial(node, printData, "]." + ndx);
3357:                        printData.appendText("]");
3358:                    } else if (node.jjtGetChild(ndx) instanceof  ASTArrayInitializer) {
3359:                        foundInitializer = true;
3360:                    }
3361:                }
3362:                int looping = node.getArrayCount();
3363:                if (foundInitializer) {
3364:                    looping++;
3365:                }
3366:
3367:                for (int ndx = last; ndx < looping; ndx++) {
3368:                    jjtAcceptSpecial(node, printData, "[." + ndx);
3369:                    printData.appendText("[");
3370:                    jjtAcceptSpecial(node, printData, "]." + ndx);
3371:                    printData.appendText("]");
3372:
3373:                }
3374:                if (foundInitializer) {
3375:                    node.jjtGetChild(last - 1).jjtAccept(this , data);
3376:                }
3377:
3378:                //  Return the data
3379:                return data;
3380:            }
3381:
3382:            /**
3383:             *  Description of the Method
3384:             *
3385:             * @param  node  Description of Parameter
3386:             * @param  data  Description of Parameter
3387:             * @return       Description of the Returned Value
3388:             */
3389:            public Object visit(ASTStatement node, Object data) {
3390:                //  Get the data
3391:                PrintData printData = (PrintData) data;
3392:
3393:                //  Traverse the children
3394:                printData.indent();
3395:                node.childrenAccept(this , data);
3396:                if (node.jjtGetFirstChild() instanceof  ASTStatementExpression) {
3397:                    //  Finish off the statement expression
3398:                    jjtAcceptSpecial(node, printData, "semicolon");
3399:                    printData.appendText(";");
3400:                    printData.newline();
3401:                }
3402:
3403:                //  Return the data
3404:                return data;
3405:            }
3406:
3407:            /**
3408:             *  Description of the Method
3409:             *
3410:             * @param  node  Description of Parameter
3411:             * @param  data  Description of Parameter
3412:             * @return       Description of the Returned Value
3413:             */
3414:            public Object visit(ASTLabeledStatement node, Object data) {
3415:                //  Get the data
3416:                PrintData printData = (PrintData) data;
3417:
3418:                //  Print the data
3419:                jjtAcceptSpecial(node, printData, "id");
3420:                printData.appendText(node.getName());
3421:                jjtAcceptSpecial(node, printData, "colon");
3422:                printData.appendText(": ");
3423:
3424:                //  Traverse the children
3425:                node.childrenAccept(this , data);
3426:
3427:                //  Return the data
3428:                return data;
3429:            }
3430:
3431:            /**
3432:             *  Description of the Method
3433:             *
3434:             * @param  node  Description of Parameter
3435:             * @param  data  Description of Parameter
3436:             * @return       Description of the Returned Value
3437:             */
3438:            public Object visit(ASTBlock node, Object data) {
3439:                //  Get the data
3440:                PrintData printData = (PrintData) data;
3441:
3442:                blockProcess(node, printData, true);
3443:
3444:                //  Return the data
3445:                return data;
3446:            }
3447:
3448:            /**
3449:             *  Description of the Method
3450:             *
3451:             * @param  node  Description of Parameter
3452:             * @param  data  Description of Parameter
3453:             * @return       Description of the Returned Value
3454:             */
3455:            public Object visit(ASTBlockStatement node, Object data) {
3456:                //  Get the data
3457:                PrintData printData = (PrintData) data;
3458:
3459:                //  Include the stuff before the class/interface declaration
3460:                if (node.hasAnyChildren()) {
3461:                    int childNo = 0;
3462:                    SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
3463:                    while (child instanceof  ASTAnnotation) {
3464:                        jjtAcceptSpecial(node, printData, "@." + childNo);
3465:                        child = (SimpleNode) node.jjtGetChild(++childNo);
3466:                    }
3467:
3468:                    if (child instanceof  ASTUnmodifiedClassDeclaration) {
3469:                        printData.beginClass();
3470:                        if (node.isFinal()) {
3471:                            jjtAcceptSpecial(node, printData, "final");
3472:                        }
3473:                        jjtAcceptSpecial(node, printData, "class");
3474:                        childNo = 0;
3475:                        child = (SimpleNode) node.jjtGetFirstChild();
3476:                        while (child instanceof  ASTAnnotation) {
3477:                            child.jjtAccept(this , data);
3478:                            child = (SimpleNode) node.jjtGetChild(++childNo);
3479:                        }
3480:                        printData.indent();
3481:                        if (node.isFinal()) {
3482:                            printData.appendKeyword("final");
3483:                            printData.space();
3484:                        }
3485:                        child.jjtAccept(this , data);
3486:                        printData.endClass();
3487:                    } else if (child instanceof  ASTUnmodifiedInterfaceDeclaration) {
3488:                        printData.beginClass();
3489:                        if (node.isFinal()) {
3490:                            jjtAcceptSpecial(node, printData, "final");
3491:                        }
3492:                        jjtAcceptSpecial(node, printData, "interface");
3493:                        childNo = 0;
3494:                        child = (SimpleNode) node.jjtGetFirstChild();
3495:                        while (child instanceof  ASTAnnotation) {
3496:                            child.jjtAccept(this , data);
3497:                            child = (SimpleNode) node.jjtGetChild(++childNo);
3498:                        }
3499:                        printData.indent();
3500:                        if (node.isFinal()) {
3501:                            printData.appendKeyword("final");
3502:                            printData.space();
3503:                        }
3504:                        child.jjtAccept(this , data);
3505:                        printData.endClass();
3506:                    } else if (printData.isInsertSpaceLocalVariables()
3507:                            && (child instanceof  ASTLocalVariableDeclaration)) {
3508:                        if (!isLastLocalVariable(node)) {
3509:                            printData.newline();
3510:                        }
3511:                        //  Traverse the children
3512:                        node.childrenAccept(this , data);
3513:                        if (!isNextLocalVariable(node)) {
3514:                            printData.newline();
3515:                            printData.newline();
3516:                        }
3517:                    } else {
3518:                        //  Traverse the children
3519:                        node.childrenAccept(this , data);
3520:                    }
3521:                }
3522:
3523:                //  Return the data
3524:                return data;
3525:            }
3526:
3527:            /**
3528:             *  Description of the Method
3529:             *
3530:             * @param  node  Description of Parameter
3531:             * @param  data  Description of Parameter
3532:             * @return       Description of the Returned Value
3533:             */
3534:            public Object visit(ASTLocalVariableDeclaration node, Object data) {
3535:                //  Get the data
3536:                PrintData printData = (PrintData) data;
3537:
3538:                //  Traverse the children
3539:                int last = node.jjtGetNumChildren();
3540:                int childNo = 0;
3541:                SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
3542:                while (child instanceof  ASTAnnotation) {
3543:                    jjtAcceptSpecial(node, printData, "@." + childNo);
3544:                    child.jjtAccept(this , data);
3545:                    child = (SimpleNode) node.jjtGetChild(++childNo);
3546:                    printData.indent();
3547:                }
3548:                Node typeNode = child;
3549:                for (int ndx = childNo + 1; ndx < last; ndx++) {
3550:                    jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
3551:                    //  Indent this type of statement
3552:                    if (printData.isVariablesAlignWithBlock()) {
3553:                        printData.decrIndent();
3554:                        printData.indent();
3555:                    } else {
3556:                        printData.indent();
3557:                    }
3558:
3559:                    //  Print the final token
3560:                    int current = 0;
3561:                    if (node.isUsingFinal()) {
3562:                        jjtAcceptSpecial(node, printData, "final");
3563:                        printData.appendKeyword("final");
3564:                        printData.space();
3565:                        current = 6;
3566:                    }
3567:
3568:                    if (printData.isDynamicFieldSpacing(false)) {
3569:                        FieldSize size = printData.topFieldSize();
3570:                        int maxModifier = size.getModifierLength();
3571:                        for (int modifierIndex = current; modifierIndex < maxModifier; modifierIndex++) {
3572:                            printData.space();
3573:                        }
3574:                    }
3575:
3576:                    //  Print the annotation (if any) type
3577:                    //childNo = 0;
3578:                    //child = (SimpleNode)node.jjtGetChild(childNo);
3579:                    //while (child instanceof ASTAnnotation) {
3580:                    //   child.jjtAccept(this, data);
3581:                    //   childNo++;
3582:                    //   child = (SimpleNode)node.jjtGetChild(childNo);
3583:                    //}
3584:                    typeNode.jjtAccept(this , data);
3585:                    printData.space();
3586:                    if (printData.isVariablesAlignWithBlock()) {
3587:                        printData.incrIndent();
3588:                    }
3589:
3590:                    if (printData.isDynamicFieldSpacing(false)) {
3591:                        current = lvla.computeTypeLength(node);
3592:
3593:                        FieldSize size = printData.topFieldSize();
3594:                        int maxType = size.getTypeLength();
3595:                        for (int typeIndex = current; typeIndex < maxType; typeIndex++) {
3596:                            printData.space();
3597:                        }
3598:                    }
3599:
3600:                    if (printData.getFieldSpaceCode() == PrintData.DFS_ALIGN_EQUALS) {
3601:                        printData.setTempEqualsLength(lvla
3602:                                .computeEqualsLength(node));
3603:                    }
3604:
3605:                    //  Visit the child
3606:                    node.jjtGetChild(ndx).jjtAccept(this , data);
3607:
3608:                    //  End the variable declaration
3609:                    printData.appendText(";");
3610:                }
3611:
3612:                //  Return the data
3613:                return data;
3614:            }
3615:
3616:            /**
3617:             *  Description of the Method
3618:             *
3619:             * @param  node  Description of Parameter
3620:             * @param  data  Description of Parameter
3621:             * @return       Description of the Returned Value
3622:             */
3623:            public Object visit(ASTEmptyStatement node, Object data) {
3624:                //  Get the data
3625:                PrintData printData = (PrintData) data;
3626:
3627:                //  Print the name of the node
3628:                jjtAcceptSpecial(node, printData, "semicolon");
3629:                printData.appendText(";");
3630:                printData.newline();
3631:
3632:                //  Return the data
3633:                return data;
3634:            }
3635:
3636:            /**
3637:             *  Description of the Method
3638:             *
3639:             * @param  node  Description of Parameter
3640:             * @param  data  Description of Parameter
3641:             * @return       Description of the Returned Value
3642:             */
3643:            public Object visit(ASTStatementExpression node, Object data) {
3644:                //  Get the data
3645:                PrintData printData = (PrintData) data;
3646:
3647:                //  Traverse the children
3648:                if (node.jjtGetFirstChild() instanceof  ASTPrimaryExpression) {
3649:                    int last = node.jjtGetNumChildren();
3650:                    node.jjtGetFirstChild().jjtAccept(this , data);
3651:                    jjtAcceptSpecial(node, printData, "id");
3652:                    printData.appendText(node.getName());
3653:                    for (int ndx = 1; ndx < last; ndx++) {
3654:                        node.jjtGetChild(ndx).jjtAccept(this , data);
3655:                    }
3656:                } else {
3657:                    node.childrenAccept(this , data);
3658:                }
3659:
3660:                //  Return the data
3661:                return data;
3662:            }
3663:
3664:            /**
3665:             *  Description of the Method
3666:             *
3667:             * @param  node  Description of Parameter
3668:             * @param  data  Description of Parameter
3669:             * @return       Description of the Returned Value
3670:             */
3671:            public Object visit(ASTSwitchStatement node, Object data) {
3672:                //  Get the data
3673:                PrintData printData = (PrintData) data;
3674:
3675:                //  Switch
3676:                jjtAcceptSpecial(node, printData, "switch");
3677:                printData.appendKeyword("switch");
3678:                jjtAcceptSpecial(node, printData, "beginExpr");
3679:                if (printData.isSpaceAfterKeyword()) {
3680:                    printData.space();
3681:                }
3682:                printData.beginExpression(true);
3683:                node.jjtGetFirstChild().jjtAccept(this , data);
3684:                jjtAcceptSpecial(node, printData, "endExpr");
3685:                printData.endExpression(true);
3686:
3687:                //  Start the block
3688:                printData.beginBlock();
3689:                printData.decrIndent();
3690:                printData.incrCaseIndent();
3691:                jjtAcceptSpecial(node, printData, "beginBlock", false);
3692:
3693:                //  Traverse the children
3694:                int last = node.jjtGetNumChildren();
3695:                for (int ndx = 1; ndx < last; ndx++) {
3696:                    Node next = node.jjtGetChild(ndx);
3697:                    if (next instanceof  ASTBlockStatement) {
3698:                        boolean indent = shouldIndentSwitchBody(next);
3699:                        if (indent) {
3700:                            printData.incrIndent();
3701:                            next.jjtAccept(this , data);
3702:                            printData.decrIndent();
3703:                        } else {
3704:                            Node child = next.jjtGetFirstChild();
3705:                            Node grandchild = child.jjtGetFirstChild();
3706:                            printData.indent();
3707:                            blockProcess((ASTBlock) grandchild, printData,
3708:                                    true, false);
3709:                        }
3710:                    } else {
3711:                        next.jjtAccept(this , data);
3712:                    }
3713:                }
3714:
3715:                //  End the block
3716:                jjtAcceptSpecial(node, printData, "endBlock");
3717:                printData.decrCaseIndent();
3718:                printData.incrIndent();
3719:                printData.endBlock();
3720:
3721:                //  Return the data
3722:                return data;
3723:            }
3724:
3725:            /**
3726:             *  Reformats the case XXX: portion of a switch statement
3727:             *
3728:             * @param  node  Description of Parameter
3729:             * @param  data  Description of Parameter
3730:             * @return       Description of the Returned Value
3731:             */
3732:            public Object visit(ASTSwitchLabel node, Object data) {
3733:                //  Get the data
3734:                PrintData printData = (PrintData) data;
3735:
3736:                //  Determine if the node has children
3737:                if (node.hasAnyChildren()) {
3738:                    jjtAcceptSpecial(node, printData, "id");
3739:                    printData.indent();
3740:                    printData.appendKeyword("case");
3741:                    printData.space();
3742:                    node.childrenAccept(this , data);
3743:                    jjtAcceptSpecial(node, printData, "colon");
3744:                    printData.appendText(":");
3745:                    printData.newline();
3746:                } else {
3747:                    jjtAcceptSpecial(node, printData, "id");
3748:                    jjtAcceptSpecial(node, printData, "colon");
3749:                    printData.indent();
3750:                    printData.appendKeyword("default");
3751:                    printData.appendText(":");
3752:                    printData.newline();
3753:                }
3754:
3755:                //  Return the data
3756:                return data;
3757:            }
3758:
3759:            /**
3760:             *  Description of the Method
3761:             *
3762:             * @param  node  Description of Parameter
3763:             * @param  data  Description of Parameter
3764:             * @return       Description of the Returned Value
3765:             */
3766:            public Object visit(ASTIfStatement node, Object data) {
3767:                //  Get the data
3768:                PrintData printData = (PrintData) data;
3769:
3770:                //  Determine if the node has children
3771:                jjtAcceptSpecial(node, printData, "if");
3772:                printData.appendKeyword("if");
3773:                jjtAcceptSpecial(node, printData, "beginExpr");
3774:                if (printData.isSpaceAfterKeyword()) {
3775:                    printData.space();
3776:                }
3777:                printData.beginExpression(true);
3778:                node.jjtGetFirstChild().jjtAccept(this , data);
3779:                jjtAcceptSpecial(node, printData, "endExpr");
3780:                printData.endExpression(true);
3781:
3782:                //  Determine if the then contains a block
3783:                boolean hasElse = (node.jjtGetNumChildren() == 3);
3784:                if (node.jjtGetNumChildren() >= 2) {
3785:                    boolean oldEnclosingIfStatement = enclosingIfStatement;
3786:                    enclosingIfStatement = true;
3787:                    forceBlock(node.jjtGetChild(1), printData, !hasElse
3788:                            && printData.isElseOnNewLine(), printData
3789:                            .isRemoveExcessBlocks()
3790:                            && !isIfStatement(node.jjtGetChild(1)));
3791:                    enclosingIfStatement = oldEnclosingIfStatement;
3792:                }
3793:
3794:                //  Determine if the else part
3795:                if (hasElse) {
3796:                    boolean shouldIndent = isShouldIndentBeforeElse(printData,
3797:                            node);
3798:                    if (shouldIndent) {
3799:                        printData.indent();
3800:                    } else {
3801:                        printData.space();
3802:                    }
3803:                    jjtAcceptSpecial(node, printData, "else", shouldIndent);
3804:                    printData.appendKeyword("else");
3805:                    //  Determine if the next item is a statement
3806:                    ASTStatement child = (ASTStatement) node.jjtGetChild(2);
3807:                    Node next = child.jjtGetFirstChild();
3808:                    if (next instanceof  ASTIfStatement) {
3809:                        printData.space();
3810:                        // this rather complex code removes unwanted new lines
3811:                        // from before "if" statements so that when they are moved
3812:                        // the comments are in the correct place.
3813:                        Token special = ((ASTIfStatement) next)
3814:                                .getSpecial("if");
3815:                        Token prev = null;
3816:                        Token first = null;
3817:                        while (special != null) {
3818:                            if (special.kind >= 4 && special.kind <= 6) {
3819:                                special.kind = 1;
3820:                                // make it a space!
3821:                                special.image = " ";
3822:                            } else if (first == null) {
3823:                                first = special;
3824:                                prev = first;
3825:                            } else {
3826:                                prev.specialToken = special;
3827:                                prev = special;
3828:                            }
3829:                            special = special.specialToken;
3830:                        }
3831:                        if (first != null) {
3832:                            prev.specialToken = null;
3833:                            special = ((ASTIfStatement) next).getSpecial("if");
3834:                            special.kind = first.kind;
3835:                            special.image = first.image;
3836:                            special.specialToken = first.specialToken;
3837:                        } else {
3838:                            ((ASTIfStatement) next).removeSpecial("if");
3839:                        }
3840:                        next.jjtAccept(this , data);
3841:                    } else {
3842:                        forceBlock(child, printData, true, printData
3843:                                .isRemoveExcessBlocks());
3844:                    }
3845:                }
3846:
3847:                //  Return the data
3848:                return data;
3849:            }
3850:
3851:            /**
3852:             *  Description of the Method
3853:             *
3854:             * @param  node  Description of Parameter
3855:             * @param  data  Description of Parameter
3856:             * @return       Description of the Returned Value
3857:             */
3858:            public Object visit(ASTWhileStatement node, Object data) {
3859:                //  Get the data
3860:                PrintData printData = (PrintData) data;
3861:
3862:                //  Determine if the node has children
3863:                jjtAcceptSpecial(node, printData, "while");
3864:                printData.appendKeyword("while");
3865:                jjtAcceptSpecial(node, printData, "beginExpr");
3866:                if (printData.isSpaceAfterKeyword()) {
3867:                    printData.space();
3868:                }
3869:                printData.beginExpression(true);
3870:                node.jjtGetFirstChild().jjtAccept(this , data);
3871:                jjtAcceptSpecial(node, printData, "endExpr");
3872:                printData.endExpression(true);
3873:
3874:                //  Process the block
3875:                Node next = node.jjtGetChild(1);
3876:                // get the Statement
3877:                forceBlock(next, printData, true, printData
3878:                        .isRemoveExcessBlocks()
3879:                        && isIfStatementWithElse(next));
3880:
3881:                //  Return the data
3882:                return data;
3883:            }
3884:
3885:            /**
3886:             *  Description of the Method
3887:             *
3888:             * @param  node  Description of Parameter
3889:             * @param  data  Description of Parameter
3890:             * @return       Description of the Returned Value
3891:             */
3892:            public Object visit(ASTDoStatement node, Object data) {
3893:                //  Get the data
3894:                PrintData printData = (PrintData) data;
3895:
3896:                //  Begin the do block
3897:                jjtAcceptSpecial(node, printData, "do");
3898:                printData.appendKeyword("do");
3899:
3900:                //  Process the block
3901:                forceBlock(node.jjtGetFirstChild(), printData, false, false);
3902:
3903:                //  Process the while block
3904:                jjtAcceptSpecial(node, printData, "while", false);
3905:                if (printData.isSpaceAfterKeyword()) {
3906:                    printData.space();
3907:                }
3908:                printData.appendKeyword("while");
3909:                jjtAcceptSpecial(node, printData, "beginExpr", false);
3910:                printData.space();
3911:                printData.beginExpression(true);
3912:                node.jjtGetChild(1).jjtAccept(this , data);
3913:                jjtAcceptSpecial(node, printData, "endExpr");
3914:                printData.endExpression(true);
3915:                jjtAcceptSpecial(node, printData, "semicolon");
3916:                printData.appendText(";");
3917:
3918:                //  Return the data
3919:                return data;
3920:            }
3921:
3922:            /**
3923:             *  Description of the Method
3924:             *
3925:             * @param  node  Description of Parameter
3926:             * @param  data  Description of Parameter
3927:             * @return       Description of the Returned Value
3928:             */
3929:            public Object visit(ASTForStatement node, Object data) {
3930:                //  Get the data
3931:                PrintData printData = (PrintData) data;
3932:
3933:                //  Start the for loop
3934:                jjtAcceptSpecial(node, printData, "for");
3935:                printData.appendKeyword("for");
3936:                jjtAcceptSpecial(node, printData, "beginExpr");
3937:                if (printData.isSpaceAfterKeyword()) {
3938:                    printData.space();
3939:                }
3940:                printData.beginExpression(node.hasAnyChildren());
3941:
3942:                //  Traverse the children
3943:                Node next = node.jjtGetFirstChild();
3944:                int index = 1;
3945:
3946:                if (next instanceof  ASTLocalVariableDeclaration) {
3947:                    // new for loop structure for JDK 1.5
3948:                    printData.setSkipNameSpacing(true);
3949:                    forInit((ASTLocalVariableDeclaration) next, data);
3950:                    printData.setSkipNameSpacing(false);
3951:                    next = node.jjtGetChild(index);
3952:                    index++;
3953:                    jjtAcceptSpecial(node, printData, "loopover");
3954:                    printData.appendText(" : ");
3955:                    if (next instanceof  ASTExpression) {
3956:                        next.jjtAccept(this , data);
3957:                        next = node.jjtGetChild(index);
3958:                        index++;
3959:                    }
3960:                } else {
3961:                    if (next instanceof  ASTForInit) {
3962:                        printData.setSkipNameSpacing(true);
3963:                        next.jjtAccept(this , data);
3964:                        printData.setSkipNameSpacing(false);
3965:                        next = node.jjtGetChild(index);
3966:                        index++;
3967:                    }
3968:                    jjtAcceptSpecial(node, printData, "init");
3969:                    printData.appendText("; ");
3970:                    if (next instanceof  ASTExpression) {
3971:                        next.jjtAccept(this , data);
3972:                        next = node.jjtGetChild(index);
3973:                        index++;
3974:                    }
3975:                    jjtAcceptSpecial(node, printData, "test");
3976:                    printData.appendText("; ");
3977:                    if (next instanceof  ASTForUpdate) {
3978:                        next.jjtAccept(this , data);
3979:                        next = node.jjtGetChild(index);
3980:                        index++;
3981:                    }
3982:                }
3983:                jjtAcceptSpecial(node, printData, "endExpr");
3984:                printData.endExpression(node.hasAnyChildren());
3985:                forceBlock(
3986:                        next,
3987:                        printData,
3988:                        true,
3989:                        printData.isRemoveExcessBlocks()
3990:                                && (!enclosingIfStatement || isIfStatementWithElse(next)));
3991:
3992:                //  Return the data
3993:                return data;
3994:            }
3995:
3996:            /**
3997:             *  Description of the Method
3998:             *
3999:             * @param  node  Description of Parameter
4000:             * @param  data  Description of Parameter
4001:             * @return       Description of the Returned Value
4002:             */
4003:            public Object visit(ASTForInit node, Object data) {
4004:                //  Get the data
4005:                PrintData printData = (PrintData) data;
4006:
4007:                //  Traverse the children
4008:                Node next = node.jjtGetFirstChild();
4009:                if (next instanceof  ASTLocalVariableDeclaration) {
4010:                    forInit((ASTLocalVariableDeclaration) next, data);
4011:                } else {
4012:                    node.childrenAccept(this , data);
4013:                }
4014:
4015:                //  Return the data
4016:                return data;
4017:            }
4018:
4019:            /**
4020:             *  Description of the Method
4021:             *
4022:             * @param  node  Description of Parameter
4023:             * @param  data  Description of Parameter
4024:             * @return       Description of the Returned Value
4025:             */
4026:            public Object visit(ASTStatementExpressionList node, Object data) {
4027:                //  Get the data
4028:                PrintData printData = (PrintData) data;
4029:
4030:                //  Traverse the children
4031:                int last = node.jjtGetNumChildren();
4032:                for (int ndx = 0; ndx < last; ndx++) {
4033:                    if (ndx > 0) {
4034:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
4035:                        printData.appendText(", ");
4036:                    }
4037:                    node.jjtGetChild(ndx).jjtAccept(this , data);
4038:                }
4039:
4040:                //  Return the data
4041:                return data;
4042:            }
4043:
4044:            /**
4045:             *  Description of the Method
4046:             *
4047:             * @param  node  Description of Parameter
4048:             * @param  data  Description of Parameter
4049:             * @return       Description of the Returned Value
4050:             */
4051:            public Object visit(ASTForUpdate node, Object data) {
4052:                //  Traverse the children
4053:                node.childrenAccept(this , data);
4054:
4055:                //  Return the data
4056:                return data;
4057:            }
4058:
4059:            /**
4060:             *  Description of the Method
4061:             *
4062:             * @param  node  Description of Parameter
4063:             * @param  data  Description of Parameter
4064:             * @return       Description of the Returned Value
4065:             */
4066:            public Object visit(ASTBreakStatement node, Object data) {
4067:                //  Get the data
4068:                PrintData printData = (PrintData) data;
4069:
4070:                //  Print the break statement
4071:                jjtAcceptSpecial(node, printData, "break");
4072:                printData.appendKeyword("break");
4073:                String name = node.getName();
4074:                if (!((name == null) || (name.length() == 0))) {
4075:                    jjtAcceptSpecial(node, printData, "id");
4076:                    printData.appendText(" " + node.getName());
4077:                }
4078:                jjtAcceptSpecial(node, printData, "semicolon");
4079:                printData.appendText(";");
4080:
4081:                //  Return the data
4082:                return data;
4083:            }
4084:
4085:            /**
4086:             *  Description of the Method
4087:             *
4088:             * @param  node  Description of Parameter
4089:             * @param  data  Description of Parameter
4090:             * @return       Description of the Returned Value
4091:             */
4092:            public Object visit(ASTContinueStatement node, Object data) {
4093:                //  Get the data
4094:                PrintData printData = (PrintData) data;
4095:
4096:                //  Print the continue statement
4097:                jjtAcceptSpecial(node, printData, "continue");
4098:                printData.appendKeyword("continue");
4099:                String name = node.getName();
4100:                if (!((name == null) || (name.length() == 0))) {
4101:                    jjtAcceptSpecial(node, printData, "id");
4102:                    printData.appendText(" " + node.getName());
4103:                }
4104:                jjtAcceptSpecial(node, printData, "semicolon");
4105:                printData.appendText(";");
4106:
4107:                //  Return the data
4108:                return data;
4109:            }
4110:
4111:            /**
4112:             *  Description of the Method
4113:             *
4114:             * @param  node  Description of Parameter
4115:             * @param  data  Description of Parameter
4116:             * @return       Description of the Returned Value
4117:             */
4118:            public Object visit(ASTReturnStatement node, Object data) {
4119:                //  Get the data
4120:                PrintData printData = (PrintData) data;
4121:
4122:                //  Traverse the children
4123:                if (node.hasAnyChildren()) {
4124:                    jjtAcceptSpecial(node, printData, "return");
4125:                    printData.appendKeyword("return");
4126:                    printData.space();
4127:                    node.childrenAccept(this , data);
4128:                    jjtAcceptSpecial(node, printData, "semicolon");
4129:                    printData.appendText(";");
4130:                } else {
4131:                    jjtAcceptSpecial(node, printData, "return");
4132:                    printData.appendKeyword("return");
4133:                    jjtAcceptSpecial(node, printData, "semicolon");
4134:                    printData.appendText(";");
4135:                }
4136:
4137:                //  Return the data
4138:                return data;
4139:            }
4140:
4141:            /**
4142:             *  Description of the Method
4143:             *
4144:             * @param  node  Description of Parameter
4145:             * @param  data  Description of Parameter
4146:             * @return       Description of the Returned Value
4147:             */
4148:            public Object visit(ASTThrowStatement node, Object data) {
4149:                //  Get the data
4150:                PrintData printData = (PrintData) data;
4151:
4152:                //  Traverse the children
4153:                jjtAcceptSpecial(node, printData, "throw");
4154:                printData.appendKeyword("throw");
4155:                printData.space();
4156:                node.childrenAccept(this , data);
4157:                jjtAcceptSpecial(node, printData, "semicolon");
4158:                printData.appendText(";");
4159:
4160:                //  Return the data
4161:                return data;
4162:            }
4163:
4164:            /**
4165:             *  Description of the Method
4166:             *
4167:             * @param  node  Description of Parameter
4168:             * @param  data  Description of Parameter
4169:             * @return       Description of the Returned Value
4170:             */
4171:            public Object visit(ASTSynchronizedStatement node, Object data) {
4172:                //  Get the data
4173:                PrintData printData = (PrintData) data;
4174:
4175:                //  Traverse the children
4176:                jjtAcceptSpecial(node, printData, "synchronized");
4177:                printData.appendKeyword("synchronized");
4178:                jjtAcceptSpecial(node, printData, "beginExpr");
4179:                if (printData.isSpaceAfterKeyword()) {
4180:                    printData.space();
4181:                }
4182:                printData.beginExpression(true);
4183:                node.jjtGetFirstChild().jjtAccept(this , data);
4184:                jjtAcceptSpecial(node, printData, "endExpr");
4185:                printData.endExpression(true);
4186:                node.jjtGetChild(1).jjtAccept(this , data);
4187:
4188:                //  Return the data
4189:                return data;
4190:            }
4191:
4192:            /**
4193:             *  Description of the Method
4194:             *
4195:             * @param  node  Description of Parameter
4196:             * @param  data  Description of Parameter
4197:             * @return       Description of the Returned Value
4198:             */
4199:            public Object visit(ASTTryStatement node, Object data) {
4200:                //  Get the data
4201:                PrintData printData = (PrintData) data;
4202:
4203:                //  Traverse the children
4204:                jjtAcceptSpecial(node, printData, "try");
4205:                printData.appendKeyword("try");
4206:                blockProcess((ASTBlock) node.jjtGetFirstChild(), printData,
4207:                        printData.isCatchOnNewLine());
4208:
4209:                //  Now work with the pairs
4210:                int last = node.jjtGetNumChildren();
4211:                boolean paired = false;
4212:                int catchCount = 0;
4213:
4214:                for (int ndx = 1; ndx < last; ndx++) {
4215:                    Node next = node.jjtGetChild(ndx);
4216:                    if (next instanceof  ASTFormalParameter) {
4217:                        if (printData.isCatchOnNewLine()) {
4218:                            printData.indent();
4219:                        } else {
4220:                            printData.space();
4221:                        }
4222:                        jjtAcceptSpecial(node, printData, "catch" + catchCount,
4223:                                printData.isCatchOnNewLine());
4224:                        printData.appendKeyword("catch");
4225:                        jjtAcceptSpecial(node, printData, "beginExpr"
4226:                                + catchCount);
4227:                        if (printData.isSpaceAfterKeyword()) {
4228:                            printData.space();
4229:                        }
4230:                        printData.beginExpression(true);
4231:                        next.jjtAccept(this , data);
4232:                        jjtAcceptSpecial(node, printData, "endExpr"
4233:                                + catchCount);
4234:                        printData.endExpression(true);
4235:                        paired = true;
4236:                        catchCount++;
4237:                    } else {
4238:                        if (!paired) {
4239:                            jjtAcceptSpecial(node, printData, "finally",
4240:                                    printData.isCatchOnNewLine());
4241:                            if (printData.isCatchOnNewLine()) {
4242:                                printData.indent();
4243:                            } else {
4244:                                printData.space();
4245:                            }
4246:                            printData.appendKeyword("finally");
4247:                        }
4248:                        blockProcess((ASTBlock) next, printData, printData
4249:                                .isCatchOnNewLine());
4250:                        paired = false;
4251:                    }
4252:                }
4253:
4254:                if (!printData.isCatchOnNewLine()) {
4255:                    printData.newline();
4256:                }
4257:
4258:                //  Return the data
4259:                return data;
4260:            }
4261:
4262:            /**
4263:             *  Visit the assertion node
4264:             *
4265:             * @param  node  the node
4266:             * @param  data  the data needed to perform the visit
4267:             * @return       the result of visiting the node
4268:             */
4269:            public Object visit(ASTAssertionStatement node, Object data) {
4270:                //  Get the data
4271:                PrintData printData = (PrintData) data;
4272:
4273:                //  Traverse the children
4274:                jjtAcceptSpecial(node, printData, "assert");
4275:                printData.appendKeyword("assert");
4276:                printData.space();
4277:                node.jjtGetFirstChild().jjtAccept(this , data);
4278:
4279:                if (node.jjtGetNumChildren() > 1) {
4280:                    printData.space();
4281:                    jjtAcceptSpecial(node, printData, "colon");
4282:                    printData.appendText(":");
4283:                    printData.space();
4284:                    node.jjtGetChild(1).jjtAccept(this , data);
4285:                }
4286:
4287:                jjtAcceptSpecial(node, printData, "semicolon");
4288:                printData.appendText(";");
4289:
4290:                //  Return the data
4291:                return data;
4292:            }
4293:
4294:            /**
4295:             *  Description of the Method
4296:             *
4297:             * @param  node  Description of Parameter
4298:             * @param  name  Description of Parameter
4299:             * @param  data  Description of Parameter
4300:             * @return       Description of the Returned Value
4301:             */
4302:            protected Object binaryExpression(SimpleNode node, String name,
4303:                    Object data) {
4304:                //  Get the data
4305:                PrintData printData = (PrintData) data;
4306:
4307:                //  Traverse the children
4308:                int childCount = node.jjtGetNumChildren();
4309:                for (int ndx = 0; ndx < childCount; ndx++) {
4310:                    if (ndx > 0) {
4311:                        if (printData.isSpaceAroundOperators()
4312:                                || name.equals("instanceof")) {
4313:                            printData.space();
4314:                        }
4315:                        jjtAcceptSpecial(node, printData, "operator."
4316:                                + (ndx - 1));
4317:                        printData.appendText(name);
4318:                        if (printData.isSpaceAroundOperators()
4319:                                || name.equals("instanceof")) {
4320:                            printData.space();
4321:                        }
4322:                    }
4323:                    node.jjtGetChild(ndx).jjtAccept(this , data);
4324:                }
4325:
4326:                //  Return the data
4327:                return data;
4328:            }
4329:
4330:            /**
4331:             *  Description of the Method
4332:             *
4333:             * @param  node   Description of Parameter
4334:             * @param  names  Description of Parameter
4335:             * @param  data   Description of Parameter
4336:             * @return        Description of the Returned Value
4337:             */
4338:            protected Object binaryExpression(SimpleNode node,
4339:                    Enumeration names, Object data) {
4340:                //  Get the data
4341:                PrintData printData = (PrintData) data;
4342:
4343:                //  Traverse the children
4344:                int childCount = node.jjtGetNumChildren();
4345:                for (int ndx = 0; ndx < childCount; ndx++) {
4346:                    if (ndx > 0) {
4347:                        if (printData.isSpaceAroundOperators()) {
4348:                            printData.space();
4349:                        }
4350:                        jjtAcceptSpecial(node, printData, "operator."
4351:                                + (ndx - 1));
4352:                        printData.appendText(names.nextElement().toString());
4353:                        if (printData.isSpaceAroundOperators()) {
4354:                            printData.space();
4355:                        }
4356:                    }
4357:                    node.jjtGetChild(ndx).jjtAccept(this , data);
4358:                }
4359:
4360:                //  Return the data
4361:                return data;
4362:            }
4363:
4364:            /**
4365:             *  Description of the Method
4366:             *
4367:             * @param  node  Description of Parameter
4368:             * @param  data  Description of Parameter
4369:             */
4370:            protected void forInit(ASTLocalVariableDeclaration node, Object data) {
4371:                //  Get the data
4372:                PrintData printData = (PrintData) data;
4373:
4374:                //  Print the final token
4375:                if (node.isUsingFinal()) {
4376:                    jjtAcceptSpecial(node, printData, "final");
4377:                    printData.appendKeyword("final");
4378:                    printData.space();
4379:                }
4380:
4381:                //  Traverse the children
4382:                int last = node.jjtGetNumChildren();
4383:                Node typeNode = node.jjtGetFirstChild();
4384:                typeNode.jjtAccept(this , data);
4385:                printData.space();
4386:
4387:                for (int ndx = 1; ndx < last; ndx++) {
4388:                    if (ndx > 1) {
4389:                        //  Add a comma between entries
4390:                        jjtAcceptSpecial(node, printData, "comma." + (ndx - 1));
4391:                        printData.appendText(", ");
4392:                    }
4393:
4394:                    //  Visit the child
4395:                    node.jjtGetChild(ndx).jjtAccept(this , data);
4396:                }
4397:            }
4398:
4399:            /**
4400:             *  Forces a block around this node, if it is not already a block
4401:             *
4402:             * @param  node            the node
4403:             * @param  printData       the print data
4404:             * @param  newline         do we have a newline at the end of the block
4405:             * @param  canRemoveBlock  Description of the Parameter
4406:             */
4407:            protected void forceBlock(Node node, PrintData printData,
4408:                    boolean newline, boolean canRemoveBlock) {
4409:                if ((node.jjtGetNumChildren() > 0)
4410:                        && (node.jjtGetFirstChild() instanceof  ASTBlock)) {
4411:                    //  We know we have a block
4412:                    ASTBlock child = (ASTBlock) node.jjtGetFirstChild();
4413:
4414:                    LocalVariableLookAhead lvla = new LocalVariableLookAhead();
4415:                    FieldSize size = lvla.run(child);
4416:                    size.update(printData.getDynamicFieldSpaces());
4417:                    printData.pushFieldSize(size);
4418:
4419:                    //  Start the block
4420:                    if (isThisBlockRequired(canRemoveBlock, node)) {
4421:                        printData.beginBlock();
4422:                    } else {
4423:                        printData.incrIndent();
4424:                    }
4425:                    jjtAcceptSpecial(child, printData, "begin", false);
4426:
4427:                    if (child.jjtGetNumChildren() > 0) {
4428:                        //  Accept the children
4429:                        child.childrenAccept(this , printData);
4430:                    }
4431:
4432:                    //  End the block
4433:                    jjtAcceptSpecial(child, printData, "end");
4434:                    if (isThisBlockRequired(canRemoveBlock, node)) {
4435:                        printData.endBlock(newline, true);
4436:                    } else {
4437:                        if (child.jjtGetNumChildren() == 0) {
4438:                            printData.indent();
4439:                            printData.appendText(";");
4440:                        }
4441:                        printData.decrIndent();
4442:                    }
4443:
4444:                    printData.popFieldSize();
4445:                } else {
4446:                    if (printData.isForcingBlock()) {
4447:                        printData.beginBlock();
4448:                    } else {
4449:                        printData.incrIndent();
4450:                    }
4451:
4452:                    printData.indent();
4453:                    ((SimpleNode) node).childrenAccept(this , printData);
4454:                    if (node.jjtGetNumChildren() == 0
4455:                            || node.jjtGetFirstChild() instanceof  ASTStatementExpression) {
4456:                        //  Finish off the statement expression
4457:                        printData.appendText(";");
4458:                        printData.newline();
4459:                    }
4460:
4461:                    if (printData.isForcingBlock()) {
4462:                        printData.endBlock(newline, true);
4463:                    } else {
4464:                        printData.decrIndent();
4465:                    }
4466:                }
4467:            }
4468:
4469:            /**
4470:             *  Check the initial token, and removes it from the object.
4471:             *
4472:             * @param  top  the result type
4473:             * @return      the initial token
4474:             */
4475:            private Token getInitialToken(ASTResultType top) {
4476:                //  Check to see if we need to go farther down
4477:                if (top.hasAnyChildren()) {
4478:                    ASTType type = (ASTType) top.jjtGetFirstChild();
4479:                    if (type.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
4480:                        ASTPrimitiveType primitiveType = (ASTPrimitiveType) type
4481:                                .jjtGetFirstChild();
4482:                        Token tok = primitiveType.getSpecial("primitive");
4483:                        primitiveType.removeSpecial("primitive");
4484:                        return tok;
4485:                    } else if (type.jjtGetFirstChild() instanceof  ASTReferenceType) {
4486:                        ASTReferenceType referenceType = (ASTReferenceType) type
4487:                                .jjtGetFirstChild();
4488:                        if (referenceType.jjtGetFirstChild() instanceof  ASTClassOrInterfaceType) {
4489:                            ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) referenceType
4490:                                    .jjtGetFirstChild();
4491:                            ASTIdentifier ident = (ASTIdentifier) name
4492:                                    .jjtGetFirstChild();
4493:                            Token tok = ident.getSpecial("id");
4494:                            ident.removeSpecial("id");
4495:                            return tok;
4496:                        } else if (referenceType.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
4497:                            ASTPrimitiveType primitiveType = (ASTPrimitiveType) referenceType
4498:                                    .jjtGetFirstChild();
4499:                            Token tok = primitiveType.getSpecial("primitive");
4500:                            primitiveType.removeSpecial("primitive");
4501:                            return tok;
4502:                        } else {
4503:                            // FIXME: we get a CompilationUnit which is suprising as a child of a ASTReferenceType
4504:                            //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: top="+top.getName());
4505:                            //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: type="+type.getName());
4506:                            //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: referenceType="+referenceType.getName());
4507:                            //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: referenceType.jjtGetFirstChild()="+referenceType.jjtGetFirstChild());
4508:                            //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: referenceType.jjtGetFirstChild()="+((SimpleNode)referenceType.jjtGetFirstChild()).getName());
4509:                            return null;
4510:                        }
4511:                    } else {
4512:                        ASTName name = (ASTName) type.jjtGetFirstChild();
4513:                        Token tok = name.getSpecial("id0");
4514:                        name.removeSpecial("id0");
4515:                        return tok;
4516:                    }
4517:                } else {
4518:                    //  No farther to go - return the token
4519:                    Token tok = top.getSpecial("primitive");
4520:                    top.removeSpecial("primitive");
4521:                    return tok;
4522:                }
4523:            }
4524:
4525:            /**
4526:             *  Check the initial token, and removes it from the object.
4527:             *
4528:             * @param  top  the type
4529:             * @return      the initial token
4530:             */
4531:            private Token getInitialToken(ASTType top) {
4532:                if (top.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
4533:                    ASTPrimitiveType primitiveType = (ASTPrimitiveType) top
4534:                            .jjtGetFirstChild();
4535:                    Token tok = primitiveType.getSpecial("primitive");
4536:                    primitiveType.removeSpecial("primitive");
4537:                    return tok;
4538:                } else if (top.jjtGetFirstChild() instanceof  ASTReferenceType) {
4539:                    ASTReferenceType reference = (ASTReferenceType) top
4540:                            .jjtGetFirstChild();
4541:                    if (reference.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
4542:                        ASTPrimitiveType primitiveType = (ASTPrimitiveType) reference
4543:                                .jjtGetFirstChild();
4544:                        Token tok = primitiveType.getSpecial("primitive");
4545:                        primitiveType.removeSpecial("primitive");
4546:                        return tok;
4547:                    } else if (reference.jjtGetFirstChild() instanceof  ASTClassOrInterfaceType) {
4548:                        ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) reference
4549:                                .jjtGetFirstChild();
4550:                        ASTIdentifier ident = (ASTIdentifier) name
4551:                                .jjtGetFirstChild();
4552:                        Token tok = ident.getSpecial("id");
4553:                        ident.removeSpecial("id");
4554:                        return tok;
4555:                    } else {
4556:                        // FIXME: we get a CompilationUnit which is suprising as a child of a ASTReferenceType
4557:                        //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: top="+top.getName());
4558:                        //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: reference="+reference.getName());
4559:                        //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: reference.jjtGetFirstChild()="+reference.jjtGetFirstChild());
4560:                        //System.out.println("PrettyPrintVisitor.getInitialToken: ERROR: reference.jjtGetFirstChild()="+((SimpleNode)reference.jjtGetFirstChild()).getName());
4561:                        return null;
4562:                    }
4563:                } else {
4564:                    ASTName name = (ASTName) top.jjtGetFirstChild();
4565:                    Token tok = name.getSpecial("id0");
4566:                    name.removeSpecial("id0");
4567:                    return tok;
4568:                }
4569:            }
4570:
4571:            /**
4572:             *  Gets the commentsPresent attribute of the PrettyPrintVisitor object
4573:             *
4574:             * @param  node  Description of the Parameter
4575:             * @return       The commentsPresent value
4576:             */
4577:            private boolean isCommentsPresent(ASTBlock node) {
4578:                Token tok = node.getSpecial("end");
4579:                if (tok == null) {
4580:                    return false;
4581:                }
4582:
4583:                //  Find the first token
4584:                Token current = tok;
4585:                Token previous = tok.specialToken;
4586:                int type;
4587:                while (previous != null) {
4588:                    type = current.kind;
4589:                    if ((type < 5) || (type > 7)) {
4590:                        return true;
4591:                    }
4592:                    current = previous;
4593:                    previous = current.specialToken;
4594:                }
4595:
4596:                //  Return the first
4597:                type = current.kind;
4598:                return ((type < 5) || (type > 7));
4599:            }
4600:
4601:            /**
4602:             *  Gets the ifStatement attribute of the PrettyPrintVisitor object
4603:             *
4604:             * @param  node  Description of the Parameter
4605:             * @return       The ifStatement value
4606:             */
4607:            private boolean isIfStatement(Node node) {
4608:                if (node.jjtGetFirstChild() instanceof  ASTBlock) {
4609:                    ASTBlock block = (ASTBlock) node.jjtGetFirstChild();
4610:                    if (block.jjtGetNumChildren() < 1) {
4611:                        return false;
4612:                    }
4613:                    ASTBlockStatement blockStatement = (ASTBlockStatement) block
4614:                            .jjtGetFirstChild();
4615:                    if (blockStatement.jjtGetFirstChild() instanceof  ASTStatement) {
4616:                        ASTStatement statement = (ASTStatement) blockStatement
4617:                                .jjtGetFirstChild();
4618:                        return (statement.jjtGetFirstChild() instanceof  ASTIfStatement);
4619:                    }
4620:                }
4621:
4622:                return false;
4623:            }
4624:
4625:            /**
4626:             *  Gets the ifStatement attribute of the PrettyPrintVisitor object
4627:             *
4628:             * @param  node  Description of the Parameter
4629:             * @return       The ifStatement value
4630:             * @since        JRefactory 2.7.00
4631:             */
4632:            private boolean isIfStatementWithElse(Node node) {
4633:                if (node.jjtGetFirstChild() instanceof  ASTBlock) {
4634:                    ASTBlock block = (ASTBlock) node.jjtGetFirstChild();
4635:                    ASTBlockStatement blockStatement = (ASTBlockStatement) block
4636:                            .jjtGetFirstChild();
4637:                    if (blockStatement.jjtGetFirstChild() instanceof  ASTStatement) {
4638:                        ASTStatement statement = (ASTStatement) blockStatement
4639:                                .jjtGetFirstChild();
4640:                        if (statement.jjtGetFirstChild() instanceof  ASTIfStatement) {
4641:                            ASTIfStatement ifstatement = (ASTIfStatement) statement
4642:                                    .jjtGetFirstChild();
4643:                            return (ifstatement.jjtGetNumChildren() == 3);
4644:                        }
4645:                    }
4646:                }
4647:
4648:                return true;
4649:            }
4650:
4651:            /**
4652:             *  Determine if the node is a field or a method in an anonymous class
4653:             *
4654:             * @param  node  The node in question
4655:             * @return       true if the node is in an anonymous class
4656:             */
4657:            private boolean isInAnonymousClass(Node node) {
4658:                return (node.jjtGetParent().jjtGetParent().jjtGetParent() instanceof  ASTAllocationExpression);
4659:            }
4660:
4661:            /**
4662:             *  Determine if the node is a field or a method in an anonymous class
4663:             *
4664:             * @param  node  The node in question
4665:             * @return       true if the node is in an anonymous class
4666:             */
4667:            private boolean isInInnerClass(Node node) {
4668:                Node greatGreatGrandparent = node.jjtGetParent().jjtGetParent()
4669:                        .jjtGetParent().jjtGetParent();
4670:
4671:                boolean topLevelClass = (greatGreatGrandparent instanceof  ASTClassDeclaration);
4672:                boolean topLevelInterface = (greatGreatGrandparent instanceof  ASTInterfaceDeclaration);
4673:
4674:                return !topLevelClass && !topLevelInterface;
4675:            }
4676:
4677:            /**
4678:             *  Determine if the class is an inner class
4679:             *
4680:             * @param  node  Description of Parameter
4681:             * @return       The InnerClass value
4682:             */
4683:            private boolean isInnerClass(Node node) {
4684:                return (node instanceof  ASTNestedClassDeclaration)
4685:                        || (node instanceof  ASTNestedInterfaceDeclaration);
4686:            }
4687:
4688:            /**
4689:             *  Gets the JavadocRequired attribute of the PrettyPrintVisitor object
4690:             *
4691:             * @param  node       Description of Parameter
4692:             * @param  printData  Description of Parameter
4693:             * @return            The JavadocRequired value
4694:             */
4695:            private boolean isJavadocRequired(SimpleNode node,
4696:                    PrintData printData) {
4697:                if (printData.isNestedClassDocumented()) {
4698:                    return node.isRequired() && !isInAnonymousClass(node);
4699:                } else {
4700:                    return node.isRequired() && !isInAnonymousClass(node)
4701:                            && !isInInnerClass(node) && !isInnerClass(node);
4702:                }
4703:            }
4704:
4705:            /**
4706:             *  Gets the JavadocRequired attribute of the PrettyPrintVisitor object
4707:             *
4708:             * @param  node       Description of Parameter
4709:             * @param  printData  Description of Parameter
4710:             * @return            The JavadocRequired value
4711:             */
4712:            private boolean isJavadocRequired(JavaDocable jdi, SimpleNode node,
4713:                    PrintData printData) {
4714:                if (printData.isNestedClassDocumented()) {
4715:                    return jdi.isRequired() && !isInAnonymousClass(node);
4716:                } else {
4717:                    return jdi.isRequired() && !isInAnonymousClass(node)
4718:                            && !isInInnerClass(node) && !isInnerClass(node);
4719:                }
4720:            }
4721:
4722:            /**
4723:             *  Gets the lastLocalVariable attribute of the PrettyPrintVisitor object
4724:             *
4725:             * @param  node  Description of the Parameter
4726:             * @return       The lastLocalVariable value
4727:             */
4728:            private boolean isLastLocalVariable(ASTBlockStatement node) {
4729:                Node parent = node.jjtGetParent();
4730:                int last = parent.jjtGetNumChildren();
4731:                return isNeighborLV(parent, node, 1, last, -1);
4732:            }
4733:
4734:            /**
4735:             *  Gets the neighborLV attribute of the PrettyPrintVisitor object
4736:             *
4737:             * @param  parent     Description of the Parameter
4738:             * @param  node       Description of the Parameter
4739:             * @param  first      Description of the Parameter
4740:             * @param  last       Description of the Parameter
4741:             * @param  direction  Description of the Parameter
4742:             * @return            The neighborLV value
4743:             */
4744:            private boolean isNeighborLV(Node parent, Node node, int first,
4745:                    int last, int direction) {
4746:                for (int ndx = first; ndx < last; ndx++) {
4747:                    if (parent.jjtGetChild(ndx) == node) {
4748:                        Node next = parent.jjtGetChild(ndx + direction);
4749:                        if (next instanceof  ASTBlockStatement) {
4750:                            return (next.jjtGetFirstChild() instanceof  ASTLocalVariableDeclaration);
4751:                        }
4752:                        return true;
4753:                    }
4754:                }
4755:                return true;
4756:            }
4757:
4758:            /**
4759:             *  Gets the nextLocalVariable attribute of the PrettyPrintVisitor object
4760:             *
4761:             * @param  node  Description of the Parameter
4762:             * @return       The nextLocalVariable value
4763:             */
4764:            private boolean isNextLocalVariable(ASTBlockStatement node) {
4765:                Node parent = node.jjtGetParent();
4766:                int last = parent.jjtGetNumChildren() - 1;
4767:                return isNeighborLV(parent, node, 0, last, 1);
4768:            }
4769:
4770:            /**
4771:             *  The rules to determine if we should indent before the block are a little more complex if we are allowed not to
4772:             *  force a block statement around the body of the then part.
4773:             *
4774:             * @param  printData  Description of the Parameter
4775:             * @param  node       Description of the Parameter
4776:             * @return            The shouldIndentBeforeElse value
4777:             */
4778:            private boolean isShouldIndentBeforeElse(PrintData printData,
4779:                    ASTIfStatement node) {
4780:                if (printData.isElseOnNewLine()) {
4781:                    return true;
4782:                }
4783:
4784:                if (printData.isForcingBlock()
4785:                        || (node.jjtGetChild(1) instanceof  ASTBlock)) {
4786:                    return false;
4787:                }
4788:
4789:                return true;
4790:            }
4791:
4792:            /**
4793:             *  Gets the thisBlockRequired attribute of the PrettyPrintVisitor object
4794:             *
4795:             * @param  canRemoveBlock  Description of the Parameter
4796:             * @param  node            Description of the Parameter
4797:             * @return                 The thisBlockRequired value
4798:             */
4799:            private boolean isThisBlockRequired(boolean canRemoveBlock,
4800:                    Node node) {
4801:                if (!canRemoveBlock) {
4802:                    return true;
4803:                }
4804:
4805:                return (node.jjtGetFirstChild().jjtGetNumChildren() > 1);
4806:            }
4807:
4808:            /**
4809:             *  Processes a block object
4810:             *
4811:             * @param  node       Description of Parameter
4812:             * @param  printData  Description of Parameter
4813:             * @param  newline    Description of Parameter
4814:             */
4815:            private void blockProcess(ASTBlock node, PrintData printData,
4816:                    boolean newline) {
4817:                blockProcess(node, printData, newline, true);
4818:            }
4819:
4820:            /**
4821:             *  Processes a block object
4822:             *
4823:             * @param  node       Description of Parameter
4824:             * @param  printData  Description of Parameter
4825:             * @param  newline    Description of Parameter
4826:             * @param  space      Description of Parameter
4827:             */
4828:            private void blockProcess(ASTBlock node, PrintData printData,
4829:                    boolean newline, boolean space) {
4830:                boolean onSingleLine = (node.jjtGetNumChildren() > 0)
4831:                        ||
4832:                        // REVISIT: should be == 0
4833:                        !printData.isEmptyBlockOnSingleLine()
4834:                        || (node.getSpecial("end") != null)
4835:                        || (node.getSpecial("begin") != null);
4836:
4837:                LocalVariableLookAhead lvla = new LocalVariableLookAhead();
4838:                FieldSize size = lvla.run(node);
4839:                size.update(printData.getDynamicFieldSpaces());
4840:                printData.pushFieldSize(size);
4841:
4842:                //  Start the block
4843:                printData.beginBlock(space, onSingleLine);
4844:                jjtAcceptSpecial(node, printData, "begin", false);
4845:
4846:                // If this is a multistatement method body, then check whether to print a beginning line
4847:                if (printData.isLineBeforeMultistatementMethodBody()
4848:                        && (node.jjtGetParent() instanceof  ASTMethodDeclaration)
4849:                        && (node.jjtGetNumChildren() > 1)
4850:                        && (printData.getMethodBlockStyle() == PrintData.BLOCK_STYLE_C)) {
4851:                    printData.newline();
4852:                }
4853:
4854:                //  Traverse the children
4855:                node.childrenAccept(this , printData);
4856:
4857:                //  Finish the block
4858:                jjtAcceptSpecial(node, printData, "end");
4859:
4860:                if (node.jjtGetParent() instanceof  ASTMethodDeclaration) {
4861:                    printData.methodBrace();
4862:                }
4863:                printData.endBlock(newline, onSingleLine);
4864:
4865:                printData.popFieldSize();
4866:            }
4867:
4868:            /**
4869:             *  Loads the footer
4870:             *
4871:             * @param  printData  where we are printing to
4872:             * @return            Description of the Return Value
4873:             */
4874:            private boolean loadFooter(PrintData printData) {
4875:                boolean foundSomething = false;
4876:                try {
4877:                    FileSettings settings = FileSettings
4878:                            .getRefactoryPrettySettings();
4879:                    String temp = settings.getString("footer.1");
4880:
4881:                    foundSomething = true;
4882:
4883:                    int ndx = 1;
4884:                    while (true) {
4885:                        String nextLine = settings.getString("footer." + ndx);
4886:                        printData.appendComment(nextLine,
4887:                                PrintData.C_STYLE_COMMENT);
4888:                        printData.newline();
4889:                        ndx++;
4890:                    }
4891:                } catch (MissingSettingsException mse) {
4892:                }
4893:
4894:                return foundSomething;
4895:            }
4896:
4897:            /**
4898:             *  Loads the header
4899:             *
4900:             * @param  node       the compilation unit
4901:             * @param  printData  where we are printing to
4902:             */
4903:            private void loadHeader(ASTCompilationUnit node, PrintData printData) {
4904:                if (node == null) {
4905:                    return;
4906:                }
4907:
4908:                try {
4909:                    FileSettings settings = FileSettings
4910:                            .getRefactoryPrettySettings();
4911:                    String temp = settings.getString("header.1");
4912:
4913:                    /*
4914:                     *  That would throw an exception if there wasn't a header.
4915:                     *  So now we are free to delete things out of the child node
4916:                     */
4917:                    SimpleNode child = (SimpleNode) node.jjtGetFirstChild();
4918:                    if (child == null) {
4919:                        return;
4920:                    } else if (child instanceof  ASTPackageDeclaration) {
4921:                        child.removeSpecial("package");
4922:                    } else if (child instanceof  ASTImportDeclaration) {
4923:                        child.removeSpecial("import");
4924:                    } else {
4925:                        //  The first thing is a type declaration - you're on your own
4926:                        return;
4927:                    }
4928:
4929:                    int ndx = 1;
4930:                    while (true) {
4931:                        String nextLine = settings.getString("header." + ndx);
4932:                        printData.appendComment(nextLine,
4933:                                PrintData.C_STYLE_COMMENT);
4934:                        printData.newline();
4935:                        ndx++;
4936:                    }
4937:                } catch (MissingSettingsException mse) {
4938:                }
4939:            }
4940:
4941:            /**
4942:             *  Determines if we should indent the statement that is contained in the switch statement.
4943:             *
4944:             * @param  next  the next node
4945:             * @return       true if we should use the indent
4946:             */
4947:            private boolean shouldIndentSwitchBody(Node next) {
4948:                Node child = next.jjtGetFirstChild();
4949:                if (child instanceof  ASTStatement) {
4950:                    Node grandchild = child.jjtGetFirstChild();
4951:                    if (grandchild instanceof  ASTBlock) {
4952:                        return false;
4953:                    }
4954:                }
4955:                return true;
4956:            }
4957:
4958:            /**
4959:             *  The standard field indent
4960:             *
4961:             * @param  printData  Description of Parameter
4962:             */
4963:            private void standardFieldIndent(PrintData printData) {
4964:                printData.space();
4965:
4966:                if (printData.isFieldNameIndented()) {
4967:                    int currentLength = printData.getLineLength();
4968:                    int desiredLength = printData.getFieldNameIndent();
4969:                    for (int ndx = currentLength; ndx < desiredLength; ndx++) {
4970:                        printData.space();
4971:                    }
4972:                }
4973:            }
4974:
4975:            /**
4976:             *  Description of the Method
4977:             *
4978:             * @param  node       Description of Parameter
4979:             * @param  printData  Description of Parameter
4980:             * @param  specials   Description of Parameter
4981:             */
4982:            private void jjtAcceptSpecials(SimpleNode node,
4983:                    PrintData printData, String[] specials) {
4984:                for (int i = 0; i < specials.length; i++) {
4985:                    node.jjtAccept(specialTokenVisitor, new SpecialTokenData(
4986:                            node.getSpecial(specials[i]), printData));
4987:                }
4988:            }
4989:
4990:            /**
4991:             *  Description of the Method
4992:             *
4993:             * @param  node       Description of Parameter
4994:             * @param  printData  Description of Parameter
4995:             * @param  specials   Description of Parameter
4996:             */
4997:            private void jjtAcceptSpecials(JavaDocable jdi, SimpleNode node,
4998:                    PrintData printData, String[] specials) {
4999:                for (int i = 0; i < specials.length; i++) {
5000:                    node.jjtAccept(specialTokenVisitor, new SpecialTokenData(
5001:                            jdi, node.getSpecial(specials[i]), printData));
5002:                }
5003:            }
5004:
5005:            /**
5006:             *  Description of the Method
5007:             *
5008:             * @param  node       Description of Parameter
5009:             * @param  printData  Description of Parameter
5010:             * @param  special    Description of Parameter
5011:             */
5012:            private void jjtAcceptSpecial(SimpleNode node, PrintData printData,
5013:                    String special) {
5014:                node.jjtAccept(specialTokenVisitor, new SpecialTokenData(node
5015:                        .getSpecial(special), printData));
5016:            }
5017:
5018:            /**
5019:             *  Description of the Method
5020:             *
5021:             * @param  node       Description of Parameter
5022:             * @param  printData  Description of Parameter
5023:             * @param  special    Description of Parameter
5024:             * @param  newline    Description of Parameter
5025:             */
5026:            private void jjtAcceptSpecial(SimpleNode node, PrintData printData,
5027:                    String special, boolean newline) {
5028:                node.jjtAccept(specialTokenVisitor, new SpecialTokenData(node
5029:                        .getSpecial(special), printData, newline));
5030:            }
5031:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.