improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / JavaProject.java
index a634464..e3fdb4d 100644 (file)
@@ -36,6 +36,7 @@ import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 
 import net.sourceforge.phpdt.core.IClasspathEntry;
+import net.sourceforge.phpdt.core.ICompilationUnit;
 import net.sourceforge.phpdt.core.IJavaElement;
 import net.sourceforge.phpdt.core.IJavaModelMarker;
 import net.sourceforge.phpdt.core.IJavaModelStatus;
@@ -43,19 +44,17 @@ import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
 import net.sourceforge.phpdt.core.IJavaProject;
 import net.sourceforge.phpdt.core.IPackageFragment;
 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
+import net.sourceforge.phpdt.core.JavaCore;
 import net.sourceforge.phpdt.core.JavaModelException;
+import net.sourceforge.phpdt.core.WorkingCopyOwner;
 import net.sourceforge.phpdt.internal.codeassist.ISearchableNameEnvironment;
 import net.sourceforge.phpdt.internal.compiler.util.ObjectVector;
+import net.sourceforge.phpdt.internal.core.util.MementoTokenizer;
+import net.sourceforge.phpdt.internal.core.util.Util;
 import net.sourceforge.phpdt.internal.corext.Assert;
 import net.sourceforge.phpeclipse.LoadPathEntry;
-import net.sourceforge.phpeclipse.PHPCore;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
-import org.apache.xerces.dom.DocumentImpl;
-import org.apache.xml.serialize.Method;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.Serializer;
-import org.apache.xml.serialize.SerializerFactory;
 import org.eclipse.core.resources.ICommand;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -73,7 +72,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Preferences;
 import org.eclipse.core.runtime.QualifiedName;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -119,7 +117,7 @@ public class JavaProject
        /**
         * The platform project this <code>IJavaProject</code> is based on
         */
-       protected IProject fProject;
+       protected IProject project;
        protected List fLoadPathEntries;
        protected boolean fScratched;
        
@@ -139,7 +137,11 @@ public class JavaProject
        public static final IClasspathEntry[] INVALID_CLASSPATH = new IClasspathEntry[0];
 
        private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$
-       
+       /*
+        * Value of project's resolved classpath while it is being resolved
+        */
+       private static final IClasspathEntry[] RESOLUTION_IN_PROGRESS = new IClasspathEntry[0];
+
        /**
         * Returns a canonicalized path from the given external path.
         * Note that the return path contains the same number of segments
@@ -221,15 +223,15 @@ public class JavaProject
        /**
         * Constructor needed for <code>IProject.getNature()</code> and <code>IProject.addNature()</code>.
         *
-        * @see #setProject
+        * @see #setProject(IProject)
         */
        public JavaProject() {
-               super(JAVA_PROJECT, null, null);
+               super(null, null);
        }
 
-       public JavaProject(IProject project, IJavaElement parent) {
-               super(JAVA_PROJECT, parent, project.getName());
-               fProject = project;
+       public JavaProject(IProject project, JavaElement parent) {
+               super(parent, project.getName());
+               this.project = project;
        }
        public void addLoadPathEntry(IProject anotherPHPProject) {
                fScratched = true;
@@ -240,7 +242,7 @@ public class JavaProject
 
        public void configure() throws CoreException {
                //      get project description and then the associated build commands 
-               IProjectDescription desc = fProject.getDescription();
+               IProjectDescription desc = project.getDescription();
                ICommand[] commands = desc.getBuildSpec();
 
                // determine if builder already associated
@@ -262,7 +264,7 @@ public class JavaProject
                        System.arraycopy(commands, 0, newCommands, 1, commands.length);
                        newCommands[0] = command;
                        desc.setBuildSpec(newCommands);
-                       fProject.setDescription(desc, null);
+                       project.setDescription(desc, null);
                }
        }
 
@@ -333,7 +335,7 @@ public class JavaProject
        }
 
        protected IFile getLoadPathEntriesFile() {
-               return fProject.getFile(".loadpath");
+               return project.getFile(".loadpath");
        }
 
        protected String getLoadPathXML() {
@@ -366,72 +368,180 @@ public class JavaProject
                        setJavaCommand(description, command);
                }
        }
+       /**
+        * @see Openable
+        */
+       protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
+       
+               // check whether the java project can be opened
+               if (!underlyingResource.isAccessible()) {
+                       throw newNotPresentException();
+               }
+               
+               IWorkspace workspace = ResourcesPlugin.getWorkspace();
+               IWorkspaceRoot wRoot = workspace.getRoot();
+               // cannot refresh cp markers on opening (emulate cp check on startup) since can create deadlocks (see bug 37274)
+//             IClasspathEntry[] resolvedClasspath = getResolvedClasspath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/);
+
+//             // compute the pkg fragment roots
+//             info.setChildren(computePackageFragmentRoots(resolvedClasspath, false));        
+//             
+//             // remember the timestamps of external libraries the first time they are looked up
+//             for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
+//                     IClasspathEntry entry = resolvedClasspath[i];
+//                     if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+//                             IPath path = entry.getPath();
+//                             Object target = JavaModel.getTarget(wRoot, path, true);
+//                             if (target instanceof java.io.File) {
+//                                     Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.externalTimeStamps;
+//                                     if (externalTimeStamps.get(path) == null) {
+//                                             long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
+//                                             externalTimeStamps.put(path, new Long(timestamp));                                                      
+//                                     }
+//                             }
+//                     }
+//             }                       
 
-       protected void closing(Object info) throws JavaModelException {
+               return true;
+       }
+       protected void closing(Object info) {
                
-               // forget source attachment recommendations
-               IPackageFragmentRoot[] roots = this.getPackageFragmentRoots();
-//             for (int i = 0; i < roots.length; i++) {
-//                     if (roots[i] instanceof JarPackageFragmentRoot){
-//                             ((JarPackageFragmentRoot) roots[i]).setSourceAttachmentProperty(null); 
+//             // forget source attachment recommendations
+//             Object[] children = ((JavaElementInfo)info).children;
+//             for (int i = 0, length = children.length; i < length; i++) {
+//                     Object child = children[i];
+//                     if (child instanceof JarPackageFragmentRoot){
+//                             ((JarPackageFragmentRoot)child).setSourceAttachmentProperty(null); 
 //                     }
 //             }
                
                super.closing(info);
        }
