new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / JavaModelManager.java
index 6652089..0ab7de9 100644 (file)
 package net.sourceforge.phpdt.internal.core;
 
 import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.DataInputStream;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -25,16 +28,21 @@ import java.util.WeakHashMap;
 import java.util.zip.ZipFile;
 
 import net.sourceforge.phpdt.core.ElementChangedEvent;
+import net.sourceforge.phpdt.core.IClasspathEntry;
 import net.sourceforge.phpdt.core.ICompilationUnit;
 import net.sourceforge.phpdt.core.IElementChangedListener;
 import net.sourceforge.phpdt.core.IJavaElement;
 import net.sourceforge.phpdt.core.IJavaElementDelta;
+import net.sourceforge.phpdt.core.IJavaModel;
 import net.sourceforge.phpdt.core.IJavaProject;
+import net.sourceforge.phpdt.core.IPackageFragment;
+import net.sourceforge.phpdt.core.IPackageFragmentRoot;
 import net.sourceforge.phpdt.core.IWorkingCopy;
-import net.sourceforge.phpdt.core.JavaCore;
 import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
+import net.sourceforge.phpeclipse.PHPCore;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.builder.PHPBuilder;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -56,6 +64,7 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Preferences;
 import org.eclipse.core.runtime.Status;
 
@@ -81,7 +90,7 @@ public class JavaModelManager implements ISaveParticipant {
        public static HashMap PreviousSessionVariables = new HashMap(5);
        public static HashSet OptionNames = new HashSet(20);
        public final static String CP_VARIABLE_PREFERENCES_PREFIX = PHPeclipsePlugin.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$
-//     public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$
+//     public final static String CP_CONTAINER_PREFERENCES_PREFIX = PHPCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$
        public final static String CP_ENTRY_IGNORE = "##<cp entry ignore>##"; //$NON-NLS-1$
                
        /**
@@ -137,38 +146,38 @@ public class JavaModelManager implements ISaveParticipant {
         * Returns whether the given full path (for a package) conflicts with the output location
         * of the given project.
         */
-//     public static boolean conflictsWithOutputLocation(IPath folderPath, JavaProject project) {
-//             try {
-//                     IPath outputLocation = project.getOutputLocation();
-//                     if (outputLocation == null) {
-//                             // in doubt, there is a conflict
-//                             return true;
-//                     }
-//                     if (outputLocation.isPrefixOf(folderPath)) {
-//                             // only allow nesting in project's output if there is a corresponding source folder
-//                             // or if the project's output is not used (in other words, if all source folders have their custom output)
-//                             IClasspathEntry[] classpath = project.getResolvedClasspath(true);
-//                             boolean isOutputUsed = false;
-//                             for (int i = 0, length = classpath.length; i < length; i++) {
-//                                     IClasspathEntry entry = classpath[i];
-//                                     if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
-//                                             if (entry.getPath().equals(outputLocation)) {
-//                                                     return false;
-//                                             }
-//                                             if (entry.getOutputLocation() == null) {
-//                                                     isOutputUsed = true;
-//                                             }
-//                                     }
-//                             }
-//                             return isOutputUsed;
-//                     }
-//                     return false;
-//             } catch (JavaModelException e) {
-//                     // in doubt, there is a conflict
-//                     return true;
-//             }
-//     }
-//
+       public static boolean conflictsWithOutputLocation(IPath folderPath, JavaProject project) {
+               try {
+                       IPath outputLocation = project.getOutputLocation();
+                       if (outputLocation == null) {
+                               // in doubt, there is a conflict
+                               return true;
+                       }
+                       if (outputLocation.isPrefixOf(folderPath)) {
+                               // only allow nesting in project's output if there is a corresponding source folder
+                               // or if the project's output is not used (in other words, if all source folders have their custom output)
+                               IClasspathEntry[] classpath = project.getResolvedClasspath(true);
+                               boolean isOutputUsed = false;
+                               for (int i = 0, length = classpath.length; i < length; i++) {
+                                       IClasspathEntry entry = classpath[i];
+                                       if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+                                               if (entry.getPath().equals(outputLocation)) {
+                                                       return false;
+                                               }
+                                               if (entry.getOutputLocation() == null) {
+                                                       isOutputUsed = true;
+                                               }
+                                       }
+                               }
+                               return isOutputUsed;
+                       }
+                       return false;
+               } catch (JavaModelException e) {
+                       // in doubt, there is a conflict
+                       return true;
+               }
+       }
+
 //     public static IClasspathContainer containerGet(IJavaProject project, IPath containerPath) {     
 //             Map projectContainers = (Map)Containers.get(project);
 //             if (projectContainers == null){
