Source Code Cross Referenced for AbstractTokenizer.java in  » Code-Analyzer » pmd-4.2rc1 » net » sourceforge » pmd » cpd » 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 » pmd 4.2rc1 » net.sourceforge.pmd.cpd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003:         * @author Zev Blut zb@ubit.com
004:         * @author Romain PELISSE belaran@gmail.com
005:         */package net.sourceforge.pmd.cpd;
006:
007:        import java.util.List;
008:
009:        public abstract class AbstractTokenizer implements  Tokenizer {
010:
011:            protected List<String> stringToken; // List<String>, should be setted by children classes
012:            protected List<String> ignorableCharacter; // List<String>, should be setted by children classes
013:            // FIXME:Maybe an array of 'char' would be better for perfomance ?
014:            protected List<String> ignorableStmt; // List<String>, should be setted by children classes
015:            protected char ONE_LINE_COMMENT_CHAR = '#'; // Most script language ( shell, ruby, python,...) use this symbol for comment line
016:
017:            private List<String> code;
018:            private int lineNumber = 0;
019:            private String currentLine;
020:
021:            protected boolean spanMultipleLinesString = true; // Most language does, so default is true
022:
023:            private boolean downcaseString = true;
024:
025:            public void tokenize(SourceCode tokens, Tokens tokenEntries) {
026:                this .code = tokens.getCode();
027:
028:                for (this .lineNumber = 0; lineNumber < this .code.size(); lineNumber++) {
029:                    this .currentLine = this .code.get(this .lineNumber);
030:                    int loc = 0;
031:                    while (loc < currentLine.length()) {
032:                        StringBuffer token = new StringBuffer();
033:                        loc = getTokenFromLine(token, loc);
034:                        if (token.length() > 0
035:                                && !isIgnorableString(token.toString())) {
036:                            if (downcaseString) {
037:                                token = new StringBuffer(token.toString()
038:                                        .toLowerCase());
039:                            }
040:                            if (CPD.debugEnable)
041:                                System.out.println("Token added:"
042:                                        + token.toString());
043:                            tokenEntries.add(new TokenEntry(token.toString(),
044:                                    tokens.getFileName(), lineNumber));
045:
046:                        }
047:                    }
048:                }
049:                tokenEntries.add(TokenEntry.getEOF());
050:            }
051:
052:            private int getTokenFromLine(StringBuffer token, int loc) {
053:                for (int j = loc; j < this .currentLine.length(); j++) {
054:                    char tok = this .currentLine.charAt(j);
055:                    if (!Character.isWhitespace(tok) && !ignoreCharacter(tok)) {
056:                        if (isComment(tok)) {
057:                            if (token.length() > 0) {
058:                                return j;
059:                            } else {
060:                                return getCommentToken(token, loc);
061:                            }
062:                        } else if (isString(tok)) {
063:                            if (token.length() > 0) {
064:                                return j; // we need to now parse the string as a seperate token.
065:                            } else {
066:                                // we are at the start of a string
067:                                return parseString(token, j, tok);
068:                            }
069:                        } else {
070:                            token.append(tok);
071:                        }
072:                    } else {
073:                        if (token.length() > 0) {
074:                            return j;
075:                        }
076:                    }
077:                    loc = j;
078:                }
079:                return loc + 1;
080:            }
081:
082:            private int parseString(StringBuffer token, int loc,
083:                    char stringDelimiter) {
084:                boolean escaped = false;
085:                boolean done = false;
086:                char tok = ' '; // this will be replaced.
087:                while ((loc < currentLine.length()) && !done) {
088:                    tok = currentLine.charAt(loc);
089:                    if (escaped && tok == stringDelimiter) // Found an escaped string
090:                        escaped = false;
091:                    else if (tok == stringDelimiter && (token.length() > 0)) // We are done, we found the end of the string...
092:                        done = true;
093:                    else if (tok == '\\') // Found an escaped char
094:                        escaped = true;
095:                    else
096:                        // Adding char...
097:                        escaped = false;
098:                    //Adding char to String:" + token.toString());
099:                    token.append(tok);
100:                    loc++;
101:                }
102:                // Handling multiple lines string
103:                if (!done && // ... we didn't find the end of the string
104:                        loc >= currentLine.length() && // ... we have reach the end of the line ( the String is incomplete, for the moment at least)
105:                        this .spanMultipleLinesString && // ... the language allow multiple line span Strings
106:                        ++this .lineNumber < this .code.size() // ... there is still more lines to parse
107:                ) {
108:                    // parsing new line
109:                    this .currentLine = this .code.get(this .lineNumber);
110:                    // Warning : recursive call !
111:                    loc = this .parseString(token, loc, stringDelimiter);
112:                }
113:                return loc + 1;
114:            }
115:
116:            private boolean ignoreCharacter(char tok) {
117:                return this .ignorableCharacter.contains("" + tok);
118:            }
119:
120:            private boolean isString(char tok) {
121:                return this .stringToken.contains("" + tok);
122:            }
123:
124:            private boolean isComment(char tok) {
125:                return tok == ONE_LINE_COMMENT_CHAR;
126:            }
127:
128:            private int getCommentToken(StringBuffer token, int loc) {
129:                while (loc < this .currentLine.length()) {
130:                    token.append(this .currentLine.charAt(loc++));
131:                }
132:                return loc;
133:            }
134:
135:            private boolean isIgnorableString(String token) {
136:                return this.ignorableStmt.contains(token);
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.