Source Code Cross Referenced for LineCommenterSet.java in  » Scripting » Kawa » gnu » kawa » ant » 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 » Kawa » gnu.kawa.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package gnu.kawa.ant;
002:
003:        import org.apache.tools.ant.types.FilterSet;
004:
005:        import org.apache.tools.ant.Project;
006:
007:        import java.util.Enumeration;
008:        import java.util.Hashtable;
009:
010:        public class LineCommenterSet extends FilterSet {
011:            // The replaceTokens method is stateful.
012:            // If this is not null, then we ignore all lines until we find that token.
013:            private String commentingUntil = null;
014:            private boolean commenting = false;
015:
016:            public LineCommenterSet() {
017:            }
018:
019:            /**
020:             * Individual filter component of filterset
021:             *
022:             * @author    Jim White
023:             * Created   2001-11-14.
024:             */
025:            public static class LineCommenter // extends FilterSet.Filter
026:            {
027:                String first;
028:                String last;
029:                boolean comment;
030:
031:                public LineCommenter() {
032:                }
033:
034:                public void setFirst(final String s) {
035:                    first = s;
036:                }
037:
038:                public void setLast(final String s) {
039:                    last = s;
040:                }
041:
042:                public void setComment(final boolean f) {
043:                    comment = f;
044:                }
045:
046:                public String getFirst() {
047:                    return first;
048:                }
049:
050:                public String getLast() {
051:                    return last;
052:                }
053:
054:                public boolean isComment() {
055:                    return comment;
056:                }
057:            }
058:
059:            /**
060:             * Gets the filter hash of the FilterSet.
061:             *
062:             * @return   The hash of the tokens and values for quick lookup.
063:             */
064:            public Hashtable getCommenterHash() {
065:                final int filterSize = getFilters().size();
066:                final Hashtable stripperHash = new Hashtable(filterSize);
067:                for (final Enumeration e = getFilters().elements(); e
068:                        .hasMoreElements();) {
069:                    LineCommenter commenter = (LineCommenter) e.nextElement();
070:                    stripperHash.put(commenter.getFirst(), commenter);
071:                }
072:                return stripperHash;
073:            }
074:
075:            /**
076:             * Does replacement on the given string with token matching.
077:             * This uses the defined begintoken and endtoken values which default to @ for both.
078:             *
079:             * @param line  The line to process the tokens in.
080:             * @return      The string with the tokens replaced.
081:             */
082:            public String replaceTokens(String line) {
083:                final String beginToken = getBeginToken();
084:                final String endToken = getEndToken();
085:                final int index = line.indexOf(beginToken);
086:
087:                if (commentingUntil != null) {
088:                    log("Commenting until: " + beginToken + commentingUntil
089:                            + endToken, Project.MSG_VERBOSE);
090:                }
091:
092:                try {
093:                    if (index < 0) {
094:                        if (commentingUntil == null) {
095:                            return line;
096:                        }
097:
098:                        return comment(line);
099:                    }
100:
101:                    final Hashtable tokens = getCommenterHash();
102:
103:                    final int endIndex = line.indexOf(endToken, index
104:                            + beginToken.length() + 1);
105:
106:                    if (endIndex < 1) {
107:                        if (commentingUntil == null) {
108:                            return line;
109:                        }
110:
111:                        return comment(line);
112:                    }
113:
114:                    final String token = line.substring(index
115:                            + beginToken.length(), endIndex);
116:
117:                    if (commentingUntil == null) {
118:                        // We're not commenting, so look for a "first" token.
119:                        if (tokens.containsKey(token)) {
120:                            final LineCommenter commenter = (LineCommenter) tokens
121:                                    .get(token);
122:                            commentingUntil = commenter.getLast();
123:                            commenting = commenter.isComment();
124:                            log("Commenting: " + beginToken + token + endToken,
125:                                    Project.MSG_VERBOSE);
126:                            // We'll begin commenting with the next line.
127:                        }
128:                    } else {
129:                        // We're commenting until we see "commentingUntil".
130:                        // This means that commenters do not nest.
131:                        if (commentingUntil.equals(token)) {
132:                            log("Commenting ends with: " + beginToken + token
133:                                    + endToken, Project.MSG_VERBOSE);
134:                            // We've found it.
135:                            // Switch back to looking for a new "first".
136:                            commentingUntil = null;
137:                        } else {
138:                            return comment(line);
139:                        }
140:                    }
141:
142:                    return line;
143:                } catch (StringIndexOutOfBoundsException e) {
144:                    return line;
145:                }
146:            }
147:
148:            private final static String commentString = "// ";
149:
150:            private String comment(final String line) {
151:                final String text = line.trim();
152:                final String whitespace = line.substring(0, line
153:                        .lastIndexOf(text));
154:
155:                if (commenting) {
156:                    if (text.startsWith(commentString))
157:                        return line;
158:
159:                    return whitespace + commentString + text;
160:                }
161:
162:                if (text.startsWith(commentString))
163:                    return whitespace + text.substring(commentString.length());
164:
165:                return line;
166:            }
167:
168:            /**
169:             * Create a new filter
170:             *
171:             * @param commenter the filter to be added
172:             */
173:            public void addLineCommenter(LineCommenter commenter) {
174:                if (isReference()) {
175:                    throw noChildrenAllowed();
176:                }
177:                getFilters().addElement(commenter);
178:            }
179:
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.