*******************************************************************************/
package net.sourceforge.phpdt.internal.core;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Map;
import net.sourceforge.phpdt.core.IJavaElement;
import net.sourceforge.phpdt.core.IJavaModel;
import net.sourceforge.phpdt.core.IJavaProject;
+import net.sourceforge.phpdt.core.IOpenable;
import net.sourceforge.phpdt.core.JavaModelException;
+import net.sourceforge.phpdt.core.WorkingCopyOwner;
+import net.sourceforge.phpdt.internal.core.util.MementoTokenizer;
+import net.sourceforge.phpdt.internal.core.util.Util;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.util.Assert;
* @exception Error if called more than once
*/
protected JavaModel() throws Error {
- super(JAVA_MODEL, null, "" /*workspace has empty name*/); //$NON-NLS-1$
+ super(null, "" /*workspace has empty name*/); //$NON-NLS-1$
+}
+protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) /*throws JavaModelException*/ {
+
+ // determine my children
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (int i = 0, max = projects.length; i < max; i++) {
+ IProject project = projects[i];
+ if (JavaProject.hasJavaNature(project)) {
+ info.addChild(getJavaProject(project));
+ }
+ }
+
+ newElements.put(this, info);
+
+ return true;
}
/*
* @see IJavaModel
*/
-//public boolean contains(IResource resource) {
-// switch (resource.getType()) {
-// case IResource.ROOT:
-// case IResource.PROJECT:
-// return true;
-// }
-// // file or folder
-// IJavaProject[] projects;
-// try {
-// projects = this.getJavaProjects();
-// } catch (JavaModelException e) {
-// return false;
-// }
-// for (int i = 0, length = projects.length; i < length; i++) {
-// JavaProject project = (JavaProject)projects[i];
-//
-// if (!project.contains(resource)) {
-// return false;
-// }
-// }
-// return true;
-//}
+public boolean contains(IResource resource) {
+ switch (resource.getType()) {
+ case IResource.ROOT:
+ case IResource.PROJECT:
+ return true;
+ }
+ // file or folder
+ IJavaProject[] projects;
+ try {
+ projects = this.getJavaProjects();
+ } catch (JavaModelException e) {
+ return false;
+ }
+ for (int i = 0, length = projects.length; i < length; i++) {
+ JavaProject project = (JavaProject)projects[i];
+
+ if (!project.contains(resource)) {
+ return false;
+ }
+ }
+ return true;
+}
/**
* @see IJavaModel
*/
-//public void copy(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
-// runOperation(new CopyResourceElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
-// } else {
-// runOperation(new CopyElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
-// }
-//}
+public void copy(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
+ if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
+ runOperation(new CopyResourceElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
+ } else {
+ runOperation(new CopyElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
+ }
+}
/**
* Returns a new element info for this element.
*/
-//protected OpenableElementInfo createElementInfo() {
-// return new JavaModelInfo();
-//}
+protected Object createElementInfo() {
+ return new JavaModelInfo();
+}
/**
* @see IJavaModel
*/
-//public void delete(IJavaElement[] elements, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
-// runOperation(new DeleteResourceElementsOperation(elements, force), monitor);
-// } else {
-// runOperation(new DeleteElementsOperation(elements, force), monitor);
-// }
-//}
+public void delete(IJavaElement[] elements, boolean force, IProgressMonitor monitor) throws JavaModelException {
+ if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
+ runOperation(new DeleteResourceElementsOperation(elements, force), monitor);
+ } else {
+ runOperation(new DeleteElementsOperation(elements, force), monitor);
+ }
+}
/**
* Finds the given project in the list of the java model's children.
* Returns null if not found.
}
return null;
}
-
+/**
+ * @see IJavaElement
+ */
+public int getElementType() {
+ return JAVA_MODEL;
+}
/**
* Flushes the cache of external files known to be existing.
*/
/**
*/
-//protected boolean generateInfos(
-// OpenableElementInfo info,
-// IProgressMonitor pm,
-// Map newElements,
-// IResource underlyingResource) throws JavaModelException {
-//
-// JavaModelManager.getJavaModelManager().putInfo(this, info);
-// // determine my children
-// IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-// for (int i = 0, max = projects.length; i < max; i++) {
-// IProject project = projects[i];
-// if (JavaProject.hasJavaNature(project)) {
-// info.addChild(getJavaProject(project));
-// }
-// }
-// return true;
-//}
+protected boolean generateInfos(
+ OpenableElementInfo info,
+ IProgressMonitor pm,
+ Map newElements,
+ IResource underlyingResource) throws JavaModelException {
+
+ JavaModelManager.getJavaModelManager().putInfo(this, info);
+ // determine my children
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (int i = 0, max = projects.length; i < max; i++) {
+ IProject project = projects[i];
+ if (JavaProject.hasJavaNature(project)) {
+ info.addChild(getJavaProject(project));
+ }
+ }
+ return true;
+}
/**
* Returns the <code>IJavaElement</code> represented by the <code>String</code>
* memento.
// }
// return type;
//}
+
+
+/*
+ * @see JavaElement
+ */
+public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
+ switch (token.charAt(0)) {
+ case JEM_COUNT:
+ return getHandleUpdatingCountFromMemento(memento, owner);
+ case JEM_JAVAPROJECT:
+ String projectName = memento.nextToken();
+ JavaElement project = (JavaElement)getJavaProject(projectName);
+ return project.getHandleFromMemento(memento, owner);
+ }
+ return null;
+}
/**
* @see JavaElement#getHandleMemento()
*/
Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
return 0;
}
+
/**
* @see IJavaModel
*/
/**
* @see IJavaModel
*/
-//public void move(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
-// runOperation(new MoveResourceElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
-// } else {
-// runOperation(new MoveElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
-// }
-//}
+public void move(IJavaElement[] elements, IJavaElement[] containers, IJavaElement[] siblings, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
+ if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
+ runOperation(new MoveResourceElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
+ } else {
+ runOperation(new MoveElementsOperation(elements, containers, force), elements, siblings, renamings, monitor);
+ }
+}
/**
* @see IJavaModel#refreshExternalArchives(IJavaElement[], IProgressMonitor)
/**
* @see IJavaModel
*/
-//public void rename(IJavaElement[] elements, IJavaElement[] destinations, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// MultiOperation op;
-// if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
-// op = new RenameResourceElementsOperation(elements, destinations, renamings, force);
-// } else {
-// op = new RenameElementsOperation(elements, destinations, renamings, force);
-// }
-//
-// runOperation(op, monitor);
-//}
+public void rename(IJavaElement[] elements, IJavaElement[] destinations, String[] renamings, boolean force, IProgressMonitor monitor) throws JavaModelException {
+ MultiOperation op;
+ if (elements != null && elements.length > 0 && elements[0] != null && elements[0].getElementType() < IJavaElement.TYPE) {
+ op = new RenameResourceElementsOperation(elements, destinations, renamings, force);
+ } else {
+ op = new RenameElementsOperation(elements, destinations, renamings, force);
+ }
+
+ runOperation(op, monitor);
+}
/*
* @see JavaElement#rootedAt(IJavaProject)
*/
/**
* Configures and runs the <code>MultiOperation</code>.
*/
-//protected void runOperation(MultiOperation op, IJavaElement[] elements, IJavaElement[] siblings, String[] renamings, IProgressMonitor monitor) throws JavaModelException {
-// op.setRenamings(renamings);
-// if (siblings != null) {
-// for (int i = 0; i < elements.length; i++) {
-// op.setInsertBefore(elements[i], siblings[i]);
-// }
-// }
+protected void runOperation(MultiOperation op, IJavaElement[] elements, IJavaElement[] siblings, String[] renamings, IProgressMonitor monitor) throws JavaModelException {
+ op.setRenamings(renamings);
+ if (siblings != null) {
+ for (int i = 0; i < elements.length; i++) {
+ op.setInsertBefore(elements[i], siblings[i]);
+ }
+ }
// runOperation(op, monitor);
-//}
+ op.runOperation(monitor);
+}
/**
* @private Debugging purposes
*/
* or null if unbound
* Internal items must be referred to using container relative paths.
*/
-//public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
-//
-// if (path == null) return null;
-//
-// // lookup - inside the container
-// if (path.getDevice() == null) { // container relative paths should not contain a device
-// // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
-// // (case of a workspace rooted at d:\ )
-// IResource resource = container.findMember(path);
-// if (resource != null){
-// if (!checkResourceExistence ||resource.exists()) return resource;
-// return null;
-// }
-// }
-//
-// // if path is relative, it cannot be an external path
-// // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
-// if (!path.isAbsolute()) return null;
-//
-// // lookup - outside the container
-// File externalFile = new File(path.toOSString());
-// if (!checkResourceExistence) {
-// return externalFile;
-// } else if (existingExternalFiles.contains(externalFile)) {
-// return externalFile;
-// } else {
-// if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
-// System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
-// }
-// if (externalFile.exists()) {
-// // cache external file
-// existingExternalFiles.add(externalFile);
-// return externalFile;
-// }
-// }
-// return null;
-//}
+public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
+
+ if (path == null) return null;
+
+ // lookup - inside the container
+ if (path.getDevice() == null) { // container relative paths should not contain a device
+ // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
+ // (case of a workspace rooted at d:\ )
+ IResource resource = container.findMember(path);
+ if (resource != null){
+ if (!checkResourceExistence ||resource.exists()) return resource;
+ return null;
+ }
+ }
+
+ // if path is relative, it cannot be an external path
+ // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
+ if (!path.isAbsolute()) return null;
+
+ // lookup - outside the container
+ File externalFile = new File(path.toOSString());
+ if (!checkResourceExistence) {
+ return externalFile;
+ } else if (existingExternalFiles.contains(externalFile)) {
+ return externalFile;
+ } else {
+ if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
+ System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (externalFile.exists()) {
+ // cache external file
+ existingExternalFiles.add(externalFile);
+ return externalFile;
+ }
+ }
+ return null;
+}
}