@@ -239,13 +248,13 @@ public class JavaModelManager implements ISaveParticipant {
                int type = resource.getType();
                switch (type) {
                        case IResource.PROJECT :
-                               return JavaCore.create((IProject) resource);
+                               return PHPCore.create((IProject) resource);
                        case IResource.FILE :
                                return create((IFile) resource, project);
                        case IResource.FOLDER :
                                return create((IFolder) resource, project);
                        case IResource.ROOT :
-                               return JavaCore.create((IWorkspaceRoot) resource);
+                               return PHPCore.create((IWorkspaceRoot) resource);
                        default :
                                return null;
                }
@@ -271,7 +280,7 @@ public class JavaModelManager implements ISaveParticipant {
                        return null;
                }
                if (project == null) {
-                       project = JavaCore.create(file.getProject());
+                       project = PHPCore.create(file.getProject());
                }
        
                if (file.getFileExtension() != null) {
@@ -302,18 +311,16 @@ public class JavaModelManager implements ISaveParticipant {
                        return null;
                }
                if (project == null) {
-                       project = JavaCore.create(folder.getProject());
+                       project = PHPCore.create(folder.getProject());
+               }
+               IJavaElement element = determineIfOnClasspath(folder, project);
+               if (conflictsWithOutputLocation(folder.getFullPath(), (JavaProject)project)
+                       || (folder.getName().indexOf('.') >= 0 
+                               && !(element instanceof IPackageFragmentRoot))) {
+                       return null; // only package fragment roots are allowed with dot names
+               } else {
+                       return element;
                }
-//     TODO khartlage temp-del
-//             IJavaElement element = determineIfOnClasspath(folder, project);
-//             if (conflictsWithOutputLocation(folder.getFullPath(), (JavaProject)project)
-//                     || (folder.getName().indexOf('.') >= 0 
-//                             && !(element instanceof IPackageFragmentRoot))) {
-//                     return null; // only package fragment roots are allowed with dot names
-//             } else {
-//                     return element;
-//             }
-return null;
        }
 
        /**
@@ -326,7 +333,7 @@ return null;
 //                     return null;
 //             }
 //             if (project == null) {
-//                     project = JavaCore.create(file.getProject());
+//                     project = PHPCore.create(file.getProject());
 //             }
 //             IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project);
 //             if (pkg == null) {
@@ -348,24 +355,20 @@ return null;
                if (file == null) return null;
 
                if (project == null) {
-                       project = JavaCore.create(file.getProject());
+                       project = PHPCore.create(file.getProject());
                }
-//     TODO khartlage temp-del
-//             IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project);
-//             if (pkg == null) {
-
+               IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project);
+               if (pkg == null) {
                        // not on classpath - make the root its folder, and a default package
-//                     IPackageFragmentRoot root = project.getPackageFragmentRoot(file.getParent());
-//                     pkg = root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
-//                     
-//                     if (VERBOSE){
-//                             System.out.println("WARNING : creating unit element outside classpath ("+ Thread.currentThread()+"): " + file.getFullPath()); //$NON-NLS-1$//$NON-NLS-2$
-//                     }
-//             }
-//             return pkg.getCompilationUnit(file.getName());
-return null;
+                       IPackageFragmentRoot root = project.getPackageFragmentRoot(file.getParent());
+                       pkg = root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
+                       
+                       if (VERBOSE){
+                               System.out.println("WARNING : creating unit element outside classpath ("+ Thread.currentThread()+"): " + file.getFullPath()); //$NON-NLS-1$//$NON-NLS-2$
+                       }
+               }
+               return pkg.getCompilationUnit(file.getName());
        }
-       
        /**
         * Creates and returns a handle for the given JAR file, its project being the given project.
         * The Java model associated with the JAR's project may be
@@ -378,7 +381,7 @@ return null;
 //                     return null;
 //             }
 //             if (project == null) {
-//                     project = JavaCore.create(file.getProject());
+//                     project = PHPCore.create(file.getProject());
 //             }
 //     
 //             // Create a jar package fragment root only if on the classpath
@@ -402,50 +405,50 @@ return null;
         * the package fragment the given resource is located in, or <code>null</code>
         * if the given resource is not on the classpath of the given project.
         */
-//     public static IJavaElement determineIfOnClasspath(
-//             IResource resource,
-//             IJavaProject project) {
-//                     
-//             IPath resourcePath = resource.getFullPath();
-//             try {
-//                     IClasspathEntry[] entries = 
-//                             Util.isJavaFileName(resourcePath.lastSegment())
-//                                     ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
-//                                     : ((JavaProject)project).getResolvedClasspath(true);
-//                             
-//                     for (int i = 0; i < entries.length; i++) {
-//                             IClasspathEntry entry = entries[i];
-//                             if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
-//                             IPath rootPath = entry.getPath();
-//                             if (rootPath.equals(resourcePath)) {
-//                                     return project.getPackageFragmentRoot(resource);
-//                             } else if (rootPath.isPrefixOf(resourcePath) && !Util.isExcluded(resource, ((ClasspathEntry)entry).fullExclusionPatternChars())) {
-//                                     // given we have a resource child of the root, it cannot be a JAR pkg root
-//                                     IPackageFragmentRoot root = ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
-//                                     if (root == null) return null;
-//                                     IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
-//                                     if (resource.getType() == IResource.FILE) {
-//                                             // if the resource is a file, then remove the last segment which
-//                                             // is the file name in the package
-//                                             pkgPath = pkgPath.removeLastSegments(1);
-//                                             
-//                                             // don't check validity of package name (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=26706)
-//                                             String pkgName = pkgPath.toString().replace('/', '.');
-//                                             return root.getPackageFragment(pkgName);
-//                                     } else {
-//                                             String pkgName = Util.packageName(pkgPath);
-//                                             if (pkgName == null || JavaConventions.validatePackageName(pkgName).getSeverity() == IStatus.ERROR) {
-//                                                     return null;
-//                                             }
-//                                             return root.getPackageFragment(pkgName);
-//                                     }
-//                             }
-//                     }
-//             } catch (JavaModelException npe) {
-//                     return null;
-//             }
-//             return null;
-//     }
+       public static IJavaElement determineIfOnClasspath(
+               IResource resource,
+               IJavaProject project) {
+                       
+               IPath resourcePath = resource.getFullPath();
+               try {
+                       IClasspathEntry[] entries = 
+                               Util.isJavaFileName(resourcePath.lastSegment())
+                                       ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
+                                       : ((JavaProject)project).getResolvedClasspath(true);
+                               
+                       for (int i = 0; i < entries.length; i++) {
+                               IClasspathEntry entry = entries[i];
+                               if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
+                               IPath rootPath = entry.getPath();
+                               if (rootPath.equals(resourcePath)) {
+                                       return project.getPackageFragmentRoot(resource);
+                               } else if (rootPath.isPrefixOf(resourcePath) && !Util.isExcluded(resource, ((ClasspathEntry)entry).fullExclusionPatternChars())) {
+                                       // given we have a resource child of the root, it cannot be a JAR pkg root
+                                       IPackageFragmentRoot root = ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
+                                       if (root == null) return null;
+                                       IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
+                                       if (resource.getType() == IResource.FILE) {
+                                               // if the resource is a file, then remove the last segment which
+                                               // is the file name in the package
+                                               pkgPath = pkgPath.removeLastSegments(1);
+                                               
+                                               // don't check validity of package name (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=26706)
+                                               String pkgName = pkgPath.toString().replace('/', '.');
+                                               return root.getPackageFragment(pkgName);
+                                       } else {
+                                               String pkgName = Util.packageName(pkgPath);
+                                               if (pkgName == null){// || JavaConventions.validatePackageName(pkgName).getSeverity() == IStatus.ERROR) {
+                                                       return null;
+                                               }
+                                               return root.getPackageFragment(pkgName);
+                                       }
+                               }
+                       }
+               } catch (JavaModelException npe) {
+                       return null;
+               }
+               return null;
+       }
        
        /**
         * The singleton manager
@@ -455,7 +458,7 @@ return null;
        /**
         * Infos cache.
         */
-//     protected JavaModelCache cache = new JavaModelCache();
+       protected JavaModelCache cache = new JavaModelCache();
 
        /**
         * Set of elements which are out of sync with their buffers.
@@ -525,8 +528,8 @@ return null;
                public IProject project;
                public Object savedState;
                public boolean triedRead;
-//             public IClasspathEntry[] classpath;
-//             public IClasspathEntry[] lastResolvedClasspath;
+               public IClasspathEntry[] classpath;
+               public IClasspathEntry[] lastResolvedClasspath;
                public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries
                public IPath outputLocation;
                public Preferences preferences;
@@ -578,7 +581,7 @@ return null;
        /**
         * Line separator to use throughout the JavaModel for any source edit operation
         */
-       //      public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+  public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
        /**
         * Constructs a new JavaModelManager
         */
@@ -652,7 +655,7 @@ return null;
         * Configure the plugin with respect to option settings defined in ".options" file
         */
        public void configurePluginDebugOptions(){
-               if(JavaCore.getPlugin().isDebugging()){
+               if(PHPCore.getPlugin().isDebugging()){
 //             TODO khartlage temp-del
                        String option = Platform.getDebugOption(BUILDER_DEBUG);
 //                     if(option != null) JavaBuilder.DEBUG = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
@@ -934,9 +937,9 @@ return null;
        /**
         *  Returns the info for the element.
         */
-//     public Object getInfo(IJavaElement element) {
-//             return this.cache.getInfo(element);
-//     }
+       public Object getInfo(IJavaElement element) {
+               return this.cache.getInfo(element);
+       }
 
        /**
         * Returns the handle to the active Java Model.
@@ -997,7 +1000,7 @@ return null;
                JavaModelManager.PerProjectInfo info = getPerProjectInfo(project, false /* don't create info */);
                if (info == null) {
                        if (!JavaProject.hasJavaNature(project)) {
-                               throw ((JavaProject)JavaCore.create(project)).newNotPresentException();
+                               throw ((JavaProject)PHPCore.create(project)).newNotPresentException();
                        }
                        info = getPerProjectInfo(project, true /* create info */);
                }
@@ -1007,12 +1010,12 @@ return null;
        /**
         * Returns the name of the variables for which an CP variable initializer is registered through an extension point
         */
-//     public static String[] getRegisteredVariableNames(){
-//             
-//             Plugin jdtCorePlugin = JavaCore.getPlugin();
-//             if (jdtCorePlugin == null) return null;
-//
-//             ArrayList variableList = new ArrayList(5);
+       public static String[] getRegisteredVariableNames(){
+               
+               Plugin jdtCorePlugin = PHPCore.getPlugin();
+               if (jdtCorePlugin == null) return null;
+
+               ArrayList variableList = new ArrayList(5);
 //             IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID);
 //             if (extension != null) {
 //                     IExtension[] extensions =  extension.getExtensions();
@@ -1024,17 +1027,17 @@ return null;
 //                             }
 //                     }       
 //             }
-//             String[] variableNames = new String[variableList.size()];
-//             variableList.toArray(variableNames);
-//             return variableNames;
-//     }       
+               String[] variableNames = new String[variableList.size()];
+               variableList.toArray(variableNames);
+               return variableNames;
+       }       
 
        /**
         * Returns the name of the container IDs for which an CP container initializer is registered through an extension point
         */
 //     public static String[] getRegisteredContainerIDs(){
 //             
-//             Plugin jdtCorePlugin = JavaCore.getPlugin();
+//             Plugin jdtCorePlugin = PHPCore.getPlugin();
 //             if (jdtCorePlugin == null) return null;
 //
 //             ArrayList containerIDList = new ArrayList(5);
@@ -1059,7 +1062,7 @@ return null;
         */
        private File getSerializationFile(IProject project) {
                if (!project.exists()) return null;
-               IPluginDescriptor descr= JavaCore.getJavaCore().getDescriptor();
+               IPluginDescriptor descr= PHPCore.getJavaCore().getDescriptor();
                IPath workingLocation= project.getPluginWorkingLocation(descr);
                return workingLocation.append("state.dat").toFile(); //$NON-NLS-1$
        }
@@ -1091,18 +1094,18 @@ return null;
                                } else { // internal resource (not an IFile or not existing)
                                        IPath location;
                                        if (file.getType() != IResource.FILE || (location = file.getLocation()) == null) {
-                                               throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
+                                               throw new CoreException(new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
                                        }
                                        fileSystemPath= location.toOSString();
                                }
                        } else if (!path.isAbsolute()) {
                                file= root.getFile(path);
                                if (file == null || file.getType() != IResource.FILE) {
-                                       throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
+                                       throw new CoreException(new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
                                }
                                IPath location = file.getLocation();
                                if (location == null) {
-                                       throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
+                                       throw new CoreException(new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, -1, Util.bind("file.notFound", path.toString()), null)); //$NON-NLS-1$
                                }
                                fileSystemPath= location.toOSString();
                        } else {
@@ -1119,7 +1122,7 @@ return null;
                                }
                                return zipFile;
                        } catch (IOException e) {
-                               throw new CoreException(new Status(Status.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind("status.IOException"), e)); //$NON-NLS-1$
+                               throw new CoreException(new Status(Status.ERROR, PHPCore.PLUGIN_ID, -1, Util.bind("status.IOException"), e)); //$NON-NLS-1$
                        }
                }
        }
