replaced a lot of deprecated code; if someone runs into a commit conflict afterwards...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / CopyResourceElementsOperation.java
index e6d149e..12ebbfe 100644 (file)
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials 
+ * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -28,13 +28,13 @@ import net.sourceforge.phpdt.core.IJavaProject;
 import net.sourceforge.phpdt.core.IPackageFragment;
 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
 import net.sourceforge.phpdt.core.IType;
-import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.core.jdom.DOMException;
 import net.sourceforge.phpdt.core.jdom.DOMFactory;
 import net.sourceforge.phpdt.core.jdom.IDOMCompilationUnit;
 import net.sourceforge.phpdt.core.jdom.IDOMNode;
-import net.sourceforge.phpdt.core.jdom.IDOMPackage;
+import net.sourceforge.phpdt.internal.core.util.Util;
 
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
@@ -62,7 +62,7 @@ import org.eclipse.core.runtime.Path;
  *    same type of container.
  *
  *    <li>This operation can be used to copy and rename elements within
- *    the same container. 
+ *    the same container.
  *
  *    <li>This operation only copies compilation units and package fragments.
  *    It does not copy package fragment roots - a platform operation must be used for that.
@@ -76,7 +76,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
         */
        protected ArrayList fRenamedCompilationUnits = null;
        /**
-        * Table specifying deltas for elements being 
+        * Table specifying deltas for elements being
         * copied/moved/renamed. Keyed by elements' project(s), and
         * values are the corresponding deltas.
         */
@@ -135,7 +135,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
 //             for (int i = 0, max = nonJavaResources.length, index = 0; i < max; i++){
 //                     if (nonJavaResources[i] instanceof IResource) actualNonJavaResources[index++] = (IResource)nonJavaResources[i];
 //             }
-               
+
 //             if (actualNonJavaResourceCount != 0) {
 //                     int correctKindChildrenSize = correctKindChildren.size();
 //                     IResource[] result = new IResource[correctKindChildrenSize + actualNonJavaResourceCount];
