1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import java.io.ByteArrayInputStream;
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.Iterator;
21 import net.sourceforge.phpdt.core.IBuffer;
22 import net.sourceforge.phpdt.core.ICompilationUnit;
23 import net.sourceforge.phpdt.core.IJavaElement;
24 import net.sourceforge.phpdt.core.IJavaElementDelta;
25 import net.sourceforge.phpdt.core.IJavaModelStatus;
26 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
27 import net.sourceforge.phpdt.core.IJavaProject;
28 import net.sourceforge.phpdt.core.IPackageFragment;
29 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
30 import net.sourceforge.phpdt.core.IType;
31 import net.sourceforge.phpdt.core.JavaModelException;
32 import net.sourceforge.phpdt.core.JavaCore;
33 import net.sourceforge.phpdt.core.jdom.DOMException;
34 import net.sourceforge.phpdt.core.jdom.DOMFactory;
35 import net.sourceforge.phpdt.core.jdom.IDOMCompilationUnit;
36 import net.sourceforge.phpdt.core.jdom.IDOMNode;
37 import net.sourceforge.phpdt.core.jdom.IDOMPackage;
39 import org.eclipse.core.resources.IContainer;
40 import org.eclipse.core.resources.IFile;
41 import org.eclipse.core.resources.IFolder;
42 import org.eclipse.core.resources.IResource;
43 import org.eclipse.core.resources.ResourcesPlugin;
44 import org.eclipse.core.runtime.CoreException;
45 import org.eclipse.core.runtime.IPath;
46 import org.eclipse.core.runtime.Path;
49 * This operation copies/moves/renames a collection of resources from their current
50 * container to a new container, optionally renaming the
53 * <li>If there is already an resource with the same name in
54 * the new container, the operation either overwrites or aborts,
55 * depending on the collision policy setting. The default setting is
58 * <li>When a compilation unit is copied to a new package, the
59 * package declaration in the compilation unit is automatically updated.
61 * <li>The collection of elements being copied must all share the
62 * same type of container.
64 * <li>This operation can be used to copy and rename elements within
67 * <li>This operation only copies compilation units and package fragments.
68 * It does not copy package fragment roots - a platform operation must be used for that.
72 public class CopyResourceElementsOperation extends MultiOperation {
74 * A collection of renamed compilation units. These cus do
75 * not need to be saved as they no longer exist.
77 protected ArrayList fRenamedCompilationUnits = null;
79 * Table specifying deltas for elements being
80 * copied/moved/renamed. Keyed by elements' project(s), and
81 * values are the corresponding deltas.
83 protected Map fDeltasPerProject= new HashMap(1);
85 * The <code>DOMFactory</code> used to manipulate the source code of
86 * <code>ICompilationUnit</code>.
88 protected DOMFactory fFactory;
90 * The list of new resources created during this operation.
92 protected ArrayList fCreatedElements;
94 * When executed, this operation will copy the given resources to the
95 * given containers. The resources and destination containers must be in
96 * the correct order. If there is > 1 destination, the number of destinations
97 * must be the same as the number of resources being copied/moved.
99 public CopyResourceElementsOperation(IJavaElement[] resourcesToCopy, IJavaElement[] destContainers, boolean force) {
100 super(resourcesToCopy, destContainers, force);
101 fFactory = new DOMFactory();
104 * When executed, this operation will copy the given resources to the
107 public CopyResourceElementsOperation(IJavaElement[] resourcesToCopy, IJavaElement destContainer, boolean force) {
108 this(resourcesToCopy, new IJavaElement[]{destContainer}, force);
111 * Returns the children of <code>source</code> which are affected by this operation.
112 * If <code>source</code> is a <code>K_SOURCE</code>, these are the <code>.java</code>
113 * files, if it is a <code>K_BINARY</code>, they are the <code>.class</code> files.
115 private IResource[] collectResourcesOfInterest(IPackageFragment source) throws JavaModelException {
116 IJavaElement[] children = source.getChildren();
117 int childOfInterest = IJavaElement.COMPILATION_UNIT;
118 // if (source.getKind() == IPackageFragmentRoot.K_BINARY) {
119 // childOfInterest = IJavaElement.CLASS_FILE;
121 ArrayList correctKindChildren = new ArrayList(children.length);
122 for (int i = 0; i < children.length; i++) {
123 IJavaElement child = children[i];
124 if (child.getElementType() == childOfInterest) {
125 correctKindChildren.add(child.getResource());
128 // Gather non-java resources
129 // Object[] nonJavaResources = source.getNonJavaResources();
130 // int actualNonJavaResourceCount = 0;
131 // for (int i = 0, max = nonJavaResources.length; i < max; i++){
132 // if (nonJavaResources[i] instanceof IResource) actualNonJavaResourceCount++;
134 // IResource[] actualNonJavaResources = new IResource[actualNonJavaResourceCount];
135 // for (int i = 0, max = nonJavaResources.length, index = 0; i < max; i++){
136 // if (nonJavaResources[i] instanceof IResource) actualNonJavaResources[index++] = (IResource)nonJavaResources[i];
139 // if (actualNonJavaResourceCount != 0) {
140 // int correctKindChildrenSize = correctKindChildren.size();
141 // IResource[] result = new IResource[correctKindChildrenSize + actualNonJavaResourceCount];
142 // correctKindChildren.toArray(result);
143 // System.arraycopy(actualNonJavaResources, 0, result, correctKindChildrenSize, actualNonJavaResourceCount);
146 IResource[] result = new IResource[correctKindChildren.size()];
147 correctKindChildren.toArray(result);
152 * Creates any destination package fragment(s) which do not exists yet.
154 private void createNeededPackageFragments(IContainer sourceFolder, IPackageFragmentRoot root, String newFragName, boolean moveFolder) throws JavaModelException {
155 IContainer parentFolder = (IContainer) root.getResource();
156 JavaElementDelta projectDelta = null;
157 String[] names = net.sourceforge.phpdt.internal.core.Util.getTrimmedSimpleNames(newFragName);
158 StringBuffer sideEffectPackageName = new StringBuffer();
159 char[][] exclusionsPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
160 for (int i = 0; i < names.length; i++) {
161 String subFolderName = names[i];
162 sideEffectPackageName.append(subFolderName);
163 IResource subFolder = parentFolder.findMember(subFolderName);
164 if (subFolder == null) {
165 // create deepest folder only if not a move (folder will be moved in processPackageFragmentResource)
166 if (!(moveFolder && i == names.length-1)) {
167 createFolder(parentFolder, subFolderName, fForce);
169 parentFolder = parentFolder.getFolder(new Path(subFolderName));
170 sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
171 if (sourceFolder.isReadOnly()) {
172 parentFolder.setReadOnly(true);
174 IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName.toString());
175 if (i < names.length - 1 // all but the last one are side effect packages
176 && !net.sourceforge.phpdt.internal.core.Util.isExcluded(parentFolder, exclusionsPatterns)) {
177 if (projectDelta == null) {
178 projectDelta = getDeltaFor(root.getJavaProject());
180 projectDelta.added(sideEffectPackage);
182 fCreatedElements.add(sideEffectPackage);
184 parentFolder = (IContainer) subFolder;
186 sideEffectPackageName.append('.');
190 * Returns the <code>JavaElementDelta</code> for <code>javaProject</code>,
191 * creating it and putting it in <code>fDeltasPerProject</code> if
192 * it does not exist yet.
194 private JavaElementDelta getDeltaFor(IJavaProject javaProject) {
195 JavaElementDelta delta = (JavaElementDelta) fDeltasPerProject.get(javaProject);
197 delta = new JavaElementDelta(javaProject);
198 fDeltasPerProject.put(javaProject, delta);
203 * @see MultiOperation
205 protected String getMainTaskName() {
206 return net.sourceforge.phpdt.internal.core.Util.bind("operation.copyResourceProgress"); //$NON-NLS-1$
209 * Sets the deltas to register the changes resulting from this operation
210 * for this source element and its destination.
211 * If the operation is a cross project operation<ul>
212 * <li>On a copy, the delta should be rooted in the dest project
213 * <li>On a move, two deltas are generated<ul>
214 * <li>one rooted in the source project
215 * <li>one rooted in the destination project</ul></ul>
216 * If the operation is rooted in a single project, the delta is rooted in that project
219 protected void prepareDeltas(IJavaElement sourceElement, IJavaElement destinationElement, boolean isMove) {
220 if (net.sourceforge.phpdt.internal.core.Util.isExcluded(sourceElement) || net.sourceforge.phpdt.internal.core.Util.isExcluded(destinationElement)) return;
221 IJavaProject destProject = destinationElement.getJavaProject();
223 IJavaProject sourceProject = sourceElement.getJavaProject();
224 getDeltaFor(sourceProject).movedFrom(sourceElement, destinationElement);
225 getDeltaFor(destProject).movedTo(destinationElement, sourceElement);
227 getDeltaFor(destProject).added(destinationElement);
231 * Copies/moves a compilation unit with the name <code>newCUName</code>
232 * to the destination package.<br>
233 * The package statement in the compilation unit is updated if necessary.
234 * The main type of the compilation unit is renamed if necessary.
236 * @exception JavaModelException if the operation is unable to
239 private void processCompilationUnitResource(ICompilationUnit source, IPackageFragment dest) throws JavaModelException {
240 String newCUName = getNewNameFor(source);
241 String destName = (newCUName != null) ? newCUName : source.getElementName();
242 String newContent = updatedContent(source, dest, newCUName); // null if unchanged
245 IFile sourceResource = (IFile)(source.isWorkingCopy() ? source.getOriginalElement() : source).getResource();
246 IContainer destFolder = (IContainer)dest.getResource(); // can be an IFolder or an IProject
247 IFile destFile = destFolder.getFile(new Path(destName));
248 if (!destFile.equals(sourceResource)) {
250 if (destFile.exists()) {
253 deleteResource(destFile, IResource.KEEP_HISTORY);
256 throw new JavaModelException(new JavaModelStatus(
257 IJavaModelStatusConstants.NAME_COLLISION,
258 Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
261 int flags = fForce ? IResource.FORCE : IResource.NONE;
263 flags |= IResource.KEEP_HISTORY;
264 sourceResource.move(destFile.getFullPath(), flags, getSubProgressMonitor(1));
266 if (newContent != null) flags |= IResource.KEEP_HISTORY;
267 sourceResource.copy(destFile.getFullPath(), flags, getSubProgressMonitor(1));
269 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
270 } catch (JavaModelException e) {
272 } catch (CoreException e) {
273 throw new JavaModelException(e);
276 // update new resource content
278 if (newContent != null){
279 String encoding = source.getJavaProject().getOption(JavaCore.CORE_ENCODING, true);
280 destFile.setContents(
281 new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)),
282 fForce ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
283 getSubProgressMonitor(1));
285 } catch(IOException e) {
286 throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
287 } catch (CoreException e) {
288 throw new JavaModelException(e);
291 // register the correct change deltas
292 ICompilationUnit destCU = dest.getCompilationUnit(destName);
293 prepareDeltas(source, destCU, isMove());
294 if (newCUName != null) {
295 //the main type has been renamed
296 String oldName = source.getElementName();
297 oldName = oldName.substring(0, oldName.length() - 5);
298 String newName = newCUName;
299 newName = newName.substring(0, newName.length() - 5);
300 prepareDeltas(source.getType(oldName), destCU.getType(newName), isMove());
304 throw new JavaModelException(new JavaModelStatus(
305 IJavaModelStatusConstants.NAME_COLLISION,
306 Util.bind("status.nameCollision", destFile.getFullPath().toString()))); //$NON-NLS-1$
308 // update new resource content
309 // in case we do a saveas on the same resource we have to simply update the contents
310 // see http://dev.eclipse.org/bugs/show_bug.cgi?id=9351
312 if (newContent != null){
313 String encoding = source.getJavaProject().getOption(JavaCore.CORE_ENCODING, true);
314 destFile.setContents(
315 new ByteArrayInputStream(encoding == null ? newContent.getBytes() : newContent.getBytes(encoding)),
316 fForce ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
317 getSubProgressMonitor(1));
319 } catch(IOException e) {
320 throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
321 } catch (CoreException e) {
322 throw new JavaModelException(e);
327 * Process all of the changed deltas generated by this operation.
329 protected void processDeltas() {
330 for (Iterator deltas = this.fDeltasPerProject.values().iterator(); deltas.hasNext();){
331 addDelta((IJavaElementDelta) deltas.next());
335 * @see MultiOperation
336 * This method delegates to <code>processCompilationUnitResource</code> or
337 * <code>processPackageFragmentResource</code>, depending on the type of
338 * <code>element</code>.
340 protected void processElement(IJavaElement element) throws JavaModelException {
341 IJavaElement dest = getDestinationParent(element);
342 switch (element.getElementType()) {
343 case IJavaElement.COMPILATION_UNIT :
344 processCompilationUnitResource((ICompilationUnit) element, (IPackageFragment) dest);
345 fCreatedElements.add(((IPackageFragment) dest).getCompilationUnit(element.getElementName()));
347 case IJavaElement.PACKAGE_FRAGMENT :
348 processPackageFragmentResource((IPackageFragment) element, (IPackageFragmentRoot) dest, getNewNameFor(element));
351 throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element));
355 * @see MultiOperation
356 * Overridden to allow special processing of <code>JavaElementDelta</code>s
357 * and <code>fResultElements</code>.
359 protected void processElements() throws JavaModelException {
360 fCreatedElements = new ArrayList(fElementsToProcess.length);
362 super.processElements();
363 } catch (JavaModelException jme) {
366 fResultElements = new IJavaElement[fCreatedElements.size()];
367 fCreatedElements.toArray(fResultElements);
372 * Copies/moves a package fragment with the name <code>newName</code>
373 * to the destination package.<br>
375 * @exception JavaModelException if the operation is unable to
378 private void processPackageFragmentResource(IPackageFragment source, IPackageFragmentRoot root, String newName) throws JavaModelException {
380 String newFragName = (newName == null) ? source.getElementName() : newName;
381 IPackageFragment newFrag = root.getPackageFragment(newFragName);
382 IResource[] resources = collectResourcesOfInterest(source);
384 // if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
385 boolean shouldMoveFolder = isMove() && !newFrag.getResource().exists(); // if new pkg fragment exists, it is an override
386 IFolder srcFolder = (IFolder)source.getResource();
387 IPath destPath = newFrag.getPath();
388 if (shouldMoveFolder) {
389 // check if destination is not included in source
390 if (srcFolder.getFullPath().isPrefixOf(destPath)) {
391 shouldMoveFolder = false;
393 // check if there are no sub-packages
394 IResource[] members = srcFolder.members();
395 for (int i = 0; i < members.length; i++) {
396 if ( members[i] instanceof IFolder) {
397 shouldMoveFolder = false;
403 createNeededPackageFragments((IContainer) source.getParent().getResource(), root, newFragName, shouldMoveFolder);
406 if (shouldMoveFolder) {
407 // move underlying resource
408 srcFolder.move(destPath, fForce, true /* keep history */, getSubProgressMonitor(1));
409 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
411 // process the leaf resources
412 if (resources.length > 0) {
414 if (! destPath.equals(source.getPath())) {
415 moveResources(resources, destPath);
417 } else if (isMove()) {
418 // we need to delete this resource if this operation wants to override existing resources
419 for (int i = 0, max = resources.length; i < max; i++) {
420 IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot().findMember(destPath.append(resources[i].getName()));
421 if (destinationResource != null) {
423 deleteResource(destinationResource, IResource.KEEP_HISTORY);
425 throw new JavaModelException(new JavaModelStatus(
426 IJavaModelStatusConstants.NAME_COLLISION,
427 Util.bind("status.nameCollision", destinationResource.getFullPath().toString()))); //$NON-NLS-1$
431 moveResources(resources, destPath);
433 // we need to delete this resource if this operation wants to override existing resources
434 for (int i = 0, max = resources.length; i < max; i++) {
435 IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot().findMember(destPath.append(resources[i].getName()));
436 if (destinationResource != null) {
438 // we need to delete this resource if this operation wants to override existing resources
439 deleteResource(destinationResource, IResource.KEEP_HISTORY);
441 throw new JavaModelException(new JavaModelStatus(
442 IJavaModelStatusConstants.NAME_COLLISION,
443 Util.bind("status.nameCollision", destinationResource.getFullPath().toString()))); //$NON-NLS-1$
447 copyResources(resources, destPath);
452 // Discard empty old package (if still empty after the rename)
453 boolean isEmpty = true;
455 // delete remaining files in this package (.class file in the case where Proj=src=bin)
456 if (srcFolder.exists()) {
457 IResource[] remaingFiles = srcFolder.members();
458 for (int i = 0, length = remaingFiles.length; i < length; i++) {
459 IResource file = remaingFiles[i];
460 if (file instanceof IFile) {
461 this.deleteResource(file, IResource.FORCE | IResource.KEEP_HISTORY);
468 IResource rootResource;
469 // check if source is included in destination
470 if (destPath.isPrefixOf(srcFolder.getFullPath())) {
471 rootResource = newFrag.getResource();
473 rootResource = source.getParent().getResource();
476 // delete recursively empty folders
477 deleteEmptyPackageFragment(source, false, rootResource);
481 // Update package statement in compilation unit if needed
482 if (!newFrag.getElementName().equals(source.getElementName())) { // if package has been renamed, update the compilation units
483 for (int i = 0; i < resources.length; i++) {
484 if (resources[i].getName().endsWith(".java")) { //$NON-NLS-1$
485 // we only consider potential compilation units
486 ICompilationUnit cu = newFrag.getCompilationUnit(resources[i].getName());
487 IDOMCompilationUnit domCU = fFactory.createCompilationUnit(cu.getSource(), cu.getElementName());
489 updatePackageStatement(domCU, newFragName);
490 IBuffer buffer = cu.getBuffer();
491 if (buffer == null) continue;
492 String bufferContents = buffer.getContents();
493 if (bufferContents == null) continue;
494 String domCUContents = domCU.getContents();
495 String cuContents = null;
496 if (domCUContents != null) {
497 cuContents = net.sourceforge.phpdt.internal.core.Util.normalizeCRs(domCU.getContents(), bufferContents);
499 // See PR http://dev.eclipse.org/bugs/show_bug.cgi?id=11285
500 cuContents = bufferContents;//$NON-NLS-1$
502 buffer.setContents(cuContents);
503 cu.save(null, false);
509 //register the correct change deltas
510 prepareDeltas(source, newFrag, isMove() && isEmpty);
511 } catch (DOMException dom) {
512 throw new JavaModelException(dom, IJavaModelStatusConstants.DOM_EXCEPTION);
513 } catch (JavaModelException e) {
515 } catch (CoreException ce) {
516 throw new JavaModelException(ce);
520 * Updates the content of <code>cu</code>, modifying the type name and/or package
521 * declaration as necessary.
523 * @return the new source
525 private String updatedContent(ICompilationUnit cu, IPackageFragment dest, String newName) throws JavaModelException {
526 String currPackageName = cu.getParent().getElementName();
527 String destPackageName = dest.getElementName();
528 if (currPackageName.equals(destPackageName) && newName == null) {
529 return null; //nothing to change
531 String typeName = cu.getElementName();
532 typeName = typeName.substring(0, typeName.length() - 5);
533 IDOMCompilationUnit cuDOM = null;
534 IBuffer buffer = cu.getBuffer();
535 if (buffer == null) return null;
536 char[] contents = buffer.getCharacters();
537 if (contents == null) return null;
538 cuDOM = fFactory.createCompilationUnit(contents, typeName);
539 updateTypeName(cu, cuDOM, cu.getElementName(), newName);
540 updatePackageStatement(cuDOM, destPackageName);
541 return cuDOM.getContents();
545 * Makes sure that <code>cu</code> declares to be in the <code>pkgName</code> package.
547 private void updatePackageStatement(IDOMCompilationUnit domCU, String pkgName) throws JavaModelException {
548 boolean defaultPackage = pkgName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME);
549 boolean seenPackageNode = false;
550 Enumeration enum = domCU.getChildren();
551 while (enum.hasMoreElements()) {
552 IDOMNode node = (IDOMNode) enum.nextElement();
553 if (node.getNodeType() == IDOMNode.PACKAGE) {
554 if (! defaultPackage) {
555 node.setName(pkgName);
559 seenPackageNode = true;
563 if (!seenPackageNode && !defaultPackage) {
564 //the cu was in a default package...no package declaration
565 //create the new package declaration as the first child of the cu
566 // IDOMPackage pkg = fFactory.createPackage("package " + pkgName + ";" + net.sourceforge.phpdt.internal.compiler.util.Util.LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
567 // IDOMNode firstChild = domCU.getFirstChild();
568 // if (firstChild != null) {
569 // firstChild.insertSibling(pkg);
570 // } // else the cu was empty: leave it empty
574 * Renames the main type in <code>cu</code>.
576 private void updateTypeName(ICompilationUnit cu, IDOMCompilationUnit domCU, String oldName, String newName) throws JavaModelException {
577 if (newName != null) {
578 if (fRenamedCompilationUnits == null) {
579 fRenamedCompilationUnits= new ArrayList(1);
581 fRenamedCompilationUnits.add(cu);
582 String oldTypeName= oldName.substring(0, oldName.length() - 5);
583 String newTypeName= newName.substring(0, newName.length() - 5);
584 // update main type name
585 IType[] types = cu.getTypes();
586 for (int i = 0, max = types.length; i < max; i++) {
587 IType currentType = types[i];
588 if (currentType.getElementName().equals(oldTypeName)) {
589 IDOMNode typeNode = ((JavaElement) currentType).findNode(domCU);
590 if (typeNode != null) {
591 typeNode.setName(newTypeName);
600 * <li>NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation
601 * <li>INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation
602 * does not match the number of elements that were supplied.
605 protected IJavaModelStatus verify() {
606 IJavaModelStatus status = super.verify();
607 if (!status.isOK()) {
611 if (fRenamingsList != null && fRenamingsList.length != fElementsToProcess.length) {
612 return new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS);
614 return JavaModelStatus.VERIFIED_OK;
617 * @see MultiOperation
619 protected void verify(IJavaElement element) throws JavaModelException {
620 if (element == null || !element.exists())
621 error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
623 if (element.isReadOnly() && (isRename() || isMove()))
624 error(IJavaModelStatusConstants.READ_ONLY, element);
626 IResource resource = element.getResource();
627 if (resource instanceof IFolder) {
628 if (resource.isLinked()) {
629 error(JavaModelStatus.INVALID_RESOURCE, element);
633 int elementType = element.getElementType();
635 if (elementType == IJavaElement.COMPILATION_UNIT) {
636 if (isMove() && ((ICompilationUnit) element).isWorkingCopy())
637 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
638 } else if (elementType != IJavaElement.PACKAGE_FRAGMENT) {
639 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
642 JavaElement dest = (JavaElement) getDestinationParent(element);
643 verifyDestination(element, dest);
644 if (fRenamings != null) {
645 verifyRenaming(element);