diff options
2 files changed, 16 insertions, 1 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidator.java index 1838d14..2b07545 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidator.java @@ -92,7 +92,7 @@ public class ResourceNameValidator implements IInputValidator { // Resource names must be valid Java identifiers, since they will // be represented as Java identifiers in the R file: if (!Character.isJavaIdentifierStart(newText.charAt(0))) { - return "The layout name must begin with a character"; + return "The resource name must begin with a character"; } for (int i = 1, n = newText.length(); i < n; i++) { char c = newText.charAt(i); @@ -102,6 +102,12 @@ public class ResourceNameValidator implements IInputValidator { } if (mIsFileType) { + char first = newText.charAt(0); + if (!(first >= 'a' && first <= 'z')) { + return String.format( + "File-based resource names must start with a lowercase letter."); + } + // AAPT only allows lowercase+digits+_: // "%s: Invalid file name: must contain only [a-z0-9_.]"," for (int i = 0, n = newText.length(); i < n; i++) { diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidatorTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidatorTest.java index b771667..a5d34ec 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidatorTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidatorTest.java @@ -23,6 +23,7 @@ import java.util.Collections; import junit.framework.TestCase; +@SuppressWarnings("javadoc") public class ResourceNameValidatorTest extends TestCase { public void testValidator() throws Exception { // Valid @@ -47,5 +48,13 @@ public class ResourceNameValidatorTest extends TestCase { .isValid("Foo123_$") != null); assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT) .isValid("foo123_") == null); + + // Can't start with _ in file-based resource names, is okay for value based resources + assertTrue(ResourceNameValidator.create(true, ResourceFolderType.VALUES) + .isValid("_foo") == null); + assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT) + .isValid("_foo") != null); + assertTrue(ResourceNameValidator.create(true, ResourceFolderType.DRAWABLE) + .isValid("_foo") != null); } } |