diff options
author | Raphael Moll <ralf@android.com> | 2012-09-17 15:54:17 -0700 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2012-09-17 16:40:11 -0700 |
commit | 4c440c37ce86dbb0f8ed72402f4ce4a921684ce9 (patch) | |
tree | 6b9dfbb31d5a75ccce0ae3cdb8185c4e6b525910 | |
parent | 0f86143e55290c4851e51b9a46ff21e198a35acc (diff) | |
download | sdk-4c440c37ce86dbb0f8ed72402f4ce4a921684ce9.zip sdk-4c440c37ce86dbb0f8ed72402f4ce4a921684ce9.tar.gz sdk-4c440c37ce86dbb0f8ed72402f4ce4a921684ce9.tar.bz2 |
Manifest Editor: class selector for <application backupAgent>.
<application android:backupAgent> needs a class selector
that accepts classes deriving from BackupAgent.
Change-Id: Id2e72e85967bc31a67d1eff2c342bcf7acc2cb3c
4 files changed, 75 insertions, 95 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java index ff555cc..da3a185 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java @@ -294,18 +294,7 @@ public final class DescriptorsUtils { name = buf.toString(); - // Replace these acronyms by upper-case versions - // - (?<=^| ) means "if preceded by a space or beginning of string" - // - (?=$| ) means "if followed by a space or end of string" - if (name.contains("sdk") || name.startsWith("Sdk")) { - name = name.replaceAll("(?<=^| )[sS]dk(?=$| )", "SDK"); - } - if (name.contains("uri") || name.startsWith("Uri")) { - name = name.replaceAll("(?<=^| )[uU]ri(?=$| )", "URI"); - } - if (name.contains("ime") || name.startsWith("Ime")) { - name = name.replaceAll("(?<=^| )[iI]me(?=$| )", "IME"); - } + name = replaceAcronyms(name); return name; } @@ -354,19 +343,30 @@ public final class DescriptorsUtils { name = buf.toString(); + name = replaceAcronyms(name); + + return name; + } + + private static String replaceAcronyms(String name) { // Replace these acronyms by upper-case versions // - (?<=^| ) means "if preceded by a space or beginning of string" // - (?=$| ) means "if followed by a space or end of string" - if (name.contains("Sdk")) { - name = name.replaceAll("(?<=^| )Sdk(?=$| )", "SDK"); + if (name.contains("sdk") || name.contains("Sdk")) { + name = name.replaceAll("(?<=^| )[sS]dk(?=$| )", "SDK"); } - if (name.contains("Uri")) { - name = name.replaceAll("(?<=^| )Uri(?=$| )", "URI"); + if (name.contains("uri") || name.contains("Uri")) { + name = name.replaceAll("(?<=^| )[uU]ri(?=$| )", "URI"); } - if (name.contains("Ime")) { - name = name.replaceAll("(?<=^| )Ime(?=$| )", "IME"); + if (name.contains("ime") || name.contains("Ime")) { + name = name.replaceAll("(?<=^| )[iI]me(?=$| )", "IME"); + } + if (name.contains("vm") || name.contains("Vm")) { + name = name.replaceAll("(?<=^| )[vV]m(?=$| )", "VM"); + } + if (name.contains("ui") || name.contains("Ui")) { + name = name.replaceAll("(?<=^| )[uU]i(?=$| )", "UI"); } - return name; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java index ba7894b..3429e43 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java @@ -197,14 +197,18 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { overrides.put("action,category,uses-permission/" + ANDROID_NAME_ATTR, //$NON-NLS-1$ ListAttributeDescriptor.CREATOR); - overrides.put("application/" + ANDROID_NAME_ATTR, //$NON-NLS-1$ - ApplicationAttributeDescriptor.CREATOR); - - overrideClassName(overrides, "activity", SdkConstants.CLASS_ACTIVITY); //$NON-NLS-1$ - overrideClassName(overrides, "receiver", SdkConstants.CLASS_BROADCASTRECEIVER); //$NON-NLS-1$ - overrideClassName(overrides, "service", SdkConstants.CLASS_SERVICE); //$NON-NLS-1$ - overrideClassName(overrides, "provider", SdkConstants.CLASS_CONTENTPROVIDER); //$NON-NLS-1$ - overrideClassName(overrides, "instrumentation", SdkConstants.CLASS_INSTRUMENTATION); //$NON-NLS-1$ + overrideClassName(overrides, "application", //$NON-NLS-1$ + SdkConstants.CLASS_APPLICATION, + false /*mandatory*/); + overrideClassName(overrides, "application/backupAgent", //$NON-NLS-1$ + "android.app.backup.BackupAgent", //$NON-NLS-1$ + false /*mandatory*/); + overrideClassName(overrides, "activity", SdkConstants.CLASS_ACTIVITY); //$NON-NLS-1$ + overrideClassName(overrides, "receiver", SdkConstants.CLASS_BROADCASTRECEIVER);//$NON-NLS-1$ + overrideClassName(overrides, "service", SdkConstants.CLASS_SERVICE); //$NON-NLS-1$ + overrideClassName(overrides, "provider", SdkConstants.CLASS_CONTENTPROVIDER); //$NON-NLS-1$ + overrideClassName(overrides, "instrumentation", + SdkConstants.CLASS_INSTRUMENTATION); //$NON-NLS-1$ // -- list element nodes already created -- // These elements are referenced by already opened editors, so we want to update them @@ -235,18 +239,52 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { SdkConstants.ANDROID_NS_NAME, SdkConstants.ANDROID_URI); insertAttribute(MANIFEST_ELEMENT, xmlns); + /* + * + * + */ assert sanityCheck(manifestMap, MANIFEST_ELEMENT); } /** - * Sets up an attribute override for ANDROID_NAME_ATTR using a ClassAttributeDescriptor + * Sets up a mandatory attribute override using a ClassAttributeDescriptor * with the specified class name. + * + * @param overrides The current map of overrides. + * @param elementName The element name to override, e.g. "application". + * If this name does NOT have a slash (/), the ANDROID_NAME_ATTR attribute will be overriden. + * Otherwise, if it contains a (/) the format is "element/attribute", for example + * "application/name" vs "application/backupAgent". + * @param className The fully qualified name of the base class of the attribute. */ private static void overrideClassName( Map<String, ITextAttributeCreator> overrides, String elementName, final String className) { - overrides.put(elementName + "/" + ANDROID_NAME_ATTR, + overrideClassName(overrides, elementName, className, true); + } + + /** + * Sets up an attribute override using a ClassAttributeDescriptor + * with the specified class name. + * + * @param overrides The current map of overrides. + * @param elementName The element name to override, e.g. "application". + * If this name does NOT have a slash (/), the ANDROID_NAME_ATTR attribute will be overriden. + * Otherwise, if it contains a (/) the format is "element/attribute", for example + * "application/name" vs "application/backupAgent". + * @param className The fully qualified name of the base class of the attribute. + * @param mandatory True if this attribute is mandatory, false if optional. + */ + private static void overrideClassName( + Map<String, ITextAttributeCreator> overrides, + String elementName, + final String className, + final boolean mandatory) { + if (elementName.indexOf('/') == -1) { + elementName = elementName + '/' + ANDROID_NAME_ATTR; + } + overrides.put(elementName, new ITextAttributeCreator() { @Override public TextAttributeDescriptor create(String xmlName, String nsUri, @@ -262,7 +300,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { xmlName, nsUri, attrInfo, - true /*mandatory */, + mandatory, true /*defaultToProjectOnly*/); } else if (SdkConstants.CLASS_BROADCASTRECEIVER.equals(className)) { return new ClassAttributeDescriptor( @@ -271,7 +309,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { xmlName, nsUri, attrInfo, - true /*mandatory */, + mandatory, true /*defaultToProjectOnly*/); } else if (SdkConstants.CLASS_INSTRUMENTATION.equals(className)) { return new ClassAttributeDescriptor( @@ -280,7 +318,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { xmlName, nsUri, attrInfo, - true /*mandatory */, + mandatory, false /*defaultToProjectOnly*/); } else { return new ClassAttributeDescriptor( @@ -288,7 +326,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { xmlName, nsUri, attrInfo, - true /*mandatory */); + mandatory); } } }); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/ApplicationAttributeDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/ApplicationAttributeDescriptor.java deleted file mode 100644 index 4f41ac2..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/ApplicationAttributeDescriptor.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.ide.eclipse.adt.internal.editors.manifest.descriptors; - -import com.android.ide.common.api.IAttributeInfo; -import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; -import com.android.ide.eclipse.adt.internal.editors.descriptors.ITextAttributeCreator; -import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; -import com.android.ide.eclipse.adt.internal.editors.manifest.model.UiClassAttributeNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -/** - * Describes an 'Application' class XML attribute. It is displayed by a - * {@link UiClassAttributeNode}, that restricts creation and selection to classes - * inheriting from android.app.Application. - * <p/> - * Used by the override for application/name in {@link AndroidManifestDescriptors}. - */ -public class ApplicationAttributeDescriptor extends TextAttributeDescriptor { - - /** - * Used by {@link DescriptorsUtils} to create instances of this descriptor. - */ - public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() { - @Override - public TextAttributeDescriptor create(String xmlLocalName, - String nsUri, IAttributeInfo attrInfo) { - return new ApplicationAttributeDescriptor( - xmlLocalName, nsUri, attrInfo); - } - }; - - private ApplicationAttributeDescriptor(String xmlLocalName, String nsUri, - IAttributeInfo attrInfo) { - super(xmlLocalName, nsUri, attrInfo); - } - - /** - * @return A new {@link UiClassAttributeNode} linked to this descriptor. - */ - @Override - public UiAttributeNode createUiNode(UiElementNode uiParent) { - return new UiClassAttributeNode("android.app.Application", //$NON-NLS-1$ - null /* postCreationAction */, false /* mandatory */, this, uiParent, - true /*defaultToProjectOnly*/); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java index 447f6de..03db189 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java @@ -68,6 +68,8 @@ public class DescriptorsUtilsTest extends TestCase { assertEquals("SDK version", DescriptorsUtils.prettyAttributeUiName("sdkVersion")); assertEquals("IME action method", DescriptorsUtils.prettyAttributeUiName("imeActionMethod")); + assertEquals("VM safe mode", DescriptorsUtils.prettyAttributeUiName("vmSafeMode")); + assertEquals("UI options", DescriptorsUtils.prettyAttributeUiName("uiOptions")); } public void testCapitalize() { @@ -96,6 +98,8 @@ public class DescriptorsUtilsTest extends TestCase { assertEquals("URI Permission", DescriptorsUtils.capitalize("uriPermission")); assertEquals("SDK Version", DescriptorsUtils.capitalize("sdkVersion")); assertEquals("Grant IME", DescriptorsUtils.capitalize("GrantIme")); + assertEquals("VM Safe Mode", DescriptorsUtils.capitalize("vmSafeMode")); + assertEquals("UI Options", DescriptorsUtils.capitalize("uiOptions")); } public void testFormatTooltip() { |