<s> package org . eclipse . jdt . internal . core ; import org . eclipse . core . resources . * ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelStatusConstants ; import org . eclipse . jdt . core . IOpenable ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . util . Messages ; public class DeleteResourceElementsOperation extends MultiOperation { protected DeleteResourceElementsOperation ( IJavaElement [ ] elementsToProcess , boolean force ) { super ( elementsToProcess , force ) ; } private void deletePackageFragment ( IPackageFragment frag ) throws JavaModelException { IResource res = ( ( JavaElement ) frag ) . resource ( ) ; if ( res != null ) { IJavaElement [ ] childrenOfInterest = frag . getChildren ( ) ; if ( childrenOfInterest . length > 0 ) { IResource [ ] resources = new IResource [ childrenOfInterest . length ] ; for ( int i = 0 ; i < childrenOfInterest . length ; i ++ ) { resources [ i ] = ( ( JavaElement ) childrenOfInterest [ i ] ) . resource ( ) ; } deleteResources ( resources , this . force ) ; } Object [ ] nonJavaResources = frag . getNonJavaResources ( ) ; int actualResourceCount = 0 ; for ( int i = 0 , max = nonJavaResources . length ; i < max ; i ++ ) { if ( nonJavaResources [ i ] instanceof IResource ) actualResourceCount ++ ; } IResource [ ] actualNonJavaResources = new IResource [ actualResourceCount ] ; for ( int i = 0 , max = nonJavaResources . length , index = 0 ; i < max ; i ++ ) { if ( nonJavaResources [ i ] instanceof IResource ) actualNonJavaResources [ index ++ ] = ( IResource ) nonJavaResources [ i ] ; } deleteResources ( actualNonJavaResources , this . force ) ; IResource [ ] remainingFiles ; try { remainingFiles = ( ( IContainer ) res ) . members ( ) ; } catch ( CoreException ce ) { throw new JavaModelException ( ce ) ; } boolean isEmpty = true ; for ( int i = 0 , length = remainingFiles . length ; i < length ; i ++ ) { IResource file = remainingFiles [ i ] ; if ( file instanceof IFile && org . eclipse . jdt . internal . compiler . util . Util . isClassFileName ( file . getName ( ) ) ) { deleteResource ( file , IResource . FORCE | IResource . KEEP_HISTORY ) ; } else { isEmpty = false ; } } if ( isEmpty && ! frag . isDefaultPackage ( ) ) { IResource fragResource = ( ( JavaElement ) frag ) . resource ( ) ; if ( fragResource != null ) { deleteEmptyPackageFragment ( frag , false , fragResource . getParent ( ) ) ; } } } } protected String getMainTaskName ( ) { return Messages . operation_deleteResourceProgress ; } protected void processElement ( IJavaElement element ) throws JavaModelException { switch ( element . getElementType ( ) ) { case IJavaElement . CLASS_FILE : case IJavaElement . COMPILATION_UNIT : deleteResource ( element . getResource ( ) , this . force ? IResource . FORCE | IResource . KEEP_HISTORY : IResource . KEEP_HISTORY ) ; break ; case IJavaElement . PACKAGE_FRAGMENT : deletePackageFragment ( ( IPackageFragment ) element ) ; break ; default : throw new JavaModelException ( new JavaModelStatus ( IJavaModelStatusConstants . INVALID_ELEMENT_TYPES , element ) ) ; } if ( element instanceof IOpenable ) { ( ( IOpenable ) element ) . close ( ) ; } } protected void verify ( IJavaElement element ) throws JavaModelException { if ( element == null || ! element . exists ( ) ) error ( IJavaModelStatusConstants . ELEMENT_DOES_NOT_EXIST , element ) ; int type = element . getElementType ( ) ; if ( type <= IJavaElement . PACKAGE_FRAGMENT_ROOT || type > IJavaElement . COMPILATION_UNIT ) error ( IJavaModelStatusConstants . INVALID_ELEMENT_TYPES , element ) ; else if ( type == IJavaElement . PACKAGE_FRAGMENT && element instanceof JarPackageFragment ) error ( IJavaModelStatusConstants . INVALID_ELEMENT_TYPES , element ) ; IResource resource = ( ( JavaElement ) element ) . resource ( ) ; if ( resource instanceof IFolder ) { if ( resource . isLinked ( ) ) { error ( IJavaModelStatusConstants . INVALID_RESOURCE , element ) ; } } } } </s>