1 11 package org.eclipse.jdt.internal.corext.refactoring.reorg; 12 13 import java.util.ArrayList ; 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 [] natures, SharableParticipants shared); 48 49 public abstract void buildDelta(IResourceChangeDescriptionFactory builder); 50 51 public void buildValidateEdits(ValidateEditChecker checker) { 52 } 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 result = new ArrayList (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 Object [] nonJavaResources = source.getNonJavaResources(); 77 for (int i= 0; i < nonJavaResources.length; i++) { 78 Object 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"); if (result instanceof IFile) 92 return (IFile)result; 93 return null; 94 } 95 } 96 | Popular Tags |