<s> package org . eclipse . jdt . internal . core ; import java . io . File ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . Map ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . Assert ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . internal . core . util . MementoTokenizer ; import org . eclipse . jdt . internal . core . util . Messages ; public class JavaModel extends Openable implements IJavaModel { public static HashSet existingExternalFiles = new HashSet ( ) ; public static HashSet existingExternalConfirmedFiles = new HashSet ( ) ; protected JavaModel ( ) throws Error { super ( null ) ; } protected boolean buildStructure ( OpenableElementInfo info , IProgressMonitor pm , Map newElements , IResource underlyingResource ) { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; int length = projects . length ; IJavaElement [ ] children = new IJavaElement [ length ] ; int index = 0 ; for ( int i = 0 ; i < length ; i ++ ) { IProject project = projects [ i ] ; if ( JavaProject . hasJavaNature ( project ) ) { children [ index ++ ] = getJavaProject ( project ) ; } } if ( index < length ) System . arraycopy ( children , 0 , children = new IJavaElement [ index ] , 0 , index ) ; info . setChildren ( children ) ; newElements . put ( this , info ) ; return true ; } public boolean contains ( IResource resource ) { switch ( resource . getType ( ) ) { case IResource . ROOT : case IResource . PROJECT : return true ; } IJavaProject [ ] projects ; try { projects = getJavaProjects ( ) ; } catch ( JavaModelException e ) { return false ; } for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { JavaProject project = ( JavaProject ) projects [ i ] ; if ( ! project . contains ( resource ) ) { return false ; } } return true ; } public void copy ( IJavaElement [ ] elements , IJavaElement [ ] containers , IJavaElement [ ] siblings , String [ ] renamings , boolean force , IProgressMonitor monitor ) throws JavaModelException { if ( elements != null && elements . length > 0 && elements [ 0 ] != null && elements [ 0 ] . getElementType ( ) < IJavaElement . TYPE ) { runOperation ( new CopyResourceElementsOperation ( elements , containers , force ) , elements , siblings , renamings , monitor ) ; } else { runOperation ( new CopyElementsOperation ( elements , containers , force ) , elements , siblings , renamings , monitor ) ; } } protected Object createElementInfo ( ) { return new JavaModelInfo ( ) ; } public void delete ( IJavaElement [ ] elements , boolean force , IProgressMonitor monitor ) throws JavaModelException { if ( elements != null && elements . length > 0 && elements [ 0 ] != null && elements [ 0 ] . getElementType ( ) < IJavaElement . TYPE ) { new DeleteResourceElementsOperation ( elements , force ) . runOperation ( monitor ) ; } else { new DeleteElementsOperation ( elements , force ) . runOperation ( monitor ) ; } } public boolean equals ( Object o ) { if ( ! ( o instanceof JavaModel ) ) return false ; return super . equals ( o ) ; } public int getElementType ( ) { return JAVA_MODEL ; } public static void flushExternalFileCache ( ) { existingExternalFiles = new HashSet ( ) ; existingExternalConfirmedFiles = new HashSet ( ) ; } public IJavaElement getHandleFromMemento ( String token , MementoTokenizer memento , WorkingCopyOwner owner ) { switch ( token . charAt ( 0 ) ) { case JEM_JAVAPROJECT : if ( ! memento . hasMoreTokens ( ) ) return this ; String projectName = memento . nextToken ( ) ; JavaElement project = ( JavaElement ) getJavaProject ( projectName ) ; return project . getHandleFromMemento ( memento , owner ) ; } return null ; } protected void getHandleMemento ( StringBuffer buff ) { buff . append ( getElementName ( ) ) ; } protected char getHandleMementoDelimiter ( ) { Assert . isTrue ( false , "" ) ; return 0 ; } public IJavaProject getJavaProject ( String projectName ) { return new JavaProject ( ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( projectName ) , this ) ; } public IJavaProject getJavaProject ( IResource resource ) { switch ( resource . getType ( ) ) { case IResource . FOLDER : return new JavaProject ( ( ( IFolder ) resource ) . getProject ( ) , this ) ; case IResource . FILE : return new JavaProject ( ( ( IFile ) resource ) . getProject ( ) , this ) ; case IResource . PROJECT : return new JavaProject ( ( IProject ) resource , this ) ; default : throw new IllegalArgumentException ( Messages . element_invalidResourceForProject ) ; } } public IJavaProject [ ] getJavaProjects ( ) throws JavaModelException { ArrayList list = getChildrenOfType ( JAVA_PROJECT ) ; IJavaProject [ ] array = new IJavaProject [ list . size ( ) ] ; list . toArray ( array ) ; return array ; } public Object [ ] getNonJavaResources ( ) throws JavaModelException { return ( ( JavaModelInfo ) getElementInfo ( ) ) . getNonJavaResources ( ) ; } public IPath getPath ( ) { return Path . ROOT ; } public IResource resource ( PackageFragmentRoot root ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; } public IResource getUnderlyingResource ( ) { return null ; } public IWorkspace getWorkspace ( ) { return ResourcesPlugin . getWorkspace ( ) ; } public void move ( IJavaElement [ ] elements , IJavaElement [ ] containers , IJavaElement [ ] siblings , String [ ] renamings , boolean force , IProgressMonitor monitor ) throws JavaModelException { if ( elements != null && elements . length > 0 && elements [ 0 ] != null && elements [ 0 ] . getElementType ( ) < IJavaElement . TYPE ) { runOperation ( new MoveResourceElementsOperation ( elements , containers , force ) , elements , siblings , renamings , monitor ) ; } else { runOperation ( new MoveElementsOperation ( elements , containers , force ) , elements , siblings , renamings , monitor ) ; } } public void refreshExternalArchives ( IJavaElement [ ] elementsScope , IProgressMonitor monitor ) throws JavaModelException { if ( elementsScope == null ) { elementsScope = new IJavaElement [ ] { this } ; } JavaModelManager . getJavaModelManager ( ) . getDeltaProcessor ( ) . checkExternalArchiveChanges ( elementsScope , monitor ) ; } public void rename ( IJavaElement [ ] elements , IJavaElement [ ] destinations , String [ ] renamings , boolean force , IProgressMonitor monitor ) throws JavaModelException { MultiOperation op ; if ( elements != null && elements . length > 0 && elements [ 0 ] != null && elements [ 0 ] . getElementType ( ) < IJavaElement . TYPE ) { op = new RenameResourceElementsOperation ( elements , destinations , renamings , force ) ; } else { op = new RenameElementsOperation ( elements , destinations , renamings , force ) ; } op . runOperation ( monitor ) ; } protected void runOperation ( MultiOperation op , IJavaElement [ ] elements , IJavaElement [ ] siblings , String [ ] renamings , IProgressMonitor monitor ) throws JavaModelException { op . setRenamings ( renamings ) ; if ( siblings != null ) { for ( int i = 0 ; i < elements . length ; i ++ ) { op . setInsertBefore ( elements [ i ] , siblings [ i ] ) ; } } op . runOperation ( monitor ) ; } protected void toStringInfo ( int tab , StringBuffer buffer , Object info , boolean showResolvedInfo ) { buffer . append ( tabString ( tab ) ) ; buffer . append ( "Java Model" ) ; if ( info == null ) { buffer . append ( " (not open)" ) ; } } public static Object getTarget ( IPath path , boolean checkResourceExistence ) { Object target = getWorkspaceTarget ( path ) ; if ( target != null ) return target ; return getExternalTarget ( path , checkResourceExistence ) ; } public static IResource getWorkspaceTarget ( IPath path ) { if ( path == null || path . getDevice ( ) != null ) return null ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; if ( workspace == null ) return null ; return workspace . getRoot ( ) . findMember ( path ) ; } public static Object getExternalTarget ( IPath path , boolean checkResourceExistence ) { if ( path == null ) return null ; ExternalFoldersManager externalFoldersManager = JavaModelManager . getExternalManager ( ) ; Object linkedFolder = externalFoldersManager . getFolder ( path ) ; if ( linkedFolder != null ) { if ( checkResourceExistence ) { File externalFile = new File ( path . toOSString ( ) ) ; if ( ! externalFile . isDirectory ( ) ) { return null ; } } return linkedFolder ; } File externalFile = new File ( path . toOSString ( ) ) ; if ( ! checkResourceExistence ) { return externalFile ; } else if ( existingExternalFilesContains ( externalFile ) ) { return externalFile ; } else { if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) { System . out . println ( "(" + Thread . currentThread ( ) + "" + path . toString ( ) ) ; } if ( externalFile . isFile ( ) ) { existingExternalFilesAdd ( externalFile ) ; return externalFile ; } } return null ; } private synchronized static void existingExternalFilesAdd ( File externalFile ) { existingExternalFiles . add ( externalFile ) ; } private synchronized static boolean existingExternalFilesContains ( File externalFile ) { return existingExternalFiles . contains ( externalFile ) ; } public static boolean isFile ( Object target ) { return getFile ( target ) != null ; } public static synchronized File getFile ( Object target ) { if ( existingExternalConfirmedFiles . contains ( target ) ) return ( File ) target ; if ( target instanceof File ) { File f = ( File ) target ; if ( f . isFile ( ) ) { existingExternalConfirmedFiles . add ( f ) ; return f ; } } return null ; } protected IStatus validateExistence ( IResource underlyingResource ) { return JavaModelStatus . VERIFIED_OK ; } } </s>