Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/task/ParseDartTask.java

Issue 214603014: Trunk CL for r=34540 (Closed) Base URL: https://dart.googlecode.com/svn/trunk/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/task/ParseHtmlTask.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 28 matching lines...) Expand all
39 39
40 import java.net.URI; 40 import java.net.URI;
41 import java.net.URISyntaxException; 41 import java.net.URISyntaxException;
42 import java.util.HashSet; 42 import java.util.HashSet;
43 43
44 /** 44 /**
45 * Instances of the class {@code ParseDartTask} parse a specific source as a Dar t file. 45 * Instances of the class {@code ParseDartTask} parse a specific source as a Dar t file.
46 */ 46 */
47 public class ParseDartTask extends AnalysisTask { 47 public class ParseDartTask extends AnalysisTask {
48 /** 48 /**
49 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
50 * given library, or {@code null} if the URI is not valid.
51 *
52 * @param context the context in which the resolution is to be performed
53 * @param librarySource the source representing the library containing the dir ective
54 * @param directive the directive which URI should be resolved
55 * @param errorListener the error listener to which errors should be reported
56 * @return the result of resolving the URI against the URI of the library
57 */
58 public static Source resolveSource(AnalysisContext analysisContext, Source lib rarySource,
59 UriBasedDirective directive, AnalysisErrorListener errorListener) {
60 StringLiteral uriLiteral = directive.getUri();
61 if (uriLiteral instanceof StringInterpolation) {
62 errorListener.onError(new AnalysisError(
63 librarySource,
64 uriLiteral.getOffset(),
65 uriLiteral.getLength(),
66 CompileTimeErrorCode.URI_WITH_INTERPOLATION));
67 return null;
68 }
69 String uriContent = uriLiteral.getStringValue().trim();
70 directive.setUriContent(uriContent);
71 if (directive instanceof ImportDirective && uriContent.startsWith(DART_EXT_S CHEME)) {
72 return null;
73 }
74 try {
75 String encodedUriContent = UriUtilities.encode(uriContent);
76 new URI(encodedUriContent);
77 Source source = analysisContext.getSourceFactory().resolveUri(
78 librarySource,
79 encodedUriContent);
80 if (!analysisContext.exists(source)) {
81 errorListener.onError(new AnalysisError(
82 librarySource,
83 uriLiteral.getOffset(),
84 uriLiteral.getLength(),
85 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
86 uriContent));
87 }
88 directive.setSource(source);
89 return source;
90 } catch (URISyntaxException exception) {
91 errorListener.onError(new AnalysisError(
92 librarySource,
93 uriLiteral.getOffset(),
94 uriLiteral.getLength(),
95 CompileTimeErrorCode.INVALID_URI,
96 uriContent));
97 }
98 return null;
99 }
100
101 /**
49 * The source to be parsed. 102 * The source to be parsed.
50 */ 103 */
51 private Source source; 104 private Source source;
52 105
53 /** 106 /**
54 * The time at which the contents of the source were last modified. 107 * The time at which the contents of the source were last modified.
55 */ 108 */
56 private long modificationTime; 109 private long modificationTime;
57 110
58 /** 111 /**
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // 292 //
240 // Then parse the token stream. 293 // Then parse the token stream.
241 // 294 //
242 TimeCounterHandle timeCounterParse = PerformanceStatistics.parse.start(); 295 TimeCounterHandle timeCounterParse = PerformanceStatistics.parse.start();
243 try { 296 try {
244 final RecordingErrorListener errorListener = new RecordingErrorListener(); 297 final RecordingErrorListener errorListener = new RecordingErrorListener();
245 Parser parser = new Parser(source, errorListener); 298 Parser parser = new Parser(source, errorListener);
246 parser.setParseFunctionBodies(getContext().getAnalysisOptions().getAnalyze FunctionBodies()); 299 parser.setParseFunctionBodies(getContext().getAnalysisOptions().getAnalyze FunctionBodies());
247 unit = parser.parseCompilationUnit(tokenStream); 300 unit = parser.parseCompilationUnit(tokenStream);
248 unit.setLineInfo(lineInfo); 301 unit.setLineInfo(lineInfo);
302 AnalysisContext analysisContext = getContext();
249 for (Directive directive : unit.getDirectives()) { 303 for (Directive directive : unit.getDirectives()) {
250 if (directive instanceof PartOfDirective) { 304 if (directive instanceof PartOfDirective) {
251 containsPartOfDirective = true; 305 containsPartOfDirective = true;
252 } else { 306 } else {
253 containsNonPartOfDirective = true; 307 containsNonPartOfDirective = true;
254 if (directive instanceof ExportDirective) { 308 if (directive instanceof ExportDirective) {
255 Source exportSource = resolveSource(source, (ExportDirective) direct ive, errorListener); 309 Source exportSource = resolveSource(
310 analysisContext,
311 source,
312 (ExportDirective) directive,
313 errorListener);
256 if (exportSource != null) { 314 if (exportSource != null) {
257 exportedSources.add(exportSource); 315 exportedSources.add(exportSource);
258 } 316 }
259 } else if (directive instanceof ImportDirective) { 317 } else if (directive instanceof ImportDirective) {
260 Source importSource = resolveSource(source, (ImportDirective) direct ive, errorListener); 318 Source importSource = resolveSource(
319 analysisContext,
320 source,
321 (ImportDirective) directive,
322 errorListener);
261 if (importSource != null) { 323 if (importSource != null) {
262 importedSources.add(importSource); 324 importedSources.add(importSource);
263 } 325 }
264 } else if (directive instanceof PartDirective) { 326 } else if (directive instanceof PartDirective) {
265 Source partSource = resolveSource(source, (PartDirective) directive, errorListener); 327 Source partSource = resolveSource(
328 analysisContext,
329 source,
330 (PartDirective) directive,
331 errorListener);
266 if (partSource != null && !partSource.equals(source)) { 332 if (partSource != null && !partSource.equals(source)) {
267 includedSources.add(partSource); 333 includedSources.add(partSource);
268 } 334 }
269 } 335 }
270 } 336 }
271 } 337 }
272 errors = errorListener.getErrorsForSource(source); 338 errors = errorListener.getErrorsForSource(source);
273 } finally { 339 } finally {
274 timeCounterParse.stop(); 340 timeCounterParse.stop();
275 } 341 }
276 } 342 }
277 343
278 /** 344 /**
279 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
280 * given library, or {@code null} if the URI is not valid.
281 *
282 * @param librarySource the source representing the library containing the dir ective
283 * @param directive the directive which URI should be resolved
284 * @param errorListener the error listener to which errors should be reported
285 * @return the result of resolving the URI against the URI of the library
286 */
287 private Source resolveSource(Source librarySource, UriBasedDirective directive ,
288 AnalysisErrorListener errorListener) {
289 StringLiteral uriLiteral = directive.getUri();
290 if (uriLiteral instanceof StringInterpolation) {
291 errorListener.onError(new AnalysisError(
292 librarySource,
293 uriLiteral.getOffset(),
294 uriLiteral.getLength(),
295 CompileTimeErrorCode.URI_WITH_INTERPOLATION));
296 return null;
297 }
298 String uriContent = uriLiteral.getStringValue().trim();
299 directive.setUriContent(uriContent);
300 if (directive instanceof ImportDirective && uriContent.startsWith(DART_EXT_S CHEME)) {
301 return null;
302 }
303 try {
304 String encodedUriContent = UriUtilities.encode(uriContent);
305 new URI(encodedUriContent);
306 AnalysisContext analysisContext = getContext();
307 Source source = analysisContext.getSourceFactory().resolveUri(
308 librarySource,
309 encodedUriContent);
310 if (!analysisContext.exists(source)) {
311 errorListener.onError(new AnalysisError(
312 librarySource,
313 uriLiteral.getOffset(),
314 uriLiteral.getLength(),
315 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
316 uriContent));
317 }
318 directive.setSource(source);
319 return source;
320 } catch (URISyntaxException exception) {
321 errorListener.onError(new AnalysisError(
322 librarySource,
323 uriLiteral.getOffset(),
324 uriLiteral.getLength(),
325 CompileTimeErrorCode.INVALID_URI,
326 uriContent));
327 }
328 return null;
329 }
330
331 /**
332 * Efficiently convert the given set of sources to an array. 345 * Efficiently convert the given set of sources to an array.
333 * 346 *
334 * @param sources the set to be converted 347 * @param sources the set to be converted
335 * @return an array containing all of the sources in the given set 348 * @return an array containing all of the sources in the given set
336 */ 349 */
337 private Source[] toArray(HashSet<Source> sources) { 350 private Source[] toArray(HashSet<Source> sources) {
338 int size = sources.size(); 351 int size = sources.size();
339 if (size == 0) { 352 if (size == 0) {
340 return Source.EMPTY_ARRAY; 353 return Source.EMPTY_ARRAY;
341 } 354 }
342 return sources.toArray(new Source[size]); 355 return sources.toArray(new Source[size]);
343 } 356 }
344 } 357 }
OLDNEW
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/task/ParseHtmlTask.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698