Source Code Cross Referenced for RemoveEmptyClassRefactoring.java in  » UML » jrefactory » org » acm » seguin » refactor » type » 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.type 
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.type;
010:
011:        import java.io.File;
012:        import java.io.IOException;
013:        import org.acm.seguin.refactor.ComplexTransform;
014:        import org.acm.seguin.refactor.Refactoring;
015:        import org.acm.seguin.refactor.RefactoringException;
016:        import org.acm.seguin.summary.FileSummary;
017:        import org.acm.seguin.summary.PackageSummary;
018:        import org.acm.seguin.summary.Summary;
019:        import org.acm.seguin.summary.TypeDeclSummary;
020:        import org.acm.seguin.summary.TypeSummary;
021:        import org.acm.seguin.summary.query.GetTypeSummary;
022:        import org.acm.seguin.summary.query.TopLevelDirectory;
023:
024:        /**
025:         *  Removes a particular class that is an abstract parent.
026:         *
027:         *@author    Chris Seguin
028:         */
029:        public class RemoveEmptyClassRefactoring extends Refactoring {
030:            private TypeSummary typeSummary;
031:            private File base;
032:
033:            /**
034:             *  Constructor for the RemoveEmptyClassRefactoring object
035:             */
036:            protected RemoveEmptyClassRefactoring() {
037:            }
038:
039:            /**
040:             *  Sets the ChildClass attribute of the RemoveAbstractParent object
041:             *
042:             *@param  packageName  The new Class value
043:             *@param  className    The new Class value
044:             */
045:            public void setClass(String packageName, String className) {
046:                setClass(GetTypeSummary.query(PackageSummary
047:                        .getPackageSummary(packageName), className));
048:            }
049:
050:            /**
051:             *  Sets the ChildClass attribute of the RemoveAbstractParent object
052:             *
053:             *@param  summary  The new Class value
054:             */
055:            public void setClass(TypeSummary summary) {
056:                typeSummary = summary;
057:            }
058:
059:            /**
060:             *  Gets the description of the refactoring
061:             *
062:             *@return    the description
063:             */
064:            public String getDescription() {
065:                return "Removes the class named " + typeSummary.getName();
066:            }
067:
068:            /**
069:             *  Gets the id for this refactoring to track which refactorings are used.
070:             *
071:             *@return    the id
072:             */
073:            public int getID() {
074:                return REMOVE_CLASS;
075:            }
076:
077:            /**
078:             *  Gets the FileSummary attribute of the RemoveEmptyClassRefactoring object
079:             *
080:             *@return    The FileSummary value
081:             */
082:            protected FileSummary getFileSummary() {
083:                FileSummary fileSummary = (FileSummary) typeSummary.getParent();
084:                return fileSummary;
085:            }
086:
087:            /**
088:             *  Checks the preconditions that must be true for this refactoring to be
089:             *  applied.
090:             *
091:             *@exception  RefactoringException  The exception
092:             */
093:            protected void preconditions() throws RefactoringException {
094:                if (typeSummary == null) {
095:                    throw new RefactoringException("No type specified");
096:                }
097:
098:                TypeDeclSummary parentDecl = typeSummary.getParentClass();
099:                TypeSummary parentSummary;
100:                if (parentDecl == null) {
101:                    parentSummary = GetTypeSummary.query(PackageSummary
102:                            .getPackageSummary("java.lang"), "Object");
103:                } else {
104:                    parentSummary = GetTypeSummary.query(parentDecl);
105:                }
106:
107:                if (parentSummary == null) {
108:                    throw new RefactoringException(
109:                            "Could not find the parent class for the specified class in the metadata");
110:                }
111:                FileSummary fileSummary = getFileSummary();
112:
113:                if (fileSummary.getFile() == null) {
114:                    throw new RefactoringException(
115:                            "This type is contained in a stub.  No refactorings allowed.");
116:                }
117:
118:                if (fileSummary.getTypeCount() != 1) {
119:                    throw new RefactoringException(
120:                            "This refactoring works only when the "
121:                                    + "type is alone in a file.  Please remove other types from "
122:                                    + fileSummary.getFile().getName());
123:                }
124:
125:                if ((typeSummary.getFieldCount() > 0)
126:                        || (typeSummary.getMethodCount() > 0)) {
127:                    throw new RefactoringException("The "
128:                            + typeSummary.getName()
129:                            + " class has at least one method or field");
130:                }
131:
132:                //  Finish the setup
133:                File deadFile = fileSummary.getFile();
134:                String path = null;
135:                try {
136:                    path = deadFile.getCanonicalPath();
137:                } catch (IOException ioe) {
138:                    path = deadFile.getPath();
139:                }
140:                File startDir = (new File(path)).getParentFile();
141:                String firstFilename = deadFile.getName();
142:                base = TopLevelDirectory.query(startDir, firstFilename);
143:            }
144:
145:            /**
146:             *  Performs the refactoring by traversing through the files and updating
147:             *  them.
148:             */
149:            protected void transform() {
150:                ComplexTransform complex = getComplexTransform();
151:                FileSummary fileSummary = getFileSummary();
152:                complex.removeFile(fileSummary.getFile());
153:
154:                String srcPackage = ((PackageSummary) fileSummary.getParent())
155:                        .getName();
156:                String oldClassName = typeSummary.getName();
157:                String newClassName;
158:
159:                TypeDeclSummary parent = typeSummary.getParentClass();
160:                String destPackage;
161:                if (parent == null) {
162:                    newClassName = "Object";
163:                    destPackage = "java.lang";
164:                } else {
165:                    newClassName = parent.getType();
166:                    TypeSummary parentTypeSummary = GetTypeSummary
167:                            .query(parent);
168:                    Summary one = parentTypeSummary.getParent();
169:                    while (!(one instanceof  PackageSummary)) {
170:                        one = one.getParent();
171:                    }
172:                    destPackage = ((PackageSummary) one).getName();
173:                }
174:
175:                FileSummary.removeFileSummary(fileSummary.getFile());
176:
177:                RemoveClassVisitor rcv = new RemoveClassVisitor(srcPackage,
178:                        oldClassName, destPackage, newClassName, base, complex);
179:                rcv.visit(null);
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.