+//     protected void closing(Object info) throws JavaModelException {
+//             
+//             // forget source attachment recommendations
+//             IPackageFragmentRoot[] roots = this.getPackageFragmentRoots();
+////           for (int i = 0; i < roots.length; i++) {
+////                   if (roots[i] instanceof JarPackageFragmentRoot){
+////                           ((JarPackageFragmentRoot) roots[i]).setSourceAttachmentProperty(null); 
+////                   }
+////           }
+//             
+//             super.closing(info);
+//     }
        
 
-
        /**
         * Internal computation of an expanded classpath. It will eliminate duplicates, and produce copies
         * of exported classpath entries to avoid possible side-effects ever after.
         */                     
        private void computeExpandedClasspath(
-               JavaProject initialProject, 
+               JavaProject initialProject,  
                boolean ignoreUnresolvedVariable,
                boolean generateMarkerOnError,
-               HashSet visitedProjects, 
-               ObjectVector accumulatedEntries) throws JavaModelException {
+               HashSet rootIDs,
+               ObjectVector accumulatedEntries,
+               Map preferredClasspaths,
+               Map preferredOutputs) throws JavaModelException {
                
-               if (visitedProjects.contains(this)){
+               String projectRootId = this.rootID();
+               if (rootIDs.contains(projectRootId)){
                        return; // break cycles if any
                }
-               visitedProjects.add(this);
+               rootIDs.add(projectRootId);
 
-               if (generateMarkerOnError && !this.equals(initialProject)){
-                       generateMarkerOnError = false;
-               }
+               IClasspathEntry[] preferredClasspath = preferredClasspaths != null ? (IClasspathEntry[])preferredClasspaths.get(this) : null;
+               IPath preferredOutput = preferredOutputs != null ? (IPath)preferredOutputs.get(this) : null;
                IClasspathEntry[] immediateClasspath = 
-                       getResolvedClasspath(ignoreUnresolvedVariable, generateMarkerOnError);
+                       preferredClasspath != null 
+                               ? getResolvedClasspath(preferredClasspath, preferredOutput, ignoreUnresolvedVariable, generateMarkerOnError, null)
+                               : getResolvedClasspath(ignoreUnresolvedVariable, generateMarkerOnError, false/*don't returnResolutionInProgress*/);
                        
                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+               boolean isInitialProject = this.equals(initialProject);
                for (int i = 0, length = immediateClasspath.length; i < length; i++){
-                       IClasspathEntry entry = immediateClasspath[i];
-
-                       boolean isInitialProject = this.equals(initialProject);
+                       ClasspathEntry entry = (ClasspathEntry) immediateClasspath[i];
                        if (isInitialProject || entry.isExported()){
+                               String rootID = entry.rootID();
+                               if (rootIDs.contains(rootID)) {
+                                       continue;
+                               }
                                
                                accumulatedEntries.add(entry);
                                
                                // recurse in project to get all its indirect exports (only consider exported entries from there on)                            
-                               if (entry.getEntryKind() == ClasspathEntry.CPE_PROJECT) {
+                               if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                                        IResource member = workspaceRoot.findMember(entry.getPath()); 
                                        if (member != null && member.getType() == IResource.PROJECT){ // double check if bound to project (23977)
                                                IProject projRsc = (IProject) member;
                                                if (JavaProject.hasJavaNature(projRsc)) {                               
-                                                       JavaProject project = (JavaProject) PHPCore.create(projRsc);
-                                                       project.computeExpandedClasspath(
+                                                       JavaProject javaProject = (JavaProject) JavaCore.create(projRsc);
+                                                       javaProject.computeExpandedClasspath(
                                                                initialProject, 
                                                                ignoreUnresolvedVariable, 
-                                                               generateMarkerOnError,
-                                                               visitedProjects, 
-                                                               accumulatedEntries);
+                                                               false /* no marker when recursing in prereq*/,
+                                                               rootIDs,
+                                                               accumulatedEntries,
+                                                               preferredClasspaths,
+                                                               preferredOutputs);
                                                }
                                        }
+                               } else {
+                                       rootIDs.add(rootID);
                                }
                        }                       
                }
        }
+       /**
+        * Internal computation of an expanded classpath. It will eliminate duplicates, and produce copies
+        * of exported classpath entries to avoid possible side-effects ever after.
+        */                     
+//     private void computeExpandedClasspath(
+//             JavaProject initialProject, 
+//             boolean ignoreUnresolvedVariable,
+//             boolean generateMarkerOnError,
+//             HashSet visitedProjects, 
+//             ObjectVector accumulatedEntries) throws JavaModelException {
+//             
+//             if (visitedProjects.contains(this)){
+//                     return; // break cycles if any
+//             }
+//             visitedProjects.add(this);
+//
+//             if (generateMarkerOnError && !this.equals(initialProject)){
+//                     generateMarkerOnError = false;
+//             }
+//             IClasspathEntry[] immediateClasspath = 
+//                     getResolvedClasspath(ignoreUnresolvedVariable, generateMarkerOnError);
+//                     
+//             IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+//             for (int i = 0, length = immediateClasspath.length; i < length; i++){
+//                     IClasspathEntry entry = immediateClasspath[i];
+//
+//                     boolean isInitialProject = this.equals(initialProject);
+//                     if (isInitialProject || entry.isExported()){
+//                             
+//                             accumulatedEntries.add(entry);
+//                             
+//                             // recurse in project to get all its indirect exports (only consider exported entries from there on)                            
+//                             if (entry.getEntryKind() == ClasspathEntry.CPE_PROJECT) {
+//                                     IResource member = workspaceRoot.findMember(entry.getPath()); 
+//                                     if (member != null && member.getType() == IResource.PROJECT){ // double check if bound to project (23977)
+//                                             IProject projRsc = (IProject) member;
+//                                             if (JavaProject.hasJavaNature(projRsc)) {                               
+//                                                     JavaProject project = (JavaProject) JavaCore.create(projRsc);
+//                                                     project.computeExpandedClasspath(
+//                                                             initialProject, 
+//                                                             ignoreUnresolvedVariable, 
+//                                                             generateMarkerOnError,
+//                                                             visitedProjects, 
+//                                                             accumulatedEntries);
+//                                             }
+//                                     }
+//                             }
+//                     }                       
+//             }
+//     }
        
        /**
         * Returns (local/all) the package fragment roots identified by the given project's classpath.
@@ -534,7 +644,7 @@ public class JavaProject
                                                }
                                        } else {
                                                // external target - only JARs allowed
-//                                             if (((java.io.File)target).isFile() && (Util.isArchiveFileName(entryPath.lastSegment()))) {
+//                                             if (((java.io.File)target).isFile() && (ProjectPrefUtil.isArchiveFileName(entryPath.lastSegment()))) {
 //                                                     accumulatedRoots.add(
 //                                                             new JarPackageFragmentRoot(entryPath, this));
 //                                                     rootIDs.add(rootID);
@@ -560,7 +670,7 @@ public class JavaProject
                                        IProject requiredProjectRsc = (IProject) member;
                                        if (JavaProject.hasJavaNature(requiredProjectRsc)){ // special builder binary output
                                                rootIDs.add(rootID);
-                                               JavaProject requiredProject = (JavaProject)PHPCore.create(requiredProjectRsc);
+                                               JavaProject requiredProject = (JavaProject)JavaCore.create(requiredProjectRsc);
                                                requiredProject.computePackageFragmentRoots(
                                                        requiredProject.getResolvedClasspath(true), 
                                                        accumulatedRoots, 
@@ -655,10 +765,10 @@ public class JavaProject
                        switch (innerMostEntry.getEntryKind()) {
                                case IClasspathEntry.CPE_SOURCE:
                                        // .class files are not visible in source folders 
-                                       return true; //!Util.isClassFileName(fullPath.lastSegment());
+                                       return true; //!net.sourceforge.phpdt.internal.compiler.util.ProjectPrefUtil.isClassFileName(fullPath.lastSegment());
                                case IClasspathEntry.CPE_LIBRARY:
                                        // .java files are not visible in library folders
-                                       return !Util.isJavaFileName(fullPath.lastSegment());
+                                       return !net.sourceforge.phpdt.internal.compiler.util.Util.isJavaFileName(fullPath.lastSegment());
                        }
                }
                if (innerMostOutput != null) {
@@ -680,7 +790,7 @@ public class JavaProject
 
                        case  IJavaModelStatusConstants.CLASSPATH_CYCLE :
                                isCycleProblem = true;
-                               if (PHPCore.ERROR.equals(getOption(PHPCore.CORE_CIRCULAR_CLASSPATH, true))) {
+                               if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) {
                                        severity = IMarker.SEVERITY_ERROR;
                                } else {
                                        severity = IMarker.SEVERITY_WARNING;
@@ -695,7 +805,7 @@ public class JavaProject
                        default:
                                IPath path = status.getPath();
                                if (path != null) arguments = new String[] { path.toString() };
-                               if (PHPCore.ERROR.equals(getOption(PHPCore.CORE_INCOMPLETE_CLASSPATH, true))) {
+                               if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true))) {
                                        severity = IMarker.SEVERITY_ERROR;
                                } else {
                                        severity = IMarker.SEVERITY_WARNING;
@@ -733,11 +843,25 @@ public class JavaProject
        /**
         * Returns a new element info for this element.
         */
-       protected OpenableElementInfo createElementInfo() {
-
+       protected Object createElementInfo() {
                return new JavaProjectElementInfo();
        }
+       
 
+       /*
+        * Returns a new search name environment for this project. This name environment first looks in the given working copies.
+        */
+//     public ISearchableNameEnvironment newSearchableNameEnvironment(ICompilationUnit[] workingCopies) throws JavaModelException {
+//             return new SearchableEnvironment(this, workingCopies);
+//     }
+
+       /*
+        * Returns a new search name environment for this project. This name environment first looks in the working copies
+        * of the given owner.
+        */
+       public ISearchableNameEnvironment newSearchableNameEnvironment(WorkingCopyOwner owner) throws JavaModelException {
+               return new SearchableEnvironment(this, owner);
+       }
        /**
         * Reads and decode an XML classpath string
         */
@@ -836,7 +960,7 @@ public class JavaProject
        protected IClasspathEntry[] defaultClasspath() throws JavaModelException {
 
                return new IClasspathEntry[] {
-                        PHPCore.newSourceEntry(getProject().getFullPath())};
+                        JavaCore.newSourceEntry(getProject().getFullPath())};
        }
 
        /**
@@ -844,51 +968,82 @@ public class JavaProject
         * This is the project bin folder
         */
        protected IPath defaultOutputLocation() throws JavaModelException {
-               return getProject().getFullPath().append("bin"); //$NON-NLS-1$
+               return null; //getProject().getFullPath().append("bin"); //$NON-NLS-1$
        }
 
        /**
         * Returns the XML String encoding of the class path.
         */
-       protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean useLineSeparator) throws JavaModelException {
-
-               Document document = new DocumentImpl();
-               Element cpElement = document.createElement("classpath"); //$NON-NLS-1$
-               document.appendChild(cpElement);
-
-               for (int i = 0; i < classpath.length; ++i) {
-                       cpElement.appendChild(((ClasspathEntry)classpath[i]).elementEncode(document, getProject().getFullPath()));
-               }
-
-               if (outputLocation != null) {
-                       outputLocation = outputLocation.removeFirstSegments(1);
-                       outputLocation = outputLocation.makeRelative();
-                       Element oElement = document.createElement("classpathentry"); //$NON-NLS-1$
-                       oElement.setAttribute("kind", ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));    //$NON-NLS-1$
-                       oElement.setAttribute("path", outputLocation.toString()); //$NON-NLS-1$
-                       cpElement.appendChild(oElement);
-               }
-
-               // produce a String output
+       protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean indent) throws JavaModelException {
                try {
                        ByteArrayOutputStream s = new ByteArrayOutputStream();
-                       OutputFormat format = new OutputFormat();
-                       if (useLineSeparator) {
-                               format.setIndenting(true);
-                               format.setLineSeparator(System.getProperty("line.separator"));  //$NON-NLS-1$
-                       } else {
-                               format.setPreserveSpace(true);
-                       }                       
-                       Serializer serializer =
-                               SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(
-                                       new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
-                                       format);
-                       serializer.asDOMSerializer().serialize(document);
-                       return s.toString("UTF8"); //$NON-NLS-1$
+                       OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
+                       XMLWriter xmlWriter = new XMLWriter(writer);
+                       
+                       xmlWriter.startTag("classpath", indent); //$NON-NLS-1$
+                       for (int i = 0; i < classpath.length; ++i) {
+                               ((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true);
+                       }
+       
+                       if (outputLocation != null) {
+                               outputLocation = outputLocation.removeFirstSegments(1);
+                               outputLocation = outputLocation.makeRelative();
+                               HashMap parameters = new HashMap();
+                               parameters.put("kind", ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));//$NON-NLS-1$
+                               parameters.put("path", String.valueOf(outputLocation));//$NON-NLS-1$
+                               xmlWriter.printTag("classpathentry", parameters, indent, true, true);//$NON-NLS-1$
+                       }
+       
+                       xmlWriter.endTag("classpath", indent);//$NON-NLS-1$
+                       writer.flush();
+                       writer.close();
+                       return s.toString("UTF8");//$NON-NLS-1$
                } catch (IOException e) {
                        throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
                }
        }
