Source Code Cross Referenced for PushDownFieldRefactoring.java in  » UML » jrefactory » org » acm » seguin » refactor » field » 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.field 
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.field;
010:
011:        import java.io.File;
012:        import java.util.Iterator;
013:        import java.util.LinkedList;
014:        import net.sourceforge.jrefactory.ast.ASTName;
015:        import net.sourceforge.jrefactory.ast.ASTPrimitiveType;
016:        import net.sourceforge.jrefactory.ast.ASTType;
017:        import net.sourceforge.jrefactory.ast.SimpleNode;
018:        import org.acm.seguin.refactor.AddImportTransform;
019:        import org.acm.seguin.refactor.ComplexTransform;
020:        import org.acm.seguin.refactor.Refactoring;
021:        import org.acm.seguin.refactor.RefactoringException;
022:        import org.acm.seguin.refactor.undo.UndoAction;
023:        import org.acm.seguin.refactor.undo.UndoStack;
024:        import org.acm.seguin.summary.FileSummary;
025:        import org.acm.seguin.summary.PackageSummary;
026:        import org.acm.seguin.summary.Summary;
027:        import org.acm.seguin.summary.TypeDeclSummary;
028:        import org.acm.seguin.summary.TypeSummary;
029:        import org.acm.seguin.summary.query.FieldQuery;
030:        import org.acm.seguin.summary.query.GetTypeSummary;
031:
032:        /**
033:         *  Performs the push down field refactoring
034:         *
035:         *@author    Chris Seguin
036:         */
037:        public class PushDownFieldRefactoring extends FieldRefactoring {
038:            private LinkedList childTypes;
039:
040:            /**
041:             *  Constructor for the PushDownFieldRefactoring object
042:             */
043:            protected PushDownFieldRefactoring() {
044:                childTypes = new LinkedList();
045:                field = null;
046:                typeSummary = null;
047:            }
048:
049:            /**
050:             *  Gets the description of the refactoring
051:             *
052:             *@return    the description
053:             */
054:            public String getDescription() {
055:                return "Moves a field " + field + " into child classes of "
056:                        + typeSummary.getName();
057:            }
058:
059:            /**
060:             *  Gets the ID attribute of the PushDownFieldRefactoring object
061:             *
062:             *@return    The ID value
063:             */
064:            public int getID() {
065:                return PUSH_DOWN_FIELD;
066:            }
067:
068:            /**
069:             *  Adds a child class where the field should be pushed into
070:             *
071:             *@param  packageName  the package name
072:             *@param  className    the class name
073:             */
074:            public void addChild(String packageName, String className) {
075:                addChild(GetTypeSummary.query(PackageSummary
076:                        .getPackageSummary(packageName), className));
077:            }
078:
079:            /**
080:             *  Adds a child class where the field should be pushed into
081:             *
082:             *@param  init  The new Class value
083:             */
084:            public void addChild(TypeSummary init) {
085:                if (init != null) {
086:                    System.out.println("Adding " + init.getName());
087:                    childTypes.add(init);
088:                }
089:            }
090:
091:            /**
092:             *  Preconditions that must be true for the refactoring to work
093:             *
094:             *@exception  RefactoringException  a problem with performing this
095:             *      refactoring
096:             */
097:            protected void preconditions() throws RefactoringException {
098:                if (field == null) {
099:                    throw new RefactoringException("No field specified");
100:                }
101:
102:                if (typeSummary == null) {
103:                    throw new RefactoringException("No type specified");
104:                }
105:
106:                if (childTypes.size() == 0) {
107:                    throw new RefactoringException("No child types specified");
108:                }
109:
110:                if (FieldQuery.query(typeSummary, field, FieldQuery.PRIVATE) == null) {
111:                    throw new RefactoringException("Field named " + field
112:                            + " does not exist in " + typeSummary.getName());
113:                }
114:
115:                if (((FileSummary) typeSummary.getParent()).getFile() == null) {
116:                    throw new RefactoringException(
117:                            "Can't push down a field from source code that you don't have");
118:                }
119:
120:                Iterator iter = childTypes.iterator();
121:                while (iter.hasNext()) {
122:                    TypeSummary next = (TypeSummary) iter.next();
123:
124:                    if (next == null) {
125:                        throw new RefactoringException(
126:                                "Can't push down a field into source code that you don't have");
127:                    }
128:
129:                    if (FieldQuery.query(next, field, FieldQuery.PRIVATE) != null) {
130:                        throw new RefactoringException("Field named " + field
131:                                + " already exists in " + next.getName());
132:                    }
133:
134:                    if (((FileSummary) next.getParent()).getFile() == null) {
135:                        throw new RefactoringException(
136:                                "Can't push up a field into source code that you don't have");
137:                    }
138:
139:                    TypeDeclSummary parentDecl = next.getParentClass();
140:                    TypeSummary parentTypeSummary = GetTypeSummary
141:                            .query(parentDecl);
142:
143:                    if (parentTypeSummary != typeSummary) {
144:                        throw new RefactoringException(
145:                                "Trying to push a field from "
146:                                        + typeSummary.getName()
147:                                        + " to "
148:                                        + next.getName()
149:                                        + " and the destination is not a subclass of the source");
150:                    }
151:                }
152:            }
153:
154:            /**
155:             *  Actually update the files
156:             */
157:            protected void transform() {
158:                FileSummary fileSummary = (FileSummary) getFileSummary(typeSummary);
159:                RemoveFieldTransform rft = new RemoveFieldTransform(field);
160:                ComplexTransform transform = getComplexTransform();
161:                transform.add(rft);
162:                transform.apply(fileSummary.getFile(), fileSummary.getFile());
163:
164:                //  Update the field declaration to have the proper permissions
165:                SimpleNode fieldDecl = rft.getFieldDeclaration();
166:                if (fieldDecl == null) {
167:                    return;
168:                }
169:
170:                Iterator iter = childTypes.iterator();
171:                while (iter.hasNext()) {
172:                    AddFieldTransform aft = new AddFieldTransform(fieldDecl);
173:                    transform.clear();
174:                    transform.add(aft);
175:                    Object fieldType = getFieldType(fieldDecl, fileSummary);
176:                    if (fieldType == null) {
177:                        //  Do nothing
178:                    } else if ((fieldType instanceof  TypeSummary)
179:                            && !isInJavaLang((TypeSummary) fieldType)) {
180:                        transform.add(new AddImportTransform(
181:                                (TypeSummary) fieldType));
182:                    } else if ((fieldType instanceof  ASTName)
183:                            && !isInJavaLang((ASTName) fieldType)) {
184:                        transform.add(new AddImportTransform(
185:                                (ASTName) fieldType));
186:                    }
187:
188:                    TypeSummary next = (TypeSummary) iter.next();
189:                    FileSummary nextFileSummary = (FileSummary) next
190:                            .getParent();
191:                    transform.apply(nextFileSummary.getFile(), nextFileSummary
192:                            .getFile());
193:                }
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.