@@ -1127,7 +1130,7 @@ return null;
 //     public void loadVariablesAndContainers() throws CoreException {
 //
 //             // backward compatibility, consider persistent property 
-//             QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID, "variables"); //$NON-NLS-1$
+//             QualifiedName qName = new QualifiedName(PHPCore.PLUGIN_ID, "variables"); //$NON-NLS-1$
 //             String xmlString = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qName);
 //             
 //             try {
@@ -1173,7 +1176,7 @@ return null;
 //             }
 //             
 //             // load variables and containers from preferences into cache
-//             Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
+//             Preferences preferences = PHPCore.getPlugin().getPluginPreferences();
 //
 //             // only get variable from preferences not set to their default
 //             String[] propertyNames = preferences.propertyNames();
@@ -1270,18 +1273,19 @@ return null;
         *  Returns the info for this element without
         *  disturbing the cache ordering.
         */ // TODO: should be synchronized, could answer unitialized info or if cache is in middle of rehash, could even answer distinct element info
-//     protected Object peekAtInfo(IJavaElement element) {
-//             return this.cache.peekAtInfo(element);
-//     }
+       protected Object peekAtInfo(IJavaElement element) {
+               return this.cache.peekAtInfo(element);
+       }
 
        /**
         * @see ISaveParticipant
         */
        public void prepareToSave(ISaveContext context) throws CoreException {
        }