+       /**
+        * Returns the XML String encoding of the class path.
+        */
+//     protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean useLineSeparator) throws JavaModelException {
+//
+//             Document document = new DocumentImpl();
+//             Element cpElement = document.createElement("classpath"); //$NON-NLS-1$
+//             document.appendChild(cpElement);
+//
+//             for (int i = 0; i < classpath.length; ++i) {
+//                     cpElement.appendChild(((ClasspathEntry)classpath[i]).elementEncode(document, getProject().getFullPath()));
+//             }
+//
+//             if (outputLocation != null) {
+//                     outputLocation = outputLocation.removeFirstSegments(1);
+//                     outputLocation = outputLocation.makeRelative();
+//                     Element oElement = document.createElement("classpathentry"); //$NON-NLS-1$
+//                     oElement.setAttribute("kind", ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));    //$NON-NLS-1$
+//                     oElement.setAttribute("path", outputLocation.toString()); //$NON-NLS-1$
+//                     cpElement.appendChild(oElement);
+//             }
+//
+//             // produce a String output
+//             try {
+//                     ByteArrayOutputStream s = new ByteArrayOutputStream();
+//                     OutputFormat format = new OutputFormat();
+//                     if (useLineSeparator) {
+//                             format.setIndenting(true);
+//                             format.setLineSeparator(System.getProperty("line.separator"));  //$NON-NLS-1$
+//                     } else {
+//                             format.setPreserveSpace(true);
+//                     }                       
+//                     Serializer serializer =
+//                             SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(
+//                                     new OutputStreamWriter(s, "UTF8"), //$NON-NLS-1$
+//                                     format);
+//                     serializer.asDOMSerializer().serialize(document);
+//                     return s.toString("UTF8"); //$NON-NLS-1$
+//             } catch (IOException e) {
+//                     throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
+//             }
+//     }
        
        /**
         * Returns true if this handle represents the same Java project
@@ -908,11 +1063,11 @@ public class JavaProject
 
                JavaProject other = (JavaProject) o;
                return getProject().equals(other.getProject())
-                       && fOccurrenceCount == other.fOccurrenceCount;
+                       && occurrenceCount == other.occurrenceCount;
        }
 
        public boolean exists() {
-               if (!hasJavaNature(fProject)) return false;
+               if (!hasJavaNature(project)) return false;
                return super.exists();
        }       
 
@@ -1111,50 +1266,50 @@ public class JavaProject
                }
        }
 
-       /**
-        * @see Openable
-        */
-       protected boolean generateInfos(
-               OpenableElementInfo info,
-               IProgressMonitor pm,
-               Map newElements,
-               IResource underlyingResource) throws JavaModelException {
-
-               boolean validInfo = false;
-               try {
-                       if (getProject().isOpen()) {
-                               // put the info now, because computing the roots requires it
-                               JavaModelManager.getJavaModelManager().putInfo(this, info);
-
-                               // compute the pkg fragment roots
-                               updatePackageFragmentRoots();                           
-       
-                               // remember the timestamps of external libraries the first time they are looked up
-                               IClasspathEntry[] resolvedClasspath = getResolvedClasspath(true/*ignore unresolved variable*/);
-                               for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
-                                       IClasspathEntry entry = resolvedClasspath[i];
-                                       if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
-                                               IPath path = entry.getPath();
-                                               Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
-                                               if (target instanceof java.io.File) {
-                                                       Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaProcessor.externalTimeStamps;
-                                                       if (externalTimeStamps.get(path) == null) {
-                                                               long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
-                                                               externalTimeStamps.put(path, new Long(timestamp));                                                      
-                                                       }
-                                               }
-                                       }
-                               }                       
-
-                               // only valid if reaches here                           
-                               validInfo = true;
-                       }
-               } finally {
-                       if (!validInfo)
-                               JavaModelManager.getJavaModelManager().removeInfo(this);
-               }
-               return validInfo;
-       }
+//     /**
+//      * @see Openable
+//      */
+//     protected boolean generateInfos(
+//             OpenableElementInfo info,
+//             IProgressMonitor pm,
+//             Map newElements,
+//             IResource underlyingResource) throws JavaModelException {
+//
+//             boolean validInfo = false;
+//             try {
+//                     if (getProject().isOpen()) {
+//                             // put the info now, because computing the roots requires it
+//                             JavaModelManager.getJavaModelManager().putInfo(this, info);
+//
+//                             // compute the pkg fragment roots
+//                             updatePackageFragmentRoots();                           
+//     
+//                             // remember the timestamps of external libraries the first time they are looked up
+//                             IClasspathEntry[] resolvedClasspath = getResolvedClasspath(true/*ignore unresolved variable*/);
+//                             for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
+//                                     IClasspathEntry entry = resolvedClasspath[i];
+//                                     if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+//                                             IPath path = entry.getPath();
+//                                             Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
+//                                             if (target instanceof java.io.File) {
+//                                                     Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaProcessor.externalTimeStamps;
+//                                                     if (externalTimeStamps.get(path) == null) {
+//                                                             long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
+//                                                             externalTimeStamps.put(path, new Long(timestamp));                                                      
+//                                                     }
+//                                             }
+//                                     }
+//                             }                       
+//
+//                             // only valid if reaches here                           
+//                             validInfo = true;
+//                     }
+//             } finally {
+//                     if (!validInfo)
+//                             JavaModelManager.getJavaModelManager().removeInfo(this);
+//             }
+//             return validInfo;
+//     }
 
        /**
         * @see IJavaProject
@@ -1201,43 +1356,105 @@ public class JavaProject
                }
                return null;
        }
-
+       /**
+        * @see IJavaElement
+        */
+       public int getElementType() {
+               return JAVA_PROJECT;
+       }
        /**
         * This is a helper method returning the expanded classpath for the project, as a list of classpath entries, 
         * where all classpath variable entries have been resolved and substituted with their final target entries.
         * All project exports have been appended to project entries.
+        * @param ignoreUnresolvedVariable boolean
+        * @return IClasspathEntry[]
+        * @throws JavaModelException
         */
        public IClasspathEntry[] getExpandedClasspath(boolean ignoreUnresolvedVariable) throws JavaModelException {
                        
-                       return getExpandedClasspath(ignoreUnresolvedVariable, false);
+                       return getExpandedClasspath(ignoreUnresolvedVariable, false/*don't create markers*/, null, null);
        }
                
