Source Code Cross Referenced for AddImportTransform.java in  » UML » jrefactory » org » acm » seguin » refactor » 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 » UML » jrefactory » org.acm.seguin.refactor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Author:  Chris Seguin
003:         *
004:         * This software has been developed under the copyleft
005:         * rules of the GNU General Public License.  Please
006:         * consult the GNU General Public License for more
007:         * details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.refactor;
010:
011:        import net.sourceforge.jrefactory.ast.Node;
012:        import net.sourceforge.jrefactory.ast.SimpleNode;
013:        import net.sourceforge.jrefactory.ast.ASTPackageDeclaration;
014:        import net.sourceforge.jrefactory.ast.ASTImportDeclaration;
015:        import net.sourceforge.jrefactory.ast.ASTName;
016:        import net.sourceforge.jrefactory.ast.ASTTypeDeclaration;
017:        import net.sourceforge.jrefactory.factory.NameFactory;
018:        import org.acm.seguin.summary.Summary;
019:        import org.acm.seguin.summary.PackageSummary;
020:        import org.acm.seguin.summary.TypeSummary;
021:        import net.sourceforge.jrefactory.parser.JavaParserTreeConstants;
022:
023:        /**
024:         *  This object revises the import statements in the tree.
025:         *
026:         *@author    Chris Seguin
027:         */
028:        public class AddImportTransform extends TransformAST {
029:            private ASTName name;
030:            private boolean ignorePackageName;
031:
032:            /**
033:             *  Constructor for the AddImportTransform object
034:             *
035:             *@param  name  Description of Parameter
036:             */
037:            public AddImportTransform(ASTName name) {
038:                this .name = name;
039:                ignorePackageName = false;
040:            }
041:
042:            /**
043:             *  Constructor for the AddImportTransform object
044:             *
045:             *@param  packageName  the package name
046:             *@param  className    the class name
047:             */
048:            public AddImportTransform(String packageName, String className) {
049:                name = NameFactory.getName(packageName, className);
050:                ignorePackageName = false;
051:            }
052:
053:            /**
054:             *  Constructor for the AddImportTransform object
055:             *
056:             *@param  typeSummary  the type symmary
057:             */
058:            public AddImportTransform(TypeSummary typeSummary) {
059:                Summary current = typeSummary;
060:                while (!(current instanceof  PackageSummary)) {
061:                    current = current.getParent();
062:                }
063:                PackageSummary packageSummary = (PackageSummary) current;
064:                name = NameFactory.getName(packageSummary.getName(),
065:                        typeSummary.getName());
066:                ignorePackageName = false;
067:            }
068:
069:            /**
070:             *  Sets the IgnorePackageName attribute of the AddImportTransform object
071:             *
072:             *@param  value  The new IgnorePackageName value
073:             */
074:            public void setIgnorePackageName(boolean value) {
075:                ignorePackageName = value;
076:            }
077:
078:            /**
079:             *  Update the syntax tree
080:             *
081:             *@param  root  Description of Parameter
082:             */
083:            public void update(SimpleNode root) {
084:                if ((name.getNameSize() == 3)
085:                        && (name.getNamePart(0).equals("java"))
086:                        && (name.getNamePart(1).equals("lang"))) {
087:                    return;
088:                }
089:
090:                int nFirstImportSpot = findLastImport(root);
091:                if (nFirstImportSpot == -1) {
092:                    return;
093:                }
094:
095:                //  Create the import
096:                ASTImportDeclaration importDecl = new ASTImportDeclaration(
097:                        JavaParserTreeConstants.JJTIMPORTDECLARATION);
098:                importDecl.jjtAddFirstChild(name);
099:                importDecl.setImportPackage(false);
100:
101:                //  Add it to the source tree
102:                root.jjtInsertChild(importDecl, nFirstImportSpot);
103:            }
104:
105:            /**
106:             *  Determine where the first import should go
107:             *
108:             *@param  root  Description of Parameter
109:             *@return       the index where new import statements should go
110:             */
111:            protected int findLastImport(SimpleNode root) {
112:                int last = root.jjtGetNumChildren();
113:                for (int ndx = 0; ndx < last; ndx++) {
114:                    Node child = root.jjtGetChild(ndx);
115:
116:                    //  Check to see if we have already imported this
117:                    if ((!ignorePackageName)
118:                            && (child instanceof  ASTPackageDeclaration)) {
119:                        ASTPackageDeclaration decl = (ASTPackageDeclaration) child;
120:                        ASTName packageName = (ASTName) child
121:                                .jjtGetFirstChild();
122:                        if (packageName.getNameSize() + 1 == name.getNameSize()) {
123:                            boolean done = true;
124:                            for (int ndx2 = 0; ndx2 < packageName.getNameSize(); ndx2++) {
125:                                if (!packageName.getNamePart(ndx2).equals(
126:                                        name.getNamePart(ndx2))) {
127:                                    done = false;
128:                                }
129:                            }
130:
131:                            if (done) {
132:                                return -1;
133:                            }
134:                        }
135:                    }
136:
137:                    //  Check to see if we have already imported this
138:                    if (child instanceof  ASTImportDeclaration) {
139:                        ASTImportDeclaration decl = (ASTImportDeclaration) child;
140:                        ASTName importName = (ASTName) child.jjtGetFirstChild();
141:                        if (importName.equals(name)) {
142:                            return -1;
143:                        }
144:                    }
145:
146:                    //  Found a type declaration, time to return the index
147:                    if (root.jjtGetChild(ndx) instanceof  ASTTypeDeclaration) {
148:                        return ndx;
149:                    }
150:                }
151:
152:                //  No point - there aren't any types defined.
153:                return -1;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.