-//     protected void putInfo(IJavaElement element, Object info) {
-//             this.cache.putInfo(element, info);
-//     }
+       
+       protected void putInfo(IJavaElement element, Object info) {
+               this.cache.putInfo(element, info);
+       }
 
        /**
         * Reads the build state for the relevant project.
@@ -1293,14 +1297,14 @@ return null;
                                DataInputStream in= new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
                                try {
                                        String pluginID= in.readUTF();
-                                       if (!pluginID.equals(JavaCore.PLUGIN_ID))
+                                       if (!pluginID.equals(PHPCore.PLUGIN_ID))
                                                throw new IOException(Util.bind("build.wrongFileFormat")); //$NON-NLS-1$
                                        String kind= in.readUTF();
                                        if (!kind.equals("STATE")) //$NON-NLS-1$
                                                throw new IOException(Util.bind("build.wrongFileFormat")); //$NON-NLS-1$
+                                       if (in.readBoolean())
+                                               return PHPBuilder.readState(project, in);
 //                             TODO khartlage temp-del
-//                                     if (in.readBoolean())
-//                                             return JavaBuilder.readState(project, in);
 //                                     if (JavaBuilder.DEBUG)
 //                                             System.out.println("Saved state thinks last build failed for " + project.getName()); //$NON-NLS-1$
                                } finally {
@@ -1308,7 +1312,7 @@ return null;
                                }
                        } catch (Exception e) {
                                e.printStackTrace();
-                               throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Platform.PLUGIN_ERROR, "Error reading last build state for project "+ project.getName(), e)); //$NON-NLS-1$
+                               throw new CoreException(new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, Platform.PLUGIN_ERROR, "Error reading last build state for project "+ project.getName(), e)); //$NON-NLS-1$
                        }
                }
                return null;
@@ -1409,9 +1413,9 @@ return null;
                }
        }
        
-//     protected void removeInfo(IJavaElement element) {
-//             this.cache.removeInfo(element);
-//     }
+       protected void removeInfo(IJavaElement element) {
+               this.cache.removeInfo(element);
+       }
 
        public void removePerProjectInfo(JavaProject javaProject) {
                synchronized(perProjectInfo) { // use the perProjectInfo collection as its own lock
@@ -1435,49 +1439,48 @@ return null;
                if (context.getKind() == ISaveContext.SNAPSHOT) return;
                
                // save built state
-               // TODO khartlage temp-del
-//             if (info.triedRead) saveBuiltState(info);
+               if (info.triedRead) saveBuiltState(info);
        }
        
        /**
         * Saves the built state for the project.
         */
