Source Code Cross Referenced for ASTUtil.java in  » Code-Analyzer » checkstyle » com » puppycrawl » tools » checkstyle » checks » usage » transmogrify » 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 » checkstyle » com.puppycrawl.tools.checkstyle.checks.usage.transmogrify 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Transmogrify License
002:        // 
003:        // Copyright (c) 2001, ThoughtWorks, Inc.
004:        // All rights reserved.
005:        // Redistribution and use in source and binary forms, with or without
006:        // modification, are permitted provided that the following conditions
007:        // are met:
008:        // - Redistributions of source code must retain the above copyright notice,
009:        //   this list of conditions and the following disclaimer.
010:        // - Redistributions in binary form must reproduce the above copyright
011:        // notice, this list of conditions and the following disclaimer in the
012:        // documentation and/or other materials provided with the distribution.
013:        // Neither the name of the ThoughtWorks, Inc. nor the names of its
014:        // contributors may be used to endorse or promote products derived from this
015:        // software without specific prior written permission.
016:        // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
017:        // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
018:        // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
019:        // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
020:        // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
021:        // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
022:        // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
023:        // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
024:        // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
025:        // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
026:        // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027:
028:        package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify;
029:
030:        import java.io.File;
031:
032:        import com.puppycrawl.tools.checkstyle.api.TokenTypes;
033:
034:        /**
035:         * <code>ASTUtil</code> is a <code>Utility Class</code> that contains utility code
036:         * for managing our SymTabAST.
037:         *
038:         * @see Definition
039:         * @see TypedDef
040:         */
041:
042:        public class ASTUtil {
043:
044:            /**
045:             * gets a line number for the tree;  if the current SymTabAST node does not have one associated
046:             * with it, traverse its children until a line number is found.  Failure results in line
047:             * number value of 0.
048:             *
049:             * @param tree the SymTabAST to process
050:             *
051:             * @return int the resulting line number (0 if none is found)
052:             */
053:            public static int getLine(SymTabAST tree) {
054:                SymTabAST indexedNode = tree;
055:
056:                // find a node that actually has line number info
057:                if (indexedNode.getLineNo() == 0) {
058:                    indexedNode = (SymTabAST) indexedNode.getFirstChild();
059:
060:                    while (indexedNode != null && indexedNode.getLineNo() == 0) {
061:                        indexedNode = (SymTabAST) indexedNode.getNextSibling();
062:                    }
063:
064:                    if (indexedNode == null) {
065:                        // we're screwed
066:                        indexedNode = tree;
067:                    }
068:                }
069:
070:                return indexedNode.getLineNo();
071:            }
072:
073:            /**
074:             * gets a column number for the tree;  if the current SymTabAST node does not have one associated
075:             * with it, traverse its children until a column number is found.  Failure results in column
076:             * number value of 0.
077:             *
078:             * @param tree the SymTabAST to process
079:             *
080:             * @return int the resulting line number (0 if none is found)
081:             */
082:            public static int getColumn(SymTabAST tree) {
083:                SymTabAST indexedNode = tree;
084:
085:                // find a node that actually has line number info
086:                // REDTAG -- a label's ':' is a real token and has (the wrong) column info
087:                // because it is the parent of the ident node that people will want
088:                if (indexedNode.getColumnNo() == 0
089:                        || indexedNode.getType() == TokenTypes.LABELED_STAT) {
090:                    indexedNode = (SymTabAST) indexedNode.getFirstChild();
091:
092:                    while (indexedNode != null
093:                            && indexedNode.getColumnNo() == 0) {
094:                        indexedNode = (SymTabAST) indexedNode.getNextSibling();
095:                    }
096:
097:                    if (indexedNode == null) {
098:                        // we're screwed
099:                        indexedNode = tree;
100:                    }
101:                }
102:
103:                return indexedNode.getColumnNo();
104:            }
105:
106:            /**
107:             * Builds the dotted name String representation of the object contained within
108:             * the SymTabAST.
109:             *
110:             * @return String
111:             * @param tree the SymTabAST contaning the entire hierarcy of the object
112:             */
113:            public static String constructDottedName(SymTabAST tree) {
114:                String result;
115:
116:                if (tree.getType() == TokenTypes.DOT) {
117:                    SymTabAST left = (SymTabAST) tree.getFirstChild();
118:                    SymTabAST right = (SymTabAST) left.getNextSibling();
119:
120:                    result = constructDottedName(left) + "."
121:                            + constructDottedName(right);
122:                } else if (tree.getType() == TokenTypes.ARRAY_DECLARATOR) {
123:                    StringBuffer buf = new StringBuffer();
124:                    SymTabAST left = (SymTabAST) tree.getFirstChild();
125:                    SymTabAST right = (SymTabAST) left.getNextSibling();
126:
127:                    buf.append(constructDottedName(left));
128:
129:                    if (right != null) {
130:                        buf.append(".");
131:                        buf.append(constructDottedName(right));
132:                    }
133:
134:                    buf.append(" []");
135:
136:                    result = buf.toString();
137:                } else if (tree.getType() == TokenTypes.METHOD_CALL) {
138:                    result = constructDottedName((SymTabAST) tree
139:                            .getFirstChild())
140:                            + "()";
141:                } else {
142:                    result = tree.getText();
143:                }
144:
145:                return result;
146:            }
147:
148:            /**
149:             * Returns the Package name in the hierarchy represented by the SymTabAST.
150:             *
151:             * @return String
152:             * @param tree the SymTabAST contaning the entire hierarcy of the object
153:             */
154:            public static String constructPackage(SymTabAST tree) {
155:                String fullName = constructDottedName(tree);
156:
157:                return fullName.substring(0, fullName.lastIndexOf("."));
158:            }
159:
160:            /**
161:             * Returns the top Class name in the hierarchy represented by the SymTabAST.
162:             *
163:             * @return String
164:             * @param tree the SymTabAST contaning the entire hierarcy of the object
165:             */
166:            public static String constructClass(SymTabAST tree) {
167:                String fullName = constructDottedName(tree);
168:
169:                return fullName.substring(fullName.lastIndexOf(".") + 1,
170:                        fullName.length());
171:            }
172:
173:            public static boolean treesBelowFilesAreEqual(SymTabAST firstRoot,
174:                    File[] firstFiles, SymTabAST secondRoot, File[] secondFiles) {
175:                boolean result = true;
176:
177:                if (firstFiles.length == secondFiles.length) {
178:                    for (int i = 0; i < firstFiles.length; i++) {
179:                        SymTabAST firstTree = (SymTabAST) getFileNode(
180:                                firstRoot, firstFiles[i]).getFirstChild();
181:                        SymTabAST secondTree = (SymTabAST) getFileNode(
182:                                secondRoot, secondFiles[i]).getFirstChild();
183:
184:                        if (!firstTree.equalsList(secondTree)) {
185:                            result = false;
186:                            break;
187:                        }
188:                    }
189:                } else {
190:                    result = false;
191:                }
192:
193:                return result;
194:            }
195:
196:            public static SymTabAST getFileNode(SymTabAST root, File file) {
197:                SymTabAST result = null;
198:
199:                SymTabAST fileNode = (SymTabAST) root.getFirstChild();
200:                while (fileNode != null && result == null) {
201:                    if (file.equals(fileNode.getFile())) {
202:                        result = fileNode;
203:                    }
204:                    fileNode = (SymTabAST) fileNode.getNextSibling();
205:                }
206:
207:                return result;
208:            }
209:        }
w___ww._j_a__v___a__2_s__.__c_om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.