KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > reorg > RefactoringModifications


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.reorg;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16
17 import org.eclipse.core.resources.IContainer;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
22
23 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
24 import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
25 import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
26 import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
27 import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker;
28
29 import org.eclipse.jdt.core.IJavaElement;
30 import org.eclipse.jdt.core.IPackageFragment;
31 import org.eclipse.jdt.core.IPackageFragmentRoot;
32
33 import org.eclipse.jdt.internal.corext.refactoring.participants.ResourceModifications;
34
35 public abstract class RefactoringModifications {
36
37     private ResourceModifications fResourceModifications;
38
39     public RefactoringModifications() {
40         fResourceModifications= new ResourceModifications();
41     }
42     
43     public ResourceModifications getResourceModifications() {
44         return fResourceModifications;
45     }
46     
47     public abstract RefactoringParticipant[] loadParticipants(RefactoringStatus status, RefactoringProcessor owner, String JavaDoc[] natures, SharableParticipants shared);
48
49     public abstract void buildDelta(IResourceChangeDescriptionFactory builder);
50     
51     public void buildValidateEdits(ValidateEditChecker checker) {
52         // Default implementation does nothing.
53
}
54
55     protected void createIncludingParents(IContainer container) {
56         while (container != null && !(container.exists() || getResourceModifications().willExist(container))) {
57             getResourceModifications().addCreate(container);
58             container= container.getParent();
59         }
60     }
61
62     protected IResource[] collectResourcesOfInterest(IPackageFragment source) throws CoreException {
63         IJavaElement[] children = source.getChildren();
64         int childOfInterest = IJavaElement.COMPILATION_UNIT;
65         if (source.getKind() == IPackageFragmentRoot.K_BINARY) {
66             childOfInterest = IJavaElement.CLASS_FILE;
67         }
68         ArrayList JavaDoc result = new ArrayList JavaDoc(children.length);
69         for (int i = 0; i < children.length; i++) {
70             IJavaElement child = children[i];
71             if (child.getElementType() == childOfInterest && child.getResource() != null) {
72                 result.add(child.getResource());
73             }
74         }
75         // Gather non-java resources
76
Object JavaDoc[] nonJavaResources = source.getNonJavaResources();
77         for (int i= 0; i < nonJavaResources.length; i++) {
78             Object JavaDoc element= nonJavaResources[i];
79             if (element instanceof IResource) {
80                 result.add(element);
81             }
82         }
83         return (IResource[]) result.toArray(new IResource[result.size()]);
84     }
85     
86     protected IFile getClasspathFile(IResource resource) {
87         IProject project= resource.getProject();
88         if (project == null)
89             return null;
90         IResource result= project.findMember(".classpath"); //$NON-NLS-1$
91
if (result instanceof IFile)
92             return (IFile)result;
93         return null;
94     }
95 }
96
Popular Tags