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

Side by Side Diff: pkg/analyzer/lib/src/generated/engine.dart

Issue 830893003: Remove the Polymer support from the analyzer and analysis_server packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import "dart:math" as math; 10 import "dart:math" as math;
(...skipping 2439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 // The source kind is always valid, so the state isn't interesting. 2450 // The source kind is always valid, so the state isn't interesting.
2451 continue; 2451 continue;
2452 } else if (descriptor == DartEntry.CONTAINING_LIBRARIES) { 2452 } else if (descriptor == DartEntry.CONTAINING_LIBRARIES) {
2453 // The list of containing libraries is always valid, so the state 2453 // The list of containing libraries is always valid, so the state
2454 // isn't interesting. 2454 // isn't interesting.
2455 continue; 2455 continue;
2456 } else if (descriptor == DartEntry.PUBLIC_NAMESPACE) { 2456 } else if (descriptor == DartEntry.PUBLIC_NAMESPACE) {
2457 // The public namespace isn't computed by performAnalysisTask() 2457 // The public namespace isn't computed by performAnalysisTask()
2458 // and therefore isn't interesting. 2458 // and therefore isn't interesting.
2459 continue; 2459 continue;
2460 } else if (descriptor == HtmlEntry.POLYMER_BUILD_ERRORS ||
2461 descriptor == HtmlEntry.POLYMER_RESOLUTION_ERRORS) {
2462 // These values are not currently being computed, so their state is
2463 // not interesting.
2464 continue;
2465 } else if (descriptor == HtmlEntry.HINTS) { 2460 } else if (descriptor == HtmlEntry.HINTS) {
2466 // We are not currently recording any hints related to HTML. 2461 // We are not currently recording any hints related to HTML.
2467 continue; 2462 continue;
2468 } 2463 }
2469 callback( 2464 callback(
2470 source, 2465 source,
2471 sourceEntry, 2466 sourceEntry,
2472 descriptor, 2467 descriptor,
2473 sourceEntry.getState(descriptor)); 2468 sourceEntry.getState(descriptor));
2474 } 2469 }
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
3182 } 3177 }
3183 String content = htmlEntry.getValue(SourceEntry.CONTENT); 3178 String content = htmlEntry.getValue(SourceEntry.CONTENT);
3184 htmlEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); 3179 htmlEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED);
3185 htmlEntry.setState(HtmlEntry.PARSE_ERRORS, CacheState.IN_PROCESS); 3180 htmlEntry.setState(HtmlEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
3186 return new AnalysisContextImpl_TaskData( 3181 return new AnalysisContextImpl_TaskData(
3187 new ParseHtmlTask(this, source, content), 3182 new ParseHtmlTask(this, source, content),
3188 false); 3183 false);
3189 } 3184 }
3190 3185
3191 /** 3186 /**
3192 * Create a [PolymerBuildHtmlTask] for the given source, marking the Polymer e lements as
3193 * being in-process.
3194 *
3195 * @param source the source whose content is to be processed
3196 * @param htmlEntry the entry for the source
3197 * @return task data representing the created task
3198 */
3199 AnalysisContextImpl_TaskData _createPolymerBuildHtmlTask(Source source,
3200 HtmlEntry htmlEntry) {
3201 if (htmlEntry.getState(HtmlEntry.RESOLVED_UNIT) != CacheState.VALID) {
3202 return _createResolveHtmlTask(source, htmlEntry);
3203 }
3204 htmlEntry.setState(HtmlEntry.POLYMER_BUILD_ERRORS, CacheState.IN_PROCESS);
3205 return new AnalysisContextImpl_TaskData(
3206 new PolymerBuildHtmlTask(
3207 this,
3208 source,
3209 htmlEntry.getValue(SourceEntry.LINE_INFO),
3210 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT)),
3211 false);
3212 }
3213
3214 /**
3215 * Create a [PolymerResolveHtmlTask] for the given source, marking the Polymer errors as
3216 * being in-process.
3217 *
3218 * @param source the source whose content is to be resolved
3219 * @param htmlEntry the entry for the source
3220 * @return task data representing the created task
3221 */
3222 AnalysisContextImpl_TaskData _createPolymerResolveHtmlTask(Source source,
3223 HtmlEntry htmlEntry) {
3224 if (htmlEntry.getState(HtmlEntry.RESOLVED_UNIT) != CacheState.VALID) {
3225 return _createResolveHtmlTask(source, htmlEntry);
3226 }
3227 htmlEntry.setState(
3228 HtmlEntry.POLYMER_RESOLUTION_ERRORS,
3229 CacheState.IN_PROCESS);
3230 return new AnalysisContextImpl_TaskData(
3231 new PolymerResolveHtmlTask(
3232 this,
3233 source,
3234 htmlEntry.getValue(SourceEntry.LINE_INFO),
3235 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT)),
3236 false);
3237 }
3238
3239 /**
3240 * Create a [ResolveDartLibraryTask] for the given source, marking ? as being in-process. 3187 * Create a [ResolveDartLibraryTask] for the given source, marking ? as being in-process.
3241 * 3188 *
3242 * @param source the source whose content is to be resolved 3189 * @param source the source whose content is to be resolved
3243 * @param dartEntry the entry for the source 3190 * @param dartEntry the entry for the source
3244 * @return task data representing the created task 3191 * @return task data representing the created task
3245 */ 3192 */
3246 AnalysisContextImpl_TaskData _createResolveDartLibraryTask(Source source, 3193 AnalysisContextImpl_TaskData _createResolveDartLibraryTask(Source source,
3247 DartEntry dartEntry) { 3194 DartEntry dartEntry) {
3248 try { 3195 try {
3249 AnalysisContextImpl_CycleBuilder builder = 3196 AnalysisContextImpl_CycleBuilder builder =
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
3786 if (parsedUnit == null) { 3733 if (parsedUnit == null) {
3787 return _createParseHtmlTask(source, htmlEntry); 3734 return _createParseHtmlTask(source, htmlEntry);
3788 } 3735 }
3789 } 3736 }
3790 CacheState resolvedUnitState = 3737 CacheState resolvedUnitState =
3791 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); 3738 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT);
3792 if (resolvedUnitState == CacheState.INVALID || 3739 if (resolvedUnitState == CacheState.INVALID ||
3793 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { 3740 (isPriority && resolvedUnitState == CacheState.FLUSHED)) {
3794 return _createResolveHtmlTask(source, htmlEntry); 3741 return _createResolveHtmlTask(source, htmlEntry);
3795 } 3742 }
3796 //
3797 // Polymer support
3798 //
3799 if (_options.analyzePolymer) {
3800 // Build elements.
3801 CacheState polymerBuildErrorsState =
3802 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS);
3803 if (polymerBuildErrorsState == CacheState.INVALID ||
3804 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) {
3805 return _createPolymerBuildHtmlTask(source, htmlEntry);
3806 }
3807 // Resolve references.
3808 CacheState polymerResolutionErrorsState =
3809 htmlEntry.getState(HtmlEntry.POLYMER_RESOLUTION_ERRORS);
3810 if (polymerResolutionErrorsState == CacheState.INVALID ||
3811 (isPriority && polymerResolutionErrorsState == CacheState.FLUSHED)) {
3812 return _createPolymerResolveHtmlTask(source, htmlEntry);
3813 }
3814 }
3815 } 3743 }
3816 return new AnalysisContextImpl_TaskData(null, false); 3744 return new AnalysisContextImpl_TaskData(null, false);
3817 } 3745 }
3818 3746
3819 /** 3747 /**
3820 * Return a change notice for the given source, creating one if one does not a lready exist. 3748 * Return a change notice for the given source, creating one if one does not a lready exist.
3821 * 3749 *
3822 * @param source the source for which changes are being reported 3750 * @param source the source for which changes are being reported
3823 * @return a change notice for the given source 3751 * @return a change notice for the given source
3824 */ 3752 */
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
4014 sources.add(source); 3942 sources.add(source);
4015 return; 3943 return;
4016 } 3944 }
4017 CacheState resolvedUnitState = 3945 CacheState resolvedUnitState =
4018 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); 3946 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT);
4019 if (resolvedUnitState == CacheState.INVALID || 3947 if (resolvedUnitState == CacheState.INVALID ||
4020 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { 3948 (isPriority && resolvedUnitState == CacheState.FLUSHED)) {
4021 sources.add(source); 3949 sources.add(source);
4022 return; 3950 return;
4023 } 3951 }
4024 // Polymer
4025 if (_options.analyzePolymer) {
4026 // Elements building.
4027 CacheState polymerBuildErrorsState =
4028 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS);
4029 if (polymerBuildErrorsState == CacheState.INVALID ||
4030 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) {
4031 sources.add(source);
4032 }
4033 // Resolution.
4034 CacheState polymerResolutionErrorsState =
4035 htmlEntry.getState(HtmlEntry.POLYMER_RESOLUTION_ERRORS);
4036 if (polymerResolutionErrorsState == CacheState.INVALID ||
4037 (isPriority && polymerResolutionErrorsState == CacheState.FLUSHED)) {
4038 sources.add(source);
4039 }
4040 }
4041 } 3952 }
4042 } 3953 }
4043 3954
4044 /** 3955 /**
4045 * Invalidate all of the resolution results computed by this context. 3956 * Invalidate all of the resolution results computed by this context.
4046 * 3957 *
4047 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 3958 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4048 * 3959 *
4049 * @param invalidateUris `true` if the cached results of converting URIs to so urce files 3960 * @param invalidateUris `true` if the cached results of converting URIs to so urce files
4050 * should also be invalidated. 3961 * should also be invalidated.
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
4488 _cache.storedAst(source); 4399 _cache.storedAst(source);
4489 ChangeNoticeImpl notice = _getNotice(source); 4400 ChangeNoticeImpl notice = _getNotice(source);
4490 notice.setErrors(htmlEntry.allErrors, lineInfo); 4401 notice.setErrors(htmlEntry.allErrors, lineInfo);
4491 return htmlEntry; 4402 return htmlEntry;
4492 } 4403 }
4493 4404
4494 /** 4405 /**
4495 * Record the results produced by performing a [task] and return the cache 4406 * Record the results produced by performing a [task] and return the cache
4496 * entry associated with the results. 4407 * entry associated with the results.
4497 */ 4408 */
4498 HtmlEntry _recordPolymerBuildHtmlTaskResults(PolymerBuildHtmlTask task) {
4499 Source source = task.source;
4500 HtmlEntry htmlEntry = _cache.get(source);
4501 CaughtException thrownException = task.exception;
4502 if (thrownException != null) {
4503 htmlEntry.recordResolutionError(thrownException);
4504 throw new AnalysisException('<rethrow>', thrownException);
4505 }
4506 htmlEntry.setValue(HtmlEntry.POLYMER_BUILD_ERRORS, task.errors);
4507 // notify about errors
4508 ChangeNoticeImpl notice = _getNotice(source);
4509 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO);
4510 notice.setErrors(htmlEntry.allErrors, lineInfo);
4511 return htmlEntry;
4512 }
4513
4514 /**
4515 * Record the results produced by performing a [task] and return the cache
4516 * entry associated with the results.
4517 */
4518 HtmlEntry _recordPolymerResolveHtmlTaskResults(PolymerResolveHtmlTask task) {
4519 Source source = task.source;
4520 HtmlEntry htmlEntry = _cache.get(source);
4521 CaughtException thrownException = task.exception;
4522 if (thrownException != null) {
4523 htmlEntry.recordResolutionError(thrownException);
4524 throw new AnalysisException('<rethrow>', thrownException);
4525 }
4526 htmlEntry.setValue(HtmlEntry.POLYMER_RESOLUTION_ERRORS, task.errors);
4527 // notify about errors
4528 ChangeNoticeImpl notice = _getNotice(source);
4529 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO);
4530 notice.setErrors(htmlEntry.allErrors, lineInfo);
4531 return htmlEntry;
4532 }
4533
4534 /**
4535 * Record the results produced by performing a [task] and return the cache
4536 * entry associated with the results.
4537 */
4538 DartEntry _recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { 4409 DartEntry _recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
4539 Source unitSource = task.source; 4410 Source unitSource = task.source;
4540 DartEntry dartEntry = _cache.get(unitSource); 4411 DartEntry dartEntry = _cache.get(unitSource);
4541 Source librarySource = task.librarySource; 4412 Source librarySource = task.librarySource;
4542 CaughtException thrownException = task.exception; 4413 CaughtException thrownException = task.exception;
4543 if (thrownException != null) { 4414 if (thrownException != null) {
4544 dartEntry.recordResolutionErrorInLibrary(librarySource, thrownException); 4415 dartEntry.recordResolutionErrorInLibrary(librarySource, thrownException);
4545 _cache.removedAst(unitSource); 4416 _cache.removedAst(unitSource);
4546 throw new AnalysisException('<rethrow>', thrownException); 4417 throw new AnalysisException('<rethrow>', thrownException);
4547 } 4418 }
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
4921 4792
4922 @override 4793 @override
4923 DartEntry visitParseDartTask(ParseDartTask task) => 4794 DartEntry visitParseDartTask(ParseDartTask task) =>
4924 AnalysisContextImpl_this._recordParseDartTaskResults(task); 4795 AnalysisContextImpl_this._recordParseDartTaskResults(task);
4925 4796
4926 @override 4797 @override
4927 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => 4798 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) =>
4928 AnalysisContextImpl_this._recordParseHtmlTaskResults(task); 4799 AnalysisContextImpl_this._recordParseHtmlTaskResults(task);
4929 4800
4930 @override 4801 @override
4931 HtmlEntry visitPolymerBuildHtmlTask(PolymerBuildHtmlTask task) =>
4932 AnalysisContextImpl_this._recordPolymerBuildHtmlTaskResults(task);
4933
4934 @override
4935 HtmlEntry visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task) =>
4936 AnalysisContextImpl_this._recordPolymerResolveHtmlTaskResults(task);
4937
4938 @override
4939 DartEntry 4802 DartEntry
4940 visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) => 4803 visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) =>
4941 AnalysisContextImpl_this.recordResolveDartLibraryCycleTaskResults(task); 4804 AnalysisContextImpl_this.recordResolveDartLibraryCycleTaskResults(task);
4942 4805
4943 @override 4806 @override
4944 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => 4807 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) =>
4945 AnalysisContextImpl_this.recordResolveDartLibraryTaskResults(task); 4808 AnalysisContextImpl_this.recordResolveDartLibraryTaskResults(task);
4946 4809
4947 @override 4810 @override
4948 DartEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => 4811 DartEntry visitResolveDartUnitTask(ResolveDartUnitTask task) =>
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
6163 */ 6026 */
6164 abstract class AnalysisOptions { 6027 abstract class AnalysisOptions {
6165 /** 6028 /**
6166 * Return `true` if analysis is to parse and analyze function bodies. 6029 * Return `true` if analysis is to parse and analyze function bodies.
6167 * 6030 *
6168 * @return `true` if analysis is to parse and analyzer function bodies 6031 * @return `true` if analysis is to parse and analyzer function bodies
6169 */ 6032 */
6170 bool get analyzeFunctionBodies; 6033 bool get analyzeFunctionBodies;
6171 6034
6172 /** 6035 /**
6173 * Return `true` if analysis is to analyze Polymer.
6174 *
6175 * @return `true` if analysis is to analyze Polymer
6176 */
6177 bool get analyzePolymer;
6178
6179 /**
6180 * Return the maximum number of sources for which AST structures should be kep t in the cache. 6036 * Return the maximum number of sources for which AST structures should be kep t in the cache.
6181 * 6037 *
6182 * @return the maximum number of sources for which AST structures should be ke pt in the cache 6038 * @return the maximum number of sources for which AST structures should be ke pt in the cache
6183 */ 6039 */
6184 int get cacheSize; 6040 int get cacheSize;
6185 6041
6186 /** 6042 /**
6187 * Return `true` if analysis is to generate dart2js related hint results. 6043 * Return `true` if analysis is to generate dart2js related hint results.
6188 * 6044 *
6189 * @return `true` if analysis is to generate dart2js related hint results 6045 * @return `true` if analysis is to generate dart2js related hint results
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
6272 * The default value for enabling enum support. 6128 * The default value for enabling enum support.
6273 */ 6129 */
6274 static bool DEFAULT_ENABLE_ENUM = false; 6130 static bool DEFAULT_ENABLE_ENUM = false;
6275 6131
6276 /** 6132 /**
6277 * A flag indicating whether analysis is to parse and analyze function bodies. 6133 * A flag indicating whether analysis is to parse and analyze function bodies.
6278 */ 6134 */
6279 bool analyzeFunctionBodies = true; 6135 bool analyzeFunctionBodies = true;
6280 6136
6281 /** 6137 /**
6282 * A flag indicating whether analysis is to analyze Polymer.
6283 */
6284 bool analyzePolymer = true;
6285
6286 /**
6287 * The maximum number of sources for which AST structures should be kept in th e cache. 6138 * The maximum number of sources for which AST structures should be kept in th e cache.
6288 */ 6139 */
6289 int cacheSize = DEFAULT_CACHE_SIZE; 6140 int cacheSize = DEFAULT_CACHE_SIZE;
6290 6141
6291 /** 6142 /**
6292 * A flag indicating whether analysis is to generate dart2js related hint resu lts. 6143 * A flag indicating whether analysis is to generate dart2js related hint resu lts.
6293 */ 6144 */
6294 bool dart2jsHint = true; 6145 bool dart2jsHint = true;
6295 6146
6296 @deprecated 6147 @deprecated
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
6352 AnalysisOptionsImpl(); 6203 AnalysisOptionsImpl();
6353 6204
6354 /** 6205 /**
6355 * Initialize a newly created set of analysis options to have the same values as those in the 6206 * Initialize a newly created set of analysis options to have the same values as those in the
6356 * given set of analysis options. 6207 * given set of analysis options.
6357 * 6208 *
6358 * @param options the analysis options whose values are being copied 6209 * @param options the analysis options whose values are being copied
6359 */ 6210 */
6360 AnalysisOptionsImpl.con1(AnalysisOptions options) { 6211 AnalysisOptionsImpl.con1(AnalysisOptions options) {
6361 analyzeFunctionBodies = options.analyzeFunctionBodies; 6212 analyzeFunctionBodies = options.analyzeFunctionBodies;
6362 analyzePolymer = options.analyzePolymer;
6363 cacheSize = options.cacheSize; 6213 cacheSize = options.cacheSize;
6364 dart2jsHint = options.dart2jsHint; 6214 dart2jsHint = options.dart2jsHint;
6365 enableDeferredLoading = options.enableDeferredLoading; 6215 enableDeferredLoading = options.enableDeferredLoading;
6366 enableEnum = options.enableEnum; 6216 enableEnum = options.enableEnum;
6367 _generateSdkErrors = options.generateSdkErrors; 6217 _generateSdkErrors = options.generateSdkErrors;
6368 hint = options.hint; 6218 hint = options.hint;
6369 incremental = options.incremental; 6219 incremental = options.incremental;
6370 incrementalApi = options.incrementalApi; 6220 incrementalApi = options.incrementalApi;
6371 incrementalValidation = options.incrementalValidation; 6221 incrementalValidation = options.incrementalValidation;
6372 preserveComments = options.preserveComments; 6222 preserveComments = options.preserveComments;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
6580 /** 6430 /**
6581 * Visit the given [task], returning the result of the visit. This method will 6431 * Visit the given [task], returning the result of the visit. This method will
6582 * throw an AnalysisException if the visitor throws an exception. 6432 * throw an AnalysisException if the visitor throws an exception.
6583 */ 6433 */
6584 E visitParseHtmlTask(ParseHtmlTask task); 6434 E visitParseHtmlTask(ParseHtmlTask task);
6585 6435
6586 /** 6436 /**
6587 * Visit the given [task], returning the result of the visit. This method will 6437 * Visit the given [task], returning the result of the visit. This method will
6588 * throw an AnalysisException if the visitor throws an exception. 6438 * throw an AnalysisException if the visitor throws an exception.
6589 */ 6439 */
6590 E visitPolymerBuildHtmlTask(PolymerBuildHtmlTask task);
6591
6592 /**
6593 * Visit the given [task], returning the result of the visit. This method will
6594 * throw an AnalysisException if the visitor throws an exception.
6595 */
6596 E visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task);
6597
6598 /**
6599 * Visit the given [task], returning the result of the visit. This method will
6600 * throw an AnalysisException if the visitor throws an exception.
6601 */
6602 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task); 6440 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task);
6603 6441
6604 /** 6442 /**
6605 * Visit the given [task], returning the result of the visit. This method will 6443 * Visit the given [task], returning the result of the visit. This method will
6606 * throw an AnalysisException if the visitor throws an exception. 6444 * throw an AnalysisException if the visitor throws an exception.
6607 */ 6445 */
6608 E visitResolveDartLibraryTask(ResolveDartLibraryTask task); 6446 E visitResolveDartLibraryTask(ResolveDartLibraryTask task);
6609 6447
6610 /** 6448 /**
6611 * Visit the given [task], returning the result of the visit. This method will 6449 * Visit the given [task], returning the result of the visit. This method will
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after
8735 /** 8573 /**
8736 * The data descriptor representing the errors resulting from resolving the 8574 * The data descriptor representing the errors resulting from resolving the
8737 * source. 8575 * source.
8738 */ 8576 */
8739 static final DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS = 8577 static final DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS =
8740 new DataDescriptor<List<AnalysisError>>( 8578 new DataDescriptor<List<AnalysisError>>(
8741 "HtmlEntry.RESOLUTION_ERRORS", 8579 "HtmlEntry.RESOLUTION_ERRORS",
8742 AnalysisError.NO_ERRORS); 8580 AnalysisError.NO_ERRORS);
8743 8581
8744 /** 8582 /**
8745 * The data descriptor representing the status of Polymer elements in the
8746 * source.
8747 */
8748 static final DataDescriptor<List<AnalysisError>> POLYMER_BUILD_ERRORS =
8749 new DataDescriptor<List<AnalysisError>>(
8750 "HtmlEntry.POLYMER_BUILD_ERRORS",
8751 AnalysisError.NO_ERRORS);
8752
8753 /**
8754 * The data descriptor representing the errors reported during Polymer
8755 * resolution.
8756 */
8757 static final DataDescriptor<List<AnalysisError>> POLYMER_RESOLUTION_ERRORS =
8758 new DataDescriptor<List<AnalysisError>>(
8759 "HtmlEntry.POLYMER_RESOLUTION_ERRORS",
8760 AnalysisError.NO_ERRORS);
8761
8762 /**
8763 * Return all of the errors associated with the HTML file that are currently 8583 * Return all of the errors associated with the HTML file that are currently
8764 * cached. 8584 * cached.
8765 */ 8585 */
8766 List<AnalysisError> get allErrors { 8586 List<AnalysisError> get allErrors {
8767 List<AnalysisError> errors = new List<AnalysisError>(); 8587 List<AnalysisError> errors = new List<AnalysisError>();
8768 errors.addAll(getValue(PARSE_ERRORS)); 8588 errors.addAll(getValue(PARSE_ERRORS));
8769 errors.addAll(getValue(RESOLUTION_ERRORS)); 8589 errors.addAll(getValue(RESOLUTION_ERRORS));
8770 errors.addAll(getValue(HINTS)); 8590 errors.addAll(getValue(HINTS));
8771 errors.addAll(getValue(POLYMER_BUILD_ERRORS));
8772 errors.addAll(getValue(POLYMER_RESOLUTION_ERRORS));
8773 if (errors.length == 0) { 8591 if (errors.length == 0) {
8774 return AnalysisError.NO_ERRORS; 8592 return AnalysisError.NO_ERRORS;
8775 } 8593 }
8776 return errors; 8594 return errors;
8777 } 8595 }
8778 8596
8779 /** 8597 /**
8780 * Return a valid parsed unit, either an unresolved AST structure or the 8598 * Return a valid parsed unit, either an unresolved AST structure or the
8781 * result of resolving the AST structure, or `null` if there is no parsed unit 8599 * result of resolving the AST structure, or `null` if there is no parsed unit
8782 * available. 8600 * available.
8783 */ 8601 */
8784 ht.HtmlUnit get anyParsedUnit { 8602 ht.HtmlUnit get anyParsedUnit {
8785 if (getState(PARSED_UNIT) == CacheState.VALID) { 8603 if (getState(PARSED_UNIT) == CacheState.VALID) {
8786 return getValue(PARSED_UNIT); 8604 return getValue(PARSED_UNIT);
8787 } 8605 }
8788 if (getState(RESOLVED_UNIT) == CacheState.VALID) { 8606 if (getState(RESOLVED_UNIT) == CacheState.VALID) {
8789 return getValue(RESOLVED_UNIT); 8607 return getValue(RESOLVED_UNIT);
8790 } 8608 }
8791 return null; 8609 return null;
8792 } 8610 }
8793 8611
8794 @override 8612 @override
8795 List<DataDescriptor> get descriptors { 8613 List<DataDescriptor> get descriptors {
8796 List<DataDescriptor> result = super.descriptors; 8614 List<DataDescriptor> result = super.descriptors;
8797 result.addAll( 8615 result.addAll(
8798 [ 8616 [
8799 HtmlEntry.ELEMENT, 8617 HtmlEntry.ELEMENT,
8800 HtmlEntry.PARSE_ERRORS, 8618 HtmlEntry.PARSE_ERRORS,
8801 HtmlEntry.PARSED_UNIT, 8619 HtmlEntry.PARSED_UNIT,
8802 HtmlEntry.POLYMER_BUILD_ERRORS,
8803 HtmlEntry.POLYMER_RESOLUTION_ERRORS,
8804 HtmlEntry.RESOLUTION_ERRORS, 8620 HtmlEntry.RESOLUTION_ERRORS,
8805 HtmlEntry.RESOLVED_UNIT, 8621 HtmlEntry.RESOLVED_UNIT,
8806 HtmlEntry.HINTS]); 8622 HtmlEntry.HINTS]);
8807 return result; 8623 return result;
8808 } 8624 }
8809 8625
8810 @override 8626 @override
8811 SourceKind get kind => SourceKind.HTML; 8627 SourceKind get kind => SourceKind.HTML;
8812 8628
8813 /** 8629 /**
(...skipping 12 matching lines...) Expand all
8826 setState(RESOLVED_UNIT, CacheState.INVALID); 8642 setState(RESOLVED_UNIT, CacheState.INVALID);
8827 invalidateAllResolutionInformation(true); 8643 invalidateAllResolutionInformation(true);
8828 } 8644 }
8829 8645
8830 /** 8646 /**
8831 * Invalidate all of the resolution information associated with the HTML file. 8647 * Invalidate all of the resolution information associated with the HTML file.
8832 * If [invalidateUris] is `true`, the cached results of converting URIs to 8648 * If [invalidateUris] is `true`, the cached results of converting URIs to
8833 * source files should also be invalidated. 8649 * source files should also be invalidated.
8834 */ 8650 */
8835 void invalidateAllResolutionInformation(bool invalidateUris) { 8651 void invalidateAllResolutionInformation(bool invalidateUris) {
8836 setState(POLYMER_BUILD_ERRORS, CacheState.INVALID);
8837 setState(POLYMER_RESOLUTION_ERRORS, CacheState.INVALID);
8838 setState(ELEMENT, CacheState.INVALID); 8652 setState(ELEMENT, CacheState.INVALID);
8839 setState(RESOLUTION_ERRORS, CacheState.INVALID); 8653 setState(RESOLUTION_ERRORS, CacheState.INVALID);
8840 setState(HINTS, CacheState.INVALID); 8654 setState(HINTS, CacheState.INVALID);
8841 if (invalidateUris) { 8655 if (invalidateUris) {
8842 setState(REFERENCED_LIBRARIES, CacheState.INVALID); 8656 setState(REFERENCED_LIBRARIES, CacheState.INVALID);
8843 } 8657 }
8844 } 8658 }
8845 8659
8846 @override 8660 @override
8847 void recordContentError(CaughtException exception) { 8661 void recordContentError(CaughtException exception) {
(...skipping 18 matching lines...) Expand all
8866 /** 8680 /**
8867 * Record that an [exception] was encountered while attempting to resolve the 8681 * Record that an [exception] was encountered while attempting to resolve the
8868 * source associated with this entry. 8682 * source associated with this entry.
8869 */ 8683 */
8870 void recordResolutionError(CaughtException exception) { 8684 void recordResolutionError(CaughtException exception) {
8871 this.exception = exception; 8685 this.exception = exception;
8872 setState(RESOLVED_UNIT, CacheState.ERROR); 8686 setState(RESOLVED_UNIT, CacheState.ERROR);
8873 setState(ELEMENT, CacheState.ERROR); 8687 setState(ELEMENT, CacheState.ERROR);
8874 setState(RESOLUTION_ERRORS, CacheState.ERROR); 8688 setState(RESOLUTION_ERRORS, CacheState.ERROR);
8875 setState(HINTS, CacheState.ERROR); 8689 setState(HINTS, CacheState.ERROR);
8876 setState(POLYMER_BUILD_ERRORS, CacheState.ERROR);
8877 setState(POLYMER_RESOLUTION_ERRORS, CacheState.ERROR);
8878 } 8690 }
8879 8691
8880 @override 8692 @override
8881 bool _isValidDescriptor(DataDescriptor descriptor) { 8693 bool _isValidDescriptor(DataDescriptor descriptor) {
8882 return descriptor == ELEMENT || 8694 return descriptor == ELEMENT ||
8883 descriptor == HINTS || 8695 descriptor == HINTS ||
8884 descriptor == PARSED_UNIT || 8696 descriptor == PARSED_UNIT ||
8885 descriptor == PARSE_ERRORS || 8697 descriptor == PARSE_ERRORS ||
8886 descriptor == POLYMER_BUILD_ERRORS ||
8887 descriptor == POLYMER_RESOLUTION_ERRORS ||
8888 descriptor == REFERENCED_LIBRARIES || 8698 descriptor == REFERENCED_LIBRARIES ||
8889 descriptor == RESOLUTION_ERRORS || 8699 descriptor == RESOLUTION_ERRORS ||
8890 descriptor == RESOLVED_UNIT || 8700 descriptor == RESOLVED_UNIT ||
8891 super._isValidDescriptor(descriptor); 8701 super._isValidDescriptor(descriptor);
8892 } 8702 }
8893 8703
8894 @override 8704 @override
8895 bool _writeDiffOn(StringBuffer buffer, SourceEntry oldEntry) { 8705 bool _writeDiffOn(StringBuffer buffer, SourceEntry oldEntry) {
8896 bool needsSeparator = super._writeDiffOn(buffer, oldEntry); 8706 bool needsSeparator = super._writeDiffOn(buffer, oldEntry);
8897 if (oldEntry is! HtmlEntry) { 8707 if (oldEntry is! HtmlEntry) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
8931 needsSeparator, 8741 needsSeparator,
8932 "referencedLibraries", 8742 "referencedLibraries",
8933 HtmlEntry.REFERENCED_LIBRARIES, 8743 HtmlEntry.REFERENCED_LIBRARIES,
8934 oldEntry); 8744 oldEntry);
8935 needsSeparator = _writeStateDiffOn( 8745 needsSeparator = _writeStateDiffOn(
8936 buffer, 8746 buffer,
8937 needsSeparator, 8747 needsSeparator,
8938 "element", 8748 "element",
8939 HtmlEntry.ELEMENT, 8749 HtmlEntry.ELEMENT,
8940 oldEntry); 8750 oldEntry);
8941 needsSeparator = _writeStateDiffOn(
8942 buffer,
8943 needsSeparator,
8944 "polymerBuildErrors",
8945 HtmlEntry.POLYMER_BUILD_ERRORS,
8946 oldEntry);
8947 needsSeparator = _writeStateDiffOn(
8948 buffer,
8949 needsSeparator,
8950 "polymerResolutionErrors",
8951 HtmlEntry.POLYMER_RESOLUTION_ERRORS,
8952 oldEntry);
8953 return needsSeparator; 8751 return needsSeparator;
8954 } 8752 }
8955 8753
8956 @override 8754 @override
8957 void _writeOn(StringBuffer buffer) { 8755 void _writeOn(StringBuffer buffer) {
8958 buffer.write("Html: "); 8756 buffer.write("Html: ");
8959 super._writeOn(buffer); 8757 super._writeOn(buffer);
8960 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS); 8758 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS);
8961 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT); 8759 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT);
8962 _writeStateOn(buffer, "resolvedUnit", RESOLVED_UNIT); 8760 _writeStateOn(buffer, "resolvedUnit", RESOLVED_UNIT);
8963 _writeStateOn(buffer, "resolutionErrors", RESOLUTION_ERRORS); 8761 _writeStateOn(buffer, "resolutionErrors", RESOLUTION_ERRORS);
8964 _writeStateOn(buffer, "referencedLibraries", REFERENCED_LIBRARIES); 8762 _writeStateOn(buffer, "referencedLibraries", REFERENCED_LIBRARIES);
8965 _writeStateOn(buffer, "element", ELEMENT); 8763 _writeStateOn(buffer, "element", ELEMENT);
8966 _writeStateOn(buffer, "polymerBuildErrors", POLYMER_BUILD_ERRORS);
8967 _writeStateOn(buffer, "polymerResolutionErrors", POLYMER_RESOLUTION_ERRORS);
8968 } 8764 }
8969 } 8765 }
8970 8766
8971 /** 8767 /**
8972 * Instances of the class `IncrementalAnalysisCache` hold information used to pe rform 8768 * Instances of the class `IncrementalAnalysisCache` hold information used to pe rform
8973 * incremental analysis. 8769 * incremental analysis.
8974 * 8770 *
8975 * See [AnalysisContextImpl.setChangedContents]. 8771 * See [AnalysisContextImpl.setChangedContents].
8976 */ 8772 */
8977 class IncrementalAnalysisCache { 8773 class IncrementalAnalysisCache {
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
10055 * The [TimeCounter] for time spent in parsing. 9851 * The [TimeCounter] for time spent in parsing.
10056 */ 9852 */
10057 static TimeCounter parse = new TimeCounter(); 9853 static TimeCounter parse = new TimeCounter();
10058 9854
10059 /** 9855 /**
10060 * The [TimeCounter] for time spent in resolving. 9856 * The [TimeCounter] for time spent in resolving.
10061 */ 9857 */
10062 static TimeCounter resolve = new TimeCounter(); 9858 static TimeCounter resolve = new TimeCounter();
10063 9859
10064 /** 9860 /**
10065 * The [TimeCounter] for time spent in Polymer analysis.
10066 */
10067 static TimeCounter polymer = new TimeCounter();
10068
10069 /**
10070 * The [TimeCounter] for time spent in error verifier. 9861 * The [TimeCounter] for time spent in error verifier.
10071 */ 9862 */
10072 static TimeCounter errors = new TimeCounter(); 9863 static TimeCounter errors = new TimeCounter();
10073 9864
10074 /** 9865 /**
10075 * The [TimeCounter] for time spent in hints generator. 9866 * The [TimeCounter] for time spent in hints generator.
10076 */ 9867 */
10077 static TimeCounter hints = new TimeCounter(); 9868 static TimeCounter hints = new TimeCounter();
10078 9869
10079 /** 9870 /**
10080 * Reset all of the time counters to zero. 9871 * Reset all of the time counters to zero.
10081 */ 9872 */
10082 static void reset() { 9873 static void reset() {
10083 io = new TimeCounter(); 9874 io = new TimeCounter();
10084 scan = new TimeCounter(); 9875 scan = new TimeCounter();
10085 parse = new TimeCounter(); 9876 parse = new TimeCounter();
10086 resolve = new TimeCounter(); 9877 resolve = new TimeCounter();
10087 polymer = new TimeCounter();
10088 errors = new TimeCounter(); 9878 errors = new TimeCounter();
10089 hints = new TimeCounter(); 9879 hints = new TimeCounter();
10090 } 9880 }
10091 } 9881 }
10092 9882
10093 /** 9883 /**
10094 * Instances of the class `PolymerBuildHtmlTask` build Polymer specific elements .
10095 */
10096 class PolymerBuildHtmlTask extends AnalysisTask {
10097 /**
10098 * The source to build which Polymer HTML elements for.
10099 */
10100 final Source source;
10101
10102 /**
10103 * The line information associated with the source.
10104 */
10105 final LineInfo _lineInfo;
10106
10107 /**
10108 * The HTML unit to be resolved.
10109 */
10110 final ht.HtmlUnit _unit;
10111
10112 /**
10113 * The resolution errors that were discovered while building elements.
10114 */
10115 List<AnalysisError> _errors = AnalysisError.NO_ERRORS;
10116
10117 /**
10118 * Initialize a newly created task to perform analysis within the given contex t.
10119 *
10120 * @param context the context in which the task is to be performed
10121 * @param source the source to be resolved
10122 * @param lineInfo the line information associated with the source
10123 * @param unit the HTML unit to build Polymer elements for
10124 */
10125 PolymerBuildHtmlTask(InternalAnalysisContext context, this.source,
10126 this._lineInfo, this._unit)
10127 : super(context);
10128
10129 List<AnalysisError> get errors => _errors;
10130
10131 @override
10132 String get taskDescription => "build Polymer elements ${source.fullName}";
10133
10134 @override
10135 accept(AnalysisTaskVisitor visitor) =>
10136 visitor.visitPolymerBuildHtmlTask(this);
10137
10138 @override
10139 void internalPerform() {
10140 RecordingErrorListener errorListener = new RecordingErrorListener();
10141 PolymerHtmlUnitBuilder resolver =
10142 new PolymerHtmlUnitBuilder(context, errorListener, source, _lineInfo, _u nit);
10143 resolver.build();
10144 _errors = errorListener.getErrorsForSource(source);
10145 }
10146 }
10147
10148 /**
10149 * Instances of the class [PolymerHtmlUnitBuilder] build Polymer specific elemen ts.
10150 */
10151 class PolymerHtmlUnitBuilder extends ht.RecursiveXmlVisitor<Object> {
10152 /**
10153 * These names are forbidden to use as a custom tag name.
10154 *
10155 * http://w3c.github.io/webcomponents/spec/custom/#concepts
10156 */
10157 static Set<String> _FORBIDDEN_TAG_NAMES = new Set();
10158
10159 final InternalAnalysisContext _context;
10160
10161 final AnalysisErrorListener _errorListener;
10162
10163 final Source _source;
10164
10165 final LineInfo _lineInfo;
10166
10167 final ht.HtmlUnit _unit;
10168
10169 List<PolymerTagHtmlElement> _tagHtmlElements = <PolymerTagHtmlElement>[];
10170
10171 ht.XmlTagNode _elementNode;
10172
10173 String _elementName;
10174
10175 PolymerTagHtmlElementImpl _htmlElement;
10176
10177 PolymerTagDartElementImpl _dartElement;
10178
10179 PolymerHtmlUnitBuilder(this._context, this._errorListener, this._source,
10180 this._lineInfo, this._unit);
10181
10182 /**
10183 * Returns the only [LibraryElement] referenced by a direct `script` child. Ma ybe
10184 * `null` if none.
10185 */
10186 LibraryElement get dartUnitElement {
10187 // TODO(scheglov) Maybe check if more than one "script".
10188 for (ht.XmlTagNode child in _elementNode.tagNodes) {
10189 if (child is ht.HtmlScriptTagNode) {
10190 HtmlScriptElement scriptElement = child.scriptElement;
10191 if (scriptElement is ExternalHtmlScriptElement) {
10192 Source scriptSource = scriptElement.scriptSource;
10193 if (scriptSource != null) {
10194 return _context.getLibraryElement(scriptSource);
10195 }
10196 }
10197 }
10198 }
10199 return null;
10200 }
10201
10202 /**
10203 * Builds Polymer specific HTML elements.
10204 */
10205 void build() {
10206 _unit.accept(this);
10207 // set Polymer tags
10208 HtmlElementImpl unitElement = _unit.element as HtmlElementImpl;
10209 unitElement.polymerTags = new List.from(_tagHtmlElements);
10210 }
10211
10212 @override
10213 Object visitXmlTagNode(ht.XmlTagNode node) {
10214 if (node.tag == "polymer-element") {
10215 _createTagHtmlElement(node);
10216 }
10217 // visit children
10218 return super.visitXmlTagNode(node);
10219 }
10220
10221 void _createAttributeElements() {
10222 // prepare "attributes" attribute
10223 ht.XmlAttributeNode attributesAttribute =
10224 _elementNode.getAttribute("attributes");
10225 if (attributesAttribute == null) {
10226 return;
10227 }
10228 // check if there is a Dart part to resolve against it
10229 if (_dartElement == null) {
10230 // TODO(scheglov) maybe report error (if it is allowed at all to have
10231 // element without Dart part)
10232 return;
10233 }
10234 // prepare value of the "attributes" attribute
10235 String attributesText = attributesAttribute.text;
10236 if (attributesText.trim().isEmpty) {
10237 _reportErrorForAttribute(
10238 attributesAttribute,
10239 PolymerCode.EMPTY_ATTRIBUTES);
10240 return;
10241 }
10242 // prepare attribute name tokens
10243 List<PolymerHtmlUnitBuilder_NameToken> nameTokens =
10244 <PolymerHtmlUnitBuilder_NameToken>[
10245 ];
10246 {
10247 int index = 0;
10248 int textOffset = attributesAttribute.textOffset;
10249 int nameOffset = -1;
10250 StringBuffer nameBuffer = new StringBuffer();
10251 while (index < attributesText.length) {
10252 int c = attributesText.codeUnitAt(index++);
10253 if (Character.isWhitespace(c)) {
10254 if (nameOffset != -1) {
10255 nameTokens.add(
10256 new PolymerHtmlUnitBuilder_NameToken(nameOffset, nameBuffer.toSt ring()));
10257 nameBuffer = new StringBuffer();
10258 nameOffset = -1;
10259 }
10260 continue;
10261 }
10262 if (nameOffset == -1) {
10263 nameOffset = textOffset + index - 1;
10264 }
10265 nameBuffer.writeCharCode(c);
10266 }
10267 if (nameOffset != -1) {
10268 nameTokens.add(
10269 new PolymerHtmlUnitBuilder_NameToken(nameOffset, nameBuffer.toString ()));
10270 nameBuffer = new StringBuffer();
10271 }
10272 }
10273 // create attributes for name tokens
10274 List<PolymerAttributeElement> attributes = <PolymerAttributeElement>[];
10275 Set<String> definedNames = new Set();
10276 ClassElement classElement = _dartElement.classElement;
10277 for (PolymerHtmlUnitBuilder_NameToken nameToken in nameTokens) {
10278 int offset = nameToken._offset;
10279 // prepare name
10280 String name = nameToken._value;
10281 if (!isValidAttributeName(name)) {
10282 _reportErrorForNameToken(
10283 nameToken,
10284 PolymerCode.INVALID_ATTRIBUTE_NAME,
10285 [name]);
10286 continue;
10287 }
10288 if (!definedNames.add(name)) {
10289 _reportErrorForNameToken(
10290 nameToken,
10291 PolymerCode.DUPLICATE_ATTRIBUTE_DEFINITION,
10292 [name]);
10293 continue;
10294 }
10295 // create attribute
10296 PolymerAttributeElementImpl attribute =
10297 new PolymerAttributeElementImpl(name, offset);
10298 attributes.add(attribute);
10299 // resolve field
10300 FieldElement field = classElement.getField(name);
10301 if (field == null) {
10302 _reportErrorForNameToken(
10303 nameToken,
10304 PolymerCode.UNDEFINED_ATTRIBUTE_FIELD,
10305 [name, classElement.displayName]);
10306 continue;
10307 }
10308 if (!_isPublishedField(field)) {
10309 _reportErrorForNameToken(
10310 nameToken,
10311 PolymerCode.ATTRIBUTE_FIELD_NOT_PUBLISHED,
10312 [name, classElement.displayName]);
10313 }
10314 attribute.field = field;
10315 }
10316 _htmlElement.attributes = attributes;
10317 }
10318
10319 void _createTagHtmlElement(ht.XmlTagNode node) {
10320 this._elementNode = node;
10321 this._elementName = null;
10322 this._htmlElement = null;
10323 this._dartElement = null;
10324 // prepare 'name' attribute
10325 ht.XmlAttributeNode nameAttribute = node.getAttribute("name");
10326 if (nameAttribute == null) {
10327 _reportErrorForToken(node.tagToken, PolymerCode.MISSING_TAG_NAME);
10328 return;
10329 }
10330 // prepare name
10331 _elementName = nameAttribute.text;
10332 if (!isValidTagName(_elementName)) {
10333 _reportErrorForAttributeValue(
10334 nameAttribute,
10335 PolymerCode.INVALID_TAG_NAME,
10336 [_elementName]);
10337 return;
10338 }
10339 // TODO(scheglov) Maybe check that at least one of "template" or "script"
10340 // children.
10341 // TODO(scheglov) Maybe check if more than one top-level "template".
10342 // create HTML element
10343 int nameOffset = nameAttribute.textOffset;
10344 _htmlElement = new PolymerTagHtmlElementImpl(_elementName, nameOffset);
10345 // bind to the corresponding Dart element
10346 _dartElement = _findTagDartElement();
10347 if (_dartElement != null) {
10348 _htmlElement.dartElement = _dartElement;
10349 _dartElement.htmlElement = _htmlElement;
10350 }
10351 // TODO(scheglov) create attributes
10352 _createAttributeElements();
10353 // done
10354 _tagHtmlElements.add(_htmlElement);
10355 }
10356
10357 /**
10358 * Returns the [PolymerTagDartElement] that corresponds to the Polymer custom tag declared
10359 * by the given [XmlTagNode].
10360 */
10361 PolymerTagDartElementImpl _findTagDartElement() {
10362 LibraryElement dartLibraryElement = dartUnitElement;
10363 if (dartLibraryElement == null) {
10364 return null;
10365 }
10366 return _findTagDartElement_inLibrary(dartLibraryElement);
10367 }
10368
10369 /**
10370 * Returns the [PolymerTagDartElementImpl] declared in the given [LibraryEleme nt] with
10371 * the [elementName]. Maybe `null`.
10372 */
10373 PolymerTagDartElementImpl
10374 _findTagDartElement_inLibrary(LibraryElement library) {
10375 try {
10376 library.accept(new _PolymerHtmlUnitBuilder_findTagDartElement(this));
10377 } on PolymerHtmlUnitBuilder_FoundTagDartElementError catch (e) {
10378 return e._result;
10379 }
10380 return null;
10381 }
10382
10383 bool _isPublishedAnnotation(ElementAnnotation annotation) {
10384 Element element = annotation.element;
10385 if (element != null && element.name == "published") {
10386 return true;
10387 }
10388 return false;
10389 }
10390
10391 bool _isPublishedField(FieldElement field) {
10392 List<ElementAnnotation> annotations = field.metadata;
10393 for (ElementAnnotation annotation in annotations) {
10394 if (_isPublishedAnnotation(annotation)) {
10395 return true;
10396 }
10397 }
10398 return false;
10399 }
10400
10401 /**
10402 * Reports an error on the attribute's value, or (if absent) on the attribute' s name.
10403 */
10404 void _reportErrorForAttribute(ht.XmlAttributeNode node, ErrorCode errorCode,
10405 [List<Object> arguments]) {
10406 _reportErrorForOffset(node.offset, node.length, errorCode, arguments);
10407 }
10408
10409 /**
10410 * Reports an error on the attribute's value, or (if absent) on the attribute' s name.
10411 */
10412 void _reportErrorForAttributeValue(ht.XmlAttributeNode node,
10413 ErrorCode errorCode, [List<Object> arguments]) {
10414 ht.Token valueToken = node.valueToken;
10415 if (valueToken == null || valueToken.isSynthetic) {
10416 _reportErrorForAttribute(node, errorCode, arguments);
10417 } else {
10418 _reportErrorForToken(valueToken, errorCode, arguments);
10419 }
10420 }
10421
10422 void _reportErrorForNameToken(PolymerHtmlUnitBuilder_NameToken token,
10423 ErrorCode errorCode, [List<Object> arguments]) {
10424 int offset = token._offset;
10425 int length = token._value.length;
10426 _reportErrorForOffset(offset, length, errorCode, arguments);
10427 }
10428
10429 void _reportErrorForOffset(int offset, int length, ErrorCode errorCode,
10430 [List<Object> arguments]) {
10431 _errorListener.onError(
10432 new AnalysisError.con2(_source, offset, length, errorCode, arguments));
10433 }
10434
10435 void _reportErrorForToken(ht.Token token, ErrorCode errorCode,
10436 [List<Object> arguments]) {
10437 int offset = token.offset;
10438 int length = token.length;
10439 _reportErrorForOffset(offset, length, errorCode, arguments);
10440 }
10441
10442 static bool isValidAttributeName(String name) {
10443 // cannot be empty
10444 if (name.isEmpty) {
10445 return false;
10446 }
10447 // check characters
10448 int length = name.length;
10449 for (int i = 0; i < length; i++) {
10450 int c = name.codeUnitAt(i);
10451 if (i == 0) {
10452 if (!Character.isLetter(c)) {
10453 return false;
10454 }
10455 } else {
10456 if (!(Character.isLetterOrDigit(c) || c == 0x5F)) {
10457 return false;
10458 }
10459 }
10460 }
10461 return true;
10462 }
10463
10464 static bool isValidTagName(String name) {
10465 // cannot be empty
10466 if (name.isEmpty) {
10467 return false;
10468 }
10469 // check for forbidden name
10470 if (_FORBIDDEN_TAG_NAMES.contains(name)) {
10471 return false;
10472 }
10473 // check characters
10474 int length = name.length;
10475 bool hasDash = false;
10476 for (int i = 0; i < length; i++) {
10477 int c = name.codeUnitAt(i);
10478 // check for '-'
10479 if (c == 0x2D) {
10480 hasDash = true;
10481 }
10482 // check character
10483 if (i == 0) {
10484 if (hasDash) {
10485 return false;
10486 }
10487 if (!Character.isLetter(c)) {
10488 return false;
10489 }
10490 } else {
10491 if (!(Character.isLetterOrDigit(c) || c == 0x2D || c == 0x5F)) {
10492 return false;
10493 }
10494 }
10495 }
10496 if (!hasDash) {
10497 return false;
10498 }
10499 return true;
10500 }
10501 }
10502
10503 class PolymerHtmlUnitBuilder_FoundTagDartElementError extends Error {
10504 final PolymerTagDartElementImpl _result;
10505
10506 PolymerHtmlUnitBuilder_FoundTagDartElementError(this._result);
10507 }
10508
10509 class PolymerHtmlUnitBuilder_NameToken {
10510 final int _offset;
10511
10512 final String _value;
10513
10514 PolymerHtmlUnitBuilder_NameToken(this._offset, this._value);
10515 }
10516
10517 /**
10518 * Instances of the class [PolymerHtmlUnitResolver] resolve Polymer specific
10519 * [XmlTagNode]s and expressions.
10520 *
10521 * TODO(scheglov) implement it
10522 */
10523 class PolymerHtmlUnitResolver extends ht.RecursiveXmlVisitor<Object> {
10524 final InternalAnalysisContext _context;
10525
10526 final AnalysisErrorListener _errorListener;
10527
10528 final Source _source;
10529
10530 final LineInfo _lineInfo;
10531
10532 final ht.HtmlUnit _unit;
10533
10534 PolymerHtmlUnitResolver(this._context, this._errorListener, this._source,
10535 this._lineInfo, this._unit);
10536
10537 /**
10538 * Resolves Polymer specific features.
10539 */
10540 void resolveUnit() {
10541 // TODO(scheglov) implement it
10542 // unit.accept(this);
10543 }
10544
10545 @override
10546 Object visitXmlAttributeNode(ht.XmlAttributeNode node) =>
10547 super.visitXmlAttributeNode(node);
10548
10549 @override
10550 Object visitXmlTagNode(ht.XmlTagNode node) => super.visitXmlTagNode(node);
10551 }
10552
10553 /**
10554 * Instances of the class `PolymerResolveHtmlTask` performs Polymer specific HTM L file
10555 * resolution.
10556 *
10557 * TODO(scheglov) implement it
10558 */
10559 class PolymerResolveHtmlTask extends AnalysisTask {
10560 /**
10561 * The source to be resolved.
10562 */
10563 final Source source;
10564
10565 /**
10566 * The line information associated with the source.
10567 */
10568 final LineInfo _lineInfo;
10569
10570 /**
10571 * The HTML unit to be resolved.
10572 */
10573 final ht.HtmlUnit _unit;
10574
10575 /**
10576 * The resolution errors that were discovered while resolving the source.
10577 */
10578 List<AnalysisError> _errors = AnalysisError.NO_ERRORS;
10579
10580 /**
10581 * Initialize a newly created task to perform analysis within the given contex t.
10582 *
10583 * @param context the context in which the task is to be performed
10584 * @param source the source to be resolved
10585 * @param unit the HTML unit to be resolved
10586 */
10587 PolymerResolveHtmlTask(InternalAnalysisContext context, this.source,
10588 this._lineInfo, this._unit)
10589 : super(context);
10590
10591 List<AnalysisError> get errors => _errors;
10592
10593 @override
10594 String get taskDescription => "resolve as Polymer ${source.fullName}";
10595
10596 @override
10597 accept(AnalysisTaskVisitor visitor) =>
10598 visitor.visitPolymerResolveHtmlTask(this);
10599
10600 @override
10601 void internalPerform() {
10602 RecordingErrorListener errorListener = new RecordingErrorListener();
10603 PolymerHtmlUnitResolver resolver =
10604 new PolymerHtmlUnitResolver(context, errorListener, source, _lineInfo, _ unit);
10605 resolver.resolveUnit();
10606 _errors = errorListener.getErrorsForSource(source);
10607 }
10608 }
10609
10610 /**
10611 * Instances of the class `RecordingErrorListener` implement an error listener t hat will 9884 * Instances of the class `RecordingErrorListener` implement an error listener t hat will
10612 * record the errors that are reported to it in a way that is appropriate for ca ching those errors 9885 * record the errors that are reported to it in a way that is appropriate for ca ching those errors
10613 * within an analysis context. 9886 * within an analysis context.
10614 */ 9887 */
10615 class RecordingErrorListener implements AnalysisErrorListener { 9888 class RecordingErrorListener implements AnalysisErrorListener {
10616 /** 9889 /**
10617 * A HashMap of lists containing the errors that were collected, keyed by each [Source]. 9890 * A HashMap of lists containing the errors that were collected, keyed by each [Source].
10618 */ 9891 */
10619 Map<Source, HashSet<AnalysisError>> _errors = 9892 Map<Source, HashSet<AnalysisError>> _errors =
10620 new HashMap<Source, HashSet<AnalysisError>>(); 9893 new HashMap<Source, HashSet<AnalysisError>>();
(...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after
12454 if (element.id == _id) { 11727 if (element.id == _id) {
12455 result = element; 11728 result = element;
12456 throw new _ElementByIdFinderException(); 11729 throw new _ElementByIdFinderException();
12457 } 11730 }
12458 super.visitElement(element); 11731 super.visitElement(element);
12459 } 11732 }
12460 } 11733 }
12461 11734
12462 class _ElementByIdFinderException { 11735 class _ElementByIdFinderException {
12463 } 11736 }
12464
12465 class _PolymerHtmlUnitBuilder_findTagDartElement extends
12466 RecursiveElementVisitor<Object> {
12467 final PolymerHtmlUnitBuilder PolymerHtmlUnitBuilder_this;
12468
12469 _PolymerHtmlUnitBuilder_findTagDartElement(this.PolymerHtmlUnitBuilder_this)
12470 : super();
12471
12472 @override
12473 Object visitPolymerTagDartElement(PolymerTagDartElement element) {
12474 if (element.name == PolymerHtmlUnitBuilder_this._elementName) {
12475 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError(
12476 element as PolymerTagDartElementImpl);
12477 }
12478 return null;
12479 }
12480 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_handle.dart ('k') | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698