X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java index 2a0a680..f803855 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java @@ -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,16 @@ 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.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 +71,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 +116,7 @@ public class JavaProject /** * The platform project this IJavaProject is based on */ - protected IProject fProject; + protected IProject project; protected List fLoadPathEntries; protected boolean fScratched; @@ -151,14 +148,14 @@ public class JavaProject if (externalPath == null) return null; -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonicalizing " + externalPath.toString()); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonicalizing " + externalPath.toString()); //$NON-NLS-1$ + } if (IS_CASE_SENSITIVE) { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (file system is case sensitive)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (file system is case sensitive)"); //$NON-NLS-1$ + } return externalPath; } @@ -166,9 +163,9 @@ public class JavaProject IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace == null) return externalPath; // protection during shutdown (30487) if (workspace.getRoot().findMember(externalPath) != null) { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (member of workspace)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (member of workspace)"); //$NON-NLS-1$ + } return externalPath; } @@ -178,9 +175,9 @@ public class JavaProject new Path(new File(externalPath.toOSString()).getCanonicalPath()); } catch (IOException e) { // default to original path -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (IOException)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (IOException)"); //$NON-NLS-1$ + } return externalPath; } @@ -188,9 +185,9 @@ public class JavaProject int canonicalLength = canonicalPath.segmentCount(); if (canonicalLength == 0) { // the java.io.File canonicalization failed -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (canonical path is empty)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (canonical path is empty)"); //$NON-NLS-1$ + } return externalPath; } else if (externalPath.isAbsolute()) { result = canonicalPath; @@ -201,9 +198,9 @@ public class JavaProject if (canonicalLength >= externalLength) { result = canonicalPath.removeFirstSegments(canonicalLength - externalLength); } else { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (canonical path is " + canonicalPath.toString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (canonical path is " + canonicalPath.toString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + } return externalPath; } } @@ -212,24 +209,24 @@ public class JavaProject if (externalPath.getDevice() == null) { result = result.setDevice(null); } -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is " + result.toString()); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is " + result.toString()); //$NON-NLS-1$ + } return result; } /** * Constructor needed for IProject.getNature() and IProject.addNature(). * - * @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 +237,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 +259,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 +330,7 @@ public class JavaProject } protected IFile getLoadPathEntriesFile() { - return fProject.getFile(".loadpath"); + return project.getFile(".loadpath"); } protected String getLoadPathXML() { @@ -366,19 +363,67 @@ 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); +// } @@ -419,7 +464,7 @@ public class JavaProject 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); + JavaProject project = (JavaProject) JavaCore.create(projRsc); project.computeExpandedClasspath( initialProject, ignoreUnresolvedVariable, @@ -534,7 +579,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 +605,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 +700,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 +725,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 +740,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 +778,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 +895,7 @@ public class JavaProject protected IClasspathEntry[] defaultClasspath() throws JavaModelException { return new IClasspathEntry[] { - PHPCore.newSourceEntry(getProject().getFullPath())}; + JavaCore.newSourceEntry(getProject().getFullPath())}; } /** @@ -844,51 +903,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 +998,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 +1201,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,7 +1291,12 @@ 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. @@ -1278,6 +1373,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. @@ -1296,7 +1413,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(); } @@ -1309,7 +1426,7 @@ public class JavaProject 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) @@ -1341,7 +1458,7 @@ public class JavaProject */ public IPath getOutputLocation() throws JavaModelException { - JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject); + JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project); IPath outputLocation = perProjectInfo.outputLocation; if (outputLocation != null) return outputLocation; @@ -1375,7 +1492,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 +1521,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; @@ -1526,9 +1643,21 @@ public class JavaProject */ 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); } @@ -1567,7 +1696,7 @@ public class JavaProject */ public IClasspathEntry[] getRawClasspath() throws JavaModelException { - JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject); + 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*/); @@ -1627,7 +1756,7 @@ public class JavaProject throws JavaModelException { JavaModelManager manager = JavaModelManager.getJavaModelManager(); - JavaModelManager.PerProjectInfo perProjectInfo = manager.getPerProjectInfoCheckExistence(fProject); + JavaModelManager.PerProjectInfo perProjectInfo = manager.getPerProjectInfoCheckExistence(project); // reuse cache if not needing to refresh markers or checking bound variables if (ignoreUnresolvedEntry && !generateMarkerOnError && perProjectInfo != null){ @@ -1646,7 +1775,7 @@ public class JavaProject if (perProjectInfo != null){ if (perProjectInfo.classpath == null // .classpath file could not be read && generateMarkerOnError - && JavaProject.hasJavaNature(fProject)) { + && JavaProject.hasJavaNature(project)) { this.createClasspathProblemMarker(new JavaModelStatus( IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT, Util.bind("classpath.cannotReadClasspathFile", this.getElementName()))); //$NON-NLS-1$ @@ -1693,7 +1822,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 { @@ -1828,7 +1957,7 @@ public class JavaProject } public int hashCode() { - return fProject.hashCode(); + return project.hashCode(); } /** @@ -1946,7 +2075,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 +2086,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 +2126,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 +2144,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 +2155,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 +2278,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 +2294,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 +2322,6 @@ public class JavaProject } } } - /** * Update the Java command in the build spec (replace existing one if present, * add one first if none). @@ -2274,20 +2404,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( @@ -2367,7 +2483,7 @@ public class JavaProject protected void setRawClasspath0(IClasspathEntry[] rawEntries) throws JavaModelException { - JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(fProject); + JavaModelManager.PerProjectInfo info = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project); synchronized (info) { if (rawEntries != null) { @@ -2438,8 +2554,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 +2607,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); } }