Source Code Cross Referenced for LineMapping.java in  » Code-Analyzer » doctorj » org » incava » text » 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 » Code Analyzer » doctorj » org.incava.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.incava.text;
002:
003:        import java.awt.Point;
004:        import java.io.*;
005:        import java.util.*;
006:
007:        /**
008:         * Converts from 0-indexed string positions to line:column values. Lines and
009:         * columns are 1-indexed, matching the Java parser.
010:         */
011:        public class LineMapping extends ArrayList {
012:            public class PositionToLocation {
013:                public int position;
014:
015:                public int line;
016:
017:                public int column;
018:
019:                public PositionToLocation(int position, int line, int column) {
020:                    this .position = position;
021:                    this .line = line;
022:                    this .column = column;
023:                }
024:
025:                public String toString() {
026:                    return "{ position: " + position + " => { line: " + line
027:                            + ", column: " + column + " } }";
028:                }
029:            }
030:
031:            public LineMapping(String text, int startLine, int startColumn) {
032:                // tr.Ace.log("position: " + 0 + " => { line: " + startLine + ", column: " + startColumn + " }");
033:                add(new PositionToLocation(0, startLine, startColumn));
034:
035:                int len = text.length();
036:
037:                // figure out where the lines start:
038:                for (int pos = 0, line = startLine; pos < len; ++pos) {
039:                    // Mac: \r, Unix: \n, DOS: \r\n
040:                    if (text.charAt(pos) == '\r') {
041:                        // might be DOS:
042:                        if (pos + 1 < len && text.charAt(pos + 1) == '\n') {
043:                            ++pos;
044:                        }
045:                        // otherwise, it's Mac (at least, before OS X)
046:                    } else if (text.charAt(pos) == '\n') {
047:                        // Unix
048:                    } else {
049:                        // we're not at a newline, so go to the next character.
050:                        continue;
051:                    }
052:
053:                    ++line;
054:
055:                    // tr.Ace.log("position: " + pos + " => { line: " + line + ", column: " + 1 + " }");
056:                    add(new PositionToLocation(pos + 1, line, 1));
057:                }
058:
059:                // tr.Ace.log("line positions: " + this);
060:            }
061:
062:            /**
063:             * Converts the string position to a line:column start and end location.
064:             */
065:            public Location[] getLocations(Point pos) {
066:                return getLocations(pos.x, pos.y);
067:            }
068:
069:            /**
070:             * Converts the string position to a line:column start and end location.
071:             */
072:            public Location[] getLocations(int startPos, int endPos) {
073:                // tr.Ace.log("parsing description");
074:                Location start = null;
075:                Location end = null;
076:
077:                // tr.Ace.log("position: " + startPos + ", " + endPos);
078:
079:                // go backward
080:                ListIterator lit = listIterator(size());
081:                while ((start == null || end == null) && lit.hasPrevious()) {
082:                    PositionToLocation pl = (PositionToLocation) lit.previous();
083:                    // tr.Ace.log("considering position/location " + pl);
084:                    if (end == null && endPos >= pl.position) {
085:                        // tr.Ace.log("assigning end");
086:                        end = new Location(pl.line, pl.column + endPos
087:                                - pl.position);
088:                    }
089:                    if (start == null && startPos >= pl.position) {
090:                        // tr.Ace.log("assigning start");
091:                        start = new Location(pl.line, pl.column + startPos
092:                                - pl.position);
093:                    }
094:                }
095:
096:                // attn Sun: tuples, please!
097:                return new Location[] { start, end };
098:            }
099:
100:            /**
101:             * Converts the string position to a line:column location.
102:             */
103:            public Location getLocation(int pos) {
104:                Location location = null;
105:
106:                // tr.Ace.log("position: " + pos);
107:
108:                // go backward
109:                ListIterator lit = listIterator(size());
110:                while (location == null && lit.hasPrevious()) {
111:                    PositionToLocation pl = (PositionToLocation) lit.previous();
112:                    // tr.Ace.log("considering position/location " + pl);
113:                    if (location == null && pos >= pl.position) {
114:                        // tr.Ace.log("creating location");
115:                        return new Location(pl.line, pl.column + pos
116:                                - pl.position);
117:                    }
118:                }
119:
120:                return null;
121:            }
122:
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.