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.ast.CompilationUnit; |
| 17 import com.google.dart.engine.ast.Directive; |
| 18 import com.google.dart.engine.ast.ExportDirective; |
| 19 import com.google.dart.engine.ast.ImportDirective; |
| 20 import com.google.dart.engine.ast.PartDirective; |
| 21 import com.google.dart.engine.context.AnalysisContext; |
16 import com.google.dart.engine.context.AnalysisException; | 22 import com.google.dart.engine.context.AnalysisException; |
17 import com.google.dart.engine.error.AnalysisError; | 23 import com.google.dart.engine.error.AnalysisError; |
| 24 import com.google.dart.engine.error.AnalysisErrorListener; |
18 import com.google.dart.engine.html.ast.HtmlScriptTagNode; | 25 import com.google.dart.engine.html.ast.HtmlScriptTagNode; |
19 import com.google.dart.engine.html.ast.HtmlUnit; | 26 import com.google.dart.engine.html.ast.HtmlUnit; |
20 import com.google.dart.engine.html.ast.XmlAttributeNode; | 27 import com.google.dart.engine.html.ast.XmlAttributeNode; |
21 import com.google.dart.engine.html.ast.visitor.RecursiveXmlVisitor; | 28 import com.google.dart.engine.html.ast.visitor.RecursiveXmlVisitor; |
22 import com.google.dart.engine.html.parser.HtmlParser; | 29 import com.google.dart.engine.html.parser.HtmlParser; |
23 import com.google.dart.engine.html.scanner.AbstractScanner; | 30 import com.google.dart.engine.html.scanner.AbstractScanner; |
24 import com.google.dart.engine.html.scanner.StringScanner; | 31 import com.google.dart.engine.html.scanner.StringScanner; |
25 import com.google.dart.engine.html.scanner.Token; | 32 import com.google.dart.engine.html.scanner.Token; |
26 import com.google.dart.engine.internal.context.InternalAnalysisContext; | 33 import com.google.dart.engine.internal.context.InternalAnalysisContext; |
27 import com.google.dart.engine.internal.context.RecordingErrorListener; | 34 import com.google.dart.engine.internal.context.RecordingErrorListener; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return "parse as html " + source.getFullName(); | 174 return "parse as html " + source.getFullName(); |
168 } | 175 } |
169 | 176 |
170 @Override | 177 @Override |
171 protected void internalPerform() throws AnalysisException { | 178 protected void internalPerform() throws AnalysisException { |
172 try { | 179 try { |
173 AbstractScanner scanner = new StringScanner(source, content); | 180 AbstractScanner scanner = new StringScanner(source, content); |
174 scanner.setPassThroughElements(new String[] {TAG_SCRIPT}); | 181 scanner.setPassThroughElements(new String[] {TAG_SCRIPT}); |
175 Token token = scanner.tokenize(); | 182 Token token = scanner.tokenize(); |
176 lineInfo = new LineInfo(scanner.getLineStarts()); | 183 lineInfo = new LineInfo(scanner.getLineStarts()); |
177 RecordingErrorListener errorListener = new RecordingErrorListener(); | 184 final RecordingErrorListener errorListener = new RecordingErrorListener(); |
178 unit = new HtmlParser(source, errorListener).parse(token, lineInfo); | 185 unit = new HtmlParser(source, errorListener).parse(token, lineInfo); |
| 186 unit.accept(new RecursiveXmlVisitor<Void>() { |
| 187 @Override |
| 188 public Void visitHtmlScriptTagNode(HtmlScriptTagNode node) { |
| 189 resolveScriptDirectives(node.getScript(), errorListener); |
| 190 return null; |
| 191 } |
| 192 }); |
179 errors = errorListener.getErrorsForSource(source); | 193 errors = errorListener.getErrorsForSource(source); |
180 referencedLibraries = getLibrarySources(); | 194 referencedLibraries = getLibrarySources(); |
181 } catch (Exception exception) { | 195 } catch (Exception exception) { |
182 throw new AnalysisException(exception); | 196 throw new AnalysisException(exception); |
183 } | 197 } |
184 } | 198 } |
185 | 199 |
186 /** | 200 /** |
187 * Return the sources of libraries that are referenced in the specified HTML f
ile. | 201 * Return the sources of libraries that are referenced in the specified HTML f
ile. |
188 * | 202 * |
(...skipping 23 matching lines...) Expand all Loading... |
212 } | 226 } |
213 } | 227 } |
214 return super.visitHtmlScriptTagNode(node); | 228 return super.visitHtmlScriptTagNode(node); |
215 } | 229 } |
216 }); | 230 }); |
217 if (libraries.isEmpty()) { | 231 if (libraries.isEmpty()) { |
218 return Source.EMPTY_ARRAY; | 232 return Source.EMPTY_ARRAY; |
219 } | 233 } |
220 return libraries.toArray(new Source[libraries.size()]); | 234 return libraries.toArray(new Source[libraries.size()]); |
221 } | 235 } |
| 236 |
| 237 /** |
| 238 * Resolves directives in the given {@link CompilationUnit}. |
| 239 */ |
| 240 private void resolveScriptDirectives(CompilationUnit script, AnalysisErrorList
ener errorListener) { |
| 241 if (script == null) { |
| 242 return; |
| 243 } |
| 244 AnalysisContext analysisContext = getContext(); |
| 245 for (Directive directive : script.getDirectives()) { |
| 246 if (directive instanceof ExportDirective) { |
| 247 ParseDartTask.resolveSource( |
| 248 analysisContext, |
| 249 source, |
| 250 (ExportDirective) directive, |
| 251 errorListener); |
| 252 } else if (directive instanceof ImportDirective) { |
| 253 ParseDartTask.resolveSource( |
| 254 analysisContext, |
| 255 source, |
| 256 (ImportDirective) directive, |
| 257 errorListener); |
| 258 } else if (directive instanceof PartDirective) { |
| 259 ParseDartTask.resolveSource( |
| 260 analysisContext, |
| 261 source, |
| 262 (PartDirective) directive, |
| 263 errorListener); |
| 264 } |
| 265 } |
| 266 } |
222 } | 267 } |
OLD | NEW |