-//     private void saveBuiltState(PerProjectInfo info) throws CoreException {
+       private void saveBuiltState(PerProjectInfo info) throws CoreException {
 //             if (JavaBuilder.DEBUG)
 //                     System.out.println(Util.bind("build.saveStateProgress", info.project.getName())); //$NON-NLS-1$
-//             File file = getSerializationFile(info.project);
-//             if (file == null) return;
-//             long t = System.currentTimeMillis();
-//             try {
-//                     DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
-//                     try {
-//                             out.writeUTF(JavaCore.PLUGIN_ID);
-//                             out.writeUTF("STATE"); //$NON-NLS-1$
-//                             if (info.savedState == null) {
-//                                     out.writeBoolean(false);
-//                             } else {
-//                                     out.writeBoolean(true);
-//                                     JavaBuilder.writeState(info.savedState, out);
-//                             }
-//                     } finally {
-//                             out.close();
-//                     }
-//             } catch (RuntimeException e) {
-//                     try {file.delete();} catch(SecurityException se) {}
-//                     throw new CoreException(
-//                             new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Platform.PLUGIN_ERROR,
-//                                     Util.bind("build.cannotSaveState", info.project.getName()), e)); //$NON-NLS-1$
-//             } catch (IOException e) {
-//                     try {file.delete();} catch(SecurityException se) {}
-//                     throw new CoreException(
-//                             new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Platform.PLUGIN_ERROR,
-//                                     Util.bind("build.cannotSaveState", info.project.getName()), e)); //$NON-NLS-1$
-//             }
+               File file = getSerializationFile(info.project);
+               if (file == null) return;
+               long t = System.currentTimeMillis();
+               try {
+                       DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
+                       try {
+                               out.writeUTF(PHPCore.PLUGIN_ID);
+                               out.writeUTF("STATE"); //$NON-NLS-1$
+                               if (info.savedState == null) {
+                                       out.writeBoolean(false);
+                               } else {
+                                       out.writeBoolean(true);
+                                       PHPBuilder.writeState(info.savedState, out);
+                               }
+                       } finally {
+                               out.close();
+                       }
+               } catch (RuntimeException e) {
+                       try {file.delete();} catch(SecurityException se) {}
+                       throw new CoreException(
+                               new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, Platform.PLUGIN_ERROR,
+                                       Util.bind("build.cannotSaveState", info.project.getName()), e)); //$NON-NLS-1$
+               } catch (IOException e) {
+                       try {file.delete();} catch(SecurityException se) {}
+                       throw new CoreException(
+                               new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, Platform.PLUGIN_ERROR,
+                                       Util.bind("build.cannotSaveState", info.project.getName()), e)); //$NON-NLS-1$
+               }
 //             if (JavaBuilder.DEBUG) {
 //                     t = System.currentTimeMillis() - t;
 //                     System.out.println(Util.bind("build.saveStateComplete", String.valueOf(t))); //$NON-NLS-1$
 //             }
