OSDN Git Service

Replace Sdk.makeRelativeTo()
authorTor Norbye <tnorbye@google.com>
Fri, 7 Jan 2011 03:09:06 +0000 (19:09 -0800)
committerTor Norbye <tnorbye@google.com>
Fri, 7 Jan 2011 14:17:21 +0000 (06:17 -0800)
IPath#makeRelativeTo(IPath) was not supported on Eclipse 3.4, so we
had a local version of it in our sourcebase, as
Sdk#makeRelativeTo(IPath,IPath). However, our version only works
correctly for directories, not plain files, but I had been using it
for files as well.

Now that we no longer need to support Eclipse 3.4, remove our local
version and use the builtin path conversion method.

(Fixed some invalid javadoc too)

Change-Id: I233875e1ecc758eb1ed333686b319b138eb47c4a

eclipse/dictionary.txt
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/properties/LibraryProperties.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java

index 8ab29e6..5aa95ed 100644 (file)
@@ -174,6 +174,7 @@ stateless
 stderr
 stdout
 stretchiness
+struct
 subclassing
 submenu
 supertype
index dc9886e..747f049 100755 (executable)
@@ -33,7 +33,6 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine;
 import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode;
 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
-import com.android.ide.eclipse.adt.internal.sdk.Sdk;
 import com.android.sdklib.SdkConstants;
 
 import org.eclipse.core.filesystem.EFS;
@@ -732,7 +731,7 @@ public class LayoutCanvas extends Canvas {
         IPath workspacePath = workspace.getLocation();
         IEditorSite editorSite = graphicalEditor.getEditorSite();
         if (workspacePath.isPrefixOf(filePath)) {
-            IPath relativePath = Sdk.makeRelativeTo(filePath, workspacePath);
+            IPath relativePath = filePath.makeRelativeTo(workspacePath);
             IResource xmlFile = workspace.findMember(relativePath);
             if (xmlFile != null) {
                 IFile leavingFile = graphicalEditor.getEditedFile();
index 89954cb..a2e664b 100644 (file)
@@ -432,7 +432,7 @@ public class Hyperlinks {
         IPath workspacePath = workspace.getLocation();
         IEditorSite editorSite = sourceEditor.getEditorSite();
         if (workspacePath.isPrefixOf(filePath)) {
-            IPath relativePath = Sdk.makeRelativeTo(filePath, workspacePath);
+            IPath relativePath = filePath.makeRelativeTo(workspacePath);
             IResource file = workspace.findMember(relativePath);
             if (file instanceof IFile) {
                 try {
index 666127e..26459d7 100644 (file)
@@ -167,8 +167,8 @@ final class LibraryProperties {
                         "Please select a library project");
                 if (javaProject != null) {
                     IProject iProject = javaProject.getProject();
-                    IPath relativePath = Sdk.makeRelativeTo(
-                            iProject.getLocation(), mState.getProject().getLocation());
+                    IPath relativePath = iProject.getLocation().makeRelativeTo(
+                            mState.getProject().getLocation());
 
                     addItem(relativePath.toString(), iProject, -1);
                     resetEnabled();
@@ -267,11 +267,11 @@ final class LibraryProperties {
 
     /**
      * Saves the state of the UI into the {@link ProjectProperties} object that was returned by
-     * {@link #setContent(ProjectState)}.
+     * {@link #setContent}.
      * <p/>This does not update the {@link ProjectState} object that was provided, nor does it save
      * the new properties on disk. Saving the properties on disk, via
-     * {@link ProjectProperties#save()}, and updating the {@link ProjectState} instance, via
-     * {@link ProjectState#reloadProperties()} must be done by the caller.
+     * {@link ProjectPropertiesWorkingCopy#save()}, and updating the {@link ProjectState} instance,
+     * via {@link ProjectState#reloadProperties()} must be done by the caller.
      * @return <code>true</code> if there was actually new data saved in the project state, false
      * otherwise.
      */
index 03083b8..c13cc73 100644 (file)
@@ -917,10 +917,10 @@ public final class Sdk  {
                 synchronized (sLock) {
                     for (ProjectState projectState : sProjectStateMap.values()) {
                         if (projectState != renamedState && projectState.isMissingLibraries()) {
-                            IPath oldRelativePath = makeRelativeTo(from,
+                            IPath oldRelativePath = from.makeRelativeTo(
                                     projectState.getProject().getFullPath());
 
-                            IPath newRelativePath = makeRelativeTo(project.getFullPath(),
+                            IPath newRelativePath = project.getFullPath().makeRelativeTo(
                                     projectState.getProject().getFullPath());
 
                             // get the current libraries
@@ -1682,38 +1682,5 @@ public final class Sdk  {
         // for this libraries, to update the project there were depending on.
         updateProjectsWithNewLibraries(updatedLibraries);
     }
-
-    /**
-     * Computes a new IPath targeting a given target, but relative to a given base.
-     * <p/>{@link IPath#makeRelativeTo(IPath)} is only available in 3.5 and later.
-     * <p/>This is based on the implementation {@link Path#makeRelativeTo(IPath)}.
-     * @param target the target of the IPath
-     * @param base the IPath to base the relative path on.
-     * @return the relative IPath
-     */
-    public static IPath makeRelativeTo(IPath target, IPath base) {
-        //can't make relative if devices are not equal
-        if (target.getDevice() != base.getDevice() && (target.getDevice() == null ||
-                !target.getDevice().equalsIgnoreCase(base.getDevice())))
-            return target;
-        int commonLength = target.matchingFirstSegments(base);
-        final int differenceLength = base.segmentCount() - commonLength;
-        final int newSegmentLength = differenceLength + target.segmentCount() - commonLength;
-        if (newSegmentLength == 0)
-            return Path.EMPTY;
-        String[] newSegments = new String[newSegmentLength];
-        //add parent references for each segment different from the base
-        Arrays.fill(newSegments, 0, differenceLength, ".."); //$NON-NLS-1$
-        //append the segments of this path not in common with the base
-        System.arraycopy(target.segments(), commonLength, newSegments,
-                differenceLength, newSegmentLength - differenceLength);
-
-        StringBuilder sb = new StringBuilder();
-        for (String s : newSegments) {
-            sb.append(s).append('/');
-        }
-
-        return new Path(null, sb.toString());
-    }
 }