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:
014: import org.eclipse.core.runtime.CoreException;
015:
016: import org.eclipse.core.resources.IContainer;
017: import org.eclipse.core.resources.IFile;
018: import org.eclipse.core.resources.IProject;
019: import org.eclipse.core.resources.IResource;
020: import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
021:
022: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
023: import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
024: import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
025: import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
026: import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker;
027:
028: import org.eclipse.jdt.core.IJavaElement;
029: import org.eclipse.jdt.core.IPackageFragment;
030: import org.eclipse.jdt.core.IPackageFragmentRoot;
031:
032: import org.eclipse.jdt.internal.corext.refactoring.participants.ResourceModifications;
033:
034: public abstract class RefactoringModifications {
035:
036: private ResourceModifications fResourceModifications;
037:
038: public RefactoringModifications() {
039: fResourceModifications = new ResourceModifications();
040: }
041:
042: public ResourceModifications getResourceModifications() {
043: return fResourceModifications;
044: }
045:
046: public abstract RefactoringParticipant[] loadParticipants(
047: RefactoringStatus status, RefactoringProcessor owner,
048: String[] natures, SharableParticipants shared);
049:
050: public abstract void buildDelta(
051: IResourceChangeDescriptionFactory builder);
052:
053: public void buildValidateEdits(ValidateEditChecker checker) {
054: // Default implementation does nothing.
055: }
056:
057: protected void createIncludingParents(IContainer container) {
058: while (container != null
059: && !(container.exists() || getResourceModifications()
060: .willExist(container))) {
061: getResourceModifications().addCreate(container);
062: container = container.getParent();
063: }
064: }
065:
066: protected IResource[] collectResourcesOfInterest(
067: IPackageFragment source) throws CoreException {
068: IJavaElement[] children = source.getChildren();
069: int childOfInterest = IJavaElement.COMPILATION_UNIT;
070: if (source.getKind() == IPackageFragmentRoot.K_BINARY) {
071: childOfInterest = IJavaElement.CLASS_FILE;
072: }
073: ArrayList result = new ArrayList(children.length);
074: for (int i = 0; i < children.length; i++) {
075: IJavaElement child = children[i];
076: if (child.getElementType() == childOfInterest
077: && child.getResource() != null) {
078: result.add(child.getResource());
079: }
080: }
081: // Gather non-java resources
082: Object[] nonJavaResources = source.getNonJavaResources();
083: for (int i = 0; i < nonJavaResources.length; i++) {
084: Object element = nonJavaResources[i];
085: if (element instanceof IResource) {
086: result.add(element);
087: }
088: }
089: return (IResource[]) result
090: .toArray(new IResource[result.size()]);
091: }
092:
093: protected IFile getClasspathFile(IResource resource) {
094: IProject project = resource.getProject();
095: if (project == null)
096: return null;
097: IResource result = project.findMember(".classpath"); //$NON-NLS-1$
098: if (result instanceof IFile)
099: return (IFile) result;
100: return null;
101: }
102: }
|