+       /*
+        * @see JavaElement
+        */
+       public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
+               switch (token.charAt(0)) {
+                       case JEM_COUNT:
+                               return getHandleUpdatingCountFromMemento(memento, owner);
+                       case JEM_PACKAGEFRAGMENTROOT:
+                               String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
+                               token = null;
+                               while (memento.hasMoreTokens()) {
+                                       token = memento.nextToken();
+                                       char firstChar = token.charAt(0);
+                                       if (firstChar != JEM_PACKAGEFRAGMENT && firstChar != JEM_COUNT) {
+                                               rootPath += token;
+                                       } else {
+                                               break;
+                                       }
+                               }
+                               JavaElement root = (JavaElement)getPackageFragmentRoot(new Path(rootPath));
+                               if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT) {
+                                       return root.getHandleFromMemento(token, memento, owner);
+                               } else {
+                                       return root.getHandleFromMemento(memento, owner);
+                               }
+               }
+               return null;
+       }
+
+       /**
+        * Returns the <code>char</code> that marks the start of this handles
+        * contribution to a memento.
+        */
+       protected char getHandleMementoDelimiter() {
+
+               return JEM_JAVAPROJECT;
+       }
+       
        /**
         * Internal variant which can create marker on project for invalid entries,
         * it will also perform classpath expansion in presence of project prerequisites
         * exporting their entries.
+        * @param ignoreUnresolvedVariable boolean
+        * @param generateMarkerOnError boolean
+        * @param preferredClasspaths Map
+        * @param preferredOutputs Map
+        * @return IClasspathEntry[]
+        * @throws JavaModelException
         */
        public IClasspathEntry[] getExpandedClasspath(
                boolean ignoreUnresolvedVariable,
-               boolean generateMarkerOnError) throws JavaModelException {
+               boolean generateMarkerOnError,
+               Map preferredClasspaths,
+               Map preferredOutputs) throws JavaModelException {
        
                ObjectVector accumulatedEntries = new ObjectVector();           
-               computeExpandedClasspath(this, ignoreUnresolvedVariable, generateMarkerOnError, new HashSet(5), accumulatedEntries);
+               computeExpandedClasspath(this, ignoreUnresolvedVariable, generateMarkerOnError, new HashSet(5), accumulatedEntries, preferredClasspaths, preferredOutputs);
                
                IClasspathEntry[] expandedPath = new IClasspathEntry[accumulatedEntries.size()];
                accumulatedEntries.copyInto(expandedPath);
 
                return expandedPath;
        }
