diff options
author | Tor Norbye <tnorbye@google.com> | 2013-01-09 17:39:33 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-01-14 16:49:35 -0800 |
commit | 8ba74eb4d7278424e9b9be2e009345208e721c39 (patch) | |
tree | dc03f3fc5bb91880814a15aee1e0145d996f3ac9 | |
parent | 918a4e76e93c4786dbf37c16355c99e52b4bcd66 (diff) | |
download | sdk-8ba74eb4d7278424e9b9be2e009345208e721c39.zip sdk-8ba74eb4d7278424e9b9be2e009345208e721c39.tar.gz sdk-8ba74eb4d7278424e9b9be2e009345208e721c39.tar.bz2 |
Improve warning message when comment preceedes XML prologue
Change-Id: I44e274c0f32e37a8a3cb1b4d64c0bb5af1df9659
-rw-r--r-- | lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java b/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java index 3e1408a..bfbe7cb 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java +++ b/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java @@ -42,9 +42,10 @@ import java.io.UnsupportedEncodingException; public class LintCliXmlParser extends PositionXmlParser implements IDomParser { @Override public Document parseXml(@NonNull XmlContext context) { + String xml = null; try { // Do we need to provide an input stream for encoding? - String xml = context.getContents(); + xml = context.getContents(); if (xml != null) { return super.parse(xml); } @@ -57,12 +58,23 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { e.getLocalizedMessage(), null); } catch (SAXException e) { + Location location = Location.create(context.file); + String message = e.getCause() != null ? e.getCause().getLocalizedMessage() : + e.getLocalizedMessage(); + if (message.startsWith("The processing instruction target matching " + + "\"[xX][mM][lL]\" is not allowed.")) { + int prologue = xml.indexOf("<?xml "); + int comment = xml.indexOf("<!--"); + if (prologue != -1 && comment != -1 && comment < prologue) { + message = "The XML prologue should appear before, not after, the first XML " + + "header/copyright comment. " + message; + } + } context.report( // Must provide an issue since API guarantees that the issue parameter // is valid - IssueRegistry.PARSER_ERROR, Location.create(context.file), - e.getCause() != null ? e.getCause().getLocalizedMessage() : - e.getLocalizedMessage(), + IssueRegistry.PARSER_ERROR, location, + message, null); } catch (Throwable t) { context.log(t, null); |