diff options
author | Tor Norbye <tnorbye@google.com> | 2013-01-04 16:15:05 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-01-04 16:16:21 -0800 |
commit | 5a56f60c78b0cff7867d9708fb0033f9f4f53211 (patch) | |
tree | 9255d4e425fc8536e3c3d5e25097f4c157c423da /eclipse/plugins | |
parent | abfe6840b8d6120c89f066d2a64ff31174b12bcd (diff) | |
download | sdk-5a56f60c78b0cff7867d9708fb0033f9f4f53211.zip sdk-5a56f60c78b0cff7867d9708fb0033f9f4f53211.tar.gz sdk-5a56f60c78b0cff7867d9708fb0033f9f4f53211.tar.bz2 |
Fix attribute validation
This is used when incrementally validating XML attributes
when a file is saved in the IDE.
Change-Id: I37d37ab8ac64aec72455c3bfbabc7bbd65595a94
Diffstat (limited to 'eclipse/plugins')
2 files changed, 23 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java index be928b0..e246975 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java @@ -20,6 +20,7 @@ import static com.android.SdkConstants.ANDROID_PREFIX; import static com.android.SdkConstants.ANDROID_THEME_PREFIX; import static com.android.SdkConstants.ID_PREFIX; import static com.android.SdkConstants.NEW_ID_PREFIX; +import static com.android.SdkConstants.PREFIX_THEME_REF; import static com.android.SdkConstants.VALUE_FALSE; import static com.android.SdkConstants.VALUE_TRUE; import static com.android.ide.common.api.IAttributeInfo.Format.BOOLEAN; @@ -211,6 +212,11 @@ public class AttributeInfo implements IAttributeInfo { // All other formats require a nonempty string if (value.isEmpty()) { + // Except for flags + if (mFormats.contains(FLAG)) { + return true; + } + return false; } char first = value.charAt(0); @@ -262,6 +268,14 @@ public class AttributeInfo implements IAttributeInfo { //String name = url.substring(nameBegin); return true; } + } else if (value.startsWith(PREFIX_THEME_REF)) { + if (projectResources != null) { + return projectResources.hasResourceItem(ResourceType.ATTR, + value.substring(PREFIX_THEME_REF.length())); + } else { + // Until proven otherwise + return true; + } } } @@ -290,7 +304,7 @@ public class AttributeInfo implements IAttributeInfo { } if (mFormats.contains(BOOLEAN)) { - if (value.equals(VALUE_TRUE) || value.equals(VALUE_FALSE)) { + if (value.equalsIgnoreCase(VALUE_TRUE) || value.equalsIgnoreCase(VALUE_FALSE)) { return true; } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttributeInfoTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttributeInfoTest.java index cde12e5..b562922 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttributeInfoTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttributeInfoTest.java @@ -35,6 +35,8 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.common.io.Files; +import junit.framework.TestCase; + import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -47,8 +49,6 @@ import java.util.EnumSet; import java.util.Map; import java.util.Set; -import junit.framework.TestCase; - @SuppressWarnings("javadoc") public class AttributeInfoTest extends TestCase { public void testSimple() throws Exception { @@ -70,7 +70,10 @@ public class AttributeInfoTest extends TestCase { assertTrue(info.isValid("true", null, null)); assertTrue(info.isValid("false", null, null)); assertFalse(info.isValid("", null, null)); - assertFalse(info.isValid("TRUE", null, null)); + assertTrue(info.isValid("TRUE", null, null)); + assertTrue(info.isValid("True", null, null)); + assertTrue(info.isValid("FALSE", null, null)); + assertTrue(info.isValid("False", null, null)); } public void testIsValidInteger() throws Exception { @@ -160,6 +163,7 @@ public class AttributeInfoTest extends TestCase { assertTrue(info.isValid("@animator/foo", null, null)); assertTrue(info.isValid("@anim/foo", null, null)); assertTrue(info.isValid("?android:attr/textAppearanceMedium", null, null)); + assertTrue(info.isValid("?textAppearanceMedium", null, null)); assertFalse(info.isValid("", null, null)); assertFalse(info.isValid("foo", null, null)); @@ -182,8 +186,8 @@ public class AttributeInfoTest extends TestCase { assertTrue(info.isValid("left", null, null)); assertTrue(info.isValid("top", null, null)); assertTrue(info.isValid("left|top", null, null)); + assertTrue(info.isValid("", null, null)); - assertFalse(info.isValid("", null, null)); assertFalse(info.isValid("other", null, null)); assertFalse(info.isValid("50", null, null)); } |