-
-       /**
-        * Returns the <code>char</code> that marks the start of this handles
-        * contribution to a memento.
-        */
-       protected char getHandleMementoDelimiter() {
-
-               return JEM_JAVAPROJECT;
-       }
+//     /**
+//      * Internal variant which can create marker on project for invalid entries,
+//      * it will also perform classpath expansion in presence of project prerequisites
+//      * exporting their entries.
+//      */
+//     public IClasspathEntry[] getExpandedClasspath(
+//             boolean ignoreUnresolvedVariable,
+//             boolean generateMarkerOnError) throws JavaModelException {
+//     
+//             ObjectVector accumulatedEntries = new ObjectVector();           
+//             computeExpandedClasspath(this, ignoreUnresolvedVariable, generateMarkerOnError, new HashSet(5), accumulatedEntries);
+//             
+//             IClasspathEntry[] expandedPath = new IClasspathEntry[accumulatedEntries.size()];
+//             accumulatedEntries.copyInto(expandedPath);
+//
+//             return expandedPath;
+//     }
 
        /**
         * Find the specific Java command amongst the build spec of a given description
@@ -1278,6 +1495,28 @@ public class JavaProject
                        return nameLookup;
                }
        }
+       /*
+        * Returns a new name lookup. This name lookup first looks in the given working copies.
+        */
+       public NameLookup newNameLookup(ICompilationUnit[] workingCopies) throws JavaModelException {
+
+               JavaProjectElementInfo info = getJavaProjectElementInfo();
+               // lock on the project info to avoid race condition while computing the pkg fragment roots and package fragment caches
+//             synchronized(info){
+//                     return new NameLookup(info.getAllPackageFragmentRoots(this), info.getAllPackageFragments(this), workingCopies);
+//             }
+               return null;
+       }
+
+       /*
+        * Returns a new name lookup. This name lookup first looks in the working copies of the given owner.
+        */
+       public NameLookup newNameLookup(WorkingCopyOwner owner) throws JavaModelException {
+               
+               JavaModelManager manager = JavaModelManager.getJavaModelManager();
+               ICompilationUnit[] workingCopies = owner == null ? null : manager.getWorkingCopies(owner, true/*add primary WCs*/);
+               return newNameLookup(workingCopies);
+       }
 //
 //     /**
 //      * Returns an array of non-java resources contained in the receiver.
@@ -1288,7 +1527,7 @@ public class JavaProject
 //     }
 
        /**
-        * @see org.eclipse.jdt.core.IJavaProject#getOption(String, boolean)
+        * @see net.sourceforge.phpdt.core.IJavaProject#getOption(String, boolean)
         */     
        public String getOption(String optionName, boolean inheritJavaCoreOptions) {
                
@@ -1296,7 +1535,7 @@ public class JavaProject
                        
                        Preferences preferences = getPreferences();
                        if (preferences == null || preferences.isDefault(optionName)) {
-                               return inheritJavaCoreOptions ? PHPCore.getOption(optionName) : null;
+                               return inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
                        }
                        return preferences.getString(optionName).trim();
                }
@@ -1304,12 +1543,12 @@ public class JavaProject
        }
        
        /**
-        * @see org.eclipse.jdt.core.IJavaProject#getOptions(boolean)
+        * @see net.sourceforge.phpdt.core.IJavaProject#getOptions(boolean)
         */
        public Map getOptions(boolean inheritJavaCoreOptions) {
                
                // initialize to the defaults from JavaCore options pool
-               Map options = inheritJavaCoreOptions ? PHPCore.getOptions() : new Hashtable(5);
+               Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5);
 
                Preferences preferences = getPreferences();
                if (preferences == null) return options; // cannot do better (non-Java project)
@@ -1339,21 +1578,48 @@ public class JavaProject
        /**
         * @see IJavaProject
         */
+//     public IPath getOutputLocation() throws JavaModelException {
+//
+//             JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project);
+//             IPath outputLocation = perProjectInfo.outputLocation;
+//             if (outputLocation != null) return outputLocation;
+//
+//             // force to read classpath - will position output location as well
+//             this.getRawClasspath();
+//             outputLocation = perProjectInfo.outputLocation;
+//             if (outputLocation == null) {
+//                     return defaultOutputLocation();
+//             }
+//             return outputLocation;
+//     }
+       /**
+        * @see IJavaProject
+        */
        public IPath getOutputLocation() throws JavaModelException {
+               // Do not create marker but log problems while getting output location
+               return this.getOutputLocation(false, true);
+       }
+       
+       /**
+        * @param createMarkers boolean
+        * @param logProblems boolean
+        * @return IPath
+        * @throws JavaModelException
+        */
+       public IPath getOutputLocation(boolean createMarkers, boolean logProblems) throws JavaModelException {
 
-               JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject);
+               JavaModelManager.PerProjectInfo perProjectInfo = getPerProjectInfo();
                IPath outputLocation = perProjectInfo.outputLocation;
                if (outputLocation != null) return outputLocation;
 
                // force to read classpath - will position output location as well
-               this.getRawClasspath();
+               this.getRawClasspath(createMarkers, logProblems);
                outputLocation = perProjectInfo.outputLocation;
                if (outputLocation == null) {
                        return defaultOutputLocation();
                }
                return outputLocation;
        }