-//     }
+       }
 
        /**
         * @see ISaveParticipant
@@ -1506,7 +1509,7 @@ return null;
                if (vStats != null) {
                        IStatus[] stats= new IStatus[vStats.size()];
                        vStats.toArray(stats);
-                       throw new CoreException(new MultiStatus(JavaCore.PLUGIN_ID, IStatus.ERROR, stats, Util.bind("build.cannotSaveStates"), null)); //$NON-NLS-1$
+                       throw new CoreException(new MultiStatus(PHPCore.PLUGIN_ID, IStatus.ERROR, stats, Util.bind("build.cannotSaveStates"), null)); //$NON-NLS-1$
                }
        }
 
@@ -1518,7 +1521,7 @@ return null;
 
                // optional behaviour
                // possible value of index 0 is Compute
-               if (!JavaCore.COMPUTE.equals(JavaCore.getOption(JavaCore.CORE_JAVA_BUILD_ORDER))) return; // cannot be customized at project level
+               if (!PHPCore.COMPUTE.equals(PHPCore.getOption(PHPCore.CORE_JAVA_BUILD_ORDER))) return; // cannot be customized at project level
                
                if (javaBuildOrder == null || javaBuildOrder.length <= 1) return;
                
@@ -1587,14 +1590,14 @@ return null;
 //             if (this.deltaProcessor.indexManager != null){ // no more indexing
 //                     this.deltaProcessor.indexManager.shutdown();
 //             }
-//             try {
-//                     IJavaModel model = this.getJavaModel();
-//                     if (model != null) {
+               try {
+                       IJavaModel model = this.getJavaModel();
+                       if (model != null) {
 
-//                             model.close();
-//                     }
-//             } catch (JavaModelException e) {
-//             }
+                               model.close();
+                       }
+               } catch (JavaModelException e) {
+               }
        }
 
        /**
@@ -1659,11 +1662,11 @@ return null;
                if (variablePath == JavaModelManager.VariableInitializationInProgress){
                        return;
                } 
-               Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
+               Preferences preferences = PHPCore.getPlugin().getPluginPreferences();
                String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
                String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString();
                preferences.setDefault(variableKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones
                preferences.setValue(variableKey, variableString);
-               JavaCore.getPlugin().savePluginPreferences();
+               PHPCore.getPlugin().savePluginPreferences();
        }
 }