Source Code Cross Referenced for SimpleCharStream.java in  » Aspect-oriented » aspectwerkz-2.0 » org » codehaus » aspectwerkz » expression » ast » 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 » Aspect oriented » aspectwerkz 2.0 » org.codehaus.aspectwerkz.expression.ast 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 3.0 */
002:        /**************************************************************************************
003:         * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
004:         * http://aspectwerkz.codehaus.org                                                    *
005:         * ---------------------------------------------------------------------------------- *
006:         * The software in this package is published under the terms of the LGPL license      *
007:         * a copy of which has been included with this distribution in the license.txt file.  *
008:         **************************************************************************************/package org.codehaus.aspectwerkz.expression.ast;
009:
010:        /**
011:         * An implementation of interface CharStream, where the stream is assumed to contain only ASCII characters (without
012:         * unicode processing).
013:         */
014:
015:        public class SimpleCharStream {
016:            public static final boolean staticFlag = true;
017:
018:            static int bufsize;
019:
020:            static int available;
021:
022:            static int tokenBegin;
023:
024:            static public int bufpos = -1;
025:
026:            static protected int bufline[];
027:
028:            static protected int bufcolumn[];
029:
030:            static protected int column = 0;
031:
032:            static protected int line = 1;
033:
034:            static protected boolean prevCharIsCR = false;
035:
036:            static protected boolean prevCharIsLF = false;
037:
038:            static protected java.io.Reader inputStream;
039:
040:            static protected char[] buffer;
041:
042:            static protected int maxNextCharInd = 0;
043:
044:            static protected int inBuf = 0;
045:
046:            static protected void ExpandBuff(boolean wrapAround) {
047:                char[] newbuffer = new char[bufsize + 2048];
048:                int newbufline[] = new int[bufsize + 2048];
049:                int newbufcolumn[] = new int[bufsize + 2048];
050:
051:                try {
052:                    if (wrapAround) {
053:                        System.arraycopy(buffer, tokenBegin, newbuffer, 0,
054:                                bufsize - tokenBegin);
055:                        System.arraycopy(buffer, 0, newbuffer, bufsize
056:                                - tokenBegin, bufpos);
057:                        buffer = newbuffer;
058:
059:                        System.arraycopy(bufline, tokenBegin, newbufline, 0,
060:                                bufsize - tokenBegin);
061:                        System.arraycopy(bufline, 0, newbufline, bufsize
062:                                - tokenBegin, bufpos);
063:                        bufline = newbufline;
064:
065:                        System.arraycopy(bufcolumn, tokenBegin, newbufcolumn,
066:                                0, bufsize - tokenBegin);
067:                        System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize
068:                                - tokenBegin, bufpos);
069:                        bufcolumn = newbufcolumn;
070:
071:                        maxNextCharInd = (bufpos += (bufsize - tokenBegin));
072:                    } else {
073:                        System.arraycopy(buffer, tokenBegin, newbuffer, 0,
074:                                bufsize - tokenBegin);
075:                        buffer = newbuffer;
076:
077:                        System.arraycopy(bufline, tokenBegin, newbufline, 0,
078:                                bufsize - tokenBegin);
079:                        bufline = newbufline;
080:
081:                        System.arraycopy(bufcolumn, tokenBegin, newbufcolumn,
082:                                0, bufsize - tokenBegin);
083:                        bufcolumn = newbufcolumn;
084:
085:                        maxNextCharInd = (bufpos -= tokenBegin);
086:                    }
087:                } catch (Throwable t) {
088:                    throw new Error(t.getMessage());
089:                }
090:
091:                bufsize += 2048;
092:                available = bufsize;
093:                tokenBegin = 0;
094:            }
095:
096:            static protected void FillBuff() throws java.io.IOException {
097:                if (maxNextCharInd == available) {
098:                    if (available == bufsize) {
099:                        if (tokenBegin > 2048) {
100:                            bufpos = maxNextCharInd = 0;
101:                            available = tokenBegin;
102:                        } else if (tokenBegin < 0) {
103:                            bufpos = maxNextCharInd = 0;
104:                        } else {
105:                            ExpandBuff(false);
106:                        }
107:                    } else if (available > tokenBegin) {
108:                        available = bufsize;
109:                    } else if ((tokenBegin - available) < 2048) {
110:                        ExpandBuff(true);
111:                    } else {
112:                        available = tokenBegin;
113:                    }
114:                }
115:
116:                int i;
117:                try {
118:                    if ((i = inputStream.read(buffer, maxNextCharInd, available
119:                            - maxNextCharInd)) == -1) {
120:                        inputStream.close();
121:                        throw new java.io.IOException();
122:                    } else {
123:                        maxNextCharInd += i;
124:                    }
125:                    return;
126:                } catch (java.io.IOException e) {
127:                    --bufpos;
128:                    backup(0);
129:                    if (tokenBegin == -1) {
130:                        tokenBegin = bufpos;
131:                    }
132:                    throw e;
133:                }
134:            }
135:
136:            static public char BeginToken() throws java.io.IOException {
137:                tokenBegin = -1;
138:                char c = readChar();
139:                tokenBegin = bufpos;
140:
141:                return c;
142:            }
143:
144:            static protected void UpdateLineColumn(char c) {
145:                column++;
146:
147:                if (prevCharIsLF) {
148:                    prevCharIsLF = false;
149:                    line += (column = 1);
150:                } else if (prevCharIsCR) {
151:                    prevCharIsCR = false;
152:                    if (c == '\n') {
153:                        prevCharIsLF = true;
154:                    } else {
155:                        line += (column = 1);
156:                    }
157:                }
158:
159:                switch (c) {
160:                case '\r':
161:                    prevCharIsCR = true;
162:                    break;
163:                case '\n':
164:                    prevCharIsLF = true;
165:                    break;
166:                case '\t':
167:                    column--;
168:                    column += (8 - (column & 07));
169:                    break;
170:                default:
171:                    break;
172:                }
173:
174:                bufline[bufpos] = line;
175:                bufcolumn[bufpos] = column;
176:            }
177:
178:            static public char readChar() throws java.io.IOException {
179:                if (inBuf > 0) {
180:                    --inBuf;
181:
182:                    if (++bufpos == bufsize) {
183:                        bufpos = 0;
184:                    }
185:
186:                    return buffer[bufpos];
187:                }
188:
189:                if (++bufpos >= maxNextCharInd) {
190:                    FillBuff();
191:                }
192:
193:                char c = buffer[bufpos];
194:
195:                UpdateLineColumn(c);
196:                return (c);
197:            }
198:
199:            /**
200:             * @deprecated @see #getEndColumn
201:             */
202:
203:            static public int getColumn() {
204:                return bufcolumn[bufpos];
205:            }
206:
207:            /**
208:             * @deprecated @see #getEndLine
209:             */
210:
211:            static public int getLine() {
212:                return bufline[bufpos];
213:            }
214:
215:            static public int getEndColumn() {
216:                return bufcolumn[bufpos];
217:            }
218:
219:            static public int getEndLine() {
220:                return bufline[bufpos];
221:            }
222:
223:            static public int getBeginColumn() {
224:                return bufcolumn[tokenBegin];
225:            }
226:
227:            static public int getBeginLine() {
228:                return bufline[tokenBegin];
229:            }
230:
231:            static public void backup(int amount) {
232:
233:                inBuf += amount;
234:                if ((bufpos -= amount) < 0) {
235:                    bufpos += bufsize;
236:                }
237:            }
238:
239:            public SimpleCharStream(java.io.Reader dstream, int startline,
240:                    int startcolumn, int buffersize) {
241:                if (inputStream != null) {
242:                    throw new Error(
243:                            "\n   ERROR: Second call to the constructor of a static SimpleCharStream.  You must\n"
244:                                    + "       either use ReInit() or set the JavaCC option STATIC to false\n"
245:                                    + "       during the generation of this class.");
246:                }
247:                inputStream = dstream;
248:                line = startline;
249:                column = startcolumn - 1;
250:
251:                available = bufsize = buffersize;
252:                buffer = new char[buffersize];
253:                bufline = new int[buffersize];
254:                bufcolumn = new int[buffersize];
255:            }
256:
257:            public SimpleCharStream(java.io.Reader dstream, int startline,
258:                    int startcolumn) {
259:                this (dstream, startline, startcolumn, 4096);
260:            }
261:
262:            public SimpleCharStream(java.io.Reader dstream) {
263:                this (dstream, 1, 1, 4096);
264:            }
265:
266:            public void ReInit(java.io.Reader dstream, int startline,
267:                    int startcolumn, int buffersize) {
268:                inputStream = dstream;
269:                line = startline;
270:                column = startcolumn - 1;
271:
272:                if (buffer == null || buffersize != buffer.length) {
273:                    available = bufsize = buffersize;
274:                    buffer = new char[buffersize];
275:                    bufline = new int[buffersize];
276:                    bufcolumn = new int[buffersize];
277:                }
278:                prevCharIsLF = prevCharIsCR = false;
279:                tokenBegin = inBuf = maxNextCharInd = 0;
280:                bufpos = -1;
281:            }
282:
283:            public void ReInit(java.io.Reader dstream, int startline,
284:                    int startcolumn) {
285:                ReInit(dstream, startline, startcolumn, 4096);
286:            }
287:
288:            public void ReInit(java.io.Reader dstream) {
289:                ReInit(dstream, 1, 1, 4096);
290:            }
291:
292:            public SimpleCharStream(java.io.InputStream dstream, int startline,
293:                    int startcolumn, int buffersize) {
294:                this (new java.io.InputStreamReader(dstream), startline,
295:                        startcolumn, 4096);
296:            }
297:
298:            public SimpleCharStream(java.io.InputStream dstream, int startline,
299:                    int startcolumn) {
300:                this (dstream, startline, startcolumn, 4096);
301:            }
302:
303:            public SimpleCharStream(java.io.InputStream dstream) {
304:                this (dstream, 1, 1, 4096);
305:            }
306:
307:            public void ReInit(java.io.InputStream dstream, int startline,
308:                    int startcolumn, int buffersize) {
309:                ReInit(new java.io.InputStreamReader(dstream), startline,
310:                        startcolumn, 4096);
311:            }
312:
313:            public void ReInit(java.io.InputStream dstream) {
314:                ReInit(dstream, 1, 1, 4096);
315:            }
316:
317:            public void ReInit(java.io.InputStream dstream, int startline,
318:                    int startcolumn) {
319:                ReInit(dstream, startline, startcolumn, 4096);
320:            }
321:
322:            static public String GetImage() {
323:                if (bufpos >= tokenBegin) {
324:                    return new String(buffer, tokenBegin, bufpos - tokenBegin
325:                            + 1);
326:                } else {
327:                    return new String(buffer, tokenBegin, bufsize - tokenBegin)
328:                            + new String(buffer, 0, bufpos + 1);
329:                }
330:            }
331:
332:            static public char[] GetSuffix(int len) {
333:                char[] ret = new char[len];
334:
335:                if ((bufpos + 1) >= len) {
336:                    System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
337:                } else {
338:                    System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret,
339:                            0, len - bufpos - 1);
340:                    System.arraycopy(buffer, 0, ret, len - bufpos - 1,
341:                            bufpos + 1);
342:                }
343:
344:                return ret;
345:            }
346:
347:            static public void Done() {
348:                buffer = null;
349:                bufline = null;
350:                bufcolumn = null;
351:            }
352:
353:            /**
354:             * Method to adjust line and column numbers for the start of a token.
355:             */
356:            static public void adjustBeginLineColumn(int newLine, int newCol) {
357:                int start = tokenBegin;
358:                int len;
359:
360:                if (bufpos >= tokenBegin) {
361:                    len = bufpos - tokenBegin + inBuf + 1;
362:                } else {
363:                    len = bufsize - tokenBegin + bufpos + 1 + inBuf;
364:                }
365:
366:                int i = 0, j = 0, k = 0;
367:                int nextColDiff = 0, columnDiff = 0;
368:
369:                while (i < len
370:                        && bufline[j = start % bufsize] == bufline[k = ++start
371:                                % bufsize]) {
372:                    bufline[j] = newLine;
373:                    nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
374:                    bufcolumn[j] = newCol + columnDiff;
375:                    columnDiff = nextColDiff;
376:                    i++;
377:                }
378:
379:                if (i < len) {
380:                    bufline[j] = newLine++;
381:                    bufcolumn[j] = newCol + columnDiff;
382:
383:                    while (i++ < len) {
384:                        if (bufline[j = start % bufsize] != bufline[++start
385:                                % bufsize]) {
386:                            bufline[j] = newLine++;
387:                        } else {
388:                            bufline[j] = newLine;
389:                        }
390:                    }
391:                }
392:
393:                line = bufline[j];
394:                column = bufcolumn[j];
395:            }
396:
397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.