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 7f8d1c4..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
  *******************************************************************************/
@@ -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];
@@ -168,12 +168,12 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                }
                                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.Util.isExcluded(parentFolder, exclusionsPatterns)) { 
+                                               && !net.sourceforge.phpdt.internal.core.util.Util.isExcluded(parentFolder, exclusionsPatterns)) {
                                        if (projectDelta == null) {
                                                projectDelta = getDeltaFor(root.getJavaProject());
                                        }
@@ -214,7 +214,7 @@ 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.Util.isExcluded(sourceElement) || net.sourceforge.phpdt.internal.core.util.Util.isExcluded(destinationElement)) return;
@@ -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
@@ -254,7 +254,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        } else {
                                                // abort
                                                throw new JavaModelException(new JavaModelStatus(
-                                                       IJavaModelStatusConstants.NAME_COLLISION, 
+                                                       IJavaModelStatusConstants.NAME_COLLISION,
                                                        Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
                                        }
                                }
@@ -266,19 +266,19 @@ 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)), 
+                                               new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)),
                                                force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
                                                getSubProgressMonitor(1));
                                }
@@ -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());
@@ -302,7 +302,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                } else {
                        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)), 
-                                               force ? 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) {
@@ -368,7 +368,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                        processDeltas();
                }
        }
-       
+
        /**
         * Copies/moves a package fragment with the name <code>newName</code>
         * to the destination package.<br>
@@ -381,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();
@@ -399,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, force, true /* keep history */, getSubProgressMonitor(1));
-                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); 
+                               this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
                        } else {
                                // process the leaf resources
                                if (resources.length > 0) {
@@ -424,7 +424,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                                        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$
                                                                }
                                                        }
@@ -440,7 +440,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                                                        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$
                                                                }
                                                        }
@@ -449,7 +449,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        }
                                }
                        }
-       
+
                        // Discard empty old package (if still empty after the rename)
                        boolean isEmpty = true;
                        if (isMove()) {
@@ -473,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++) {
@@ -506,7 +506,7 @@ public class CopyResourceElementsOperation extends MultiOperation {
                                        }
                                }
                        }
-       
+
                        //register the correct change deltas
                        prepareDeltas(source, newFrag, isMove() && isEmpty);
                } catch (DOMException dom) {
@@ -548,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);
@@ -608,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);
                }
@@ -620,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);
 
@@ -630,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) {