/*******************************************************************************
* 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
*******************************************************************************/
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;
* 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.
*/
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.
*/
// 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];
}
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());
}
* <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;
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
} else {
// abort
throw new JavaModelException(new JavaModelStatus(
- IJavaModelStatusConstants.NAME_COLLISION,
+ IJavaModelStatusConstants.NAME_COLLISION,
Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
}
}
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));
}
} catch (CoreException e) {
throw new JavaModelException(e);
}
-
+
// register the correct change deltas
ICompilationUnit destCU = dest.getCompilationUnit(destName);
prepareDeltas(source, destCU, isMove());
} 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
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) {
processDeltas();
}
}
-
+
/**
* Copies/moves a package fragment with the name <code>newName</code>
* to the destination package.<br>
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();
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) {
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$
}
}
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$
}
}
}
}
}
-
+
// Discard empty old package (if still empty after the rename)
boolean isEmpty = true;
if (isMove()) {
} 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++) {
}
}
}
-
+
//register the correct change deltas
prepareDeltas(source, newFrag, isMove() && isEmpty);
} catch (DOMException dom) {
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);
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);
if (!status.isOK()) {
return status;
}
-
+
if (fRenamingsList != null && fRenamingsList.length != fElementsToProcess.length) {
return new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS);
}
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);
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) {