OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.internal.task; | 14 package com.google.dart.engine.internal.task; |
15 | 15 |
16 import com.google.dart.engine.context.AnalysisException; | 16 import com.google.dart.engine.context.AnalysisException; |
| 17 import com.google.dart.engine.error.AnalysisError; |
| 18 import com.google.dart.engine.html.ast.HtmlScriptTagNode; |
17 import com.google.dart.engine.html.ast.HtmlUnit; | 19 import com.google.dart.engine.html.ast.HtmlUnit; |
18 import com.google.dart.engine.html.ast.XmlAttributeNode; | 20 import com.google.dart.engine.html.ast.XmlAttributeNode; |
19 import com.google.dart.engine.html.ast.XmlTagNode; | |
20 import com.google.dart.engine.html.ast.visitor.RecursiveXmlVisitor; | 21 import com.google.dart.engine.html.ast.visitor.RecursiveXmlVisitor; |
21 import com.google.dart.engine.html.parser.HtmlParseResult; | 22 import com.google.dart.engine.html.parser.HtmlParseResult; |
22 import com.google.dart.engine.html.parser.HtmlParser; | 23 import com.google.dart.engine.html.parser.HtmlParser; |
23 import com.google.dart.engine.html.scanner.HtmlScanResult; | 24 import com.google.dart.engine.html.scanner.HtmlScanResult; |
24 import com.google.dart.engine.html.scanner.HtmlScanner; | 25 import com.google.dart.engine.html.scanner.HtmlScanner; |
25 import com.google.dart.engine.internal.context.InternalAnalysisContext; | 26 import com.google.dart.engine.internal.context.InternalAnalysisContext; |
| 27 import com.google.dart.engine.internal.context.RecordingErrorListener; |
26 import com.google.dart.engine.source.Source; | 28 import com.google.dart.engine.source.Source; |
27 import com.google.dart.engine.utilities.source.LineInfo; | 29 import com.google.dart.engine.utilities.source.LineInfo; |
28 | 30 |
29 import java.net.URI; | 31 import java.net.URI; |
30 import java.net.URISyntaxException; | 32 import java.net.URISyntaxException; |
31 import java.util.ArrayList; | 33 import java.util.ArrayList; |
32 | 34 |
33 /** | 35 /** |
34 * Instances of the class {@code ParseHtmlTask} parse a specific source as an HT
ML file. | 36 * Instances of the class {@code ParseHtmlTask} parse a specific source as an HT
ML file. |
35 */ | 37 */ |
(...skipping 12 matching lines...) Expand all Loading... |
48 * The line information that was produced. | 50 * The line information that was produced. |
49 */ | 51 */ |
50 private LineInfo lineInfo; | 52 private LineInfo lineInfo; |
51 | 53 |
52 /** | 54 /** |
53 * The HTML unit that was produced by parsing the source. | 55 * The HTML unit that was produced by parsing the source. |
54 */ | 56 */ |
55 private HtmlUnit unit; | 57 private HtmlUnit unit; |
56 | 58 |
57 /** | 59 /** |
| 60 * The errors that were produced by scanning and parsing the source. |
| 61 */ |
| 62 private AnalysisError[] errors = AnalysisError.NO_ERRORS; |
| 63 |
| 64 /** |
58 * An array containing the sources of the libraries that are referenced within
the HTML. | 65 * An array containing the sources of the libraries that are referenced within
the HTML. |
59 */ | 66 */ |
60 private Source[] referencedLibraries = Source.EMPTY_ARRAY; | 67 private Source[] referencedLibraries = Source.EMPTY_ARRAY; |
61 | 68 |
62 /** | 69 /** |
63 * The name of the 'src' attribute in a HTML tag. | 70 * The name of the 'src' attribute in a HTML tag. |
64 */ | 71 */ |
65 private static final String ATTRIBUTE_SRC = "src"; | 72 private static final String ATTRIBUTE_SRC = "src"; |
66 | 73 |
67 /** | 74 /** |
(...skipping 22 matching lines...) Expand all Loading... |
90 super(context); | 97 super(context); |
91 this.source = source; | 98 this.source = source; |
92 } | 99 } |
93 | 100 |
94 @Override | 101 @Override |
95 public <E> E accept(AnalysisTaskVisitor<E> visitor) throws AnalysisException { | 102 public <E> E accept(AnalysisTaskVisitor<E> visitor) throws AnalysisException { |
96 return visitor.visitParseHtmlTask(this); | 103 return visitor.visitParseHtmlTask(this); |
97 } | 104 } |
98 | 105 |
99 /** | 106 /** |
| 107 * Return the errors that were produced by scanning and parsing the source, or
{@code null} if the |
| 108 * task has not yet been performed or if an exception occurred. |
| 109 * |
| 110 * @return the errors that were produced by scanning and parsing the source |
| 111 */ |
| 112 public AnalysisError[] getErrors() { |
| 113 return errors; |
| 114 } |
| 115 |
| 116 /** |
100 * Return the HTML unit that was produced by parsing the source. | 117 * Return the HTML unit that was produced by parsing the source. |
101 * | 118 * |
102 * @return the HTML unit that was produced by parsing the source | 119 * @return the HTML unit that was produced by parsing the source |
103 */ | 120 */ |
104 public HtmlUnit getHtmlUnit() { | 121 public HtmlUnit getHtmlUnit() { |
105 return unit; | 122 return unit; |
106 } | 123 } |
107 | 124 |
108 /** | 125 /** |
109 * Return the line information that was produced, or {@code null} if the task
has not yet been | 126 * Return the line information that was produced, or {@code null} if the task
has not yet been |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 protected void internalPerform() throws AnalysisException { | 172 protected void internalPerform() throws AnalysisException { |
156 HtmlScanner scanner = new HtmlScanner(source); | 173 HtmlScanner scanner = new HtmlScanner(source); |
157 try { | 174 try { |
158 source.getContents(scanner); | 175 source.getContents(scanner); |
159 } catch (Exception exception) { | 176 } catch (Exception exception) { |
160 throw new AnalysisException(exception); | 177 throw new AnalysisException(exception); |
161 } | 178 } |
162 HtmlScanResult scannerResult = scanner.getResult(); | 179 HtmlScanResult scannerResult = scanner.getResult(); |
163 modificationTime = scannerResult.getModificationTime(); | 180 modificationTime = scannerResult.getModificationTime(); |
164 lineInfo = new LineInfo(scannerResult.getLineStarts()); | 181 lineInfo = new LineInfo(scannerResult.getLineStarts()); |
165 HtmlParseResult result = new HtmlParser(source).parse(scannerResult); | 182 final RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 183 HtmlParseResult result = new HtmlParser(source, errorListener).parse(scanner
Result); |
166 unit = result.getHtmlUnit(); | 184 unit = result.getHtmlUnit(); |
| 185 errors = errorListener.getErrors(source); |
167 referencedLibraries = getLibrarySources(); | 186 referencedLibraries = getLibrarySources(); |
168 } | 187 } |
169 | 188 |
170 /** | 189 /** |
171 * Return the sources of libraries that are referenced in the specified HTML f
ile. | 190 * Return the sources of libraries that are referenced in the specified HTML f
ile. |
172 * | 191 * |
173 * @return the sources of libraries that are referenced in the HTML file | 192 * @return the sources of libraries that are referenced in the HTML file |
174 */ | 193 */ |
175 private Source[] getLibrarySources() { | 194 private Source[] getLibrarySources() { |
176 final ArrayList<Source> libraries = new ArrayList<Source>(); | 195 final ArrayList<Source> libraries = new ArrayList<Source>(); |
177 unit.accept(new RecursiveXmlVisitor<Void>() { | 196 unit.accept(new RecursiveXmlVisitor<Void>() { |
178 @Override | 197 @Override |
179 public Void visitXmlTagNode(XmlTagNode node) { | 198 public Void visitHtmlScriptTagNode(HtmlScriptTagNode node) { |
180 if (node.getTag().getLexeme().equalsIgnoreCase(TAG_SCRIPT)) { | 199 XmlAttributeNode scriptAttribute = null; |
181 boolean isDartScript = false; | 200 for (XmlAttributeNode attribute : node.getAttributes()) { |
182 XmlAttributeNode scriptAttribute = null; | 201 if (attribute.getName().getLexeme().equalsIgnoreCase(ATTRIBUTE_SRC)) { |
183 for (XmlAttributeNode attribute : node.getAttributes()) { | 202 scriptAttribute = attribute; |
184 if (attribute.getName().getLexeme().equalsIgnoreCase(ATTRIBUTE_SRC))
{ | |
185 scriptAttribute = attribute; | |
186 } else if (attribute.getName().getLexeme().equalsIgnoreCase(ATTRIBUT
E_TYPE)) { | |
187 if (attribute.getText().equalsIgnoreCase(TYPE_DART)) { | |
188 isDartScript = true; | |
189 } | |
190 } | |
191 } | |
192 if (isDartScript && scriptAttribute != null) { | |
193 try { | |
194 URI uri = new URI(null, null, scriptAttribute.getText(), null); | |
195 String fileName = uri.getPath(); | |
196 Source librarySource = getContext().getSourceFactory().resolveUri(
source, fileName); | |
197 if (librarySource != null && librarySource.exists()) { | |
198 libraries.add(librarySource); | |
199 } | |
200 } catch (URISyntaxException e) { | |
201 // ignored - invalid URI reported during resolution phase | |
202 } | |
203 } | 203 } |
204 } | 204 } |
205 return super.visitXmlTagNode(node); | 205 if (scriptAttribute != null) { |
| 206 try { |
| 207 URI uri = new URI(null, null, scriptAttribute.getText(), null); |
| 208 String fileName = uri.getPath(); |
| 209 Source librarySource = getContext().getSourceFactory().resolveUri(so
urce, fileName); |
| 210 if (librarySource != null && librarySource.exists()) { |
| 211 libraries.add(librarySource); |
| 212 } |
| 213 } catch (URISyntaxException e) { |
| 214 // ignored - invalid URI reported during resolution phase |
| 215 } |
| 216 } |
| 217 return super.visitHtmlScriptTagNode(node); |
206 } | 218 } |
207 }); | 219 }); |
208 if (libraries.isEmpty()) { | 220 if (libraries.isEmpty()) { |
209 return Source.EMPTY_ARRAY; | 221 return Source.EMPTY_ARRAY; |
210 } | 222 } |
211 return libraries.toArray(new Source[libraries.size()]); | 223 return libraries.toArray(new Source[libraries.size()]); |
212 } | 224 } |
213 } | 225 } |
OLD | NEW |