Source Code Cross Referenced for OverwriteHelper.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » corext » refactoring » reorg » 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 » IDE Eclipse » jdt » org.eclipse.jdt.internal.corext.refactoring.reorg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.reorg;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.Assert;
016:        import org.eclipse.core.runtime.CoreException;
017:
018:        import org.eclipse.core.resources.IContainer;
019:        import org.eclipse.core.resources.IFile;
020:        import org.eclipse.core.resources.IFolder;
021:        import org.eclipse.core.resources.IResource;
022:
023:        import org.eclipse.jdt.core.ICompilationUnit;
024:        import org.eclipse.jdt.core.IJavaElement;
025:        import org.eclipse.jdt.core.IJavaProject;
026:        import org.eclipse.jdt.core.IPackageFragment;
027:        import org.eclipse.jdt.core.IPackageFragmentRoot;
028:
029:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
030:        import org.eclipse.jdt.internal.corext.refactoring.util.ResourceUtil;
031:        import org.eclipse.jdt.internal.corext.util.Messages;
032:
033:        class OverwriteHelper {
034:            private Object fDestination;
035:            private IFile[] fFiles = new IFile[0];
036:            private IFolder[] fFolders = new IFolder[0];
037:            private ICompilationUnit[] fCus = new ICompilationUnit[0];
038:            private IPackageFragmentRoot[] fRoots = new IPackageFragmentRoot[0];
039:            private IPackageFragment[] fPackageFragments = new IPackageFragment[0];
040:
041:            public void setFiles(IFile[] files) {
042:                Assert.isNotNull(files);
043:                fFiles = files;
044:            }
045:
046:            public void setFolders(IFolder[] folders) {
047:                Assert.isNotNull(folders);
048:                fFolders = folders;
049:            }
050:
051:            public void setCus(ICompilationUnit[] cus) {
052:                Assert.isNotNull(cus);
053:                fCus = cus;
054:            }
055:
056:            public void setPackageFragmentRoots(IPackageFragmentRoot[] roots) {
057:                Assert.isNotNull(roots);
058:                fRoots = roots;
059:            }
060:
061:            public void setPackages(IPackageFragment[] fragments) {
062:                Assert.isNotNull(fragments);
063:                fPackageFragments = fragments;
064:            }
065:
066:            public IFile[] getFilesWithoutUnconfirmedOnes() {
067:                return fFiles;
068:            }
069:
070:            public IFolder[] getFoldersWithoutUnconfirmedOnes() {
071:                return fFolders;
072:            }
073:
074:            public ICompilationUnit[] getCusWithoutUnconfirmedOnes() {
075:                return fCus;
076:            }
077:
078:            public IPackageFragmentRoot[] getPackageFragmentRootsWithoutUnconfirmedOnes() {
079:                return fRoots;
080:            }
081:
082:            public IPackageFragment[] getPackagesWithoutUnconfirmedOnes() {
083:                return fPackageFragments;
084:            }
085:
086:            public void confirmOverwriting(IReorgQueries reorgQueries,
087:                    Object destination) {
088:                Assert.isNotNull(destination);
089:                Assert.isNotNull(reorgQueries);
090:                fDestination = destination;
091:                confirmOverwritting(reorgQueries);
092:            }
093:
094:            private void confirmOverwritting(IReorgQueries reorgQueries) {
095:                IConfirmQuery overwriteQuery = reorgQueries
096:                        .createYesYesToAllNoNoToAllQuery(
097:                                RefactoringCoreMessages.OverwriteHelper_0,
098:                                true, IReorgQueries.CONFIRM_OVERWRITING);
099:                IConfirmQuery skipQuery = reorgQueries.createSkipQuery(
100:                        RefactoringCoreMessages.OverwriteHelper_2,
101:                        IReorgQueries.CONFIRM_SKIPPING);
102:                confirmFileOverwritting(overwriteQuery, skipQuery);
103:                confirmFolderOverwritting(skipQuery);
104:                confirmCuOverwritting(overwriteQuery);
105:                confirmPackageFragmentRootOverwritting(skipQuery,
106:                        overwriteQuery);
107:                confirmPackageOverwritting(overwriteQuery);
108:            }
109:
110:            private void confirmPackageFragmentRootOverwritting(
111:                    IConfirmQuery skipQuery, IConfirmQuery overwriteQuery) {
112:                List toNotOverwrite = new ArrayList(1);
113:                for (int i = 0; i < fRoots.length; i++) {
114:                    IPackageFragmentRoot root = fRoots[i];
115:                    if (canOverwrite(root)) {
116:                        if (root.getResource() instanceof  IContainer) {
117:                            if (!skip(root.getElementName(), skipQuery))
118:                                toNotOverwrite.add(root);
119:                        } else {
120:                            if (!overwrite(root.getResource(), overwriteQuery))
121:                                toNotOverwrite.add(root);
122:                        }
123:                    }
124:                }
125:                IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) toNotOverwrite
126:                        .toArray(new IPackageFragmentRoot[toNotOverwrite.size()]);
127:                fRoots = ArrayTypeConverter
128:                        .toPackageFragmentRootArray(ReorgUtils.setMinus(fRoots,
129:                                roots));
130:            }
131:
132:            private void confirmCuOverwritting(IConfirmQuery overwriteQuery) {
133:                List cusToNotOverwrite = new ArrayList(1);
134:                for (int i = 0; i < fCus.length; i++) {
135:                    ICompilationUnit cu = fCus[i];
136:                    if (canOverwrite(cu) && !overwrite(cu, overwriteQuery))
137:                        cusToNotOverwrite.add(cu);
138:                }
139:                ICompilationUnit[] cus = (ICompilationUnit[]) cusToNotOverwrite
140:                        .toArray(new ICompilationUnit[cusToNotOverwrite.size()]);
141:                fCus = ArrayTypeConverter.toCuArray(ReorgUtils.setMinus(fCus,
142:                        cus));
143:            }
144:
145:            private void confirmFolderOverwritting(IConfirmQuery overwriteQuery) {
146:                List foldersToNotOverwrite = new ArrayList(1);
147:                for (int i = 0; i < fFolders.length; i++) {
148:                    IFolder folder = fFolders[i];
149:                    if (willOverwrite(folder)
150:                            && !skip(folder.getName(), overwriteQuery))
151:                        foldersToNotOverwrite.add(folder);
152:                }
153:                IFolder[] folders = (IFolder[]) foldersToNotOverwrite
154:                        .toArray(new IFolder[foldersToNotOverwrite.size()]);
155:                fFolders = ArrayTypeConverter.toFolderArray(ReorgUtils
156:                        .setMinus(fFolders, folders));
157:            }
158:
159:            private void confirmFileOverwritting(IConfirmQuery overwriteQuery,
160:                    IConfirmQuery skipQuery) {
161:                List filesToNotOverwrite = new ArrayList(1);
162:                for (int i = 0; i < fFiles.length; i++) {
163:                    IFile file = fFiles[i];
164:                    if (willOverwrite(file)) {
165:                        IContainer destination = (IContainer) ResourceUtil
166:                                .getResource(fDestination);
167:                        if (ParentChecker.isDescendantOf(file, destination
168:                                .findMember(file.getName()))) {
169:                            if (!skip(file.getName(), skipQuery)) {
170:                                filesToNotOverwrite.add(file);
171:                            }
172:                        } else if (!overwrite(file, overwriteQuery)) {
173:                            filesToNotOverwrite.add(file);
174:                        }
175:                    }
176:                }
177:                IFile[] files = (IFile[]) filesToNotOverwrite
178:                        .toArray(new IFile[filesToNotOverwrite.size()]);
179:                fFiles = ArrayTypeConverter.toFileArray(ReorgUtils.setMinus(
180:                        fFiles, files));
181:            }
182:
183:            private void confirmPackageOverwritting(IConfirmQuery overwriteQuery) {
184:                List toNotOverwrite = new ArrayList(1);
185:                for (int i = 0; i < fPackageFragments.length; i++) {
186:                    IPackageFragment pack = fPackageFragments[i];
187:                    if (canOverwrite(pack) && !overwrite(pack, overwriteQuery))
188:                        toNotOverwrite.add(pack);
189:                }
190:                IPackageFragment[] packages = (IPackageFragment[]) toNotOverwrite
191:                        .toArray(new IPackageFragment[toNotOverwrite.size()]);
192:                fPackageFragments = ArrayTypeConverter
193:                        .toPackageArray(ReorgUtils.setMinus(fPackageFragments,
194:                                packages));
195:            }
196:
197:            private boolean canOverwrite(IPackageFragment pack) {
198:                if (fDestination instanceof  IPackageFragmentRoot) {
199:                    IPackageFragmentRoot destination = (IPackageFragmentRoot) fDestination;
200:                    return !destination.equals(pack.getParent())
201:                            && destination.getPackageFragment(
202:                                    pack.getElementName()).exists();
203:                } else {
204:                    return willOverwrite(pack.getResource());
205:                }
206:            }
207:
208:            /*
209:             * Will resource override a member of destination? 
210:             */
211:            private boolean willOverwrite(IResource resource) {
212:                if (resource == null)
213:                    return false;
214:
215:                IResource destinationResource = ResourceUtil
216:                        .getResource(fDestination);
217:                if (destinationResource.equals(resource.getParent()))
218:                    return false;
219:
220:                if (destinationResource instanceof  IContainer) {
221:                    IContainer container = (IContainer) destinationResource;
222:                    IResource member = container.findMember(resource.getName());
223:                    if (member == null || !member.exists())
224:                        return false;
225:
226:                    return true;
227:                }
228:                return false;
229:            }
230:
231:            private boolean canOverwrite(IPackageFragmentRoot root) {
232:                if (fDestination instanceof  IJavaProject) {
233:                    IJavaProject destination = (IJavaProject) fDestination;
234:                    IFolder conflict = destination.getProject().getFolder(
235:                            root.getElementName());
236:                    try {
237:                        return !destination.equals(root.getParent())
238:                                && conflict.exists()
239:                                && conflict.members().length > 0;
240:                    } catch (CoreException e) {
241:                        return true;
242:                    }
243:                } else {
244:                    return willOverwrite(root.getResource());
245:                }
246:            }
247:
248:            private boolean canOverwrite(ICompilationUnit cu) {
249:                if (fDestination instanceof  IPackageFragment) {
250:                    IPackageFragment destination = (IPackageFragment) fDestination;
251:                    return !destination.equals(cu.getParent())
252:                            && destination.getCompilationUnit(
253:                                    cu.getElementName()).exists();
254:                } else {
255:                    return willOverwrite(ReorgUtils.getResource(cu));
256:                }
257:            }
258:
259:            private static boolean overwrite(IResource resource,
260:                    IConfirmQuery overwriteQuery) {
261:                return overwrite(resource.getName(), overwriteQuery);
262:            }
263:
264:            private static boolean overwrite(IJavaElement element,
265:                    IConfirmQuery overwriteQuery) {
266:                return overwrite(element.getElementName(), overwriteQuery);
267:            }
268:
269:            private static boolean overwrite(String name,
270:                    IConfirmQuery overwriteQuery) {
271:                String question = Messages.format(
272:                        RefactoringCoreMessages.OverwriteHelper_1, name);
273:                return overwriteQuery.confirm(question);
274:            }
275:
276:            private static boolean skip(String name,
277:                    IConfirmQuery overwriteQuery) {
278:                String question = Messages.format(
279:                        RefactoringCoreMessages.OverwriteHelper_3, name);
280:                return overwriteQuery.confirm(question);
281:            }
282:        }
ww__w.___ja__v__a___2s._co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.