Source Code Cross Referenced for PrettyPrinter.java in  » Testing » KeY » de » uka » ilkd » key » java » 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 » Testing » KeY » de.uka.ilkd.key.java 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // This file is part of KeY - Integrated Deductive Software Design
0002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
0003:        //                         Universitaet Koblenz-Landau, Germany
0004:        //                         Chalmers University of Technology, Sweden
0005:        //
0006:        // The KeY system is protected by the GNU General Public License. 
0007:        // See LICENSE.TXT for details.
0008:        //
0009:        //
0010:
0011:        package de.uka.ilkd.key.java;
0012:
0013:        import java.io.IOException;
0014:        import java.io.Writer;
0015:        import java.util.HashMap;
0016:        import java.util.LinkedList;
0017:
0018:        import org.apache.log4j.Logger;
0019:
0020:        import de.uka.ilkd.key.java.abstraction.ArrayType;
0021:        import de.uka.ilkd.key.java.abstraction.Type;
0022:        import de.uka.ilkd.key.java.declaration.*;
0023:        import de.uka.ilkd.key.java.declaration.modifier.Final;
0024:        import de.uka.ilkd.key.java.declaration.modifier.Private;
0025:        import de.uka.ilkd.key.java.declaration.modifier.Protected;
0026:        import de.uka.ilkd.key.java.declaration.modifier.Public;
0027:        import de.uka.ilkd.key.java.expression.*;
0028:        import de.uka.ilkd.key.java.expression.Operator;
0029:        import de.uka.ilkd.key.java.expression.literal.*;
0030:        import de.uka.ilkd.key.java.expression.operator.*;
0031:        import de.uka.ilkd.key.java.reference.*;
0032:        import de.uka.ilkd.key.java.statement.*;
0033:        import de.uka.ilkd.key.logic.ProgramElementName;
0034:        import de.uka.ilkd.key.logic.op.*;
0035:        import de.uka.ilkd.key.pp.Range;
0036:        import de.uka.ilkd.key.rule.inst.SVInstantiations;
0037:        import de.uka.ilkd.key.rule.metaconstruct.ProgramMetaConstruct;
0038:        import de.uka.ilkd.key.rule.soundness.ProgramSVProxy;
0039:        import de.uka.ilkd.key.util.Debug;
0040:
0041:        /**
0042:         A configurable pretty printer for Java source elements originally from COMPOST.
0043:
0044:         @author AL
0045:        
0046:         CHANGED FOR KeY. Comments are not printed!
0047:         */
0048:        public class PrettyPrinter {
0049:
0050:            /**
0051:               Line number, not directly used.
0052:             */
0053:            private int line = 0;
0054:
0055:            /**
0056:               Column number. Used to keep track of indentations.
0057:             */
0058:            private int column = 0;
0059:
0060:            /**
0061:               Level.
0062:             */
0063:            protected int level = 0;
0064:            protected Writer out;
0065:            protected StringBuffer outBuf;
0066:            protected boolean noLinefeed = false;
0067:            protected boolean noSemicolons = false;
0068:            protected boolean fileWriterMode = false; //enfoces the output of real Java syntax that can be compiled.
0069:            protected Type classToPrint = null;
0070:
0071:            protected int firstStatementStart = -1;
0072:            protected int firstStatementEnd = -1;
0073:            protected boolean startAlreadyMarked = false;
0074:            protected boolean endAlreadyMarked = false;
0075:            protected Object firstStatement = null;
0076:            protected SVInstantiations instantiations = SVInstantiations.EMPTY_SVINSTANTIATIONS;
0077:            static Logger logger = Logger.getLogger(PrettyPrinter.class
0078:                    .getName());
0079:
0080:            /** creates a new PrettyPrinter */
0081:            public PrettyPrinter(Writer o) {
0082:                setWriter(o);
0083:                outBuf = new StringBuffer();
0084:            }
0085:
0086:            public PrettyPrinter(Writer o, boolean noLinefeed,
0087:                    boolean fileWriterMode) {
0088:                this (o, noLinefeed);
0089:                this .fileWriterMode = fileWriterMode;
0090:            }
0091:
0092:            public PrettyPrinter(Writer o, SVInstantiations svi) {
0093:                this (o);
0094:                this .instantiations = svi;
0095:            }
0096:
0097:            public PrettyPrinter(Writer o, boolean noLinefeed) {
0098:                this (o);
0099:                this .noLinefeed = noLinefeed;
0100:            }
0101:
0102:            public PrettyPrinter(Writer o, boolean noLinefeed,
0103:                    SVInstantiations svi) {
0104:                this (o, noLinefeed);
0105:                this .instantiations = svi;
0106:            }
0107:
0108:            /** The number of charcters that have been send to the writer */
0109:            protected int writtenCharacters = 0;
0110:
0111:            protected void output() throws IOException {
0112:                if (noSemicolons)
0113:                    removeChar(outBuf, ';');
0114:                if (noLinefeed)
0115:                    removeChar(outBuf, '\n');
0116:                String toWrite = outBuf.toString();
0117:                writtenCharacters += toWrite.length();
0118:                out.write(toWrite);
0119:                outBuf = new StringBuffer();
0120:
0121:            }
0122:
0123:            /** Numbers of generated characters */
0124:            protected int getCurrentPos() {
0125:                return writtenCharacters + outBuf.length();
0126:            }
0127:
0128:            /**
0129:             * Marks the start of the first executable statement ...
0130:             * @param n offset from the current position
0131:             * @param stmt current statement;
0132:             */
0133:            protected void markStart(int n, Object stmt) {
0134:                if (!startAlreadyMarked) {
0135:
0136:                    // System.err.println("Mark start ... called");
0137:
0138:                    firstStatementStart = getCurrentPos() + n;
0139:                    firstStatement = stmt;
0140:                    startAlreadyMarked = true;
0141:                }
0142:            }
0143:
0144:            /**
0145:             * Marks the end of the first executable statement ...
0146:             * @param n offset from the current position
0147:             */
0148:            protected void markEnd(int n, Object stmt) {
0149:                if (!endAlreadyMarked && (firstStatement == stmt)) {
0150:
0151:                    //  System.err.println("Mark end ... called ");
0152:
0153:                    firstStatementEnd = getCurrentPos() + n;
0154:                    endAlreadyMarked = true;
0155:                }
0156:            }
0157:
0158:            /**
0159:             * @return the range of the first executable statement that means
0160:             * the corresponding start and end position in the string representation
0161:             */
0162:            public Range getRangeOfFirstExecutableStatement() {
0163:                return new Range(firstStatementStart, firstStatementEnd);
0164:            }
0165:
0166:            /**
0167:             * Resets the state of this pretty printer ...
0168:             */
0169:            public void reset() {
0170:                firstStatementStart = -1;
0171:                firstStatementEnd = -1;
0172:                firstStatement = null;
0173:                startAlreadyMarked = false;
0174:                endAlreadyMarked = false;
0175:                writtenCharacters = 0;
0176:                outBuf = new StringBuffer();
0177:            }
0178:
0179:            /**
0180:               Flag to indicate if a single line comment is being put out.
0181:               Needed to disable the worklist meanwhile.
0182:             */
0183:            private boolean isPrintingSingleLineComments = false;
0184:
0185:            private HashMap indentMap = new HashMap();
0186:
0187:            /**
0188:               Set a new stream to write to. Useful to redirect the output
0189:               while retaining all other settings. Resets the current source
0190:               positions and comments.
0191:             */
0192:            public void setWriter(Writer out) {
0193:                this .out = out;
0194:                column = 0;
0195:                line = 0;
0196:            }
0197:
0198:            /**
0199:               Get current line number.
0200:               @return the line number, starting with 0.
0201:             */
0202:            public int getLine() {
0203:                return line;
0204:            }
0205:
0206:            /**
0207:               Get current column number.
0208:               @return the column number, starting with 0.
0209:             */
0210:            public int getColumn() {
0211:                return column;
0212:            }
0213:
0214:            /**
0215:               Get indentation level.
0216:               @return the int value.
0217:             */
0218:            public int getIndentationLevel() {
0219:                return level;
0220:            }
0221:
0222:            /**
0223:               Set indentation level.
0224:               @param level an int value.
0225:             */
0226:            public void setIndentationLevel(int level) {
0227:                this .level = level;
0228:            }
0229:
0230:            /**
0231:               Get total indentation.
0232:               @return the int value.
0233:             */
0234:            public int getTotalIndentation() {
0235:                return indentation * level;
0236:            }
0237:
0238:            /**
0239:               Change level.
0240:               @param delta an int value.
0241:             */
0242:            public void changeLevel(int delta) {
0243:                level += delta;
0244:            }
0245:
0246:            private static char[] BLANKS = new char[128];
0247:
0248:            private static char[] FEEDS = new char[8];
0249:
0250:            static {
0251:                for (int i = 0; i < FEEDS.length; i++) {
0252:                    FEEDS[i] = '\n';
0253:                }
0254:                for (int i = 0; i < BLANKS.length; i++) {
0255:                    BLANKS[i] = ' ';
0256:                }
0257:            }
0258:
0259:            /**
0260:               Convenience method to write indentation chars.
0261:             */
0262:            protected void writeIndentation(int lf, int blanks)
0263:                    throws IOException {
0264:                if (!noLinefeed) {
0265:                    if (lf > 0) {
0266:                        do {
0267:                            int n = Math.min(lf, FEEDS.length);
0268:                            write(FEEDS, 0, n);
0269:                            lf -= n;
0270:                        } while (lf > 0);
0271:                    }
0272:                    while (blanks > 0) {
0273:                        int n = Math.min(blanks, BLANKS.length);
0274:                        write(BLANKS, 0, n);
0275:                        blanks -= n;
0276:                    }
0277:                }
0278:            }
0279:
0280:            /**
0281:               Convenience method to write indentation chars.
0282:             */
0283:            protected void writeIndentation(Position relative)
0284:                    throws IOException {
0285:                writeIndentation(relative.getLine(), relative.getColumn());
0286:            }
0287:
0288:            /**
0289:               Write indentation.
0290:               @param elem a source element.
0291:               @exception IOException occasionally thrown.
0292:             */
0293:            protected void writeIndentation(SourceElement elem)
0294:                    throws IOException {
0295:                writeIndentation(getRelativePosition(elem.getFirstElement()));
0296:            }
0297:
0298:            /**
0299:               Write internal indentation.
0300:               @param elem a source element.
0301:               @exception IOException occasionally thrown.
0302:             */
0303:            protected void writeInternalIndentation(SourceElement elem)
0304:                    throws IOException {
0305:                writeIndentation(getRelativePosition(elem));
0306:            }
0307:
0308:            /**
0309:               Write symbol.
0310:               @param lf an int value.
0311:               @param levelChange an int value.
0312:               @param symbol a string.
0313:               @exception IOException occasionally thrown.
0314:             */
0315:            protected void writeSymbol(int lf, int levelChange, String symbol)
0316:                    throws IOException {
0317:                level += levelChange;
0318:                writeIndentation(lf, getTotalIndentation());
0319:                write(symbol);
0320:            }
0321:
0322:            /**
0323:               Replace all unicode characters above ?
0324:               by their explicite representation.
0325:               @param str the input string.
0326:               @return the encoded string.
0327:             */
0328:            protected static String encodeUnicodeChars(String str) {
0329:                int len = str.length();
0330:                StringBuffer buf = new StringBuffer(len + 4);
0331:                for (int i = 0; i < len; i += 1) {
0332:                    char c = str.charAt(i);
0333:                    if (c >= 0x0100) {
0334:                        if (c < 0x1000) {
0335:                            buf.append("\\u0" + Integer.toString(c, 16));
0336:                        } else {
0337:                            buf.append("\\u" + Integer.toString(c, 16));
0338:                        }
0339:                    } else {
0340:                        buf.append(c);
0341:                    }
0342:                }
0343:                return buf.toString();
0344:            }
0345:
0346:            /**
0347:               Store the given comment until the next line feed is written.
0348:               @param slc the comment to delay.
0349:             */
0350:            protected void scheduleComment(SingleLineComment slc) {
0351:            }
0352:
0353:            /**
0354:               Adds indentation for a program element if necessary and if required,
0355:               but does not print the indentation itself.       
0356:             */
0357:            protected void writeElement(int lf, int levelChange, int blanks,
0358:                    SourceElement elem) throws IOException {
0359:                level += levelChange;
0360:                if (lf > 0) {
0361:                    blanks += getTotalIndentation();
0362:                }
0363:                SourceElement first = elem.getFirstElement();
0364:                Position indent = getRelativePosition(first);
0365:                if (indent == Position.UNDEFINED) {
0366:                    indent = new Position(lf, blanks);
0367:                } else {
0368:                    if (lf > indent.getLine()) {
0369:                        indent = new Position(lf, indent.getColumn());
0370:                    }
0371:                    if (blanks > indent.getColumn()) {
0372:                        indent = new Position(indent.getLine(), blanks);
0373:                    }
0374:                }
0375:                indentMap.put(first, indent);
0376:                elem.prettyPrint(this );
0377:            }
0378:
0379:            private Position getRelativePosition(SourceElement first) {
0380:                //	System.out.println(indentMap);
0381:                if (indentMap.containsKey(first)) {
0382:                    return (Position) indentMap.get(first);
0383:                } else {
0384:                    if (first != null)
0385:                        return first.getRelativePosition();
0386:                    else
0387:                        return Position.UNDEFINED;
0388:                }
0389:            }
0390:
0391:            /**
0392:               Writes an implicit terminal token of a NonTerminal, including
0393:               its indentation. Sets the indentation if it is necessary or
0394:               required.
0395:               @see SourceElement#prettyPrint
0396:             */
0397:            protected void writeToken(int lf, int blanks, String image,
0398:                    NonTerminalProgramElement parent) throws IOException {
0399:                if (lf > 0) {
0400:                    blanks += getTotalIndentation();
0401:                }
0402:                Position indent = getRelativePosition(parent);
0403:                if (indent == Position.UNDEFINED) {
0404:                    indent = new Position(lf, blanks);
0405:                } else {
0406:                    if (lf > indent.getLine()) {
0407:                        indent = new Position(lf, indent.getColumn());
0408:                    }
0409:                    if (blanks > indent.getColumn()) {
0410:                        indent = new Position(indent.getLine(), blanks);
0411:                    }
0412:                }
0413:                indentMap.put(parent.getFirstElement(), indent); //needed ?????
0414:                writeIndentation(indent);
0415:                //	if (overwriteParsePositions) {
0416:                //	    parent.setInternalParsedLine(line);
0417:                //	    parent.setInternalParsedColumn(column);
0418:                //	}
0419:                write(image);
0420:            }
0421:
0422:            protected final void writeToken(int blanks, String image,
0423:                    NonTerminalProgramElement parent) throws IOException {
0424:                writeToken(0, blanks, image, parent);
0425:            }
0426:
0427:            protected final void writeToken(String image,
0428:                    NonTerminalProgramElement parent) throws IOException {
0429:                writeToken(0, 0, image, parent);
0430:            }
0431:
0432:            /**
0433:               Write a source element.
0434:               @param lf an int value.
0435:               @param blanks an int value.
0436:               @param elem a source element.
0437:               @exception IOException occasionally thrown.
0438:             */
0439:            protected void writeElement(int lf, int blanks, SourceElement elem)
0440:                    throws IOException {
0441:                writeElement(lf, 0, blanks, elem);
0442:            }
0443:
0444:            /**
0445:               Write source element.
0446:               @param blanks an int value.
0447:               @param elem a source element.
0448:               @exception IOException occasionally thrown.
0449:             */
0450:            protected void writeElement(int blanks, SourceElement elem)
0451:                    throws IOException {
0452:                writeElement(0, 0, blanks, elem);
0453:            }
0454:
0455:            /**
0456:               Write source element.
0457:               @param elem a source element.
0458:               @exception IOException occasionally thrown.
0459:             */
0460:            protected void writeElement(SourceElement elem) throws IOException {
0461:                writeElement(0, 0, 0, elem);
0462:            }
0463:
0464:            /**
0465:               Write a complete ArrayOfProgramElement.
0466:             */
0467:            protected void writeArrayOfProgramElement(int firstLF,
0468:                    int levelChange, int firstBlanks, String separationSymbol,
0469:                    int separationLF, int separationBlanks,
0470:                    ArrayOfProgramElement list) throws IOException {
0471:                int s = list.size();
0472:                if (s == 0) {
0473:                    return;
0474:                }
0475:                writeElement(firstLF, levelChange, firstBlanks, list
0476:                        .getProgramElement(0));
0477:                for (int i = 1; i < s; i += 1) {
0478:                    write(separationSymbol);
0479:                    writeElement(separationLF, separationBlanks, list
0480:                            .getProgramElement(i));
0481:                }
0482:            }
0483:
0484:            /**
0485:               Write a complete ArrayOfProgramElement using "Keyword" style.
0486:             */
0487:            protected void writeKeywordList(int firstLF, int levelChange,
0488:                    int firstBlanks, ArrayOfProgramElement list)
0489:                    throws IOException {
0490:                writeArrayOfProgramElement(firstLF, levelChange, firstBlanks,
0491:                        "", 0, 1, list);
0492:            }
0493:
0494:            /**
0495:               Write keyword list.
0496:               @param list a program element list.
0497:               @exception IOException occasionally thrown.
0498:             */
0499:            protected void writeKeywordList(ArrayOfProgramElement list)
0500:                    throws IOException {
0501:                writeArrayOfProgramElement(0, 0, 0, "", 0, 1, list);
0502:            }
0503:
0504:            /**
0505:               Write a complete ArrayOfProgramElement using "Comma" style.
0506:             */
0507:            protected void writeCommaList(int firstLF, int levelChange,
0508:                    int firstBlanks, ArrayOfProgramElement list)
0509:                    throws IOException {
0510:                writeArrayOfProgramElement(firstLF, levelChange, firstBlanks,
0511:                        ",", 0, 1, list);
0512:            }
0513:
0514:            /**
0515:               Write comma list.
0516:               @param list a program element list.
0517:               @exception IOException occasionally thrown.
0518:             */
0519:            protected void writeCommaList(int separationBlanks,
0520:                    ArrayOfProgramElement list) throws IOException {
0521:                writeArrayOfProgramElement(0, 0, 0, ",", 0, separationBlanks,
0522:                        list);
0523:            }
0524:
0525:            /**
0526:               Write comma list.
0527:               @param list a program element list.
0528:               @exception IOException occasionally thrown.
0529:             */
0530:            protected void writeCommaList(ArrayOfProgramElement list)
0531:                    throws IOException {
0532:                writeArrayOfProgramElement(0, 0, 0, ",", 0, 1, list);
0533:            }
0534:
0535:            /**
0536:               Write a complete ArrayOfProgramElement using "Line" style.
0537:             */
0538:            protected void writeLineList(int firstLF, int levelChange,
0539:                    int firstBlanks, ArrayOfProgramElement list)
0540:                    throws IOException {
0541:                writeArrayOfProgramElement(firstLF, levelChange, firstBlanks,
0542:                        "", 1, 0, list);
0543:            }
0544:
0545:            /**
0546:               Write line list.
0547:               @param list a program element list.
0548:               @exception IOException occasionally thrown.
0549:             */
0550:            protected void writeLineList(ArrayOfProgramElement list)
0551:                    throws IOException {
0552:                writeArrayOfProgramElement(0, 0, 0, "", 1, 0, list);
0553:            }
0554:
0555:            /**
0556:               Write a complete ArrayOfProgramElement using "Block" style.
0557:             */
0558:            protected void writeBlockList(int firstLF, int levelChange,
0559:                    int firstBlanks, ArrayOfProgramElement list)
0560:                    throws IOException {
0561:                writeArrayOfProgramElement(firstLF, levelChange, firstBlanks,
0562:                        "", 2, 0, list);
0563:            }
0564:
0565:            /**
0566:               Write block list.
0567:               @param list a program element list.
0568:               @exception IOException occasionally thrown.
0569:             */
0570:            protected void writeBlockList(ArrayOfProgramElement list)
0571:                    throws IOException {
0572:                writeArrayOfProgramElement(0, 0, 0, "", 2, 0, list);
0573:            }
0574:
0575:            private void dumpComments() throws IOException {
0576:            }
0577:
0578:            /**
0579:               Write.
0580:               @param c an int value.
0581:               @exception IOException occasionally thrown.
0582:             */
0583:            public void write(int c) throws IOException {
0584:                if (c == '\n') {
0585:                    if (!isPrintingSingleLineComments) {
0586:                        dumpComments();
0587:                    }
0588:                    column = 0;
0589:                    line += 1;
0590:                } else {
0591:                    column += 1;
0592:                }
0593:                outBuf.append(c);
0594:            }
0595:
0596:            /**
0597:               Write.
0598:               @param cbuf a char value.
0599:               @exception IOException occasionally thrown.
0600:             */
0601:            public void write(char[] cbuf) throws IOException {
0602:                write(cbuf, 0, cbuf.length);
0603:            }
0604:
0605:            /**
0606:               Write.
0607:               @param cbuf an array of char.
0608:               @param off an int value.
0609:               @param len an int value.
0610:               @exception IOException occasionally thrown.
0611:             */
0612:            public void write(char[] cbuf, int off, int len) throws IOException {
0613:                boolean col = false;
0614:
0615:                for (int i = off + len - 1; i >= off; i -= 1) {
0616:                    if (cbuf[i] == '\n') {
0617:                        if (!isPrintingSingleLineComments) {
0618:                            dumpComments();
0619:                        }
0620:                        line += 1;
0621:                        if (!col) {
0622:                            column = (off + len - 1 - i);
0623:                            col = true;
0624:                        }
0625:                    }
0626:                }
0627:                if (!col) {
0628:                    column += len;
0629:                    /*
0630:                      int i;
0631:                      for (i = off + len - 1; (i >= off && cbuf[i] != '\n'); i -= 1) ;
0632:                      column = (i >= off) ? (off + len - 1 - i) : (column + len);
0633:                     */
0634:                }
0635:                outBuf.append(cbuf, off, len);
0636:            }
0637:
0638:            /**
0639:               Write.
0640:               @param str a string.
0641:               @exception IOException occasionally thrown.
0642:             */
0643:            public void write(String str) throws IOException {
0644:                int i = str.lastIndexOf('\n');
0645:                if (i >= 0) {
0646:                    column = str.length() - i + 1;
0647:                    do {
0648:                        dumpComments();
0649:                        line += 1;
0650:                        i = str.lastIndexOf('\n', i - 1);
0651:                    } while (i >= 0);
0652:                } else {
0653:                    column += str.length();
0654:                }
0655:                outBuf.append(str);
0656:            }
0657:
0658:            /**
0659:               Write.
0660:               @param str a string.
0661:               @param off an int value.
0662:               @param len an int value.
0663:               @exception IOException occasionally thrown.
0664:             */
0665:            public void write(String str, int off, int len) throws IOException {
0666:                write(str.substring(off, off + len));
0667:            }
0668:
0669:            /**
0670:               Indentation (cached).
0671:             */
0672:            private int indentation = 2;
0673:
0674:            /*
0675:               Wrap threshold (cached).
0676:               private int wrap;
0677:             */
0678:
0679:            /**
0680:               Overwrite indentation flag (cached).
0681:             */
0682:            private boolean overwriteIndentation;
0683:
0684:            /**
0685:               Overwrite parse positions flag (cached).
0686:             */
0687:            private boolean overwriteParsePositions;
0688:
0689:            /**
0690:               Get indentation amount (blanks per level).
0691:               @return the value of getIntegerProperty("indentationAmount").
0692:             */
0693:            protected int getIndentation() {
0694:                return indentation;
0695:            }
0696:
0697:            /**
0698:               Returns true if the pretty printer should also reformat existing
0699:               code. 
0700:               @return the value of the overwriteIndentation property.
0701:             */
0702:            protected boolean isOverwritingIndentation() {
0703:                return overwriteIndentation;
0704:            }
0705:
0706:            /**
0707:               Returns true if the pretty printer should reset the parse positions
0708:               accordingly.
0709:               @return the value of the overwriteParsePositions property.
0710:             */
0711:            protected boolean isOverwritingParsePositions() {
0712:                return overwriteParsePositions;
0713:            }
0714:
0715:            /**
0716:               Print program element header.
0717:               @param lf an int value.
0718:               @param blanks an int value.
0719:               @param elem a program element.
0720:               @exception IOException occasionally thrown.
0721:             */
0722:            protected void printHeader(int lf, int blanks, ProgramElement elem)
0723:                    throws IOException {
0724:
0725:                printHeader(lf, 0, blanks, elem);
0726:            }
0727:
0728:            /**
0729:               Print program element header.
0730:               @param blanks an int value.
0731:               @param elem a program element.
0732:               @exception IOException occasionally thrown.
0733:             */
0734:            protected void printHeader(int blanks, ProgramElement elem)
0735:                    throws IOException {
0736:                printHeader(0, 0, blanks, elem);
0737:            }
0738:
0739:            /**
0740:               Print program element header.
0741:               @param elem a program element.
0742:               @exception IOException occasionally thrown.
0743:             */
0744:            protected void printHeader(ProgramElement elem) throws IOException {
0745:                printHeader(0, 0, 0, elem);
0746:            }
0747:
0748:            /**
0749:               Print program element header.
0750:               @param lf number of line feeds.
0751:               @param levelChange the level change.
0752:               @param blanks number of white spaces.
0753:               @param x the program element.
0754:               @exception IOException occasionally thrown.
0755:             */
0756:            protected void printHeader(int lf, int levelChange, int blanks,
0757:                    ProgramElement x) throws IOException {
0758:
0759:                level += levelChange;
0760:                if (lf > 0) {
0761:                    blanks += getTotalIndentation();
0762:                }
0763:                SourceElement first = x.getFirstElement();
0764:                Position indent = getRelativePosition(first);
0765:                if (indent == Position.UNDEFINED) {
0766:                    indent = new Position(lf, blanks);
0767:                } else {
0768:                    if (lf > indent.getLine()) {
0769:                        indent = new Position(lf, indent.getColumn());
0770:                    }
0771:                    if (blanks > indent.getColumn()) {
0772:                        indent = new Position(indent.getLine(), blanks);
0773:                    }
0774:                }
0775:                indentMap.put(first, indent);
0776:            }
0777:
0778:            /**
0779:               Print program element footer.
0780:               @param x the program element.
0781:               @exception IOException occasionally thrown.
0782:             */
0783:            protected void printFooter(ProgramElement x) throws IOException {
0784:                output();
0785:            }
0786:
0787:            protected void printOperator(Operator x, String symbol)
0788:                    throws java.io.IOException {
0789:
0790:                // Mark statement start ...
0791:                markStart(0, x);
0792:
0793:                ArrayOfExpression children = x.getArguments();
0794:                if (children != null) {
0795:                    //          boolean addParentheses = x.isToBeParenthesized();
0796:                    //          if (addParentheses) {
0797:                    //          write('(');
0798:                    //          }  //????
0799:
0800:                    if (!noLinefeed) {
0801:                        writeSymbol(1, 0, "");
0802:                    }
0803:                    output();
0804:
0805:                    boolean wasNoSemicolons = noSemicolons;
0806:                    boolean wasNoLinefeed = noLinefeed;
0807:                    noSemicolons = true;
0808:                    //	    noLinefeed=true;
0809:                    switch (x.getArity()) {
0810:                    case 2:
0811:                        noLinefeed = true;
0812:                        writeElement(0, children.getExpression(0));
0813:                        writeToken(0, symbol, x);
0814:                        output();
0815:                        writeElement(0, children.getExpression(1));
0816:                        break;
0817:                    case 1:
0818:                        switch (x.getNotation()) {
0819:                        case Operator.PREFIX:
0820:                            noLinefeed = true;
0821:                            writeToken(symbol, x);
0822:                            writeElement(0, children.getExpression(0));
0823:                            output();
0824:                            break;
0825:                        case Operator.POSTFIX:
0826:                            noLinefeed = true;
0827:                            writeElement(0, children.getExpression(0));
0828:                            writeToken(1, symbol, x);
0829:                            break;
0830:                        default:
0831:                            break;
0832:                        }
0833:                    }
0834:                    output();
0835:                    noSemicolons = wasNoSemicolons;
0836:                    noLinefeed = wasNoLinefeed;
0837:                    //           if (addParentheses) {
0838:                    //    write(')');
0839:                    // }   //???? as above
0840:                    if (x instanceof  Assignment) {
0841:                        // 		if (((Assignment)x).getStatementContainer() != null) {
0842:                        write(";"); //????
0843:
0844:                        // 		}
0845:                    }
0846:                    output();
0847:                    // Mark statement end ...
0848:                    markEnd(0, x);
0849:
0850:                    /*if (!noLinefeed) {
0851:                    writeSymbol(1,0, "");
0852:                    }*/
0853:                }
0854:            }
0855:
0856:            public void printProgramElementName(ProgramElementName x)
0857:                    throws java.io.IOException {
0858:
0859:                printHeader(x);
0860:                writeInternalIndentation(x);
0861:                write(x.getProgramName());
0862:                printFooter(x);
0863:            }
0864:
0865:            public void printProgramVariable(ProgramVariable x)
0866:                    throws java.io.IOException {
0867:
0868:                printHeader(x);
0869:                writeInternalIndentation(x);
0870:                if (fileWriterMode) {
0871:                    write(x.name().toString().substring(
0872:                            x.name().toString().lastIndexOf(":") + 1));
0873:                } else {
0874:                    write(x.name().toString());
0875:                }
0876:                printFooter(x);
0877:            }
0878:
0879:            public void printProgramMethod(ProgramMethod x)
0880:                    throws java.io.IOException {
0881:
0882:                printHeader(x);
0883:                writeInternalIndentation(x);
0884:                write(x.getMethodDeclaration().getProgramElementName()
0885:                        .toString());
0886:                printFooter(x);
0887:            }
0888:
0889:            public void printProgramMetaConstruct(ProgramMetaConstruct x)
0890:                    throws java.io.IOException {
0891:                printHeader(x);
0892:                write(x.name().toString());
0893:                writeToken("(", x);
0894:                boolean oldNoLinefeed = noLinefeed;
0895:                noLinefeed = true;
0896:                if (x.getChildAt(0) != null) {
0897:                    writeElement(1, +1, 0, x.getChildAt(0));
0898:                    writeSymbol(1, -1, ")");
0899:                } else {
0900:                    write(")");
0901:                }
0902:                noLinefeed = oldNoLinefeed;
0903:                printFooter(x);
0904:            }
0905:
0906:            public void printContextStatementBlock(ContextStatementBlock x)
0907:                    throws java.io.IOException {
0908:                printHeader(x);
0909:
0910:                if (x.getStatementCount() > 0) {
0911:                    writeToken("{ .. ", x);
0912:                    writeLineList(1, +1, 0, x.getBody());
0913:                    writeSymbol(1, -1, " ... }");
0914:                } else {
0915:                    markStart(0, x);
0916:                    writeToken("{ .. ", x);
0917:                    write(" ... }");
0918:                    markEnd(0, x);
0919:                }
0920:                printFooter(x);
0921:            }
0922:
0923:            public void printIntLiteral(IntLiteral x)
0924:                    throws java.io.IOException {
0925:                printHeader(x);
0926:                writeInternalIndentation(x);
0927:                write(x.getValue());
0928:                printFooter(x);
0929:            }
0930:
0931:            public void printBooleanLiteral(BooleanLiteral x)
0932:                    throws java.io.IOException {
0933:                printHeader(x);
0934:                writeInternalIndentation(x);
0935:                write(x.getValue() ? "true" : "false");
0936:                printFooter(x);
0937:            }
0938:
0939:            public void printStringLiteral(StringLiteral x)
0940:                    throws java.io.IOException {
0941:                printHeader(x);
0942:                writeInternalIndentation(x);
0943:                if (fileWriterMode
0944:                        && !encodeUnicodeChars(x.getValue()).startsWith("\"")) {
0945:                    write("\"");
0946:                }
0947:                write(encodeUnicodeChars(x.getValue()));
0948:                if (fileWriterMode
0949:                        && !encodeUnicodeChars(x.getValue()).startsWith("\"")) {
0950:                    write("\"");
0951:                }
0952:                printFooter(x);
0953:            }
0954:
0955:            public void printNullLiteral(NullLiteral x)
0956:                    throws java.io.IOException {
0957:                printHeader(x);
0958:                writeInternalIndentation(x);
0959:                write("null");
0960:                printFooter(x);
0961:            }
0962:
0963:            public void printCharLiteral(CharLiteral x)
0964:                    throws java.io.IOException {
0965:                printHeader(x);
0966:                writeInternalIndentation(x);
0967:                write(encodeUnicodeChars(x.getValue()));
0968:                printFooter(x);
0969:            }
0970:
0971:            public void printDoubleLiteral(DoubleLiteral x)
0972:                    throws java.io.IOException {
0973:                printHeader(x);
0974:                writeInternalIndentation(x);
0975:                write(x.getValue());
0976:                printFooter(x);
0977:            }
0978:
0979:            public void printLongLiteral(LongLiteral x)
0980:                    throws java.io.IOException {
0981:                printHeader(x);
0982:                writeInternalIndentation(x);
0983:                write(x.getValue());
0984:                printFooter(x);
0985:            }
0986:
0987:            public void printFloatLiteral(FloatLiteral x)
0988:                    throws java.io.IOException {
0989:                printHeader(x);
0990:                writeInternalIndentation(x);
0991:                write(x.getValue());
0992:                printFooter(x);
0993:            }
0994:
0995:            public void printPackageSpecification(PackageSpecification x)
0996:                    throws java.io.IOException {
0997:
0998:                printHeader(x);
0999:                writeInternalIndentation(x);
1000:                write("package");
1001:                writeElement(1, x.getPackageReference());
1002:                write(";");
1003:                printFooter(x);
1004:            }
1005:
1006:            public void printAssert(Assert x) throws java.io.IOException {
1007:                printHeader(x);
1008:
1009:                // Mark statement start ...
1010:                markStart(0, x);
1011:
1012:                boolean wasNoLinefeed = noLinefeed;
1013:                boolean wasNoSemicolon = noSemicolons;
1014:
1015:                write("assert ");
1016:
1017:                noLinefeed = true;
1018:                noSemicolons = true;
1019:                writeElement(0, x.getCondition());
1020:
1021:                if (x.getMessage() != null) {
1022:                    write(" : ");
1023:                    writeElement(0, x.getMessage());
1024:                }
1025:
1026:                noSemicolons = wasNoSemicolon;
1027:                noLinefeed = wasNoLinefeed;
1028:
1029:                write(";");
1030:
1031:                output();
1032:                // Mark statement end ...
1033:                markEnd(0, x);
1034:
1035:            }
1036:
1037:            public void printArrayDeclaration(ArrayDeclaration type)
1038:                    throws java.io.IOException {
1039:                Type baseType = type.getBaseType().getKeYJavaType()
1040:                        .getJavaType();
1041:                if (baseType instanceof  ArrayDeclaration) {
1042:                    printArrayDeclaration((ArrayDeclaration) baseType);
1043:                } else {
1044:                    writeSymbol(1, 0, baseType.getFullName());
1045:                }
1046:                write("[]");
1047:            }
1048:
1049:            public void printTypeReference(TypeReference x)
1050:                    throws java.io.IOException {
1051:                if (x.getKeYJavaType().getJavaType() instanceof  ArrayDeclaration) {
1052:                    printArrayDeclaration((ArrayDeclaration) x.getKeYJavaType()
1053:                            .getJavaType());
1054:                } else if (x.getProgramElementName() != null) {
1055:                    printHeader(x);
1056:                    if (x.getReferencePrefix() != null) {
1057:                        writeElement(x.getReferencePrefix());
1058:                        writeToken(".", x);
1059:                    }
1060:                    writeElement(x.getProgramElementName());
1061:                }
1062:                printFooter(x);
1063:            }
1064:
1065:            public void printSchemaTypeReference(SchemaTypeReference x)
1066:                    throws java.io.IOException {
1067:                printHeader(x);
1068:                if (x.getReferencePrefix() != null) {
1069:                    boolean wasNoSemicolons = noSemicolons;
1070:                    noSemicolons = true;
1071:                    writeElement(x.getReferencePrefix());
1072:                    noSemicolons = wasNoSemicolons;
1073:                    writeToken(".", x);
1074:                }
1075:
1076:                if (x.getProgramElementName() != null) {
1077:                    writeElement(x.getProgramElementName());
1078:                }
1079:                printFooter(x);
1080:            }
1081:
1082:            public void printFieldReference(FieldReference x)
1083:                    throws java.io.IOException {
1084:                printHeader(x);
1085:                if (x.getReferencePrefix() != null) {
1086:                    boolean wasNoSemicolons = noSemicolons;
1087:                    noSemicolons = true;
1088:                    writeElement(x.getReferencePrefix());
1089:                    noSemicolons = wasNoSemicolons;
1090:                    writeToken(".", x);
1091:                }
1092:                if (x.getProgramElementName() != null) {
1093:                    writeElement(x.getProgramElementName());
1094:                }
1095:                printFooter(x);
1096:            }
1097:
1098:            public void printPackageReference(PackageReference x)
1099:                    throws java.io.IOException {
1100:                printHeader(x);
1101:                if (x.getReferencePrefix() != null) {
1102:                    writeElement(x.getReferencePrefix());
1103:                    writeToken(".", x);
1104:                }
1105:                if (x.getProgramElementName() != null) {
1106:                    writeElement(x.getProgramElementName());
1107:                }
1108:                printFooter(x);
1109:            }
1110:
1111:            public void printThrows(Throws x) throws java.io.IOException {
1112:                printHeader(x);
1113:                if (x.getExceptions() != null) {
1114:                    writeInternalIndentation(x);
1115:                    write("throws");
1116:
1117:                    writeCommaList(0, 0, 1, x.getExceptions());
1118:                }
1119:                printFooter(x);
1120:            }
1121:
1122:            public void printArrayInitializer(ArrayInitializer x)
1123:                    throws java.io.IOException {
1124:
1125:                printHeader(x);
1126:                writeToken("{", x);
1127:                if (x.getArguments() != null) {
1128:                    writeCommaList(0, 0, 1, x.getArguments());
1129:                }
1130:                if (x.getArguments() != null && x.getArguments().size() > 0
1131:                        && getRelativePosition(x).getLine() > 0) {
1132:
1133:                    writeSymbol(1, 0, "}");
1134:                } else {
1135:                    write(" }");
1136:                }
1137:                printFooter(x);
1138:            }
1139:
1140:            public void printCompilationUnit(CompilationUnit x)
1141:                    throws java.io.IOException {
1142:                printHeader(x);
1143:                setIndentationLevel(0);
1144:                boolean hasPackageSpec = (x.getPackageSpecification() != null);
1145:                if (hasPackageSpec) {
1146:                    writeElement(x.getPackageSpecification());
1147:                }
1148:                boolean hasImports = (x.getImports() != null)
1149:                        && (x.getImports().size() > 0);
1150:                if (hasImports) {
1151:                    writeLineList(
1152:                            (x.getPackageSpecification() != null) ? 2 : 0, 0,
1153:                            0, x.getImports());
1154:                }
1155:                if (x.getDeclarations() != null) {
1156:                    writeBlockList((hasImports || hasPackageSpec) ? 2 : 0, 0,
1157:                            0, x.getDeclarations());
1158:                }
1159:                printFooter(x);
1160:                // we do this linefeed here to allow flushing of the pretty printer
1161:                // single line comment work list
1162:                writeIndentation(1, 0);
1163:            }
1164:
1165:            public void printClassDeclaration(ClassDeclaration x)
1166:                    throws java.io.IOException {
1167:                if (fileWriterMode) {
1168:                    classToPrint = x;
1169:                }
1170:                printHeader(x);
1171:                int m = 0;
1172:                if (x.getModifiers() != null) {
1173:                    m = x.getModifiers().size();
1174:                }
1175:                if (m > 0) {
1176:                    ArrayOfModifier mods = x.getModifiers();
1177:                    if (fileWriterMode) {
1178:                        mods = replacePrivateByPublic(mods);
1179:                    }
1180:                    writeKeywordList(mods);
1181:                    m = 1;
1182:                }
1183:                if (x.getProgramElementName() != null) {
1184:                    writeToken(m, "class", x);
1185:                    writeElement(1, x.getProgramElementName());
1186:                }
1187:                if (x.getExtendedTypes() != null) {
1188:                    writeElement(1, x.getExtendedTypes());
1189:                }
1190:                if (x.getImplementedTypes() != null) {
1191:                    writeElement(1, x.getImplementedTypes());
1192:                }
1193:                if (x.getProgramElementName() != null) {
1194:                    write(" {");
1195:                } else { // anonymous class
1196:                    write("{");
1197:                }
1198:                if (x.getMembers() != null) {
1199:                    //	    services.getJavaInfo().getKeYProgModelInfo().getConstructors(kjt)
1200:                    if (fileWriterMode
1201:                            && !containsDefaultConstructor(x.getMembers())) {
1202:                        write("\n   public " + x.getProgramElementName()
1203:                                + "(){}\n");
1204:                    }
1205:                    writeBlockList(2, 1, 0, x.getMembers());
1206:                }
1207:                writeSymbol(1, (x.getMembers() != null) ? -1 : 0, "}");
1208:                printFooter(x);
1209:                if (fileWriterMode) {
1210:                    classToPrint = null;
1211:                }
1212:            }
1213:
1214:            private boolean containsDefaultConstructor(
1215:                    ArrayOfMemberDeclaration members) {
1216:                for (int i = 0; i < members.size(); i++) {
1217:                    MemberDeclaration md = members.getMemberDeclaration(i);
1218:                    if (md instanceof  ProgramMethod) {
1219:                        md = ((ProgramMethod) md).getMethodDeclaration();
1220:                    }
1221:                    if ((md instanceof  ConstructorDeclaration)
1222:                            && ((ConstructorDeclaration) md)
1223:                                    .getParameterDeclarationCount() == 0) {
1224:                        return true;
1225:                    }
1226:                }
1227:                return false;
1228:            }
1229:
1230:            public void printInterfaceDeclaration(InterfaceDeclaration x)
1231:                    throws java.io.IOException {
1232:
1233:                printHeader(x);
1234:                int m = 0;
1235:                if (x.getModifiers() != null) {
1236:                    m = x.getModifiers().size();
1237:                }
1238:                if (m > 0) {
1239:                    writeKeywordList(x.getModifiers());
1240:                    m = 1;
1241:                }
1242:                if (x.getProgramElementName() != null) {
1243:                    writeToken(m, "interface", x);
1244:                    writeElement(1, x.getProgramElementName());
1245:                }
1246:                if (x.getExtendedTypes() != null) {
1247:                    writeElement(1, x.getExtendedTypes());
1248:                }
1249:                write(" {");
1250:                if (x.getMembers() != null) {
1251:                    writeBlockList(2, 1, 0, x.getMembers());
1252:                }
1253:                writeSymbol(1, (x.getMembers() != null) ? -1 : 0, "}");
1254:                printFooter(x);
1255:            }
1256:
1257:            private ArrayOfModifier removeFinal(ArrayOfModifier ma) {
1258:                LinkedList l = new LinkedList();
1259:                for (int i = 0; i < ma.size(); i++) {
1260:                    if (!(ma.getModifier(i) instanceof  Final)) {
1261:                        l.add(ma.getModifier(i));
1262:                    }
1263:                }
1264:                return new ArrayOfModifier(l);
1265:            }
1266:
1267:            private ArrayOfModifier replacePrivateByPublic(ArrayOfModifier ma) {
1268:                LinkedList l = new LinkedList();
1269:                boolean publicFound = false;
1270:                for (int i = 0; i < ma.size(); i++) {
1271:                    if (ma.getModifier(i) instanceof  Private) {
1272:                        l.add(new Public());
1273:                        publicFound = true;
1274:                    } else if (ma.getModifier(i) instanceof  Public) {
1275:                        l.add(ma.getModifier(i));
1276:                        publicFound = true;
1277:                    } else if (ma.getModifier(i) instanceof  Protected) {
1278:                        l.add(new Public());
1279:                        publicFound = true;
1280:                    } else {
1281:                        l.add(ma.getModifier(i));
1282:                    }
1283:                }
1284:                if (!publicFound) {
1285:                    l.add(new Public());
1286:                }
1287:                return new ArrayOfModifier(l);
1288:            }
1289:
1290:            public void printFieldDeclaration(FieldDeclaration x)
1291:                    throws java.io.IOException {
1292:                if (!fileWriterMode
1293:                        || !((ProgramVariable) x.getVariables()
1294:                                .lastVariableSpecification()
1295:                                .getProgramVariable()).isImplicit()) {
1296:                    printHeader(x);
1297:                    int m = 0;
1298:                    if (x.getModifiers() != null) {
1299:                        ArrayOfModifier mods = x.getModifiers();
1300:                        m = mods.size();
1301:                        if (fileWriterMode
1302:                                && x.isFinal()
1303:                                && (!x.isStatic() || !(x.getVariables()
1304:                                        .getVariableSpecification(0)
1305:                                        .getProgramVariable() instanceof  ProgramConstant))) {
1306:                            m--;
1307:                            mods = removeFinal(mods);
1308:                        }
1309:                        writeKeywordList(mods);
1310:                    }
1311:                    writeElement((m > 0) ? 1 : 0, x.getTypeReference());
1312:                    final ArrayOfVariableSpecification varSpecs = x
1313:                            .getVariables();
1314:                    assert varSpecs != null : "Strange: a field declaration without a"
1315:                            + " variable specification";
1316:                    writeCommaList(0, 0, 1, varSpecs);
1317:                    write(";");
1318:                    printFooter(x);
1319:                    // provides a set method for each field. Necessary for unittest
1320:                    // generation. 
1321:                    if (fileWriterMode) {
1322:                        for (int i = 0; i < varSpecs.size(); i++) {
1323:                            VariableSpecification varSpec = varSpecs
1324:                                    .getVariableSpecification(i);
1325:                            ProgramVariable pv = (ProgramVariable) varSpec
1326:                                    .getProgramVariable();
1327:                            if (!(x.isFinal() && x.isStatic() && pv instanceof  ProgramConstant)) {
1328:                                final String pvName = pv
1329:                                        .getProgramElementName()
1330:                                        .getProgramName();
1331:                                String typeName;
1332:                                final Type javaType = pv.getKeYJavaType()
1333:                                        .getJavaType();
1334:                                if (javaType instanceof  ArrayType) {
1335:                                    typeName = ((ArrayType) javaType)
1336:                                            .getAlternativeNameRepresentation();
1337:                                } else {
1338:                                    typeName = javaType.getFullName();
1339:                                }
1340:
1341:                                String typeNameNoBrackets = getTypeNameForAccessMethods(pv
1342:                                        .getKeYJavaType().getName());
1343:                                printHeader(x);
1344:                                write("\n\npublic "
1345:                                        + (x.isStatic() ? "static " : "")
1346:                                        + "void _set" + pvName
1347:                                        + typeNameNoBrackets + "(" + typeName
1348:                                        + " _" + pvName + "){\n");
1349:                                write("    " + pvName + " = _" + pvName + ";\n");
1350:                                write("}");
1351:                                write("\n\npublic "
1352:                                        + (x.isStatic() ? "static " : "")
1353:                                        + typeName + " _" + pvName
1354:                                        + typeNameNoBrackets + "(){\n");
1355:                                write("    return " + pvName + ";\n");
1356:                                write("}");
1357:                                printFooter(x);
1358:                            }
1359:                        }
1360:                    }
1361:                }
1362:            }
1363:
1364:            public static String getTypeNameForAccessMethods(String typeName) {
1365:                typeName = typeName.replace('[', '_');
1366:                return typeName.replace('.', '_');
1367:            }
1368:
1369:            public void printLocalVariableDeclaration(LocalVariableDeclaration x)
1370:                    throws java.io.IOException {
1371:                printHeader(x);
1372:                // Mark statement start ...
1373:                markStart(0, x);
1374:                int m = 0;
1375:                if (x.getModifiers() != null) {
1376:                    m = x.getModifiers().size();
1377:                    writeKeywordList(x.getModifiers());
1378:                }
1379:                writeElement((m > 0) ? 1 : 0, x.getTypeReference());
1380:                write(" ");
1381:                ArrayOfVariableSpecification varSpecs = x.getVariables();
1382:                boolean wasNoSemicolons = noSemicolons;
1383:                boolean wasNoLinefeed = noLinefeed;
1384:                noSemicolons = true;
1385:                noLinefeed = true;
1386:                if (varSpecs != null) {
1387:                    writeCommaList(0, 0, 1, varSpecs);
1388:                }
1389:                // !!!!!!!!!! HAS TO BE CHANGED
1390:                //       if (!(x.getStatementContainer() instanceof LoopStatement)) {
1391:                write(";");
1392:                //        }
1393:
1394:                // Mark statement end ...
1395:                markEnd(0, x);
1396:                noSemicolons = wasNoSemicolons;
1397:                noLinefeed = wasNoLinefeed;
1398:                printFooter(x);
1399:            }
1400:
1401:            public void printVariableDeclaration(VariableDeclaration x)
1402:                    throws java.io.IOException {
1403:
1404:                printHeader(x);
1405:
1406:                // Mark statement start ...
1407:                markStart(0, x);
1408:
1409:                int m = 0;
1410:                if (x.getModifiers() != null) {
1411:                    m = x.getModifiers().size();
1412:                    writeKeywordList(x.getModifiers());
1413:                }
1414:                writeElement((m > 0) ? 1 : 0, x.getTypeReference());
1415:                write(" ");
1416:                ArrayOfVariableSpecification varSpecs = x.getVariables();
1417:                if (varSpecs != null) {
1418:                    writeCommaList(0, 0, 1, varSpecs);
1419:                }
1420:
1421:                // Mark statement end ...
1422:                markEnd(0, x);
1423:
1424:                printFooter(x);
1425:            }
1426:
1427:            public void printMethodDeclaration(MethodDeclaration x)
1428:                    throws java.io.IOException {
1429:                if (!fileWriterMode || x.getFullName().indexOf("<") == -1) {
1430:                    printHeader(x);
1431:                    Comment[] c = x.getComments();
1432:                    int m = c.length;
1433:                    for (int i = 0; i < c.length; i++) {
1434:                        printComment(c[i]);
1435:                    }
1436:                    if (x.getModifiers() != null) {
1437:                        ArrayOfModifier mods = x.getModifiers();
1438:                        if ((x instanceof  ConstructorDeclaration)
1439:                                && fileWriterMode) {
1440:                            mods = replacePrivateByPublic(mods);
1441:                        }
1442:                        m += mods.size();
1443:                        writeKeywordList(mods);
1444:                    }
1445:                    if (x.getTypeReference() != null) {
1446:                        if (m > 0) {
1447:                            writeElement(1, x.getTypeReference());
1448:                        } else {
1449:                            writeElement(x.getTypeReference());
1450:                        }
1451:                        writeElement(1, x.getProgramElementName());
1452:                    } else if (x.getTypeReference() == null
1453:                            && !(x instanceof  ConstructorDeclaration)) {
1454:                        write(" void ");
1455:                        writeElement(1, x.getProgramElementName());
1456:                    } else {
1457:                        if (m > 0) {
1458:                            writeElement(1, x.getProgramElementName());
1459:                        } else {
1460:                            writeElement(x.getProgramElementName());
1461:                        }
1462:                    }
1463:                    write(" (");
1464:                    if (x.getParameters() != null) {
1465:                        writeCommaList(1, x.getParameters());
1466:                    }
1467:                    write(")");
1468:                    if (x.getThrown() != null) {
1469:                        writeElement(1, x.getThrown());
1470:                    }
1471:                    if (x.getBody() != null) {
1472:                        writeElement(1, x.getBody());
1473:                    } else {
1474:                        write(";");
1475:                    }
1476:                    printFooter(x);
1477:                }
1478:            }
1479:
1480:            public void printClassInitializer(ClassInitializer x)
1481:                    throws java.io.IOException {
1482:
1483:                printHeader(x);
1484:                int m = 0;
1485:                if (x.getModifiers() != null) {
1486:                    m = x.getModifiers().size();
1487:                    writeKeywordList(x.getModifiers());
1488:                }
1489:                if (x.getBody() != null) {
1490:                    writeElement(m > 0 ? 1 : 0, x.getBody());
1491:                }
1492:                printFooter(x);
1493:            }
1494:
1495:            public void printStatementBlock(StatementBlock x)
1496:                    throws java.io.IOException {
1497:                printHeader(x);
1498:
1499:                if (!(x.getBody() != null && x.getBody().size() > 0)) {
1500:                    // We have an empty statement block ...
1501:
1502:                    // Mark statement start ...
1503:                    markStart(0, x);
1504:
1505:                }
1506:
1507:                // Hack to insert space after "if (cond)", etc. but not
1508:                // at beginning of diamond.
1509:                if (column != 0) {
1510:                    write(" ");
1511:                }
1512:                write("{");
1513:                if (x.getBody() != null && x.getBody().size() > 0) {
1514:                    writeLineList(1, +1, 0, x.getBody());
1515:                    writeSymbol(1, -1, "}");
1516:                } else {
1517:                    write("}");
1518:
1519:                    // Mark statement end ...
1520:                    markEnd(0, x);
1521:
1522:                }
1523:                printFooter(x);
1524:            }
1525:
1526:            public void printBreak(Break x) throws java.io.IOException {
1527:                printHeader(x);
1528:                writeInternalIndentation(x);
1529:
1530:                // Mark statement start ...
1531:                markStart(0, x);
1532:
1533:                write("break ");
1534:                noLinefeed = true;
1535:                if (x.getProgramElementName() != null) {
1536:                    writeElement(1, x.getProgramElementName());
1537:                }
1538:                write(";");
1539:                noLinefeed = false;
1540:
1541:                // Mark statement end ...
1542:                markEnd(0, x);
1543:
1544:                printFooter(x);
1545:            }
1546:
1547:            public void printContinue(Continue x) throws java.io.IOException {
1548:                printHeader(x);
1549:                writeInternalIndentation(x);
1550:
1551:                // Mark statement start ...
1552:                markStart(0, x);
1553:
1554:                write("continue ");
1555:                noLinefeed = true;
1556:                if (x.getProgramElementName() != null) {
1557:                    writeElement(1, x.getProgramElementName());
1558:                }
1559:                write(";");
1560:                noLinefeed = false;
1561:
1562:                // Mark statement end ...
1563:                markEnd(0, x);
1564:
1565:                printFooter(x);
1566:            }
1567:
1568:            public void printReturn(Return x) throws java.io.IOException {
1569:                printHeader(x);
1570:                writeInternalIndentation(x);
1571:
1572:                // Mark statement start ...
1573:                markStart(0, x);
1574:
1575:                write("return ");
1576:                if (x.getExpression() != null) {
1577:                    noSemicolons = true;
1578:                    writeElement(1, x.getExpression());
1579:                    noSemicolons = false;
1580:                }
1581:                write(";");
1582:
1583:                // Mark statement end ...
1584:                markEnd(0, x);
1585:
1586:                printFooter(x);
1587:            }
1588:
1589:            public void printThrow(Throw x) throws java.io.IOException {
1590:                printHeader(x);
1591:                writeInternalIndentation(x);
1592:
1593:                // Mark statement start ...
1594:                markStart(0, x);
1595:
1596:                write("throw ");
1597:                if (x.getExpression() != null) {
1598:                    noSemicolons = true;
1599:                    writeElement(1, x.getExpression());
1600:                    noSemicolons = false;
1601:                }
1602:                write(";");
1603:
1604:                // Mark statement end ...
1605:                markEnd(0, x);
1606:
1607:                printFooter(x);
1608:            }
1609:
1610:            public void printDo(Do x) throws java.io.IOException {
1611:                printHeader(x);
1612:                writeInternalIndentation(x);
1613:
1614:                // Mark statement start ...
1615:                markStart(0, x);
1616:
1617:                write("do");
1618:                if (x.getBody() == null
1619:                        || x.getBody() instanceof  EmptyStatement) {
1620:                    write(";");
1621:                    //w.writeElement(1, body);
1622:                } else {
1623:                    if (x.getBody() instanceof  StatementBlock) {
1624:                        writeElement(1, 0, x.getBody());
1625:                    } else {
1626:                        writeElement(1, +1, 0, x.getBody());
1627:                        changeLevel(-1);
1628:                    }
1629:                }
1630:                writeSymbol(1, 0, "while");
1631:                noLinefeed = true;
1632:                noSemicolons = true;
1633:                write(" (");
1634:                if (x.getGuardExpression() != null) {
1635:                    write(" ");
1636:                    writeElement(x.getGuardExpression());
1637:                    write(" ");
1638:                }
1639:                noLinefeed = false;
1640:                noSemicolons = false;
1641:                write(");");
1642:
1643:                // Mark statement end ...
1644:                markEnd(0, x);
1645:
1646:                printFooter(x);
1647:            }
1648:
1649:            private static void removeChar(StringBuffer sb, char c) {
1650:                for (int i = 0; i < sb.length(); i++) {
1651:                    if (sb.charAt(i) == c) {
1652:                        sb.deleteCharAt(i);
1653:                    }
1654:                }
1655:            }
1656:
1657:            public void printFor(For x) throws java.io.IOException {
1658:                printHeader(x);
1659:                writeInternalIndentation(x);
1660:                output();
1661:
1662:                // Mark statement start ...
1663:                markStart(0, x);
1664:
1665:                write("for (");
1666:                noLinefeed = true;
1667:                noSemicolons = true;
1668:                write(" ");
1669:                if (x.getInitializers() != null) {
1670:                    writeCommaList(x.getInitializers());
1671:                }
1672:                noSemicolons = false;
1673:                write("; ");
1674:                output();
1675:                noSemicolons = true;
1676:                if (x.getGuardExpression() != null) {
1677:                    writeElement(1, x.getGuardExpression());
1678:                }
1679:                noSemicolons = false;
1680:                write("; ");
1681:                output();
1682:                noSemicolons = true;
1683:                if (x.getUpdates() != null) {
1684:                    writeCommaList(0, 0, 1, x.getUpdates());
1685:                }
1686:                write(" ");
1687:                write(")");
1688:                output();
1689:                noLinefeed = false;
1690:                noSemicolons = false;
1691:                if (x.getBody() == null
1692:                        || x.getBody() instanceof  EmptyStatement) {
1693:                    write(";");
1694:                } else {
1695:                    if (x.getBody() instanceof  StatementBlock) {
1696:                        writeElement(1, 0, x.getBody());
1697:                    } else {
1698:                        writeElement(1, +1, 0, x.getBody());
1699:                        changeLevel(-1);
1700:                    }
1701:                }
1702:
1703:                // Mark statement end ...
1704:                markEnd(0, x);
1705:
1706:                printFooter(x);
1707:            }
1708:
1709:            public void printWhile(While x) throws java.io.IOException {
1710:                printHeader(x);
1711:                writeInternalIndentation(x);
1712:                output();
1713:                noLinefeed = true;
1714:                noSemicolons = true;
1715:
1716:                // Mark statement start ...
1717:                markStart(0, x);
1718:
1719:                write("while (");
1720:                write(" ");
1721:                if (x.getGuardExpression() != null) {
1722:                    writeElement(x.getGuardExpression());
1723:                }
1724:                write(" )");
1725:                output();
1726:                noLinefeed = false;
1727:                noSemicolons = false;
1728:                if (x.getBody() == null
1729:                        || x.getBody() instanceof  EmptyStatement) {
1730:                    write(";");
1731:                } else {
1732:                    if (x.getBody() instanceof  StatementBlock) {
1733:                        writeElement(0, 0, x.getBody());
1734:                    } else {
1735:                        writeElement(1, +1, 0, x.getBody());
1736:                        changeLevel(-1);
1737:                    }
1738:                }
1739:
1740:                // Mark statement end ...
1741:                markEnd(0, x);
1742:
1743:                printFooter(x);
1744:            }
1745:
1746:            public void printIf(If x) throws java.io.IOException {
1747:                printHeader(x);
1748:                writeInternalIndentation(x);
1749:                output();
1750:
1751:                noLinefeed = true;
1752:                noSemicolons = true;
1753:
1754:                // Mark statement start ...
1755:                markStart(0, x);
1756:
1757:                write("if (");
1758:                if (x.getExpression() != null) {
1759:                    writeElement(1, x.getExpression());
1760:                }
1761:                write(")");
1762:
1763:                noLinefeed = false;
1764:                noSemicolons = false;
1765:
1766:                if (x.getThen() != null) {
1767:                    if (x.getThen().getBody() instanceof  StatementBlock) {
1768:                        writeElement(1, 0, x.getThen());
1769:                    } else {
1770:                        writeElement(1, +1, 0, x.getThen());
1771:                        changeLevel(-1);
1772:                    }
1773:                }
1774:                if (x.getElse() != null) {
1775:                    writeElement(1, 0, x.getElse());
1776:                }
1777:
1778:                // Mark statement end ...
1779:                markEnd(0, x);
1780:
1781:                printFooter(x);
1782:            }
1783:
1784:            public void printSwitch(Switch x) throws java.io.IOException {
1785:                printHeader(x);
1786:                writeInternalIndentation(x);
1787:
1788:                // Mark statement start ...
1789:                markStart(0, x);
1790:
1791:                write("switch (");
1792:                if (x.getExpression() != null) {
1793:                    noSemicolons = true;
1794:                    writeElement(x.getExpression());
1795:                    noSemicolons = false;
1796:                }
1797:                write(") {");
1798:                if (x.getBranchList() != null) {
1799:                    writeLineList(1, 0, 0, x.getBranchList());
1800:                }
1801:                writeSymbol(1, 0, "}");
1802:
1803:                // Mark statement end ...
1804:                markEnd(0, x);
1805:
1806:                printFooter(x);
1807:            }
1808:
1809:            public void printTry(Try x) throws java.io.IOException {
1810:                printHeader(x);
1811:                writeInternalIndentation(x);
1812:
1813:                // // Mark statement start ...
1814:                // markStart(0,x);
1815:
1816:                write("try");
1817:
1818:                if (x.getBody() != null) {
1819:                    writeElement(0, 0, x.getBody());
1820:                }
1821:                if (x.getBranchList() != null) {
1822:                    writeLineList(1, 0, 0, x.getBranchList());
1823:                }
1824:
1825:                // // Mark statement end ...
1826:                // markEnd(0,x);
1827:
1828:                printFooter(x);
1829:            }
1830:
1831:            public void printLabeledStatement(LabeledStatement x)
1832:                    throws java.io.IOException {
1833:
1834:                printHeader(x);
1835:
1836:                if (x.getLabel() != null) {
1837:                    writeElement(x.getLabel());
1838:                    writeToken(":", x);
1839:                }
1840:
1841:                if (x.getBody() != null) {
1842:                    writeElement(1, 0, x.getBody());
1843:                }
1844:
1845:                printFooter(x);
1846:            }
1847:
1848:            public void printMethodFrame(MethodFrame x)
1849:                    throws java.io.IOException {
1850:
1851:                printHeader(x);
1852:
1853:                noLinefeed = false;
1854:
1855:                write("method-frame(");
1856:                IProgramVariable pvar = x.getProgramVariable();
1857:                if (pvar != null) {
1858:                    write("result->");
1859:                    writeElement(pvar);
1860:                    write(", ");
1861:                }
1862:
1863:                if (x.getExecutionContext() instanceof  ExecutionContext) {
1864:                    writeElement(x.getExecutionContext());
1865:                } else {
1866:                    printSchemaVariable((SchemaVariable) x
1867:                            .getExecutionContext());
1868:                }
1869:
1870:                write(")");
1871:                writeToken(":", x);
1872:
1873:                noLinefeed = false;
1874:                noSemicolons = false;
1875:
1876:                if (x.getBody() != null) {
1877:                    writeElement(0, 0, x.getBody());
1878:                }
1879:
1880:                printFooter(x);
1881:            }
1882:
1883:            public void printCatchAllStatement(CatchAllStatement x)
1884:                    throws java.io.IOException {
1885:                printHeader(x);
1886:                markStart(0, x);
1887:                write("#catchAll");
1888:                write("(");
1889:                writeElement(x.getParameterDeclaration());
1890:                write(")");
1891:                writeElement(1, x.getBody());
1892:                printFooter(x);
1893:
1894:            }
1895:
1896:            public void printMethodBodyStatement(MethodBodyStatement x)
1897:                    throws java.io.IOException {
1898:
1899:                boolean wasNoLinefeed = noLinefeed;
1900:                noLinefeed = false;
1901:
1902:                printHeader(x);
1903:                writeInternalIndentation(x);
1904:                markStart(0, x);
1905:
1906:                IProgramVariable pvar = x.getResultVariable();
1907:                if (pvar != null) {
1908:                    writeElement(pvar);
1909:                    write("=");
1910:                }
1911:
1912:                printMethodReference(x.getMethodReference(), false);
1913:                //CHG:
1914:                if (!fileWriterMode) {
1915:                    write("@");
1916:                    final TypeReference tr = x.getBodySourceAsTypeReference();
1917:                    if (tr instanceof  SchemaTypeReference) {
1918:                        printSchemaTypeReference((SchemaTypeReference) tr);
1919:                    } else if (tr instanceof  SchemaVariable) {
1920:                        printSchemaVariable((SchemaVariable) tr);
1921:                    } else {
1922:                        printTypeReference(tr);
1923:                    }
1924:                }
1925:                write(";");
1926:                markEnd(0, x);
1927:                printFooter(x);
1928:
1929:                noLinefeed = wasNoLinefeed;
1930:            }
1931:
1932:            public void printSynchronizedBlock(SynchronizedBlock x)
1933:                    throws java.io.IOException {
1934:
1935:                printHeader(x);
1936:                writeInternalIndentation(x);
1937:                write("synchronized");
1938:                if (x.getExpression() != null) {
1939:                    write("(");
1940:                    writeElement(x.getExpression());
1941:                    write(")");
1942:                }
1943:                if (x.getBody() != null) {
1944:                    writeElement(1, x.getBody());
1945:                }
1946:                printFooter(x);
1947:            }
1948:
1949:            public void printImport(Import x) throws java.io.IOException {
1950:                printHeader(x);
1951:                writeInternalIndentation(x);
1952:                write("import");
1953:                writeElement(1, x.getReference());
1954:                if (x.isMultiImport()) {
1955:                    write(".*;");
1956:                } else {
1957:                    write(";");
1958:                }
1959:                printFooter(x);
1960:            }
1961:
1962:            public void printExtends(Extends x) throws java.io.IOException {
1963:                printHeader(x);
1964:                if (x.getSupertypes() != null) {
1965:                    writeInternalIndentation(x);
1966:                    write("extends");
1967:                    writeCommaList(0, 0, 1, x.getSupertypes());
1968:                }
1969:                printFooter(x);
1970:            }
1971:
1972:            public void printImplements(Implements x)
1973:                    throws java.io.IOException {
1974:                printHeader(x);
1975:                if (x.getSupertypes() != null) {
1976:                    writeInternalIndentation(x);
1977:                    write("implements");
1978:                    writeCommaList(0, 0, 1, x.getSupertypes());
1979:                }
1980:                printFooter(x);
1981:            }
1982:
1983:            public void printVariableSpecification(VariableSpecification x)
1984:                    throws java.io.IOException {
1985:
1986:                printHeader(x);
1987:
1988:                // Mark statement start ...
1989:                markStart(0, x);
1990:
1991:                x.getProgramVariable().prettyPrint(this );
1992:                //writeElement(x.getProgramElementName());
1993:                for (int i = 0; i < x.getDimensions(); i += 1) {
1994:                    write("[]");
1995:                }
1996:                if (x.getInitializer() != null) {
1997:                    //            w.writeIndentation(getInternalLinefeeds(),
1998:                    // getInternalIndentation());
1999:                    write(" = ");
2000:                    writeElement(0, 0, 1, x.getInitializer());
2001:                }
2002:                // Mark statement end ...
2003:                markEnd(0, x);
2004:
2005:                printFooter(x);
2006:
2007:            }
2008:
2009:            public void printBinaryAnd(BinaryAnd x) throws java.io.IOException {
2010:                printHeader(x);
2011:                printOperator(x, "&");
2012:                printFooter(x);
2013:            }
2014:
2015:            public void printBinaryAndAssignment(BinaryAndAssignment x)
2016:                    throws java.io.IOException {
2017:
2018:                printHeader(x);
2019:                printOperator(x, "&=");
2020:                printFooter(x);
2021:            }
2022:
2023:            public void printBinaryOrAssignment(BinaryOrAssignment x)
2024:                    throws java.io.IOException {
2025:
2026:                printHeader(x);
2027:                printOperator(x, "|=");
2028:                printFooter(x);
2029:            }
2030:
2031:            public void printBinaryXOrAssignment(BinaryXOrAssignment x)
2032:                    throws java.io.IOException {
2033:
2034:                printHeader(x);
2035:                printOperator(x, "^=");
2036:                printFooter(x);
2037:            }
2038:
2039:            public void printCopyAssignment(CopyAssignment x)
2040:                    throws java.io.IOException {
2041:                printHeader(x);
2042:                //output();
2043:                //	noLinefeed=true;
2044:                printOperator(x, "=");
2045:                //	noLinefeed=false;
2046:                //write("\n");
2047:                printFooter(x);
2048:            }
2049:
2050:            public void printDivideAssignment(DivideAssignment x)
2051:                    throws java.io.IOException {
2052:                printHeader(x);
2053:                printOperator(x, "/=");
2054:                printFooter(x);
2055:            }
2056:
2057:            public void printMinusAssignment(MinusAssignment x)
2058:                    throws java.io.IOException {
2059:                printHeader(x);
2060:                printOperator(x, "-=");
2061:                printFooter(x);
2062:            }
2063:
2064:            public void printModuloAssignment(ModuloAssignment x)
2065:                    throws java.io.IOException {
2066:                printHeader(x);
2067:                printOperator(x, "%=");
2068:                printFooter(x);
2069:            }
2070:
2071:            public void printPlusAssignment(PlusAssignment x)
2072:                    throws java.io.IOException {
2073:                printHeader(x);
2074:                printOperator(x, "+=");
2075:                printFooter(x);
2076:            }
2077:
2078:            public void printPostDecrement(PostDecrement x)
2079:                    throws java.io.IOException {
2080:                printHeader(x);
2081:                printOperator(x, "--");
2082:                printFooter(x);
2083:            }
2084:
2085:            public void printPostIncrement(PostIncrement x)
2086:                    throws java.io.IOException {
2087:                printHeader(x);
2088:                printOperator(x, "++");
2089:                printFooter(x);
2090:            }
2091:
2092:            public void printPreDecrement(PreDecrement x)
2093:                    throws java.io.IOException {
2094:                printHeader(x);
2095:                printOperator(x, "--");
2096:                printFooter(x);
2097:            }
2098:
2099:            public void printPreIncrement(PreIncrement x)
2100:                    throws java.io.IOException {
2101:                printHeader(x);
2102:                printOperator(x, "++");
2103:                printFooter(x);
2104:            }
2105:
2106:            public void printShiftLeftAssignment(ShiftLeftAssignment x)
2107:                    throws java.io.IOException {
2108:
2109:                printHeader(x);
2110:                printOperator(x, "<<=");
2111:                printFooter(x);
2112:            }
2113:
2114:            public void printShiftRightAssignment(ShiftRightAssignment x)
2115:                    throws java.io.IOException {
2116:
2117:                printHeader(x);
2118:                printOperator(x, ">>=");
2119:                printFooter(x);
2120:            }
2121:
2122:            public void printTimesAssignment(TimesAssignment x)
2123:                    throws java.io.IOException {
2124:                printHeader(x);
2125:                printOperator(x, "*=");
2126:                printFooter(x);
2127:            }
2128:
2129:            public void printUnsignedShiftRightAssignment(
2130:                    UnsignedShiftRightAssignment x) throws java.io.IOException {
2131:
2132:                printHeader(x);
2133:                printOperator(x, ">>>=");
2134:                printFooter(x);
2135:            }
2136:
2137:            public void printBinaryNot(BinaryNot x) throws java.io.IOException {
2138:                printHeader(x);
2139:                printOperator(x, "~");
2140:                printFooter(x);
2141:            }
2142:
2143:            public void printBinaryOr(BinaryOr x) throws java.io.IOException {
2144:                printHeader(x);
2145:                printOperator(x, "|");
2146:                printFooter(x);
2147:            }
2148:
2149:            public void printBinaryXOr(BinaryXOr x) throws java.io.IOException {
2150:                printHeader(x);
2151:                printOperator(x, "^");
2152:                printFooter(x);
2153:            }
2154:
2155:            public void printConditional(Conditional x)
2156:                    throws java.io.IOException {
2157:                printHeader(x);
2158:
2159:                boolean addParentheses = x.isToBeParenthesized();
2160:                if (x.getArguments() != null) {
2161:                    if (addParentheses) {
2162:                        write("(");
2163:                    }
2164:                    writeElement(0, x.getArguments().getExpression(0));
2165:                    write(" ?");
2166:                    writeElement(1, x.getArguments().getExpression(1));
2167:                    write(" :");
2168:                    writeElement(1, x.getArguments().getExpression(2));
2169:                    if (addParentheses) {
2170:                        write(")");
2171:                    }
2172:                }
2173:                printFooter(x);
2174:            }
2175:
2176:            public void printDivide(Divide x) throws java.io.IOException {
2177:                printHeader(x);
2178:                printOperator(x, "/");
2179:                printFooter(x);
2180:            }
2181:
2182:            public void printEquals(Equals x) throws java.io.IOException {
2183:                printHeader(x);
2184:                printOperator(x, "==");
2185:                printFooter(x);
2186:            }
2187:
2188:            public void printGreaterOrEquals(GreaterOrEquals x)
2189:                    throws java.io.IOException {
2190:                printHeader(x);
2191:                printOperator(x, ">=");
2192:                printFooter(x);
2193:            }
2194:
2195:            public void printGreaterThan(GreaterThan x)
2196:                    throws java.io.IOException {
2197:                printHeader(x);
2198:                printOperator(x, ">");
2199:                printFooter(x);
2200:            }
2201:
2202:            public void printLessOrEquals(LessOrEquals x)
2203:                    throws java.io.IOException {
2204:                printHeader(x);
2205:                printOperator(x, "<=");
2206:                printFooter(x);
2207:            }
2208:
2209:            public void printLessThan(LessThan x) throws java.io.IOException {
2210:                printHeader(x);
2211:                printOperator(x, "<");
2212:                printFooter(x);
2213:            }
2214:
2215:            public void printNotEquals(NotEquals x) throws java.io.IOException {
2216:                printHeader(x);
2217:                printOperator(x, "!=");
2218:                printFooter(x);
2219:            }
2220:
2221:            public void printNewArray(NewArray x) throws java.io.IOException {
2222:                printHeader(x);
2223:                boolean addParentheses = x.isToBeParenthesized();
2224:                if (addParentheses) {
2225:                    write("(");
2226:                }
2227:                writeInternalIndentation(x);
2228:                write("new ");
2229:                writeElement(1, x.getTypeReference());
2230:                int i = 0;
2231:                if (x.getArguments() != null) {
2232:                    for (; i < x.getArguments().size(); i += 1) {
2233:                        write("[");
2234:                        writeElement(x.getArguments().getExpression(i));
2235:                        write("]");
2236:                    }
2237:                }
2238:                for (; i < x.getDimensions(); i += 1) {
2239:                    write("[]");
2240:                }
2241:                if (x.getArrayInitializer() != null) {
2242:                    writeElement(1, x.getArrayInitializer());
2243:                }
2244:                if (addParentheses) {
2245:                    write(")");
2246:                }
2247:                printFooter(x);
2248:            }
2249:
2250:            public void printInstanceof(Instanceof x)
2251:                    throws java.io.IOException {
2252:                printHeader(x);
2253:                boolean addParentheses = x.isToBeParenthesized();
2254:                if (addParentheses) {
2255:                    write("(");
2256:                }
2257:                if (x.getArguments() != null) {
2258:                    writeElement(0, x.getExpressionAt(0));
2259:                }
2260:                writeInternalIndentation(x);
2261:                write(" instanceof ");
2262:                if (x.getTypeReference() != null) {
2263:                    writeElement(1, x.getTypeReference());
2264:                }
2265:                if (addParentheses) {
2266:                    write(")");
2267:                }
2268:                printFooter(x);
2269:            }
2270:
2271:            public void printExactInstanceof(ExactInstanceof x)
2272:                    throws java.io.IOException {
2273:                printHeader(x);
2274:                boolean addParentheses = x.isToBeParenthesized();
2275:                if (addParentheses) {
2276:                    write("(");
2277:                }
2278:                if (x.getArguments() != null) {
2279:                    writeElement(0, x.getExpressionAt(0));
2280:                }
2281:                writeInternalIndentation(x);
2282:                write(" exactInstanceof ");
2283:                if (x.getTypeReference() != null) {
2284:                    writeElement(1, x.getTypeReference());
2285:                }
2286:                if (addParentheses) {
2287:                    write(")");
2288:                }
2289:                printFooter(x);
2290:            }
2291:
2292:            public void printNew(New x) throws java.io.IOException {
2293:                printHeader(x);
2294:
2295:                // Mark statement start ...
2296:                markStart(0, x);
2297:
2298:                boolean addParentheses = x.isToBeParenthesized();
2299:                if (addParentheses) {
2300:                    write("(");
2301:                }
2302:                if (x.getReferencePrefix() != null) {
2303:                    writeElement(0, x.getReferencePrefix());
2304:                    write(".");
2305:                }
2306:                writeInternalIndentation(x);
2307:                write("new ");
2308:                writeElement(1, x.getTypeReference());
2309:                write(" (");
2310:                if (x.getArguments() != null) {
2311:                    writeCommaList(x.getArguments());
2312:                }
2313:                write(")");
2314:                if (x.getClassDeclaration() != null) {
2315:                    writeElement(1, x.getClassDeclaration());
2316:                }
2317:                if (addParentheses) {
2318:                    write(")");
2319:                }
2320:                // !!!!!!!!!! HAS TO BE CHANGED
2321:                //	if (x.getStatementContainer() != null && fileWriterMode) {
2322:                //	   write(";");
2323:                //	}
2324:
2325:                // Mark statement end ...
2326:                markEnd(0, x);
2327:                printFooter(x);
2328:            }
2329:
2330:            public void printTypeCast(TypeCast x) throws java.io.IOException {
2331:                printHeader(x);
2332:                boolean addParentheses = x.isToBeParenthesized();
2333:                if (addParentheses) {
2334:                    write("(");
2335:                }
2336:                writeInternalIndentation(x);
2337:                write("(");
2338:                if (x.getTypeReference() != null) {
2339:                    writeElement(0, x.getTypeReference());
2340:                }
2341:                write(")");
2342:                if (x.getArguments() != null) {
2343:                    writeElement(0, x.getArguments().getExpression(0));
2344:                }
2345:                if (addParentheses) {
2346:                    write(")");
2347:                }
2348:                printFooter(x);
2349:            }
2350:
2351:            public void printLogicalAnd(LogicalAnd x)
2352:                    throws java.io.IOException {
2353:                printHeader(x);
2354:                printOperator(x, "&&");
2355:                printFooter(x);
2356:            }
2357:
2358:            public void printLogicalNot(LogicalNot x)
2359:                    throws java.io.IOException {
2360:                printHeader(x);
2361:                printOperator(x, "!");
2362:                printFooter(x);
2363:            }
2364:
2365:            public void printLogicalOr(LogicalOr x) throws java.io.IOException {
2366:                printHeader(x);
2367:                printOperator(x, "||");
2368:                printFooter(x);
2369:            }
2370:
2371:            public void printMinus(Minus x) throws java.io.IOException {
2372:                printHeader(x);
2373:                printOperator(x, "-");
2374:                printFooter(x);
2375:            }
2376:
2377:            public void printModulo(Modulo x) throws java.io.IOException {
2378:                printHeader(x);
2379:                printOperator(x, "%");
2380:                printFooter(x);
2381:            }
2382:
2383:            public void printNegative(Negative x) throws java.io.IOException {
2384:                printHeader(x);
2385:                printOperator(x, "-");
2386:                printFooter(x);
2387:            }
2388:
2389:            public void printPlus(Plus x) throws java.io.IOException {
2390:                printHeader(x);
2391:                printOperator(x, "+");
2392:                printFooter(x);
2393:            }
2394:
2395:            public void printPositive(Positive x) throws java.io.IOException {
2396:                printHeader(x);
2397:                printOperator(x, "+");
2398:                printFooter(x);
2399:            }
2400:
2401:            public void printShiftLeft(ShiftLeft x) throws java.io.IOException {
2402:                printHeader(x);
2403:                printOperator(x, "<<");
2404:                printFooter(x);
2405:            }
2406:
2407:            public void printShiftRight(ShiftRight x)
2408:                    throws java.io.IOException {
2409:                printHeader(x);
2410:                printOperator(x, ">>");
2411:                printFooter(x);
2412:            }
2413:
2414:            public void printTimes(Times x) throws java.io.IOException {
2415:                printHeader(x);
2416:                printOperator(x, "*");
2417:                printFooter(x);
2418:            }
2419:
2420:            public void printUnsignedShiftRight(UnsignedShiftRight x)
2421:                    throws java.io.IOException {
2422:
2423:                printHeader(x);
2424:                printOperator(x, ">>>");
2425:                printFooter(x);
2426:            }
2427:
2428:            public void printArrayReference(ArrayReference x)
2429:                    throws java.io.IOException {
2430:                printHeader(x);
2431:                if (x.getReferencePrefix() != null) {
2432:                    writeElement(x.getReferencePrefix());
2433:                }
2434:                if (x.getDimensionExpressions() != null) {
2435:                    int s = x.getDimensionExpressions().size();
2436:                    for (int i = 0; i < s; i += 1) {
2437:                        write("[");
2438:                        writeElement(x.getDimensionExpressions().getExpression(
2439:                                i));
2440:                        write("]");
2441:                    }
2442:                }
2443:                printFooter(x);
2444:            }
2445:
2446:            public void printMetaClassReference(MetaClassReference x)
2447:                    throws java.io.IOException {
2448:
2449:                printHeader(x);
2450:                if (x.getTypeReference() != null) {
2451:                    writeElement(x.getTypeReference());
2452:                    writeToken(".", x);
2453:                }
2454:                write("class");
2455:                printFooter(x);
2456:            }
2457:
2458:            public void printMethodReference(MethodReference x)
2459:                    throws java.io.IOException {
2460:                printMethodReference(x, !noSemicolons);
2461:            }
2462:
2463:            private void printMethodReference(MethodReference x,
2464:                    boolean withSemicolon) throws java.io.IOException {
2465:                printHeader(x);
2466:                // Mark statement start ...
2467:                markStart(0, x);
2468:
2469:                if (x.getReferencePrefix() != null) {
2470:                    writeElement(x.getReferencePrefix());
2471:                    write(".");
2472:                }
2473:                if (x.getProgramElementName() != null) {
2474:                    x.getMethodName().prettyPrint(this );
2475:                    //writeElement(x.getProgramElementName());
2476:                }
2477:
2478:                write("(");
2479:                boolean wasNoSemicolons = noSemicolons;
2480:                boolean wasNoLinefeed = noLinefeed;
2481:                noLinefeed = true;
2482:                noSemicolons = true;
2483:                if (x.getArguments() != null) {
2484:                    writeCommaList(x.getArguments());
2485:                }
2486:                write(")");
2487:                if (withSemicolon) {
2488:                    write(";");
2489:                }
2490:                noLinefeed = wasNoLinefeed;
2491:                noSemicolons = wasNoSemicolons;
2492:                output();
2493:
2494:                // Mark statement end ...
2495:                markEnd(0, x);
2496:
2497:            }
2498:
2499:            public void printMethod(ProgramMethod x) throws java.io.IOException {
2500:                //        printHeader(x);
2501:                write(x.name().toString());
2502:                //        printFooter(x);
2503:            }
2504:
2505:            public void printExecutionContext(ExecutionContext x)
2506:                    throws java.io.IOException {
2507:                write("source=");
2508:                writeElement(x.getTypeReference());
2509:                if (x.getRuntimeInstance() != null) {
2510:                    write(",this=");
2511:                    writeElement(x.getRuntimeInstance());
2512:                }
2513:            }
2514:
2515:            public void printSuperConstructorReference(
2516:                    SuperConstructorReference x) throws java.io.IOException {
2517:
2518:                printHeader(x);
2519:                markStart(0, x);
2520:
2521:                if (x.getReferencePrefix() != null) {
2522:                    writeElement(x.getReferencePrefix());
2523:                    write(".");
2524:                }
2525:                writeToken("super (", x);
2526:                if (x.getArguments() != null) {
2527:                    writeCommaList(0, 0, 0, x.getArguments());
2528:                }
2529:                write(");");
2530:                markEnd(0, x);
2531:                printFooter(x);
2532:            }
2533:
2534:            public void printThisConstructorReference(ThisConstructorReference x)
2535:                    throws java.io.IOException {
2536:
2537:                printHeader(x);
2538:                markStart(0, x);
2539:                writeInternalIndentation(x);
2540:                write("this (");
2541:                if (x.getArguments() != null) {
2542:                    writeCommaList(x.getArguments());
2543:                }
2544:                write(");");
2545:                markEnd(0, x);
2546:                printFooter(x);
2547:            }
2548:
2549:            public void printSuperReference(SuperReference x)
2550:                    throws java.io.IOException {
2551:                printHeader(x);
2552:                markStart(0, x);
2553:                if (x.getReferencePrefix() != null) {
2554:                    writeElement(x.getReferencePrefix());
2555:                    writeToken(".super", x);
2556:                } else {
2557:                    writeToken("super", x);
2558:                }
2559:                markEnd(0, x);
2560:                printFooter(x);
2561:            }
2562:
2563:            public void printThisReference(ThisReference x)
2564:                    throws java.io.IOException {
2565:                printHeader(x);
2566:                markStart(0, x);
2567:                if (x.getReferencePrefix() != null) {
2568:                    writeElement(x.getReferencePrefix());
2569:                    writeToken(".this", x);
2570:                } else {
2571:                    writeToken("this", x);
2572:                }
2573:                markEnd(0, x);
2574:                printFooter(x);
2575:            }
2576:
2577:            public void printArrayLengthReference(ArrayLengthReference x)
2578:                    throws java.io.IOException {
2579:                printHeader(x);
2580:                if (x.getReferencePrefix() != null) {
2581:                    writeElement(x.getReferencePrefix());
2582:                    write(".");
2583:                }
2584:                writeToken("length", x);
2585:                printFooter(x);
2586:            }
2587:
2588:            public void printThen(Then x) throws java.io.IOException {
2589:                printHeader(x);
2590:                if (x.getBody() != null) {
2591:                    writeElement(x.getBody());
2592:                }
2593:                printFooter(x);
2594:            }
2595:
2596:            public void printElse(Else x) throws java.io.IOException {
2597:                printHeader(x);
2598:                writeInternalIndentation(x);
2599:                write("else");
2600:                if (x.getBody() != null) {
2601:                    if (x.getBody() instanceof  StatementBlock) {
2602:                        writeElement(1, 0, x.getBody());
2603:                    } else {
2604:                        writeElement(1, +1, 0, x.getBody());
2605:                        changeLevel(-1);
2606:                    }
2607:                }
2608:
2609:                printFooter(x);
2610:            }
2611:
2612:            public void printCase(Case x) throws java.io.IOException {
2613:                printHeader(x);
2614:                writeInternalIndentation(x);
2615:                write("case ");
2616:                if (x.getExpression() != null) {
2617:                    boolean wasNoSemicolons = noSemicolons;
2618:                    noSemicolons = true;
2619:                    writeElement(1, x.getExpression());
2620:                    noSemicolons = wasNoSemicolons;
2621:                }
2622:                write(":");
2623:                if (x.getBody() != null && x.getBody().size() > 0) {
2624:                    writeLineList(1, +1, 0, x.getBody());
2625:                    changeLevel(-1);
2626:                }
2627:                printFooter(x);
2628:            }
2629:
2630:            public void printCatch(Catch x) throws java.io.IOException {
2631:                printHeader(x);
2632:                writeToken("catch (", x);
2633:                if (x.getParameterDeclaration() != null) {
2634:                    noLinefeed = true;
2635:                    noSemicolons = true;
2636:                    writeElement(x.getParameterDeclaration());
2637:                }
2638:                write(")");
2639:                noSemicolons = false;
2640:                noLinefeed = false;
2641:                if (x.getBody() != null) {
2642:                    writeElement(1, x.getBody());
2643:                }
2644:                printFooter(x);
2645:            }
2646:
2647:            public void printDefault(Default x) throws java.io.IOException {
2648:                printHeader(x);
2649:                writeInternalIndentation(x);
2650:                write("default:");
2651:                if (x.getBody() != null && x.getBody().size() > 0) {
2652:                    writeLineList(1, +1, 0, x.getBody());
2653:                    changeLevel(-1);
2654:                }
2655:                printFooter(x);
2656:            }
2657:
2658:            public void printFinally(Finally x) throws java.io.IOException {
2659:                printHeader(x);
2660:                writeInternalIndentation(x);
2661:                noLinefeed = true;
2662:                output();
2663:                noLinefeed = false;
2664:                write("finally");
2665:                if (x.getBody() != null) {
2666:                    writeElement(1, x.getBody());
2667:                }
2668:                printFooter(x);
2669:            }
2670:
2671:            public void printModifier(Modifier x) throws java.io.IOException {
2672:                printHeader(x);
2673:                writeInternalIndentation(x);
2674:                write(x.getText());
2675:                printFooter(x);
2676:            }
2677:
2678:            public void printSchemaVariable(SchemaVariable x)
2679:                    throws java.io.IOException {
2680:                if (x instanceof  ProgramSV) {
2681:                    if (!noSemicolons) {
2682:                        markStart(0, x);
2683:                    }
2684:                    Object o = instantiations.getInstantiation(x);
2685:                    if (o == null) {
2686:                        printHeader((ProgramSV) x);
2687:                        writeInternalIndentation((ProgramSV) x);
2688:                        write(x.name().toString());
2689:                        printFooter((ProgramSV) x);
2690:                    } else {
2691:                        //logger.debug(o.toString() + "  " + o.getClass().getName());
2692:                        //Debug.assertTrue(o instanceof ProgramElement);
2693:                        if (o instanceof  ProgramElement) {
2694:                            ((ProgramElement) o).prettyPrint(this );
2695:                        } else if (o instanceof  ArrayOfProgramElement) {
2696:                            writeBlockList((ArrayOfProgramElement) o);
2697:                        } else {
2698:                            logger.warn("No PrettyPrinting available for "
2699:                                    + o.getClass().getName());
2700:                        }
2701:                    }
2702:                    if (!noSemicolons) {
2703:                        markEnd(0, x);
2704:                    }
2705:                } else {
2706:                    Debug
2707:                            .fail("That cannot happen! Don't know how to pretty print non program SV in programs.");
2708:                }
2709:
2710:            }
2711:
2712:            public void printEmptyStatement(EmptyStatement x)
2713:                    throws java.io.IOException {
2714:                printHeader(x);
2715:                writeInternalIndentation(x);
2716:
2717:                // Mark statement start ...
2718:                markStart(0, x);
2719:
2720:                write(";");
2721:
2722:                // Mark statement end ...
2723:                markEnd(0, x);
2724:
2725:                printFooter(x);
2726:            }
2727:
2728:            public void printComment(Comment x) throws java.io.IOException {
2729:                if (fileWriterMode) {
2730:                    write("\n");
2731:                    if (x.getText().startsWith("/*")) {
2732:                        write(x.getText());
2733:                        if (x.getText().indexOf("*/") == -1) {
2734:                            write("*/");
2735:                        }
2736:                    } else {
2737:                        write("/*" + x.getText() + "*/");
2738:                    }
2739:                }
2740:            }
2741:
2742:            public void printParenthesizedExpression(ParenthesizedExpression x)
2743:                    throws IOException {
2744:
2745:                writeToken("(", x);
2746:                if (x.getArguments() != null) {
2747:                    writeElement(x.getArguments().getExpression(0));
2748:                }
2749:                write(")");
2750:                output();
2751:            }
2752:
2753:            public void printProgramSVProxy(ProgramSVProxy x)
2754:                    throws java.io.IOException {
2755:
2756:                printHeader(x);
2757:                writeInternalIndentation(x);
2758:
2759:                // Mark statement start ...
2760:                markStart(0, x);
2761:
2762:                writeElement(x.op());
2763:
2764:                write(" (");
2765:                boolean wasNoSemicolons = noSemicolons;
2766:                boolean wasNoLinefeed = noLinefeed;
2767:                noLinefeed = true;
2768:                noSemicolons = true;
2769:                writeCommaList(1, x.getInfluencingPVs());
2770:                noSemicolons = false;
2771:                write("; ");
2772:                output();
2773:                noLinefeed = wasNoLinefeed;
2774:                noSemicolons = wasNoSemicolons;
2775:                writeKeywordList(x.getJumpTable());
2776:                write(")");
2777:                write(";");
2778:                output();
2779:
2780:                // Mark statement end ...
2781:                markEnd(0, x);
2782:
2783:            }
2784:
2785:            public void printPassiveExpression(PassiveExpression x)
2786:                    throws IOException {
2787:
2788:                writeToken("@(", x);
2789:                if (x.getArguments() != null) {
2790:                    writeElement(x.getArguments().getExpression(0));
2791:                }
2792:                write(")");
2793:                output();
2794:            }
2795:
2796:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.