Source Code Cross Referenced for AntlrASTProcessSnippets.java in  » Scripting » groovy-1.0 » org » codehaus » groovy » antlr » 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 » Scripting » groovy 1.0 » org.codehaus.groovy.antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         * Copyright 2005 Jeremy Rayner
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         * http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         *
017:         **/package org.codehaus.groovy.antlr;
018:
019:        /**
020:         * Process to decorate antlr AST with ending line/col info, and if
021:         * possible the snipppet of source from the start/end line/col for each node.
022:         *
023:         * @author <a href="mailto:groovy@ross-rayner.com">Jeremy Rayner</a>
024:         * @version $Revision: 3701 $
025:         */
026:
027:        import antlr.collections.AST;
028:        import java.util.*;
029:
030:        public class AntlrASTProcessSnippets implements  AntlrASTProcessor {
031:            private SourceBuffer sourceBuffer;
032:
033:            public AntlrASTProcessSnippets(SourceBuffer sourceBuffer) {
034:                this .sourceBuffer = sourceBuffer;
035:            }
036:
037:            /**
038:             * decorate antlr AST with ending line/col info, and if
039:             * possible the snipppet of source from the start/end line/col for each node.
040:             * @param t the AST to decorate
041:             * @return the decorated AST
042:             */
043:            public AST process(AST t) {
044:                // first visit
045:                List l = new ArrayList();
046:                t = traverse((GroovySourceAST) t, l, null);
047:
048:                //System.out.println("l:" + l);
049:                // second visit
050:                Iterator itr = l.iterator();
051:                if (itr.hasNext()) {
052:                    itr.next(); /* discard first */
053:                }
054:                t = traverse((GroovySourceAST) t, null, itr);
055:                return t;
056:            }
057:
058:            /**
059:             * traverse an AST node
060:             * @param t the AST node to traverse
061:             * @param l A list to add line/col info to
062:             * @param itr An iterator over a list of line/col
063:             * @return A decorated AST node
064:             */
065:            private AST traverse(GroovySourceAST t, List l, Iterator itr) {
066:                if (t == null) {
067:                    return t;
068:                }
069:
070:                // first visit of node
071:                if (l != null) {
072:                    l.add(new LineColumn(t.getLine(), t.getColumn()));
073:                }
074:
075:                // second vist of node
076:                if (itr != null && itr.hasNext()) {
077:                    LineColumn lc = (LineColumn) itr.next();
078:                    if (t.getLineLast() == 0) {
079:                        int nextLine = lc.getLine();
080:                        int nextColumn = lc.getColumn();
081:                        if (nextLine < t.getLine()
082:                                || (nextLine == t.getLine() && nextColumn < t
083:                                        .getColumn())) {
084:                            nextLine = t.getLine();
085:                            nextColumn = t.getColumn();
086:                        }
087:                        t.setLineLast(nextLine);
088:                        t.setColumnLast(nextColumn);
089:                        // This is a good point to call t.setSnippet(),
090:                        // but it bulks up the AST too much for production code.
091:                    }
092:                }
093:
094:                GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
095:                if (child != null) {
096:                    traverse(child, l, itr);
097:                }
098:
099:                GroovySourceAST sibling = (GroovySourceAST) t.getNextSibling();
100:                if (sibling != null) {
101:                    traverse(sibling, l, itr);
102:                }
103:
104:                return t;
105:            }
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.