aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-09-23 15:59:57 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-09-23 15:59:57 -0700
commitdd9cd2224fa9ef8ea309a3a97c6238de7b7e4dd1 (patch)
tree13a4a47bf93d290a1db14e43b2679811f248bf8c
parentfebb04611e9aff5828440d6c7170ad545edfcf4d (diff)
parentacbf16e065f27550c5baffe7e4fcd20ff974d435 (diff)
downloadsdk-dd9cd2224fa9ef8ea309a3a97c6238de7b7e4dd1.zip
sdk-dd9cd2224fa9ef8ea309a3a97c6238de7b7e4dd1.tar.gz
sdk-dd9cd2224fa9ef8ea309a3a97c6238de7b7e4dd1.tar.bz2
am acbf16e0: Merge "Use the new ResourceUrl API in sdk-common"
* commit 'acbf16e065f27550c5baffe7e4fcd20ff974d435': Use the new ResourceUrl API in sdk-common
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java12
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java26
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java7
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextAction.java17
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java11
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceParticipantTest.java13
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java45
7 files changed, 68 insertions, 63 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
index 98a1fab..3db3808 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
@@ -20,7 +20,7 @@ import static com.android.SdkConstants.ANDROID_URI;
import static com.android.SdkConstants.XMLNS_ANDROID;
import static com.android.SdkConstants.XMLNS_URI;
-import com.android.ide.common.resources.ResourceRepository;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
@@ -344,9 +344,13 @@ public class AaptQuickFix implements IMarkerResolutionGenerator2, IQuickAssistPr
}
private void perform() {
- Pair<ResourceType,String> resource = ResourceRepository.parseResource(mResource);
- ResourceType type = resource.getFirst();
- String name = resource.getSecond();
+ ResourceUrl resource = ResourceUrl.parse(mResource);
+ if (resource == null) {
+ return;
+ }
+ ResourceType type = resource.type;
+ String name = resource.name;
+ assert !resource.framework;
String value = ""; //$NON-NLS-1$
// Try to pick a reasonable first guess. The new value will be highlighted and
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
index 0e46255..91c4049 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
@@ -41,7 +41,6 @@ import static com.android.SdkConstants.TAG_STYLE;
import static com.android.SdkConstants.TOOLS_URI;
import static com.android.SdkConstants.VIEW;
import static com.android.SdkConstants.VIEW_FRAGMENT;
-import static com.android.ide.common.resources.ResourceRepository.parseResource;
import static com.android.xml.AndroidManifest.ATTRIBUTE_NAME;
import static com.android.xml.AndroidManifest.ATTRIBUTE_PACKAGE;
import static com.android.xml.AndroidManifest.NODE_ACTIVITY;
@@ -54,6 +53,7 @@ import com.android.annotations.VisibleForTesting;
import com.android.ide.common.resources.ResourceFile;
import com.android.ide.common.resources.ResourceFolder;
import com.android.ide.common.resources.ResourceRepository;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
@@ -226,12 +226,9 @@ public class Hyperlinks {
return !ATTR_ID.equals(attribute.getLocalName());
}
- Pair<ResourceType,String> resource = parseResource(value);
+ ResourceUrl resource = ResourceUrl.parse(value);
if (resource != null) {
- ResourceType type = resource.getFirst();
- if (type != null) {
- return true;
- }
+ return true;
}
return false;
@@ -1130,7 +1127,7 @@ public class Hyperlinks {
}
}
- Pair<ResourceType,String> resource = parseResource(url);
+ ResourceUrl resource = ResourceUrl.parse(url);
if (resource == null) {
String androidStyle = ANDROID_STYLE_RESOURCE_PREFIX;
if (url.startsWith(ANDROID_PREFIX)) {
@@ -1163,18 +1160,16 @@ public class Hyperlinks {
*/
@Nullable
public static IHyperlink[] getResourceLinks(@Nullable IRegion range, @NonNull String url,
- @NonNull IProject project, @Nullable FolderConfiguration configuration) {
+ @Nullable IProject project, @Nullable FolderConfiguration configuration) {
List<IHyperlink> links = new ArrayList<IHyperlink>();
- Pair<ResourceType,String> resource = parseResource(url);
- if (resource == null || resource.getFirst() == null) {
+ ResourceUrl resource = ResourceUrl.parse(url);
+ if (resource == null) {
return null;
}
- ResourceType type = resource.getFirst();
- String name = resource.getSecond();
-
- boolean isFramework = url.startsWith(ANDROID_PREFIX)
- || url.startsWith(ANDROID_THEME_PREFIX);
+ ResourceType type = resource.type;
+ String name = resource.name;
+ boolean isFramework = resource.framework;
if (project == null) {
// Local reference *within* a framework
isFramework = true;
@@ -1479,6 +1474,7 @@ public class Hyperlinks {
}
/** Returns the project applicable to this hyperlink detection */
+ @Nullable
private static IProject getProject() {
IFile file = AdtUtils.getActiveFile();
if (file != null) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
index 88423e4..aa8c119 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
@@ -16,6 +16,7 @@
package com.android.ide.eclipse.adt.internal.editors.layout.refactoring;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate;
@@ -26,7 +27,6 @@ import com.android.ide.eclipse.adt.internal.refactorings.core.RenameResourceXmlT
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringRefactoring;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringWizard;
import com.android.resources.ResourceType;
-import com.android.utils.Pair;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
@@ -106,7 +106,7 @@ public class RefactoringAssistant implements IQuickAssistProcessor {
boolean isTagName = false;
boolean isAttributeName = false;
boolean isStylableAttribute = false;
- Pair<ResourceType, String> resource = null;
+ ResourceUrl resource = null;
IStructuredModel model = null;
try {
model = xmlEditor.getModelForRead();
@@ -185,8 +185,7 @@ public class RefactoringAssistant implements IQuickAssistProcessor {
new ExtractStringRefactoring(file, xmlEditor, textSelection)));
} else if (resource != null) {
RenameResourceProcessor processor = new RenameResourceProcessor(
- file.getProject(), resource.getFirst(),
- resource.getSecond(), null);
+ file.getProject(), resource.type, resource.name, null);
RenameRefactoring refactoring = new RenameRefactoring(processor);
proposals.add(new RefactoringProposal(xmlEditor, refactoring));
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextAction.java
index 3b1fa52..8ecb088 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextAction.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextAction.java
@@ -25,7 +25,7 @@ import static com.android.SdkConstants.TAG_ITEM;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
-import com.android.ide.common.resources.ResourceRepository;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.DomUtilities;
import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo;
@@ -33,7 +33,6 @@ import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.ide.eclipse.adt.internal.sdk.ProjectState;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.resources.ResourceType;
-import com.android.utils.Pair;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -108,15 +107,15 @@ public final class RenameResourceXmlTextAction extends Action {
return;
}
- Pair<ResourceType, String> resource = findResource(document, selection.getOffset());
+ ResourceUrl resource = findResource(document, selection.getOffset());
if (resource == null) {
resource = findItemDefinition(document, selection.getOffset());
}
if (resource != null) {
- ResourceType type = resource.getFirst();
- String name = resource.getSecond();
+ ResourceType type = resource.type;
+ String name = resource.name;
Shell shell = mEditor.getSite().getShell();
boolean canClear = false;
@@ -176,7 +175,7 @@ public final class RenameResourceXmlTextAction extends Action {
* @return a resource pair, or null if not found
*/
@Nullable
- public static Pair<ResourceType,String> findResource(@NonNull IDocument document, int offset) {
+ public static ResourceUrl findResource(@NonNull IDocument document, int offset) {
try {
int max = document.getLength();
if (offset >= max) {
@@ -220,7 +219,7 @@ public final class RenameResourceXmlTextAction extends Action {
return null;
}
- return ResourceRepository.parseResource(url);
+ return ResourceUrl.parse(url);
}
}
} catch (BadLocationException e) {
@@ -238,7 +237,7 @@ public final class RenameResourceXmlTextAction extends Action {
* Searches for an item definition around the caret, such as
* {@code <string name="foo">My String</string>}
*/
- private Pair<ResourceType, String> findItemDefinition(IDocument document, int offset) {
+ private ResourceUrl findItemDefinition(IDocument document, int offset) {
Node node = DomUtilities.getNode(document, offset);
if (node == null) {
return null;
@@ -264,7 +263,7 @@ public final class RenameResourceXmlTextAction extends Action {
}
ResourceType type = ResourceType.getEnum(typeString);
if (type != null) {
- return Pair.of(type, name);
+ return ResourceUrl.create(type, name, false, false);
}
return null;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
index 978980b..8da18dd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
@@ -34,8 +34,8 @@ import static com.android.ide.eclipse.adt.AdtConstants.WS_SEP;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.resources.ResourceDeltaKind;
-import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.ResourceResolver;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.common.resources.configuration.CountryCodeQualifier;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.FolderConfiguration;
@@ -249,10 +249,13 @@ public class ResourceHelper {
return false;
}
- Pair<ResourceType,String> parsed = ResourceRepository.parseResource(resource);
+ ResourceUrl parsed = ResourceUrl.parse(resource);
if (parsed != null) {
- ResourceType type = parsed.getFirst();
- String name = parsed.getSecond();
+ if (parsed.framework) {
+ return false;
+ }
+ ResourceType type = parsed.type;
+ String name = parsed.name;
// Make sure the name is valid
ResourceNameValidator validator =
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceParticipantTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceParticipantTest.java
index ccf6e4f..3f029b9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceParticipantTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceParticipantTest.java
@@ -16,10 +16,9 @@
package com.android.ide.eclipse.adt.internal.refactorings.core;
import com.android.annotations.NonNull;
-import com.android.ide.common.resources.ResourceRepository;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.resources.ResourceType;
-import com.android.utils.Pair;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -366,10 +365,12 @@ public class RenameResourceParticipantTest extends RefactoringTestBase {
if (resource instanceof String) {
String url = (String) resource;
assert url.startsWith("@") : resource;
- Pair<ResourceType, String> pair = ResourceRepository.parseResource(url);
- assertNotNull(url, pair);
- ResourceType type = pair.getFirst();
- String currentName = pair.getSecond();
+
+ ResourceUrl parsedUrl = ResourceUrl.parse(url);
+ assertNotNull(url, parsedUrl);
+ assert parsedUrl != null; // null analysis doesn't recognize assertNotNull
+ ResourceType type = parsedUrl.type;
+ String currentName = parsedUrl.name;
RenameResourceProcessor p;
p = new RenameResourceProcessor(project, type, currentName, newName);
p.setUpdateReferences(updateReferences);
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java
index 11fc81a..e00a44b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java
@@ -15,8 +15,8 @@
*/
package com.android.ide.eclipse.adt.internal.refactorings.core;
+import com.android.ide.common.resources.ResourceUrl;
import com.android.resources.ResourceType;
-import com.android.utils.Pair;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@@ -31,25 +31,29 @@ public class RenameResourceXmlTextActionTest extends TestCase {
checkWord("^@bogus", null);
checkWord("@bo^gus", null);
checkWord("bogus@^", null);
- checkWord(" @string/nam^e ", Pair.of(ResourceType.STRING, "name"));
- checkWord("@string/nam^e ", Pair.of(ResourceType.STRING, "name"));
- checkWord("\"^@string/name ", Pair.of(ResourceType.STRING, "name"));
- checkWord("^@string/name ", Pair.of(ResourceType.STRING, "name"));
- checkWord("\n^@string/name ", Pair.of(ResourceType.STRING, "name"));
- checkWord("\n^@string/name(", Pair.of(ResourceType.STRING, "name"));
- checkWord("\n^@string/name;", Pair.of(ResourceType.STRING, "name"));
- checkWord("\n^@string/name5", Pair.of(ResourceType.STRING, "name5"));
- checkWord("\n@string/name5^", Pair.of(ResourceType.STRING, "name5"));
- checkWord("\n@string/name5^(", Pair.of(ResourceType.STRING, "name5"));
- checkWord("\n@stri^ng/name5(", Pair.of(ResourceType.STRING, "name5"));
- checkWord("\n@string^/name5(", Pair.of(ResourceType.STRING, "name5"));
- checkWord("\n@string/^name5(", Pair.of(ResourceType.STRING, "name5"));
+ checkWord(" @string/nam^e ", getUrl(ResourceType.STRING, "name"));
+ checkWord("@string/nam^e ", getUrl(ResourceType.STRING, "name"));
+ checkWord("\"^@string/name ", getUrl(ResourceType.STRING, "name"));
+ checkWord("^@string/name ", getUrl(ResourceType.STRING, "name"));
+ checkWord("\n^@string/name ", getUrl(ResourceType.STRING, "name"));
+ checkWord("\n^@string/name(", getUrl(ResourceType.STRING, "name"));
+ checkWord("\n^@string/name;", getUrl(ResourceType.STRING, "name"));
+ checkWord("\n^@string/name5", getUrl(ResourceType.STRING, "name5"));
+ checkWord("\n@string/name5^", getUrl(ResourceType.STRING, "name5"));
+ checkWord("\n@string/name5^(", getUrl(ResourceType.STRING, "name5"));
+ checkWord("\n@stri^ng/name5(", getUrl(ResourceType.STRING, "name5"));
+ checkWord("\n@string^/name5(", getUrl(ResourceType.STRING, "name5"));
+ checkWord("\n@string/^name5(", getUrl(ResourceType.STRING, "name5"));
checkWord("\n@string^name5(", null);
checkWord("\n@strings^/name5(", null);
- checkWord("\n@+id/^myid(", Pair.of(ResourceType.ID, "myid"));
- checkWord("\n?a^ttr/foo\"", Pair.of(ResourceType.ATTR, "foo"));
- checkWord("\n?f^oo\"", Pair.of(ResourceType.ATTR, "foo"));
- checkWord("\n^?foo\"", Pair.of(ResourceType.ATTR, "foo"));
+ checkWord("\n@+id/^myid(", getUrl(ResourceType.ID, "myid"));
+ checkWord("\n?a^ttr/foo\"", getUrl(ResourceType.ATTR, "foo"));
+ checkWord("\n?f^oo\"", getUrl(ResourceType.ATTR, "foo"));
+ checkWord("\n^?foo\"", getUrl(ResourceType.ATTR, "foo"));
+ }
+
+ private static ResourceUrl getUrl(ResourceType type, String name) {
+ return ResourceUrl.create(type, name, false, false);
}
public void testClassNames() throws Exception {
@@ -89,7 +93,7 @@ public class RenameResourceXmlTextActionTest extends TestCase {
assertEquals(expectedClassName, className);
}
- private void checkWord(String contents, Pair<ResourceType, String> expectedResource)
+ private void checkWord(String contents, ResourceUrl expectedResource)
throws Exception {
int cursor = contents.indexOf('^');
assertTrue("Must set cursor position with ^ in " + contents, cursor != -1);
@@ -100,8 +104,7 @@ public class RenameResourceXmlTextActionTest extends TestCase {
IDocument document = new Document();
document.replace(0, 0, contents);
- Pair<ResourceType, String> resource =
- RenameResourceXmlTextAction.findResource(document, cursor);
+ ResourceUrl resource = RenameResourceXmlTextAction.findResource(document, cursor);
assertEquals(expectedResource, resource);
}
}