-
        /**
         * @return A handle to the package fragment root identified by the given path.
         * This method is handle-only and the element may or may not exist. Returns
@@ -1375,7 +1641,7 @@ public class JavaProject
                        default:
                                // a path ending with .jar/.zip is still ambiguous and could still resolve to a source/lib folder 
                                // thus will try to guess based on existing resource
-//                             if (Util.isArchiveFileName(path.lastSegment())) {
+//                             if (ProjectPrefUtil.isArchiveFileName(path.lastSegment())) {
 //                                     IResource resource = getProject().getWorkspace().getRoot().findMember(path); 
 //                                     if (resource != null && resource.getType() == IResource.FOLDER){
 //                                             return getPackageFragmentRoot(resource);
@@ -1404,7 +1670,7 @@ public class JavaProject
 
                switch (resource.getType()) {
                        case IResource.FILE:
-//                             if (Util.isArchiveFileName(resource.getName())) {
+//                             if (ProjectPrefUtil.isArchiveFileName(resource.getName())) {
 //                                     return new JarPackageFragmentRoot(resource, this);
 //                             } else {
                                        return null;
@@ -1521,14 +1787,30 @@ public class JavaProject
                return this.getProject().getFullPath();
        }
        
+       public JavaModelManager.PerProjectInfo getPerProjectInfo() throws JavaModelException {
+               return JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.project);
+       }
+       
        /**
         * @see IJavaProject
         */
        public IProject getProject() {
 
-               return fProject;
+               return project;
+       }
+       /**
+        * Sets the underlying kernel project of this Java project,
+        * and fills in its parent and name.
+        * Called by IProject.getNature().
+        *
+        * @see IProjectNature#setProject(IProject)
+        */
+       public void setProject(IProject project) {
+
+               this.project = project;
+               this.parent = JavaModelManager.getJavaModelManager().getJavaModel();
+               this.name = project.getName();
        }
-       
        protected IProject getProject(String name) {
                return PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
        }
@@ -1565,13 +1847,61 @@ public class JavaProject
        /**
         * @see IJavaProject
         */
+//     public IClasspathEntry[] getRawClasspath() throws JavaModelException {
+//
+//             JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project);
+//             IClasspathEntry[] classpath = perProjectInfo.classpath;
+//             if (classpath != null) return classpath;
+//             classpath = this.readClasspathFile(false/*don't create markers*/, true/*log problems*/);
+//             
+//             // extract out the output location
+//             IPath outputLocation = null;
+//             if (classpath != null && classpath.length > 0) {
+//                     IClasspathEntry entry = classpath[classpath.length - 1];
+//                     if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
+//                             outputLocation = entry.getPath();
+//                             IClasspathEntry[] copy = new IClasspathEntry[classpath.length - 1];
+//                             System.arraycopy(classpath, 0, copy, 0, copy.length);
+//                             classpath = copy;
+//                     }
+//             }
+//             if (classpath == null) {
+//                     return defaultClasspath();
+//             }
+//             /* Disable validate: classpath can contain CP variables and container that need to be resolved 
+//             if (classpath != INVALID_CLASSPATH
+//                             && !JavaConventions.validateClasspath(this, classpath, outputLocation).isOK()) {
+//                     classpath = INVALID_CLASSPATH;
+//             }
+//             */
+//             perProjectInfo.classpath = classpath;
+//             perProjectInfo.outputLocation = outputLocation;
+//             return classpath;
+//     }
+       /**
+        * @see IJavaProject
+        */
        public IClasspathEntry[] getRawClasspath() throws JavaModelException {
+               // Do not create marker but log problems while getting raw classpath
+               return getRawClasspath(false, true);
+       }
 
-               JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject);
-               IClasspathEntry[] classpath = perProjectInfo.classpath;
-               if (classpath != null) return classpath;
-               classpath = this.readClasspathFile(false/*don't create markers*/, true/*log problems*/);
-               
+       /*
+        * Internal variant allowing to parameterize problem creation/logging
+        */
+       public IClasspathEntry[] getRawClasspath(boolean createMarkers, boolean logProblems) throws JavaModelException {
+
+               JavaModelManager.PerProjectInfo perProjectInfo = null;
+               IClasspathEntry[] classpath;
+               if (createMarkers) {
+                       this.flushClasspathProblemMarkers(false/*cycle*/, true/*format*/);
+                       classpath = this.readClasspathFile(createMarkers, logProblems);
+               } else {
+                       perProjectInfo = getPerProjectInfo();
+                       classpath = perProjectInfo.rawClasspath;
+                       if (classpath != null) return classpath;
+                       classpath = this.readClasspathFile(createMarkers, logProblems);
+               }
                // extract out the output location
                IPath outputLocation = null;
                if (classpath != null && classpath.length > 0) {
@@ -1592,11 +1922,13 @@ public class JavaProject
                        classpath = INVALID_CLASSPATH;
                }
                */
-               perProjectInfo.classpath = classpath;
-               perProjectInfo.outputLocation = outputLocation;
+               if (!createMarkers) {
+                       perProjectInfo.rawClasspath = classpath;
+                       perProjectInfo.outputLocation = outputLocation;
+               }
                return classpath;
        }
-
+       
        /**
         * @see IJavaProject#getRequiredProjectNames
         */
