Source Code Cross Referenced for SourceCode.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:         */package net.sourceforge.pmd.cpd;
004:
005:        import net.sourceforge.pmd.PMD;
006:
007:        import java.io.File;
008:        import java.io.LineNumberReader;
009:        import java.io.Reader;
010:        import java.io.StringReader;
011:        import java.io.FileInputStream;
012:        import java.io.InputStreamReader;
013:        import java.lang.ref.SoftReference;
014:        import java.util.ArrayList;
015:        import java.util.List;
016:
017:        public class SourceCode {
018:
019:            public static abstract class CodeLoader {
020:                private SoftReference<List<String>> code;
021:
022:                public List<String> getCode() {
023:                    List<String> c = null;
024:                    if (code != null) {
025:                        c = code.get();
026:                    }
027:                    if (c != null) {
028:                        return c;
029:                    }
030:                    this .code = new SoftReference<List<String>>(load());
031:                    return code.get();
032:                }
033:
034:                public abstract String getFileName();
035:
036:                protected abstract Reader getReader() throws Exception;
037:
038:                protected List<String> load() {
039:                    LineNumberReader lnr = null;
040:                    try {
041:                        lnr = new LineNumberReader(getReader());
042:                        List<String> lines = new ArrayList<String>();
043:                        String currentLine;
044:                        while ((currentLine = lnr.readLine()) != null) {
045:                            lines.add(currentLine);
046:                        }
047:                        return lines;
048:                    } catch (Exception e) {
049:                        e.printStackTrace();
050:                        throw new RuntimeException("Problem while reading "
051:                                + getFileName() + ":" + e.getMessage());
052:                    } finally {
053:                        try {
054:                            if (lnr != null)
055:                                lnr.close();
056:                        } catch (Exception e) {
057:                            throw new RuntimeException("Problem while reading "
058:                                    + getFileName() + ":" + e.getMessage());
059:                        }
060:                    }
061:                }
062:            }
063:
064:            public static class FileCodeLoader extends CodeLoader {
065:                private File file;
066:                private String encoding;
067:
068:                public FileCodeLoader(File file, String encoding) {
069:                    this .file = file;
070:                    this .encoding = encoding;
071:                }
072:
073:                public Reader getReader() throws Exception {
074:                    return new InputStreamReader(new FileInputStream(file),
075:                            encoding);
076:                }
077:
078:                public String getFileName() {
079:                    return this .file.getAbsolutePath();
080:                }
081:            }
082:
083:            public static class StringCodeLoader extends CodeLoader {
084:                public static final String DEFAULT_NAME = "CODE_LOADED_FROM_STRING";
085:
086:                private String source_code;
087:
088:                private String name;
089:
090:                public StringCodeLoader(String code) {
091:                    this (code, DEFAULT_NAME);
092:                }
093:
094:                public StringCodeLoader(String code, String name) {
095:                    this .source_code = code;
096:                    this .name = name;
097:                }
098:
099:                public Reader getReader() {
100:                    return new StringReader(source_code);
101:                }
102:
103:                public String getFileName() {
104:                    return name;
105:                }
106:            }
107:
108:            private CodeLoader cl;
109:
110:            public SourceCode(CodeLoader cl) {
111:                this .cl = cl;
112:            }
113:
114:            public List<String> getCode() {
115:                return cl.getCode();
116:            }
117:
118:            public StringBuffer getCodeBuffer() {
119:                StringBuffer sb = new StringBuffer();
120:                List<String> lines = cl.getCode();
121:                for (String line : lines) {
122:                    sb.append(line);
123:                    sb.append(PMD.EOL);
124:                }
125:                return sb;
126:            }
127:
128:            public String getSlice(int startLine, int endLine) {
129:                StringBuffer sb = new StringBuffer();
130:                List lines = cl.getCode();
131:                for (int i = startLine - 1; i < endLine && i < lines.size(); i++) {
132:                    if (sb.length() != 0) {
133:                        sb.append(PMD.EOL);
134:                    }
135:                    sb.append((String) lines.get(i));
136:                }
137:                return sb.toString();
138:            }
139:
140:            public String getFileName() {
141:                return cl.getFileName();
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.