@@ -154,7 +154,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
        private void createNeededPackageFragments(IContainer sourceFolder, IPackageFragmentRoot root, String newFragName, boolean moveFolder) throws JavaModelException {
                IContainer parentFolder = (IContainer) root.getResource();
                JavaElementDelta projectDelta = null;
-               String[] names = net.sourceforge.phpdt.internal.core.Util.getTrimmedSimpleNames(newFragName);
+               String[] names = net.sourceforge.phpdt.internal.core.util.Util.getTrimmedSimpleNames(newFragName);
                StringBuffer sideEffectPackageName = new StringBuffer();
                char[][] exclusionsPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
                for (int i = 0; i < names.length; i++) {
@@ -164,16 +164,16 @@ public class CopyResourceElementsOperation extends MultiOperation {
                        if (subFolder == null) {
                                // create deepest folder only if not a move (folder will be moved in processPackageFragmentResource)
                                if (!(moveFolder && i == names.length-1)) {
-                                       createFolder(parentFolder, subFolderName, fForce);
+                                       createFolder(parentFolder, subFolderName, force);
                                }
                                parentFolder = parentFolder.getFolder(new Path(subFolderName));
                                sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
-                               if (sourceFolder.isReadOnly()) {
-                                       parentFolder.setReadOnly(true);
+                               if (sourceFolder.getResourceAttributes().isReadOnly()) {
+                                       parentFolder.getResourceAttributes().setReadOnly(true);
                                }
                                IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName.toString());
                                if (i < names.length - 1 // all but the last one are side effect packages
-                                               && !net.sourceforge.phpdt.internal.core.Util.isExcluded(parentFolder, exclusionsPatterns)) { 
+                                               && !net.sourceforge.phpdt.internal.core.util.Util.isExcluded(parentFolder, exclusionsPatterns)) {
                                        if (projectDelta == null) {
                                                projectDelta = getDeltaFor(root.getJavaProject());
                                        }
@@ -203,7 +203,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
         * @see MultiOperation
         */
        protected String getMainTaskName() {
-               return net.sourceforge.phpdt.internal.core.Util.bind("operation.copyResourceProgress"); //$NON-NLS-1$
+               return net.sourceforge.phpdt.internal.core.util.Util.bind("operation.copyResourceProgress"); //$NON-NLS-1$
        }
        /**
         * Sets the deltas to register the changes resulting from this operation
@@ -214,10 +214,10 @@ public class CopyResourceElementsOperation extends MultiOperation {
         *                      <li>one rooted in the source project
         *                      <li>one rooted in the destination project</ul></ul>
         * If the operation is rooted in a single project, the delta is rooted in that project
-        *       
+        *
         */
        protected void prepareDeltas(IJavaElement sourceElement, IJavaElement destinationElement, boolean isMove) {
-               if (net.sourceforge.phpdt.internal.core.Util.isExcluded(sourceElement) || net.sourceforge.phpdt.internal.core.Util.isExcluded(destinationElement)) return;
+               if (net.sourceforge.phpdt.internal.core.util.Util.isExcluded(sourceElement) || net.sourceforge.phpdt.internal.core.util.Util.isExcluded(destinationElement)) return;
                IJavaProject destProject = destinationElement.getJavaProject();
                if (isMove) {
                        IJavaProject sourceProject = sourceElement.getJavaProject();
@@ -240,7 +240,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                String newCUName = getNewNameFor(source);
                String destName = (newCUName != null) ? newCUName : source.getElementName();
                String newContent = updatedContent(source, dest, newCUName); // null if unchanged
-       
+
                // copy resource
                IFile sourceResource = (IFile)(source.isWorkingCopy() ? source.getOriginalElement() : source).getResource();
                IContainer destFolder = (IContainer)dest.getResource(); // can be an IFolder or an IProject
@@ -248,17 +248,17 @@ public class CopyResourceElementsOperation extends MultiOperation {
                if (!destFile.equals(sourceResource)) {
                        try {
                                if (destFile.exists()) {
-                                       if (fForce) {
+                                       if (force) {
                                                // we can remove it
                                                deleteResource(destFile, IResource.KEEP_HISTORY);
                                        } else {
                                                // abort
                                                throw new JavaModelException(new JavaModelStatus(
-                                                       IJavaModelStatusConstants.NAME_COLLISION, 
+                                                       IJavaModelStatusConstants.NAME_COLLISION,
                                                        Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
                                        }
                                }
-                               int flags = fForce ? IResource.FORCE : IResource.NONE;
+                               int flags = force ? IResource.FORCE : IResource.NONE;
                                if (this.isMove()) {
                                        flags |= IResource.KEEP_HISTORY;
                                        sourceResource.move(destFile.getFullPath(), flags, getSubProgressMonitor(1));
@@ -266,20 +266,20 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        if (newContent != null) flags |= IResource.KEEP_HISTORY;
                                        sourceResource.copy(destFile.getFullPath(), flags, getSubProgressMonitor(1));
                                }
-                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); 
+                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
                        } catch (JavaModelException e) {
                                throw e;
                        } catch (CoreException e) {
                                throw new JavaModelException(e);
                        }
-       
+
                        // update new resource content
                        try {
                                if (newContent != null){
                                        String encoding = source.getJavaProject().getOption(JavaCore.CORE_ENCODING, true);
                                        destFile.setContents(
-                                               new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)), 
-                                               fForce ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
+                                               new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)),
+                                               force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
                                                getSubProgressMonitor(1));
                                }
                        } catch(IOException e) {
@@ -287,7 +287,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                        } catch (CoreException e) {
                                throw new JavaModelException(e);
                        }
-               
+
                        // register the correct change deltas
                        ICompilationUnit destCU = dest.getCompilationUnit(destName);
                        prepareDeltas(source, destCU, isMove());
@@ -300,9 +300,9 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                prepareDeltas(source.getType(oldName), destCU.getType(newName), isMove());
                        }
                } else {
-                       if (!fForce) {
+                       if (!force) {
                                throw new JavaModelException(new JavaModelStatus(
-                                       IJavaModelStatusConstants.NAME_COLLISION, 
+                                       IJavaModelStatusConstants.NAME_COLLISION,
                                        Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
                        }
                        // update new resource content
@@ -312,8 +312,8 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                if (newContent != null){
                                        String encoding = source.getJavaProject().getOption(JavaCore.CORE_ENCODING, true);
                                        destFile.setContents(
-                                               new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)), 
-                                               fForce ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, 
+                                               new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)),
+                                               force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
                                                getSubProgressMonitor(1));
                                }
                        } catch(IOException e) {
@@ -363,11 +363,12 @@ public class CopyResourceElementsOperation extends MultiOperation {
                } catch (JavaModelException jme) {
                        throw jme;
                } finally {
-                       fResultElements = new IJavaElement[fCreatedElements.size()];
-                       fCreatedElements.toArray(fResultElements);
+                       resultElements = new IJavaElement[fCreatedElements.size()];
+                       fCreatedElements.toArray(resultElements);
                        processDeltas();
                }
        }
+
        /**
         * Copies/moves a package fragment with the name <code>newName</code>
         * to the destination package.<br>
@@ -380,7 +381,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                        String newFragName = (newName == null) ? source.getElementName() : newName;
                        IPackageFragment newFrag = root.getPackageFragment(newFragName);
                        IResource[] resources = collectResourcesOfInterest(source);
-                       
+
                        // if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
                        boolean shouldMoveFolder = isMove() && !newFrag.getResource().exists(); // if new pkg fragment exists, it is an override
                        IFolder srcFolder = (IFolder)source.getResource();
@@ -398,15 +399,15 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                        break;
                                                }
                                        }
-                               }       
+                               }
                        }
                        createNeededPackageFragments((IContainer) source.getParent().getResource(), root, newFragName, shouldMoveFolder);
-       
+
                        // Process resources
                        if (shouldMoveFolder) {
                                // move underlying resource
-                               srcFolder.move(destPath, fForce, true /* keep history */, getSubProgressMonitor(1));
-                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); 
+                               srcFolder.move(destPath, force, true /* keep history */, getSubProgressMonitor(1));
+                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
                        } else {
                                // process the leaf resources
                                if (resources.length > 0) {
@@ -419,11 +420,11 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                for (int i = 0, max = resources.length; i < max; i++) {
                                                        IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot().findMember(destPath.append(resources[i].getName()));
                                                        if (destinationResource != null) {
-                                                               if (fForce) {
+                                                               if (force) {
                                                                        deleteResource(destinationResource, IResource.KEEP_HISTORY);
                                                                } else {
                                                                        throw new JavaModelException(new JavaModelStatus(
-                                                                               IJavaModelStatusConstants.NAME_COLLISION, 
+                                                                               IJavaModelStatusConstants.NAME_COLLISION,
                                                                                Util.bind("status.nameCollision", destinationResource.getFullPath().toString()))); //$NON-NLS-1$
                                                                }
                                                        }
@@ -434,12 +435,12 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                for (int i = 0, max = resources.length; i < max; i++) {
                                                        IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot().findMember(destPath.append(resources[i].getName()));
                                                        if (destinationResource != null) {
-                                                               if (fForce) {
+                                                               if (force) {
                                                                        // we need to delete this resource if this operation wants to override existing resources
                                                                        deleteResource(destinationResource, IResource.KEEP_HISTORY);
                                                                } else {
                                                                        throw new JavaModelException(new JavaModelStatus(
-                                                                               IJavaModelStatusConstants.NAME_COLLISION, 
+                                                                               IJavaModelStatusConstants.NAME_COLLISION,
                                                                                Util.bind("status.nameCollision", destinationResource.getFullPath().toString()))); //$NON-NLS-1$
                                                                }
                                                        }
@@ -448,7 +449,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        }
                                }
                        }
-       
+
                        // Discard empty old package (if still empty after the rename)
                        boolean isEmpty = true;
                        if (isMove()) {
@@ -472,12 +473,12 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        } else {
                                                rootResource =  source.getParent().getResource();
                                        }
-                                       
+
                                        // delete recursively empty folders
                                        deleteEmptyPackageFragment(source, false, rootResource);
                                }
                        }
-       
+
                        // Update package statement in compilation unit if needed
                        if (!newFrag.getElementName().equals(source.getElementName())) { // if package has been renamed, update the compilation units
                                for (int i = 0; i < resources.length; i++) {
@@ -494,7 +495,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                        String domCUContents = domCU.getContents();
                                                        String cuContents = null;
                                                        if (domCUContents != null) {
-                                                               cuContents = net.sourceforge.phpdt.internal.core.Util.normalizeCRs(domCU.getContents(), bufferContents);
+                                                               cuContents = net.sourceforge.phpdt.internal.core.util.Util.normalizeCRs(domCU.getContents(), bufferContents);
                                                        } else {
                                                                // See PR http://dev.eclipse.org/bugs/show_bug.cgi?id=11285
                                                                cuContents = bufferContents;//$NON-NLS-1$
@@ -505,7 +506,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        }
                                }
                        }
-       
+
                        //register the correct change deltas
                        prepareDeltas(source, newFrag, isMove() && isEmpty);
                } catch (DOMException dom) {
@@ -547,9 +548,9 @@ public class CopyResourceElementsOperation extends MultiOperation {
        private void updatePackageStatement(IDOMCompilationUnit domCU, String pkgName) throws JavaModelException {
                boolean defaultPackage = pkgName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME);
                boolean seenPackageNode = false;
-               Enumeration enum = domCU.getChildren();
-               while (enum.hasMoreElements()) {
-                       IDOMNode node = (IDOMNode) enum.nextElement();
+               Enumeration e = domCU.getChildren();
+               while (e.hasMoreElements()) {
+                       IDOMNode node = (IDOMNode) e.nextElement();
                        if (node.getNodeType() == IDOMNode.PACKAGE) {
                                if (! defaultPackage) {
                                        node.setName(pkgName);
@@ -563,7 +564,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                if (!seenPackageNode && !defaultPackage) {
                        //the cu was in a default package...no package declaration
                        //create the new package declaration as the first child of the cu
-//                     IDOMPackage pkg = fFactory.createPackage("package " + pkgName + ";" + net.sourceforge.phpdt.internal.compiler.util.Util.LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
+//                     IDOMPackage pkg = fFactory.createPackage("package " + pkgName + ";" + net.sourceforge.phpdt.internal.compiler.util.ProjectPrefUtil.LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
 //                     IDOMNode firstChild = domCU.getFirstChild();
 //                     if (firstChild != null) {
 //                             firstChild.insertSibling(pkg);
@@ -607,7 +608,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                if (!status.isOK()) {
                        return status;
                }
-       
+
                if (fRenamingsList != null && fRenamingsList.length != fElementsToProcess.length) {
                        return new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS);
                }
@@ -619,7 +620,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
        protected void verify(IJavaElement element) throws JavaModelException {
                if (element == null || !element.exists())
                        error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
-                       
+
                if (element.isReadOnly() && (isRename() || isMove()))
                        error(IJavaModelStatusConstants.READ_ONLY, element);
 
@@ -629,16 +630,16 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                error(JavaModelStatus.INVALID_RESOURCE, element);
                        }
                }
-       
+
                int elementType = element.getElementType();
-       
+
                if (elementType == IJavaElement.COMPILATION_UNIT) {
                        if (isMove() && ((ICompilationUnit) element).isWorkingCopy())
                                error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
                } else if (elementType != IJavaElement.PACKAGE_FRAGMENT) {
                        error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
                }
-               
+
                JavaElement dest = (JavaElement) getDestinationParent(element);
                verifyDestination(element, dest);
                if (fRenamings != null) {