<s> package org . eclipse . jdt . internal . core ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . Map ; import org . codehaus . jdt . groovy . integration . LanguageSupportFactory ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IClassFile ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJarEntryResource ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelStatusConstants ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . util . Util ; class JarPackageFragment extends PackageFragment { protected JarPackageFragment ( PackageFragmentRoot root , String [ ] names ) { super ( root , names ) ; } protected boolean buildStructure ( OpenableElementInfo info , IProgressMonitor pm , Map newElements , IResource underlyingResource ) throws JavaModelException { JarPackageFragmentRoot root = ( JarPackageFragmentRoot ) getParent ( ) ; JarPackageFragmentRootInfo parentInfo = ( JarPackageFragmentRootInfo ) root . getElementInfo ( ) ; ArrayList [ ] entries = ( ArrayList [ ] ) parentInfo . rawPackageInfo . get ( this . names ) ; if ( entries == null ) throw newNotPresentException ( ) ; JarPackageFragmentInfo fragInfo = ( JarPackageFragmentInfo ) info ; fragInfo . setChildren ( computeChildren ( entries [ 0 ] ) ) ; fragInfo . setNonJavaResources ( computeNonJavaResources ( entries [ 1 ] ) ) ; newElements . put ( this , fragInfo ) ; return true ; } private IJavaElement [ ] computeChildren ( ArrayList namesWithoutExtension ) { int size = namesWithoutExtension . size ( ) ; if ( size == 0 ) return NO_ELEMENTS ; IJavaElement [ ] children = new IJavaElement [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { String nameWithoutExtension = ( String ) namesWithoutExtension . get ( i ) ; children [ i ] = new ClassFile ( this , nameWithoutExtension ) ; } return children ; } private Object [ ] computeNonJavaResources ( ArrayList entryNames ) { int length = entryNames . size ( ) ; if ( length == 0 ) return JavaElementInfo . NO_NON_JAVA_RESOURCES ; HashMap jarEntries = new HashMap ( ) ; HashMap childrenMap = new HashMap ( ) ; boolean isInteresting = LanguageSupportFactory . isInterestingProject ( this . getJavaProject ( ) . getProject ( ) ) ; ArrayList topJarEntries = new ArrayList ( ) ; for ( int i = 0 ; i < length ; i ++ ) { String resName = ( String ) entryNames . get ( i ) ; if ( ( ! Util . isJavaLikeFileName ( resName ) || ( isInteresting && LanguageSupportFactory . isInterestingSourceFile ( resName ) ) ) ) { IPath filePath = new Path ( resName ) ; IPath childPath = filePath . removeFirstSegments ( this . names . length ) ; if ( jarEntries . containsKey ( childPath ) ) { continue ; } JarEntryFile file = new JarEntryFile ( filePath . lastSegment ( ) ) ; jarEntries . put ( childPath , file ) ; if ( childPath . segmentCount ( ) == 1 ) { file . setParent ( this ) ; topJarEntries . add ( file ) ; } else { IPath parentPath = childPath . removeLastSegments ( 1 ) ; while ( parentPath . segmentCount ( ) > 0 ) { ArrayList parentChildren = ( ArrayList ) childrenMap . get ( parentPath ) ; if ( parentChildren == null ) { Object dir = new JarEntryDirectory ( parentPath . lastSegment ( ) ) ; jarEntries . put ( parentPath , dir ) ; childrenMap . put ( parentPath , parentChildren = new ArrayList ( ) ) ; parentChildren . add ( childPath ) ; if ( parentPath . segmentCount ( ) == 1 ) { topJarEntries . add ( dir ) ; break ; } childPath = parentPath ; parentPath = childPath . removeLastSegments ( 1 ) ; } else { parentChildren . add ( childPath ) ; break ; } } } } } Iterator entries = childrenMap . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; IPath entryPath = ( IPath ) entry . getKey ( ) ; ArrayList entryValue = ( ArrayList ) entry . getValue ( ) ; JarEntryDirectory jarEntryDirectory = ( JarEntryDirectory ) jarEntries . get ( entryPath ) ; int size = entryValue . size ( ) ; IJarEntryResource [ ] children = new IJarEntryResource [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { JarEntryResource child = ( JarEntryResource ) jarEntries . get ( entryValue . get ( i ) ) ; child . setParent ( jarEntryDirectory ) ; children [ i ] = child ; } jarEntryDirectory . setChildren ( children ) ; if ( entryPath . segmentCount ( ) == 1 ) { jarEntryDirectory . setParent ( this ) ; } } return topJarEntries . toArray ( new Object [ topJarEntries . size ( ) ] ) ; } public boolean containsJavaResources ( ) throws JavaModelException { return ( ( JarPackageFragmentInfo ) getElementInfo ( ) ) . containsJavaResources ( ) ; } public ICompilationUnit createCompilationUnit ( String cuName , String contents , boolean force , IProgressMonitor monitor ) throws JavaModelException { throw new JavaModelException ( new JavaModelStatus ( IJavaModelStatusConstants . READ_ONLY , this ) ) ; } protected Object createElementInfo ( ) { return new JarPackageFragmentInfo ( ) ; } public IClassFile [ ] getClassFiles ( ) throws JavaModelException { ArrayList list = getChildrenOfType ( CLASS_FILE ) ; IClassFile [ ] array = new IClassFile [ list . size ( ) ] ; list . toArray ( array ) ; return array ; } public ICompilationUnit [ ] getCompilationUnits ( ) { return NO_COMPILATION_UNITS ; } public IResource getCorrespondingResource ( ) { return null ; } public Object [ ] getNonJavaResources ( ) throws JavaModelException { if ( isDefaultPackage ( ) ) { return JavaElementInfo . NO_NON_JAVA_RESOURCES ; } else { return storedNonJavaResources ( ) ; } } public boolean isReadOnly ( ) { return true ; } protected Object [ ] storedNonJavaResources ( ) throws JavaModelException { return ( ( JarPackageFragmentInfo ) getElementInfo ( ) ) . getNonJavaResources ( ) ; } } </s>