<s> package org . eclipse . jdt . internal . core ; import java . util . ArrayList ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . jobs . ISchedulingRule ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelStatus ; import org . eclipse . jdt . core . IJavaModelStatusConstants ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaConventions ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . core . util . Messages ; import org . eclipse . jdt . internal . core . util . Util ; public class CreatePackageFragmentOperation extends JavaModelOperation { protected String [ ] pkgName ; public CreatePackageFragmentOperation ( IPackageFragmentRoot parentElement , String packageName , boolean force ) { super ( null , new IJavaElement [ ] { parentElement } , force ) ; this . pkgName = packageName == null ? null : Util . getTrimmedSimpleNames ( packageName ) ; } protected void executeOperation ( ) throws JavaModelException { try { JavaElementDelta delta = null ; PackageFragmentRoot root = ( PackageFragmentRoot ) getParentElement ( ) ; beginTask ( Messages . operation_createPackageFragmentProgress , this . pkgName . length ) ; IContainer parentFolder = ( IContainer ) root . resource ( ) ; String [ ] sideEffectPackageName = CharOperation . NO_STRINGS ; ArrayList results = new ArrayList ( this . pkgName . length ) ; char [ ] [ ] inclusionPatterns = root . fullInclusionPatternChars ( ) ; char [ ] [ ] exclusionPatterns = root . fullExclusionPatternChars ( ) ; int i ; for ( i = 0 ; i < this . pkgName . length ; i ++ ) { String subFolderName = this . pkgName [ i ] ; sideEffectPackageName = Util . arrayConcat ( sideEffectPackageName , subFolderName ) ; IResource subFolder = parentFolder . findMember ( subFolderName ) ; if ( subFolder == null ) { createFolder ( parentFolder , subFolderName , this . force ) ; parentFolder = parentFolder . getFolder ( new Path ( subFolderName ) ) ; IPackageFragment addedFrag = root . getPackageFragment ( sideEffectPackageName ) ; if ( ! Util . isExcluded ( parentFolder , inclusionPatterns , exclusionPatterns ) ) { if ( delta == null ) { delta = newJavaElementDelta ( ) ; } delta . added ( addedFrag ) ; } results . add ( addedFrag ) ; } else { parentFolder = ( IContainer ) subFolder ; } worked ( 1 ) ; } if ( results . size ( ) > 0 ) { this . resultElements = new IJavaElement [ results . size ( ) ] ; results . toArray ( this . resultElements ) ; if ( delta != null ) { addDelta ( delta ) ; } } } finally { done ( ) ; } } protected ISchedulingRule getSchedulingRule ( ) { if ( this . pkgName . length == 0 ) return null ; IResource parentResource = ( ( JavaElement ) getParentElement ( ) ) . resource ( ) ; IResource resource = ( ( IContainer ) parentResource ) . getFolder ( new Path ( this . pkgName [ 0 ] ) ) ; return resource . getWorkspace ( ) . getRuleFactory ( ) . createRule ( resource ) ; } public IJavaModelStatus verify ( ) { IJavaElement parentElement = getParentElement ( ) ; if ( parentElement == null ) { return new JavaModelStatus ( IJavaModelStatusConstants . NO_ELEMENTS_TO_PROCESS ) ; } String packageName = this . pkgName == null ? null : Util . concatWith ( this . pkgName , '.' ) ; IJavaProject project = parentElement . getJavaProject ( ) ; if ( this . pkgName == null || ( this . pkgName . length > 0 && JavaConventions . validatePackageName ( packageName , project . getOption ( JavaCore . COMPILER_SOURCE , true ) , project . getOption ( JavaCore . COMPILER_COMPLIANCE , true ) ) . getSeverity ( ) == IStatus . ERROR ) ) { return new JavaModelStatus ( IJavaModelStatusConstants . INVALID_NAME , packageName ) ; } IJavaElement root = getParentElement ( ) ; if ( root . isReadOnly ( ) ) { return new JavaModelStatus ( IJavaModelStatusConstants . READ_ONLY , root ) ; } IContainer parentFolder = ( IContainer ) ( ( JavaElement ) root ) . resource ( ) ; int i ; for ( i = 0 ; i < this . pkgName . length ; i ++ ) { IResource subFolder = parentFolder . findMember ( this . pkgName [ i ] ) ; if ( subFolder != null ) { if ( subFolder . getType ( ) != IResource . FOLDER ) { return new JavaModelStatus ( IJavaModelStatusConstants . NAME_COLLISION , Messages . bind ( Messages . status_nameCollision , subFolder . getFullPath ( ) . toString ( ) ) ) ; } parentFolder = ( IContainer ) subFolder ; } } return JavaModelStatus . VERIFIED_OK ; } } </s>