@@ -1625,39 +1957,108 @@ public class JavaProject
                boolean ignoreUnresolvedEntry,
                boolean generateMarkerOnError)
                throws JavaModelException {
+         return 
+               getResolvedClasspath(
+                       ignoreUnresolvedEntry, 
+                       generateMarkerOnError,
+                       true // returnResolutionInProgress
+               );
+//             JavaModelManager manager = JavaModelManager.getJavaModelManager();
+//             JavaModelManager.PerProjectInfo perProjectInfo = manager.getPerProjectInfoCheckExistence(project);
+//             
+//             // reuse cache if not needing to refresh markers or checking bound variables
+//             if (ignoreUnresolvedEntry && !generateMarkerOnError && perProjectInfo != null){
+//                     // resolved path is cached on its info
+//                     IClasspathEntry[] infoPath = perProjectInfo.lastResolvedClasspath;
+//                     if (infoPath != null) return infoPath;
+//             }
+//             Map reverseMap = perProjectInfo == null ? null : new HashMap(5);
+//             IClasspathEntry[] resolvedPath = getResolvedClasspath(
+//                     getRawClasspath(), 
+//                     generateMarkerOnError ? getOutputLocation() : null, 
+//                     ignoreUnresolvedEntry, 
+//                     generateMarkerOnError,
+//                     reverseMap);
+//
+//             if (perProjectInfo != null){
+//                     if (perProjectInfo.classpath == null // .classpath file could not be read
+//                             && generateMarkerOnError 
+//                             && JavaProject.hasJavaNature(project)) {
+//                                     this.createClasspathProblemMarker(new JavaModelStatus(
+//                                             IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
+//                                             Util.bind("classpath.cannotReadClasspathFile", this.getElementName()))); //$NON-NLS-1$
+//                             }
+//
+//                     perProjectInfo.lastResolvedClasspath = resolvedPath;
+//                     perProjectInfo.resolvedPathToRawEntries = reverseMap;
+//             }
+//             return resolvedPath;
+       }
+       /*
+        * Internal variant which can create marker on project for invalid entries
+        * and caches the resolved classpath on perProjectInfo.
+        * If requested, return a special classpath (RESOLUTION_IN_PROGRESS) if the classpath is being resolved.
+        */
+       public IClasspathEntry[] getResolvedClasspath(
+               boolean ignoreUnresolvedEntry,
+               boolean generateMarkerOnError,
+               boolean returnResolutionInProgress)
+               throws JavaModelException {
 
-               JavaModelManager manager = JavaModelManager.getJavaModelManager();
-               JavaModelManager.PerProjectInfo perProjectInfo = manager.getPerProjectInfoCheckExistence(fProject);
-               
-               // reuse cache if not needing to refresh markers or checking bound variables
-               if (ignoreUnresolvedEntry && !generateMarkerOnError && perProjectInfo != null){
-                       // resolved path is cached on its info
-                       IClasspathEntry[] infoPath = perProjectInfo.lastResolvedClasspath;
-                       if (infoPath != null) return infoPath;
+           JavaModelManager manager = JavaModelManager.getJavaModelManager();
+               JavaModelManager.PerProjectInfo perProjectInfo = null;
+               if (ignoreUnresolvedEntry && !generateMarkerOnError) {
+                       perProjectInfo = getPerProjectInfo();
+                       if (perProjectInfo != null) {
+                               // resolved path is cached on its info
+                               IClasspathEntry[] infoPath = perProjectInfo.resolvedClasspath;
+                               if (infoPath != null) {
+                                       return infoPath;
+                               } else if  (returnResolutionInProgress && manager.isClasspathBeingResolved(this)) {
+                                       if (JavaModelManager.CP_RESOLVE_VERBOSE) {
+                                               Util.verbose(
+                                                       "CPResolution: reentering raw classpath resolution, will use empty classpath instead" + //$NON-NLS-1$
+                                                       "       project: " + getElementName() + '\n' + //$NON-NLS-1$
+                                                       "       invocation stack trace:"); //$NON-NLS-1$
+                                               new Exception("<Fake exception>").printStackTrace(System.out); //$NON-NLS-1$
+                                       }                                               
+                                   return RESOLUTION_IN_PROGRESS;
+                               }
+                       }
                }
                Map reverseMap = perProjectInfo == null ? null : new HashMap(5);
-               IClasspathEntry[] resolvedPath = getResolvedClasspath(
-                       getRawClasspath(), 
-                       generateMarkerOnError ? getOutputLocation() : null, 
-                       ignoreUnresolvedEntry, 
-                       generateMarkerOnError,
-                       reverseMap);
+               IClasspathEntry[] resolvedPath = null;
+               boolean nullOldResolvedCP = perProjectInfo != null && perProjectInfo.resolvedClasspath == null;
+               try {
+                       // protect against misbehaving clients (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=61040)
+                       if (nullOldResolvedCP) manager.setClasspathBeingResolved(this, true);
+                       resolvedPath = getResolvedClasspath(
+                               getRawClasspath(generateMarkerOnError, !generateMarkerOnError), 
+                               generateMarkerOnError ? getOutputLocation() : null, 
+                               ignoreUnresolvedEntry, 
+                               generateMarkerOnError,
+                               reverseMap);
+               } finally {
+                       if (nullOldResolvedCP) perProjectInfo.resolvedClasspath = null;
+               }
 
                if (perProjectInfo != null){
-                       if (perProjectInfo.classpath == null // .classpath file could not be read
+                       if (perProjectInfo.rawClasspath == null // .classpath file could not be read
                                && generateMarkerOnError 
-                               && JavaProject.hasJavaNature(fProject)) {
+                               && JavaProject.hasJavaNature(this.project)) {
+                                       // flush .classpath format markers (bug 39877), but only when file cannot be read (bug 42366)
+                                       this.flushClasspathProblemMarkers(false, true);
                                        this.createClasspathProblemMarker(new JavaModelStatus(
                                                IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
                                                Util.bind("classpath.cannotReadClasspathFile", this.getElementName()))); //$NON-NLS-1$
-                               }
+                       }
 
-                       perProjectInfo.lastResolvedClasspath = resolvedPath;
+                       perProjectInfo.resolvedClasspath = resolvedPath;
                        perProjectInfo.resolvedPathToRawEntries = reverseMap;
+                       manager.setClasspathBeingResolved(this, false);
                }
                return resolvedPath;
        }
-       
        /**
         * Internal variant which can process any arbitrary classpath
         */
@@ -1693,7 +2094,7 @@ public class JavaProject
                                
                                case IClasspathEntry.CPE_VARIABLE :
                                
-                                       IClasspathEntry resolvedEntry = PHPCore.getResolvedClasspathEntry(rawEntry);
+                                       IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(rawEntry);
                                        if (resolvedEntry == null) {
                                                if (!ignoreUnresolvedEntry) throw new JavaModelException(status);
                                        } else {
@@ -1765,11 +2166,12 @@ public class JavaProject
        public ISearchableNameEnvironment getSearchableNameEnvironment()
                throws JavaModelException {
 
-               JavaProjectElementInfo info = getJavaProjectElementInfo();
-               if (info.getSearchableEnvironment() == null) {
-                       info.setSearchableEnvironment(new SearchableEnvironment(this));
-               }
-               return info.getSearchableEnvironment();
+//             JavaProjectElementInfo info = getJavaProjectElementInfo();
+//             if (info.getSearchableEnvironment() == null) {
+//                     info.setSearchableEnvironment(new SearchableEnvironment(this));
+//             }
+//             return info.getSearchableEnvironment();
+         return null;
        }
 
        /**
@@ -1828,7 +2230,7 @@ public class JavaProject
        }
 
        public int hashCode() {
-               return fProject.hashCode();
+               return project.hashCode();
        }
 
        /**
@@ -1926,7 +2328,7 @@ public class JavaProject
                for (int i = 0; i < classpath.length; i++) {
                        IClasspathEntry entry = classpath[i];
                        if (entry.getPath().isPrefixOf(path) 
-                                       && !Util.isExcluded(path, ((ClasspathEntry)entry).fullExclusionPatternChars())) {
+                                       && !Util.isExcluded(path, null,((ClasspathEntry)entry).fullExclusionPatternChars(),true)) {
                                return true;
                        }
                }
@@ -1946,7 +2348,9 @@ public class JavaProject
                return this.isOnClasspath(path);
        }
 
-
+       private IPath getPluginWorkingLocation() {
+               return this.project.getWorkingLocation(JavaCore.PLUGIN_ID);
+       }       
        /*
         * load preferences from a shareable format (VCM-wise)
         */
@@ -1955,7 +2359,7 @@ public class JavaProject
                Preferences preferences = new Preferences();
                
 //             File prefFile = getProject().getLocation().append(PREF_FILENAME).toFile();
-               IPath projectMetaLocation = getProject().getPluginWorkingLocation(PHPCore.getPlugin().getDescriptor());
+               IPath projectMetaLocation = getPluginWorkingLocation();
                if (projectMetaLocation != null) {
                        File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
                        if (prefFile.exists()) { // load preferences from file
@@ -1995,7 +2399,7 @@ public class JavaProject
 //             throws JavaModelException {
 //
 //             if (region == null) {
-//                     throw new IllegalArgumentException(Util.bind("hierarchy.nullRegion"));//$NON-NLS-1$
+//                     throw new IllegalArgumentException(ProjectPrefUtil.bind("hierarchy.nullRegion"));//$NON-NLS-1$
 //             }
 //             CreateTypeHierarchyOperation op =
 //                     new CreateTypeHierarchyOperation(null, region, this, true);
@@ -2013,10 +2417,10 @@ public class JavaProject
 //             throws JavaModelException {
 //
 //             if (type == null) {
-//                     throw new IllegalArgumentException(Util.bind("hierarchy.nullFocusType"));//$NON-NLS-1$
+//                     throw new IllegalArgumentException(ProjectPrefUtil.bind("hierarchy.nullFocusType"));//$NON-NLS-1$
 //             }
 //             if (region == null) {
-//                     throw new IllegalArgumentException(Util.bind("hierarchy.nullRegion"));//$NON-NLS-1$
+//                     throw new IllegalArgumentException(ProjectPrefUtil.bind("hierarchy.nullRegion"));//$NON-NLS-1$
 //             }
 //             CreateTypeHierarchyOperation op =
 //                     new CreateTypeHierarchyOperation(type, region, this, true);
@@ -2024,17 +2428,17 @@ public class JavaProject
 //             return op.getResult();
 //     }
 
-       /**
-        * Open project if resource isn't closed
-        */
-       protected void openWhenClosed(IProgressMonitor pm) throws JavaModelException {
-
-               if (!this.fProject.isOpen()) {
-                       throw newNotPresentException();
-               } else {
-                       super.openWhenClosed(pm);
-               }
-       }
+//     /**
+//      * Open project if resource isn't closed
+//      */
+//     protected void openWhenClosed(IProgressMonitor pm) throws JavaModelException {
+//
+//             if (!this.fProject.isOpen()) {
+//                     throw newNotPresentException();
+//             } else {
+//                     super.openWhenClosed(pm);
+//             }
+//     }
 
        public String[] projectPrerequisites(IClasspathEntry[] entries)
                throws JavaModelException {
@@ -2147,13 +2551,13 @@ public class JavaProject
                }
        }
 
+
        /**
         * Save project custom preferences to shareable file (.jprefs)
         */
        private void savePreferences(Preferences preferences) {
                
-               IProject project = getProject();
-               if (!JavaProject.hasJavaNature(project)) return; // ignore
+               if (!JavaProject.hasJavaNature(this.project)) return; // ignore
                
                if (preferences == null || (!preferences.needsSaving() && preferences.propertyNames().length != 0)) {
                        // nothing to save
@@ -2163,8 +2567,8 @@ public class JavaProject
                // preferences need to be saved
                // the preferences file is located in the plug-in's state area
                // at a well-known name (.jprefs)
-//             File prefFile = getProject().getLocation().append(PREF_FILENAME).toFile();
-               File prefFile = project.getPluginWorkingLocation(PHPCore.getPlugin().getDescriptor()).append(PREF_FILENAME).toFile();
+//             File prefFile = this.project.getLocation().append(PREF_FILENAME).toFile();
+               File prefFile = getPluginWorkingLocation().append(PREF_FILENAME).toFile();
                if (preferences.propertyNames().length == 0) {
                        // there are no preference settings
                        // rather than write an empty file, just delete any existing file
@@ -2191,7 +2595,6 @@ public class JavaProject
                        }
                }
        }
-
        /**
         * Update the Java command in the build spec (replace existing one if present,
         * add one first if none).
@@ -2226,7 +2629,7 @@ public class JavaProject
        }
 
        /**
-        * @see org.eclipse.jdt.core.IJavaProject#setOptions(Map)
+        * @see net.sourceforge.phpdt.core.IJavaProject#setOptions(Map)
         */
        public void setOptions(Map newOptions) {
 
@@ -2274,20 +2677,6 @@ public class JavaProject
        }
 
        /**
-        * Sets the underlying kernel project of this Java project,
-        * and fills in its parent and name.
-        * Called by IProject.getNature().
-        *
-        * @see IProjectNature#setProject
-        */
-       public void setProject(IProject project) {
-
-               fProject = project;
-               fParent = JavaModelManager.getJavaModelManager().getJavaModel();
-               fName = project.getName();
-       }
-
-       /**
         * @see IJavaProject
         */
        public void setRawClasspath(
@@ -2364,21 +2753,21 @@ public class JavaProject
         *
         * @exception NotPresentException if this project does not exist.
         */
-       protected void setRawClasspath0(IClasspathEntry[] rawEntries)
-               throws JavaModelException {
-
-               JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject);
-       
-               synchronized (info) {
-                       if (rawEntries != null) {
-                               info.classpath = rawEntries;
-                       }
-                       
-                       // clear cache of resolved classpath
-                       info.lastResolvedClasspath = null;
-                       info.resolvedPathToRawEntries = null;
-               }
-       }
+//     protected void setRawClasspath0(IClasspathEntry[] rawEntries)
+//             throws JavaModelException {
+//
+//             JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project);
+//     
+//             synchronized (info) {
+//                     if (rawEntries != null) {
+//                             info.classpath = rawEntries;
+//                     }
+//                     
+//                     // clear cache of resolved classpath
+//                     info.lastResolvedClasspath = null;
+//                     info.resolvedPathToRawEntries = null;
+//             }
+//     }
 
        /**
         * Record a shared persistent property onto a project.
@@ -2438,8 +2827,8 @@ public class JavaProject
                        
                        if (cycleParticipants.contains(project.getPath())){
                                IMarker cycleMarker = project.getCycleMarker();
-                               String circularCPOption = project.getOption(PHPCore.CORE_CIRCULAR_CLASSPATH, true);
-                               int circularCPSeverity = PHPCore.ERROR.equals(circularCPOption) ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING;
+                               String circularCPOption = project.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true);
+                               int circularCPSeverity = JavaCore.ERROR.equals(circularCPOption) ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING;
                                if (cycleMarker != null) {
                                        // update existing cycle marker if needed
                                        try {
@@ -2491,7 +2880,7 @@ public class JavaProject
                                                if (!traversed.contains(prereqProjectPath)) {
                                                        IResource member = workspaceRoot.findMember(prereqProjectPath);
                                                        if (member != null && member.getType() == IResource.PROJECT){
-                                                               JavaProject project = (JavaProject)PHPCore.create((IProject)member);
+                                                               JavaProject project = (JavaProject)JavaCore.create((IProject)member);
                                                                project.updateCycleParticipants(null, prereqChain, cycleParticipants, workspaceRoot, traversed);
                                                        }
                                                }