Source Code Cross Referenced for ResultTree.java in  » Parser » runcc » fri » patterns » interpreter » parsergenerator » lexer » 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 » Parser » runcc » fri.patterns.interpreter.parsergenerator.lexer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package fri.patterns.interpreter.parsergenerator.lexer;
002:
003:        import java.util.*;
004:        import fri.patterns.interpreter.parsergenerator.Token;
005:        import fri.patterns.interpreter.parsergenerator.syntax.Rule;
006:
007:        /**
008:         Lexer result tree element, holding texts, its line/column range, and result children.
009:        
010:         @author Fritz Ritzberger, 2003
011:         */
012:
013:        public class ResultTree {
014:            private Rule rule;
015:            private List sequenceList;
016:            private Token.Range range;
017:            private StringBuffer buffer;
018:            private String stringResult;
019:
020:            ResultTree(Rule rule) {
021:                this .rule = rule;
022:            }
023:
024:            /** Returns the character- or byte-range within input where the token was found. */
025:            public Token.Range getRange() {
026:                return range;
027:            }
028:
029:            void setRange(Token.Range range) {
030:                this .range = range;
031:            }
032:
033:            /** Returns true if this ResultTree or any of its children has text. */
034:            public boolean hasText() {
035:                for (int i = 0; sequenceList != null && i < sequenceList.size(); i++) {
036:                    Object o = sequenceList.get(i);
037:                    if (o instanceof  ResultTree == false)
038:                        return true; // StringBuffer was allocated with minimum one char
039:                    else if (((ResultTree) o).hasText())
040:                        return true;
041:                }
042:                return false;
043:            }
044:
045:            /** Returns the String text of this ResultTree, including any text of its children. */
046:            public String toString() {
047:                if (stringResult == null) {
048:                    StringBuffer sb = new StringBuffer();
049:                    for (int i = 0; sequenceList != null
050:                            && i < sequenceList.size(); i++) {
051:                        Object o = sequenceList.get(i);
052:                        if (o instanceof  ResultTree)
053:                            sb.append(((ResultTree) o).toString());
054:                        else
055:                            sb.append(o.toString());
056:                        // since JDK 1.4: sb.append((StringBuffer) o);	// is faster than o.toString()
057:                    }
058:                    stringResult = sb.toString();
059:                }
060:                return stringResult;
061:            }
062:
063:            /** Returns the rule this ResultTree was built from. */
064:            public Rule getRule() {
065:                return rule;
066:            }
067:
068:            /** Returns the child at index i of this element, which could be StringBuffer or ResultTree. */
069:            public Object getChild(int i) {
070:                Object o = sequenceList.get(i);
071:                return o instanceof  StringBuffer ? o.toString() : o; // avoid StringBuffer.append calls
072:            }
073:
074:            /** Returns the count of children of this element. */
075:            public int getChildCount() {
076:                return sequenceList != null ? sequenceList.size() : 0;
077:            }
078:
079:            ResultTree append(char c) {
080:                ensureStringBuffer(null).append(c);
081:                return this ;
082:            }
083:
084:            ResultTree append(String s) {
085:                ensureStringBuffer(s);
086:                return this ;
087:            }
088:
089:            ResultTree addChild(ResultTree r) {
090:                if (r.hasText()) {
091:                    ensureSequenceList().add(r);
092:                    buffer = null; // force new list element
093:                }
094:                return this ;
095:            }
096:
097:            private List ensureSequenceList() {
098:                if (sequenceList == null)
099:                    sequenceList = new ArrayList(rule != null ? rule
100:                            .rightSize() : 1);
101:                return sequenceList;
102:            }
103:
104:            private StringBuffer ensureStringBuffer(String toStore) {
105:                if (buffer == null) {
106:                    if (toStore == null)
107:                        buffer = new StringBuffer(8);
108:                    else
109:                        buffer = new StringBuffer(toStore);
110:                    ensureSequenceList().add(buffer);
111:                } else if (toStore != null) {
112:                    buffer.append(toStore);
113:                }
114:                return buffer;
115:            }
116:
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.