/** @see 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);

    IResource resource = ((JavaElement) element).resource();
    if (resource instanceof IFolder) {
      if (resource.isLinked()) {
        error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
      }
    }

    int elementType = element.getElementType();

    if (elementType == IJavaElement.COMPILATION_UNIT) {
      org.eclipse.jdt.internal.core.CompilationUnit compilationUnit =
          (org.eclipse.jdt.internal.core.CompilationUnit) element;
      if (isMove() && compilationUnit.isWorkingCopy() && !compilationUnit.isPrimary())
        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 (this.renamings != null) {
      verifyRenaming(element);
    }
  }
  private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root)
      throws JavaModelException {
    IResource resource = root.getResource();
    if (resource != null && resource.isLinked()) {
      // XXX using this code is a workaround for jcore bug 31998
      // jcore cannot handle linked stuff
      // normally, we should always create DeletePackageFragmentRootChange
      CompositeChange composite =
          new DynamicValidationStateChange(
              RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root);

      ClasspathChange change =
          ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry());
      if (change != null) {
        composite.add(change);
      }
      Assert.isTrue(!Checks.isClasspathDelete(root)); // checked in preconditions
      composite.add(createDeleteChange(resource));

      return composite;
    } else {
      Assert.isTrue(!root.isExternal());
      // TODO remove the query argument
      return new DeletePackageFragmentRootChange(root, true, null);
    }
  }
 private static boolean hasReadOnlyResourcesAndSubResources(IResource resource)
     throws CoreException {
   if (resource.isLinked()) // we don't want to count these because we never actually delete linked
     // resources
     return false;
   if (Resources.isReadOnly(resource)) return true;
   if (resource instanceof IContainer)
     return hasReadOnlyResourcesAndSubResources(((IContainer) resource).members());
   return false;
 }
 private static Change createSourceManipulationDeleteChange(ISourceManipulation element) {
   // XXX workaround for bug 31384, in case of linked ISourceManipulation delete the resource
   if (element instanceof ICompilationUnit || element instanceof IPackageFragment) {
     IResource resource;
     if (element instanceof ICompilationUnit)
       resource = ReorgUtils.getResource((ICompilationUnit) element);
     else resource = ((IPackageFragment) element).getResource();
     if (resource != null && resource.isLinked()) return createDeleteChange(resource);
   }
   return new DeleteSourceManipulationChange(element, true);
 }
 private Map<IPath, IResource> getSourceArchives() {
   if (archives == null) {
     Map<IPath, IResource> tempSourceArchives = new HashMap<>();
     IProject project = getExternalSourceArchivesProject();
     try {
       if (!project.isAccessible()) {
         if (project.exists()) {
           // workspace was moved
           openExternalSourceArchivesProject(project, null /*no progress*/);
         } else {
           // if project doesn't exist, do not open and recreate it as it means that there are no
           // external source archives
           return archives = Collections.synchronizedMap(tempSourceArchives);
         }
       }
       IResource[] members = project.members();
       for (int i = 0, length = members.length; i < length; i++) {
         IResource member = members[i];
         if (member.getType() == IResource.FOLDER
             && member.isLinked()
             && member.getName().startsWith(LINKED_FOLDER_NAME)) {
           String path = member.getLocationURI().getPath();
           if (path != null) {
             if (path.endsWith(CeylonArchiveFileSystem.JAR_SUFFIX)) {
               path = path.substring(0, path.length() - 2);
             }
             IPath externalSourceArchivePath = new Path(path);
             tempSourceArchives.put(externalSourceArchivePath, member);
           }
         }
       }
     } catch (CoreException e) {
       Util.log(e, "Exception while initializing external folders");
     }
     archives = Collections.synchronizedMap(tempSourceArchives);
   }
   return archives;
 }
 private HashMap getFolders() {
   if (this.folders == null) {
     this.folders = new HashMap();
     IProject project = getExternalFoldersProject();
     if (project.isAccessible()) {
       try {
         IResource[] members = project.members();
         for (int i = 0, length = members.length; i < length; i++) {
           IResource member = members[i];
           if (member.getType() == IResource.FOLDER
               && member.isLinked()
               && member.getName().startsWith(LINKED_FOLDER_NAME)) {
             IPath externalFolderPath = member.getLocation();
             this.folders.put(externalFolderPath, member);
           }
         }
       } catch (CoreException e) {
         Util.log(e, "Exception while initializing external folders"); // $NON-NLS-1$
       }
     }
   }
   return this.folders;
 }