| OLD | NEW |
| 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.resolver; | 8 library engine.resolver; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 145 } |
| 146 // no Element | 146 // no Element |
| 147 return null; | 147 return null; |
| 148 } | 148 } |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * Parses given selector text and returns [AngularSelectorElement]. May be `nu
ll` if | 151 * Parses given selector text and returns [AngularSelectorElement]. May be `nu
ll` if |
| 152 * cannot parse. | 152 * cannot parse. |
| 153 */ | 153 */ |
| 154 static AngularSelectorElement parseSelector(int offset, String text) { | 154 static AngularSelectorElement parseSelector(int offset, String text) { |
| 155 // [attribute] |
| 155 if (StringUtilities.startsWithChar(text, 0x5B) && StringUtilities.endsWithCh
ar(text, 0x5D)) { | 156 if (StringUtilities.startsWithChar(text, 0x5B) && StringUtilities.endsWithCh
ar(text, 0x5D)) { |
| 156 int nameOffset = offset + "[".length; | 157 int nameOffset = offset + "[".length; |
| 157 String attributeName = text.substring(1, text.length - 1); | 158 String attributeName = text.substring(1, text.length - 1); |
| 158 // TODO(scheglov) report warning if there are spaces between [ and identif
ier | 159 // TODO(scheglov) report warning if there are spaces between [ and identif
ier |
| 159 return new HasAttributeSelectorElementImpl(attributeName, nameOffset); | 160 return new HasAttributeSelectorElementImpl(attributeName, nameOffset); |
| 160 } | 161 } |
| 162 // tag[attribute] |
| 163 if (StringUtilities.endsWithChar(text, 0x5D)) { |
| 164 int index = StringUtilities.indexOf1(text, 0, 0x5B); |
| 165 if (index != -1) { |
| 166 String tagName = text.substring(0, index); |
| 167 String attributeName = text.substring(index + 1, text.length - 1); |
| 168 if (StringUtilities.isTagName(tagName)) { |
| 169 return new IsTagHasAttributeSelectorElementImpl(tagName, attributeName
); |
| 170 } |
| 171 } |
| 172 } |
| 173 // tag |
| 161 if (StringUtilities.isTagName(text)) { | 174 if (StringUtilities.isTagName(text)) { |
| 162 return new IsTagSelectorElementImpl(text, offset); | 175 return new IsTagSelectorElementImpl(text, offset); |
| 163 } | 176 } |
| 164 return null; | 177 return null; |
| 165 } | 178 } |
| 166 | 179 |
| 167 /** | 180 /** |
| 168 * Adds [AngularElement] declared by the given top-level [Element]. | 181 * Adds [AngularElement] declared by the given top-level [Element]. |
| 169 * | 182 * |
| 170 * @param angularElements the list to fill with top-level [AngularElement]s | 183 * @param angularElements the list to fill with top-level [AngularElement]s |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 404 } |
| 392 | 405 |
| 393 /** | 406 /** |
| 394 * Checks if [annotation] is an annotation with required name. | 407 * Checks if [annotation] is an annotation with required name. |
| 395 */ | 408 */ |
| 396 bool isAngularAnnotation2(String name) => isAngularAnnotation(_annotation, nam
e); | 409 bool isAngularAnnotation2(String name) => isAngularAnnotation(_annotation, nam
e); |
| 397 | 410 |
| 398 void parseNgComponent() { | 411 void parseNgComponent() { |
| 399 bool isValid = true; | 412 bool isValid = true; |
| 400 // publishAs | 413 // publishAs |
| 401 if (!hasStringArgument(_PUBLISH_AS)) { | 414 String name = null; |
| 402 reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []); | 415 int nameOffset = -1; |
| 403 isValid = false; | 416 if (hasStringArgument(_PUBLISH_AS)) { |
| 417 name = getStringArgument(_PUBLISH_AS); |
| 418 nameOffset = getStringArgumentOffset(_PUBLISH_AS); |
| 404 } | 419 } |
| 405 // selector | 420 // selector |
| 406 AngularSelectorElement selector = null; | 421 AngularSelectorElement selector = null; |
| 407 if (!hasStringArgument(_SELECTOR)) { | 422 if (!hasStringArgument(_SELECTOR)) { |
| 408 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); | 423 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); |
| 409 isValid = false; | 424 isValid = false; |
| 410 } else { | 425 } else { |
| 411 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR); | 426 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR); |
| 412 selector = parseSelector2(selectorLiteral); | 427 selector = parseSelector2(selectorLiteral); |
| 413 if (selector == null) { | 428 if (selector == null) { |
| 414 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se
lectorLiteral]); | 429 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se
lectorLiteral]); |
| 415 isValid = false; | 430 isValid = false; |
| 416 } | 431 } |
| 417 } | 432 } |
| 418 // templateUrl | 433 // templateUrl |
| 419 if (!hasStringArgument(_TEMPLATE_URL)) { | 434 String templateUri = null; |
| 420 reportErrorForAnnotation(AngularCode.MISSING_TEMPLATE_URL, []); | 435 int templateUriOffset = -1; |
| 421 isValid = false; | 436 if (hasStringArgument(_TEMPLATE_URL)) { |
| 437 templateUri = getStringArgument(_TEMPLATE_URL); |
| 438 templateUriOffset = getStringArgumentOffset(_TEMPLATE_URL); |
| 422 } | 439 } |
| 423 // cssUrl | 440 // cssUrl |
| 424 if (!hasStringArgument(_CSS_URL)) { | 441 String styleUri = null; |
| 425 reportErrorForAnnotation(AngularCode.MISSING_CSS_URL, []); | 442 int styleUriOffset = -1; |
| 426 isValid = false; | 443 if (hasStringArgument(_CSS_URL)) { |
| 444 styleUri = getStringArgument(_CSS_URL); |
| 445 styleUriOffset = getStringArgumentOffset(_CSS_URL); |
| 427 } | 446 } |
| 428 // create | 447 // create |
| 429 if (isValid) { | 448 if (isValid) { |
| 430 String name = getStringArgument(_PUBLISH_AS); | |
| 431 int nameOffset = getStringArgumentOffset(_PUBLISH_AS); | |
| 432 String templateUri = getStringArgument(_TEMPLATE_URL); | |
| 433 int templateUriOffset = getStringArgumentOffset(_TEMPLATE_URL); | |
| 434 String styleUri = getStringArgument(_CSS_URL); | |
| 435 int styleUriOffset = getStringArgumentOffset(_CSS_URL); | |
| 436 AngularComponentElementImpl element = new AngularComponentElementImpl(name
, nameOffset); | 449 AngularComponentElementImpl element = new AngularComponentElementImpl(name
, nameOffset); |
| 437 element.selector = selector; | 450 element.selector = selector; |
| 438 element.templateUri = templateUri; | 451 element.templateUri = templateUri; |
| 439 element.templateUriOffset = templateUriOffset; | 452 element.templateUriOffset = templateUriOffset; |
| 440 // resolve template URI | 453 // resolve template URI |
| 441 // TODO(scheglov) resolve to HtmlElement to allow F3 ? | 454 // TODO(scheglov) resolve to HtmlElement to allow F3 ? |
| 442 { | 455 if (templateUri != null) { |
| 443 try { | 456 try { |
| 444 parseUriWithException(templateUri); | 457 parseUriWithException(templateUri); |
| 445 // TODO(scheglov) think if there is better solution | 458 // TODO(scheglov) think if there is better solution |
| 446 if (templateUri.startsWith("packages/")) { | 459 if (templateUri.startsWith("packages/")) { |
| 447 templateUri = "package:${templateUri.substring("packages/".length)}"
; | 460 templateUri = "package:${templateUri.substring("packages/".length)}"
; |
| 448 } | 461 } |
| 449 Source templateSource = _context.sourceFactory.resolveUri(_source, tem
plateUri); | 462 Source templateSource = _context.sourceFactory.resolveUri(_source, tem
plateUri); |
| 450 if (templateSource == null || !templateSource.exists()) { | 463 if (templateSource == null || !templateSource.exists()) { |
| 464 templateSource = _context.sourceFactory.resolveUri(_source, "package
:${templateUri}"); |
| 465 } |
| 466 if (templateSource == null || !templateSource.exists()) { |
| 451 reportErrorForArgument(_TEMPLATE_URL, AngularCode.URI_DOES_NOT_EXIST
, [templateUri]); | 467 reportErrorForArgument(_TEMPLATE_URL, AngularCode.URI_DOES_NOT_EXIST
, [templateUri]); |
| 452 } | 468 } |
| 453 element.templateSource = templateSource; | 469 if (AnalysisEngine.isHtmlFileName(templateUri)) { |
| 470 element.templateSource = templateSource; |
| 471 } |
| 454 } on URISyntaxException catch (exception) { | 472 } on URISyntaxException catch (exception) { |
| 455 reportErrorForArgument(_TEMPLATE_URL, AngularCode.INVALID_URI, [templa
teUri]); | 473 reportErrorForArgument(_TEMPLATE_URL, AngularCode.INVALID_URI, [templa
teUri]); |
| 456 } | 474 } |
| 457 } | 475 } |
| 458 element.styleUri = styleUri; | 476 element.styleUri = styleUri; |
| 459 element.styleUriOffset = styleUriOffset; | 477 element.styleUriOffset = styleUriOffset; |
| 460 element.properties = parseNgComponentProperties(true); | 478 element.properties = parseNgComponentProperties(true); |
| 461 _classToolkitObjects.add(element); | 479 _classToolkitObjects.add(element); |
| 462 } | 480 } |
| 463 } | 481 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } else if (StringUtilities.startsWith3(spec, 0, 0x3C, 0x3D, 0x3E)) { | 582 } else if (StringUtilities.startsWith3(spec, 0, 0x3C, 0x3D, 0x3E)) { |
| 565 kind = AngularPropertyKind.TWO_WAY; | 583 kind = AngularPropertyKind.TWO_WAY; |
| 566 fieldNameOffset = 3; | 584 fieldNameOffset = 3; |
| 567 } else { | 585 } else { |
| 568 reportError(specLiteral, AngularCode.INVALID_PROPERTY_KIND, [spec]); | 586 reportError(specLiteral, AngularCode.INVALID_PROPERTY_KIND, [spec]); |
| 569 continue; | 587 continue; |
| 570 } | 588 } |
| 571 String fieldName = spec.substring(fieldNameOffset); | 589 String fieldName = spec.substring(fieldNameOffset); |
| 572 fieldNameOffset += specLiteral.valueOffset; | 590 fieldNameOffset += specLiteral.valueOffset; |
| 573 // prepare field | 591 // prepare field |
| 574 FieldElement field = _classElement.getField(fieldName); | 592 PropertyAccessorElement setter = _classElement.type.lookUpSetter(fieldName
, _classElement.library); |
| 575 if (field == null) { | 593 if (setter == null) { |
| 576 reportError2(fieldNameOffset, fieldName.length, AngularCode.INVALID_PROP
ERTY_FIELD, [fieldName]); | 594 reportError2(fieldNameOffset, fieldName.length, AngularCode.INVALID_PROP
ERTY_FIELD, [fieldName]); |
| 577 continue; | 595 continue; |
| 578 } | 596 } |
| 597 FieldElement field = setter.variable as FieldElement; |
| 579 // add property | 598 // add property |
| 580 AngularPropertyElementImpl property = new AngularPropertyElementImpl(name,
nameOffset); | 599 AngularPropertyElementImpl property = new AngularPropertyElementImpl(name,
nameOffset); |
| 581 property.field = field; | 600 property.field = field; |
| 582 property.propertyKind = kind; | 601 property.propertyKind = kind; |
| 583 property.fieldNameOffset = fieldNameOffset; | 602 property.fieldNameOffset = fieldNameOffset; |
| 584 properties.add(property); | 603 properties.add(property); |
| 585 } | 604 } |
| 586 } | 605 } |
| 587 | 606 |
| 588 void parseNgController() { | 607 void parseNgController() { |
| (...skipping 7604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8193 Source getSource(UriBasedDirective directive) { | 8212 Source getSource(UriBasedDirective directive) { |
| 8194 StringLiteral uriLiteral = directive.uri; | 8213 StringLiteral uriLiteral = directive.uri; |
| 8195 if (uriLiteral is StringInterpolation) { | 8214 if (uriLiteral is StringInterpolation) { |
| 8196 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.of
fset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); | 8215 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.of
fset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); |
| 8197 return null; | 8216 return null; |
| 8198 } | 8217 } |
| 8199 String uriContent = uriLiteral.stringValue.trim(); | 8218 String uriContent = uriLiteral.stringValue.trim(); |
| 8200 _directiveUris[directive] = uriContent; | 8219 _directiveUris[directive] = uriContent; |
| 8201 uriContent = Uri.encodeFull(uriContent); | 8220 uriContent = Uri.encodeFull(uriContent); |
| 8202 if (directive is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME))
{ | 8221 if (directive is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME))
{ |
| 8203 String uriBase = uriContent.substring(_DART_EXT_SCHEME.length); | |
| 8204 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, "
${uriBase}.dll"); | |
| 8205 if (source == null || !source.exists()) { | |
| 8206 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${uri
Base}.so"); | |
| 8207 if (source == null || !source.exists()) { | |
| 8208 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${u
riBase}.dylib"); | |
| 8209 if (source == null || !source.exists()) { | |
| 8210 _errorListener.onError(new AnalysisError.con2(librarySource, uriLite
ral.offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriCont
ent])); | |
| 8211 } | |
| 8212 } | |
| 8213 } | |
| 8214 _libraryElement.hasExtUri2 = true; | 8222 _libraryElement.hasExtUri2 = true; |
| 8215 return null; | 8223 return null; |
| 8216 } | 8224 } |
| 8217 try { | 8225 try { |
| 8218 parseUriWithException(uriContent); | 8226 parseUriWithException(uriContent); |
| 8219 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, u
riContent); | 8227 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, u
riContent); |
| 8220 if (source == null || !source.exists()) { | 8228 if (source == null || !source.exists()) { |
| 8221 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.
offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]
)); | 8229 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.
offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]
)); |
| 8222 } | 8230 } |
| 8223 return source; | 8231 return source; |
| (...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10765 | 10773 |
| 10766 /** | 10774 /** |
| 10767 * Return the library element for the library containing the compilation unit
being resolved. | 10775 * Return the library element for the library containing the compilation unit
being resolved. |
| 10768 * | 10776 * |
| 10769 * @return the library element for the library containing the compilation unit
being resolved | 10777 * @return the library element for the library containing the compilation unit
being resolved |
| 10770 */ | 10778 */ |
| 10771 LibraryElement get definingLibrary => _definingLibrary; | 10779 LibraryElement get definingLibrary => _definingLibrary; |
| 10772 | 10780 |
| 10773 /** | 10781 /** |
| 10774 * Replaces the current [Scope] with the enclosing [Scope]. | 10782 * Replaces the current [Scope] with the enclosing [Scope]. |
| 10783 * |
| 10784 * @return the enclosing [Scope]. |
| 10775 */ | 10785 */ |
| 10776 void popNameScope() { | 10786 Scope popNameScope() { |
| 10777 _nameScope = _nameScope.enclosingScope; | 10787 _nameScope = _nameScope.enclosingScope; |
| 10788 return _nameScope; |
| 10778 } | 10789 } |
| 10779 | 10790 |
| 10780 /** | 10791 /** |
| 10781 * Pushes a new [Scope] into the visitor. | 10792 * Pushes a new [Scope] into the visitor. |
| 10782 * | 10793 * |
| 10783 * @return the new [Scope]. | 10794 * @return the new [Scope]. |
| 10784 */ | 10795 */ |
| 10785 Scope pushNameScope() { | 10796 Scope pushNameScope() { |
| 10786 Scope newScope = new EnclosedScope(_nameScope); | 10797 Scope newScope = new EnclosedScope(_nameScope); |
| 10787 _nameScope = newScope; | 10798 _nameScope = newScope; |
| 10788 return newScope; | 10799 return _nameScope; |
| 10789 } | 10800 } |
| 10790 | 10801 |
| 10791 /** | 10802 /** |
| 10792 * Report an error with the given analysis error. | 10803 * Report an error with the given analysis error. |
| 10793 * | 10804 * |
| 10794 * @param errorCode analysis error | 10805 * @param errorCode analysis error |
| 10795 */ | 10806 */ |
| 10796 void reportError(AnalysisError analysisError) { | 10807 void reportError(AnalysisError analysisError) { |
| 10797 _errorListener.onError(analysisError); | 10808 _errorListener.onError(analysisError); |
| 10798 } | 10809 } |
| (...skipping 10242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21041 * @param correction the template used to create the correction to be displaye
d for the error | 21052 * @param correction the template used to create the correction to be displaye
d for the error |
| 21042 */ | 21053 */ |
| 21043 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri
ng correction) : super(name, ordinal) { | 21054 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri
ng correction) : super(name, ordinal) { |
| 21044 this.correction9 = correction; | 21055 this.correction9 = correction; |
| 21045 } | 21056 } |
| 21046 | 21057 |
| 21047 String get correction => correction9; | 21058 String get correction => correction9; |
| 21048 | 21059 |
| 21049 ErrorSeverity get errorSeverity => type.severity; | 21060 ErrorSeverity get errorSeverity => type.severity; |
| 21050 } | 21061 } |
| OLD | NEW |