Source Code Cross Referenced for ParentChecker.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:
017:        import org.eclipse.core.resources.IResource;
018:
019:        import org.eclipse.jdt.core.IJavaElement;
020:        import org.eclipse.jdt.core.JavaCore;
021:
022:        public class ParentChecker {
023:            private IResource[] fResources;
024:            private IJavaElement[] fJavaElements;
025:
026:            public ParentChecker(IResource[] resources,
027:                    IJavaElement[] javaElements) {
028:                Assert.isNotNull(resources);
029:                Assert.isNotNull(javaElements);
030:                fResources = resources;
031:                fJavaElements = javaElements;
032:            }
033:
034:            public boolean haveCommonParent() {
035:                return getCommonParent() != null;
036:            }
037:
038:            public Object getCommonParent() {
039:                if (fJavaElements.length == 0 && fResources.length == 0)
040:                    return null;
041:                if (!resourcesHaveCommonParent()
042:                        || !javaElementsHaveCommonParent())
043:                    return null;
044:                if (fJavaElements.length == 0) {
045:                    IResource commonResourceParent = getCommonResourceParent();
046:                    Assert.isNotNull(commonResourceParent);
047:                    IJavaElement convertedToJava = JavaCore
048:                            .create(commonResourceParent);
049:                    if (convertedToJava != null && convertedToJava.exists())
050:                        return convertedToJava;
051:                    else
052:                        return commonResourceParent;
053:                }
054:                if (fResources.length == 0)
055:                    return getCommonJavaElementParent();
056:
057:                IResource commonResourceParent = getCommonResourceParent();
058:                IJavaElement commonJavaElementParent = getCommonJavaElementParent();
059:                Assert.isNotNull(commonJavaElementParent);
060:                Assert.isNotNull(commonResourceParent);
061:                IJavaElement convertedToJava = JavaCore
062:                        .create(commonResourceParent);
063:                if (convertedToJava == null || !convertedToJava.exists()
064:                        || !commonJavaElementParent.equals(convertedToJava))
065:                    return null;
066:                return commonJavaElementParent;
067:            }
068:
069:            private IJavaElement getCommonJavaElementParent() {
070:                Assert.isNotNull(fJavaElements);
071:                Assert.isTrue(fJavaElements.length > 0);//safe - checked before
072:                return fJavaElements[0].getParent();
073:            }
074:
075:            private IResource getCommonResourceParent() {
076:                Assert.isNotNull(fResources);
077:                Assert.isTrue(fResources.length > 0);//safe - checked before
078:                return fResources[0].getParent();
079:            }
080:
081:            private boolean javaElementsHaveCommonParent() {
082:                if (fJavaElements.length == 0)
083:                    return true;
084:                IJavaElement firstParent = fJavaElements[0].getParent();
085:                Assert.isNotNull(firstParent); //this should never happen			
086:                for (int i = 1; i < fJavaElements.length; i++) {
087:                    if (!firstParent.equals(fJavaElements[i].getParent()))
088:                        return false;
089:                }
090:                return true;
091:            }
092:
093:            private boolean resourcesHaveCommonParent() {
094:                if (fResources.length == 0)
095:                    return true;
096:                IResource firstParent = fResources[0].getParent();
097:                Assert.isNotNull(firstParent);
098:                for (int i = 1; i < fResources.length; i++) {
099:                    if (!firstParent.equals(fResources[i].getParent()))
100:                        return false;
101:                }
102:                return true;
103:            }
104:
105:            public IResource[] getResources() {
106:                return fResources;
107:            }
108:
109:            public IJavaElement[] getJavaElements() {
110:                return fJavaElements;
111:            }
112:
113:            public void removeElementsWithAncestorsOnList(
114:                    boolean removeOnlyJavaElements) {
115:                if (!removeOnlyJavaElements) {
116:                    removeResourcesDescendantsOfResources();
117:                    removeResourcesDescendantsOfJavaElements();
118:                }
119:                removeJavaElementsDescendantsOfJavaElements();
120:                //		removeJavaElementsChildrenOfResources(); //this case is covered by removeUnconfirmedArchives
121:            }
122:
123:            private void removeResourcesDescendantsOfJavaElements() {
124:                List subResources = new ArrayList(3);
125:                for (int i = 0; i < fResources.length; i++) {
126:                    IResource subResource = fResources[i];
127:                    for (int j = 0; j < fJavaElements.length; j++) {
128:                        IJavaElement super Elements = fJavaElements[j];
129:                        if (isDescendantOf(subResource, super Elements))
130:                            subResources.add(subResource);
131:                    }
132:                }
133:                removeFromSetToDelete((IResource[]) subResources
134:                        .toArray(new IResource[subResources.size()]));
135:            }
136:
137:            private void removeJavaElementsDescendantsOfJavaElements() {
138:                List subElements = new ArrayList(3);
139:                for (int i = 0; i < fJavaElements.length; i++) {
140:                    IJavaElement subElement = fJavaElements[i];
141:                    for (int j = 0; j < fJavaElements.length; j++) {
142:                        IJavaElement super Element = fJavaElements[j];
143:                        if (isDescendantOf(subElement, super Element))
144:                            subElements.add(subElement);
145:                    }
146:                }
147:                removeFromSetToDelete((IJavaElement[]) subElements
148:                        .toArray(new IJavaElement[subElements.size()]));
149:            }
150:
151:            private void removeResourcesDescendantsOfResources() {
152:                List subResources = new ArrayList(3);
153:                for (int i = 0; i < fResources.length; i++) {
154:                    IResource subResource = fResources[i];
155:                    for (int j = 0; j < fResources.length; j++) {
156:                        IResource super Resource = fResources[j];
157:                        if (isDescendantOf(subResource, super Resource))
158:                            subResources.add(subResource);
159:                    }
160:                }
161:                removeFromSetToDelete((IResource[]) subResources
162:                        .toArray(new IResource[subResources.size()]));
163:            }
164:
165:            public static boolean isDescendantOf(IResource subResource,
166:                    IJavaElement super Element) {
167:                IResource parent = subResource.getParent();
168:                while (parent != null) {
169:                    IJavaElement el = JavaCore.create(parent);
170:                    if (el != null && el.exists() && el.equals(super Element))
171:                        return true;
172:                    parent = parent.getParent();
173:                }
174:                return false;
175:            }
176:
177:            public static boolean isDescendantOf(IJavaElement subElement,
178:                    IJavaElement super Element) {
179:                if (subElement.equals(super Element))
180:                    return false;
181:                IJavaElement parent = subElement.getParent();
182:                while (parent != null) {
183:                    if (parent.equals(super Element))
184:                        return true;
185:                    parent = parent.getParent();
186:                }
187:                return false;
188:            }
189:
190:            public static boolean isDescendantOf(IResource subResource,
191:                    IResource super Resource) {
192:                return !subResource.equals(super Resource)
193:                        && super Resource.getFullPath().isPrefixOf(
194:                                subResource.getFullPath());
195:            }
196:
197:            private void removeFromSetToDelete(IResource[] resourcesToNotDelete) {
198:                fResources = ReorgUtils.setMinus(fResources,
199:                        resourcesToNotDelete);
200:            }
201:
202:            private void removeFromSetToDelete(
203:                    IJavaElement[] elementsToNotDelete) {
204:                fJavaElements = ReorgUtils.setMinus(fJavaElements,
205:                        elementsToNotDelete);
206:            }
207:        }
w___w__w___.j_a___v___a___2_s.___c_o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.