From db6bf7972148e38434bccc283464de9272a1977e Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Thu, 6 Jan 2011 19:09:06 -0800 Subject: [PATCH] Replace Sdk.makeRelativeTo() 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 | 1 + .../internal/editors/layout/gle2/LayoutCanvas.java | 3 +- .../adt/internal/editors/xml/Hyperlinks.java | 2 +- .../adt/internal/properties/LibraryProperties.java | 10 +++--- .../android/ide/eclipse/adt/internal/sdk/Sdk.java | 37 ++-------------------- 5 files changed, 10 insertions(+), 43 deletions(-) diff --git a/eclipse/dictionary.txt b/eclipse/dictionary.txt index 8ab29e624..5aa95ed40 100644 --- a/eclipse/dictionary.txt +++ b/eclipse/dictionary.txt @@ -174,6 +174,7 @@ stateless stderr stdout stretchiness +struct subclassing submenu supertype diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index dc9886edb..747f04904 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -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(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java index 89954cb9f..a2e664b0a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java @@ -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 { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/properties/LibraryProperties.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/properties/LibraryProperties.java index 666127e71..26459d7b2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/properties/LibraryProperties.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/properties/LibraryProperties.java @@ -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}. *

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 true if there was actually new data saved in the project state, false * otherwise. */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java index 03083b874..c13cc73a4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java @@ -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. - *

{@link IPath#makeRelativeTo(IPath)} is only available in 3.5 and later. - *

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()); - } } -- 2.11.0