diff options
author | Tor Norbye <tnorbye@google.com> | 2012-09-19 09:09:57 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-09-20 10:21:13 -0700 |
commit | f48bde52e60fefec0763cad1b45bc1dcd1bf0841 (patch) | |
tree | 160870cc163cb2a7fc7411b27baf93ae2206dc77 /sdk_common/src/com/android/ide/common/resources/ScanningContext.java | |
parent | 0be1d50d12ff9f241c2d9afc9e62da7f323aae5b (diff) | |
download | sdk-f48bde52e60fefec0763cad1b45bc1dcd1bf0841.zip sdk-f48bde52e60fefec0763cad1b45bc1dcd1bf0841.tar.gz sdk-f48bde52e60fefec0763cad1b45bc1dcd1bf0841.tar.bz2 |
Validate user edits in XML files
Around ADT 15 or so we introduced a bunch of optimizations to run AAPT
much less frequently, since with large projects it can take a long
time, and end up blocking the UI if you try to save twice.
Unfortunately, one side effect of this change is that if you edit only
the *value* of an attribute, we will not re-run aapt, which means
that if you set the value to a bogus value, you will get no error
message until the next time AAPT runs (usually when you try to run).
This changeset fixes this. We already have the attribute metadata
which aapt uses, so now, when an XML file is changed and saved, we
process it with an XML pull parser, and validate all the Android
namespace attributes. If any are found to not be correct, then we
request a full AAPT process, which will then display errors as
appropriate.
Change-Id: I374c19648e29c27c6d82616b3ee602cb2343cd3a
Diffstat (limited to 'sdk_common/src/com/android/ide/common/resources/ScanningContext.java')
-rw-r--r-- | sdk_common/src/com/android/ide/common/resources/ScanningContext.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sdk_common/src/com/android/ide/common/resources/ScanningContext.java b/sdk_common/src/com/android/ide/common/resources/ScanningContext.java index e4ed275..43561e8 100644 --- a/sdk_common/src/com/android/ide/common/resources/ScanningContext.java +++ b/sdk_common/src/com/android/ide/common/resources/ScanningContext.java @@ -15,6 +15,9 @@ */ package com.android.ide.common.resources; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; + import java.util.ArrayList; import java.util.List; @@ -24,7 +27,7 @@ import java.util.List; * so on. */ public class ScanningContext { - private final ResourceRepository mRepository; + protected final ResourceRepository mRepository; private boolean mNeedsFullAapt; private List<String> mErrors = null; @@ -33,7 +36,7 @@ public class ScanningContext { * * @param repository the associated resource repository */ - public ScanningContext(ResourceRepository repository) { + public ScanningContext(@NonNull ResourceRepository repository) { super(); mRepository = repository; } @@ -43,6 +46,7 @@ public class ScanningContext { * * @return a list of errors encountered during scanning (or null) */ + @Nullable public List<String> getErrors() { return mErrors; } @@ -55,7 +59,7 @@ public class ScanningContext { * @param error the error message, including file name and line number at * the beginning */ - public void addError(String error) { + public void addError(@NonNull String error) { if (mErrors == null) { mErrors = new ArrayList<String>(); } @@ -67,6 +71,7 @@ public class ScanningContext { * * @return the associated repository, never null */ + @NonNull public ResourceRepository getRepository() { return mRepository; } @@ -89,4 +94,17 @@ public class ScanningContext { public boolean needsFullAapt() { return mNeedsFullAapt; } + + /** + * Asks the context to check whether the given attribute name and value is valid + * in this context. + * + * @param uri the XML namespace URI + * @param name the attribute local name + * @param value the attribute value + * @return true if the attribute is valid + */ + public boolean checkValue(@Nullable String uri, @NonNull String name, @NonNull String value) { + return true; + } } |