X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModel.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModel.java index 41c449f..daa7f05 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModel.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModel.java @@ -10,14 +10,17 @@ *******************************************************************************/ 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.JavaModelException; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -25,6 +28,7 @@ import org.eclipse.core.resources.IResource; 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; @@ -60,55 +64,55 @@ protected JavaModel() throws Error { /* * @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 OpenableElementInfo 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. @@ -136,23 +140,23 @@ public static void flushExternalFileCache() { /** */ -//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 IJavaElement represented by the String * memento. @@ -425,13 +429,13 @@ public IWorkspace getWorkspace() { /** * @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) @@ -446,16 +450,16 @@ public IWorkspace getWorkspace() { /** * @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) */ @@ -466,15 +470,15 @@ public IJavaElement rootedAt(IJavaProject project) { /** * Configures and runs the MultiOperation. */ -//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); -//} +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); +} /** * @private Debugging purposes */ @@ -491,41 +495,41 @@ protected void toStringInfo(int tab, StringBuffer buffer, Object info) { * 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; +} }