| 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.html; | 8 library engine.html; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 import 'java_core.dart'; | 11 import 'java_core.dart'; |
| 12 import 'java_engine.dart'; | 12 import 'java_engine.dart'; |
| 13 import 'source.dart'; | 13 import 'source.dart'; |
| 14 import 'error.dart' show AnalysisErrorListener; | 14 import 'error.dart' show AnalysisErrorListener; |
| 15 import 'scanner.dart' as sc show Scanner, SubSequenceReader, Token; | 15 import 'scanner.dart' as sc show Scanner, SubSequenceReader, Token; |
| 16 import 'parser.dart' show Parser; | 16 import 'parser.dart' show Parser; |
| 17 import 'ast.dart'; | 17 import 'ast.dart'; |
| 18 import 'element.dart'; | 18 import 'element.dart'; |
| 19 import 'engine.dart' show AnalysisEngine, AngularHtmlUnitResolver; | 19 import 'engine.dart' show AnalysisEngine, AngularHtmlUnitResolver, ExpressionVis
itor; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Instances of the class `Token` represent a token that was scanned from the in
put. Each | 22 * Instances of the class `Token` represent a token that was scanned from the in
put. Each |
| 23 * token knows which token follows it, acting as the head of a linked list of to
kens. | 23 * token knows which token follows it, acting as the head of a linked list of to
kens. |
| 24 * | 24 * |
| 25 * @coverage dart.engine.html | 25 * @coverage dart.engine.html |
| 26 */ | 26 */ |
| 27 class Token { | 27 class Token { |
| 28 /** | 28 /** |
| 29 * The offset from the beginning of the file to the first character in the tok
en. | 29 * The offset from the beginning of the file to the first character in the tok
en. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 Token setNext(Token token) { | 134 Token setNext(Token token) { |
| 135 _next = token; | 135 _next = token; |
| 136 token.previous = this; | 136 token.previous = this; |
| 137 return token; | 137 return token; |
| 138 } | 138 } |
| 139 | 139 |
| 140 String toString() => lexeme; | 140 String toString() => lexeme; |
| 141 } | 141 } |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * Instances of the class `EmbeddedExpression` represent an expression enclosed
between | 144 * Implementation of [XmlExpression] for an [Expression] embedded without any wr
apping |
| 145 * <code>{{</code> and <code>}}</code> delimiters. | 145 * characters. |
| 146 */ | 146 */ |
| 147 class EmbeddedExpression { | 147 class RawXmlExpression extends XmlExpression { |
| 148 /** | |
| 149 * The offset of the first character of the opening delimiter. | |
| 150 */ | |
| 151 final int openingOffset; | |
| 152 | |
| 153 /** | |
| 154 * The expression that is enclosed between the delimiters. | |
| 155 */ | |
| 156 final Expression expression; | 148 final Expression expression; |
| 157 | 149 |
| 158 /** | 150 RawXmlExpression(this.expression); |
| 159 * The offset of the first character of the closing delimiter. | |
| 160 */ | |
| 161 final int closingOffset; | |
| 162 | 151 |
| 163 /** | 152 int get end => expression.end; |
| 164 * An empty array of embedded expressions. | |
| 165 */ | |
| 166 static List<EmbeddedExpression> EMPTY_ARRAY = new List<EmbeddedExpression>(0); | |
| 167 | 153 |
| 168 /** | 154 int get length => expression.length; |
| 169 * Initialize a newly created embedded expression to represent the given expre
ssion. | 155 |
| 170 * | 156 int get offset => expression.offset; |
| 171 * @param openingOffset the offset of the first character of the opening delim
iter | 157 |
| 172 * @param expression the expression that is enclosed between the delimiters | 158 XmlExpression_Reference getReference(int offset) { |
| 173 * @param closingOffset the offset of the first character of the closing delim
iter | 159 ASTNode node = new NodeLocator.con1(offset).searchWithin(expression); |
| 174 */ | 160 if (node != null) { |
| 175 EmbeddedExpression(this.openingOffset, this.expression, this.closingOffset); | 161 Element element = ElementLocator.locate(node); |
| 162 return new XmlExpression_Reference(element, node.offset, node.length); |
| 163 } |
| 164 return null; |
| 165 } |
| 176 } | 166 } |
| 177 | 167 |
| 178 /** | 168 /** |
| 179 * Instances of `HtmlParseResult` hold the result of parsing an HTML file. | 169 * Instances of `HtmlParseResult` hold the result of parsing an HTML file. |
| 180 * | 170 * |
| 181 * @coverage dart.engine.html | 171 * @coverage dart.engine.html |
| 182 */ | 172 */ |
| 183 class HtmlParseResult extends HtmlScanResult { | 173 class HtmlParseResult extends HtmlScanResult { |
| 184 /** | 174 /** |
| 185 * The unit containing the parsed information (not `null`). | 175 * The unit containing the parsed information (not `null`). |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 /** | 279 /** |
| 290 * Returns the [Expression] that is part of the given [HtmlUnit] and encloses
the | 280 * Returns the [Expression] that is part of the given [HtmlUnit] and encloses
the |
| 291 * given offset. | 281 * given offset. |
| 292 */ | 282 */ |
| 293 static Expression getExpression(HtmlUnit htmlUnit, int offset) { | 283 static Expression getExpression(HtmlUnit htmlUnit, int offset) { |
| 294 if (htmlUnit == null) { | 284 if (htmlUnit == null) { |
| 295 return null; | 285 return null; |
| 296 } | 286 } |
| 297 List<Expression> result = [null]; | 287 List<Expression> result = [null]; |
| 298 try { | 288 try { |
| 299 htmlUnit.accept(new RecursiveXmlVisitor_HtmlUnitUtils_getExpression(offset
, result)); | 289 // TODO(scheglov) this code is very Angular specific |
| 290 htmlUnit.accept(new ExpressionVisitor_HtmlUnitUtils_getExpression(offset,
result)); |
| 300 } on HtmlUnitUtils_FoundExpressionError catch (e) { | 291 } on HtmlUnitUtils_FoundExpressionError catch (e) { |
| 301 return result[0]; | 292 return result[0]; |
| 302 } | 293 } |
| 303 return null; | 294 return null; |
| 304 } | 295 } |
| 305 | 296 |
| 306 /** | 297 /** |
| 307 * Returns the [XmlTagNode] that is part of the given [HtmlUnit] and encloses
the | 298 * Returns the [XmlTagNode] that is part of the given [HtmlUnit] and encloses
the |
| 308 * given offset. | 299 * given offset. |
| 309 */ | 300 */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 Object visitXmlAttributeNode(XmlAttributeNode node) { | 345 Object visitXmlAttributeNode(XmlAttributeNode node) { |
| 355 Token nameToken = node.nameToken; | 346 Token nameToken = node.nameToken; |
| 356 if (nameToken.offset <= offset && offset < nameToken.end) { | 347 if (nameToken.offset <= offset && offset < nameToken.end) { |
| 357 result[0] = node; | 348 result[0] = node; |
| 358 throw new HtmlUnitUtils_FoundAttributeNodeError(); | 349 throw new HtmlUnitUtils_FoundAttributeNodeError(); |
| 359 } | 350 } |
| 360 return super.visitXmlAttributeNode(node); | 351 return super.visitXmlAttributeNode(node); |
| 361 } | 352 } |
| 362 } | 353 } |
| 363 | 354 |
| 364 class RecursiveXmlVisitor_HtmlUnitUtils_getExpression extends RecursiveXmlVisito
r<Object> { | 355 class ExpressionVisitor_HtmlUnitUtils_getExpression extends ExpressionVisitor { |
| 365 int offset = 0; | 356 int offset = 0; |
| 366 | 357 |
| 367 List<Expression> result; | 358 List<Expression> result; |
| 368 | 359 |
| 369 RecursiveXmlVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : su
per(); | 360 ExpressionVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : supe
r(); |
| 370 | 361 |
| 371 Object visitXmlAttributeNode(XmlAttributeNode node) { | 362 void visitExpression(Expression expression) { |
| 372 findExpression(offset, result, node.expressions); | 363 Expression at = HtmlUnitUtils.getExpressionAt(expression, offset); |
| 373 return super.visitXmlAttributeNode(node); | 364 if (at != null) { |
| 374 } | 365 result[0] = at; |
| 375 | 366 throw new HtmlUnitUtils_FoundExpressionError(); |
| 376 Object visitXmlTagNode(XmlTagNode node) { | |
| 377 findExpression(offset, result, node.expressions); | |
| 378 return super.visitXmlTagNode(node); | |
| 379 } | |
| 380 | |
| 381 void findExpression(int offset, List<Expression> result, List<EmbeddedExpressi
on> expressions) { | |
| 382 for (EmbeddedExpression embeddedExpression in expressions) { | |
| 383 Expression expression = embeddedExpression.expression; | |
| 384 Expression at = HtmlUnitUtils.getExpressionAt(expression, offset); | |
| 385 if (at != null) { | |
| 386 result[0] = at; | |
| 387 throw new HtmlUnitUtils_FoundExpressionError(); | |
| 388 } | |
| 389 } | 367 } |
| 390 } | 368 } |
| 391 } | 369 } |
| 392 | 370 |
| 393 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { | 371 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { |
| 394 int offset = 0; | 372 int offset = 0; |
| 395 | 373 |
| 396 List<XmlTagNode> result; | 374 List<XmlTagNode> result; |
| 397 | 375 |
| 398 RecursiveXmlVisitor_HtmlUnitUtils_getTagNode(this.offset, this.result) : super
(); | 376 RecursiveXmlVisitor_HtmlUnitUtils_getTagNode(this.offset, this.result) : super
(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 622 |
| 645 /** | 623 /** |
| 646 * Set the parent of this node to the given node. | 624 * Set the parent of this node to the given node. |
| 647 * | 625 * |
| 648 * @param newParent the node that is to be made the parent of this node | 626 * @param newParent the node that is to be made the parent of this node |
| 649 */ | 627 */ |
| 650 void set parent(XmlNode newParent) { | 628 void set parent(XmlNode newParent) { |
| 651 XmlNode current = newParent; | 629 XmlNode current = newParent; |
| 652 while (current != null) { | 630 while (current != null) { |
| 653 if (identical(current, this)) { | 631 if (identical(current, this)) { |
| 654 AnalysisEngine.instance.logger.logError3(new IllegalArgumentException(bu
ildRecursiveStructureMessage(newParent))); | 632 AnalysisEngine.instance.logger.logError2("Circular structure while setti
ng an XML node's parent", new IllegalArgumentException(buildRecursiveStructureMe
ssage(newParent))); |
| 655 return; | 633 return; |
| 656 } | 634 } |
| 657 current = current.parent; | 635 current = current.parent; |
| 658 } | 636 } |
| 659 _parent = newParent; | 637 _parent = newParent; |
| 660 } | 638 } |
| 661 } | 639 } |
| 662 | 640 |
| 663 /** | 641 /** |
| 664 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing | 642 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 /** | 1002 /** |
| 1025 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The | 1003 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The |
| 1026 * scanning logic is in the superclass. | 1004 * scanning logic is in the superclass. |
| 1027 * | 1005 * |
| 1028 * @coverage dart.engine.html | 1006 * @coverage dart.engine.html |
| 1029 */ | 1007 */ |
| 1030 class StringScanner extends AbstractScanner { | 1008 class StringScanner extends AbstractScanner { |
| 1031 /** | 1009 /** |
| 1032 * The string from which characters will be read. | 1010 * The string from which characters will be read. |
| 1033 */ | 1011 */ |
| 1034 String _string; | 1012 CharSequence _string; |
| 1035 | 1013 |
| 1036 /** | 1014 /** |
| 1037 * The number of characters in the string. | 1015 * The number of characters in the string. |
| 1038 */ | 1016 */ |
| 1039 int _stringLength = 0; | 1017 int _stringLength = 0; |
| 1040 | 1018 |
| 1041 /** | 1019 /** |
| 1042 * The index, relative to the string, of the last character that was read. | 1020 * The index, relative to the string, of the last character that was read. |
| 1043 */ | 1021 */ |
| 1044 int _charOffset = 0; | 1022 int _charOffset = 0; |
| 1045 | 1023 |
| 1046 /** | 1024 /** |
| 1047 * Initialize a newly created scanner to scan the characters in the given stri
ng. | 1025 * Initialize a newly created scanner to scan the characters in the given stri
ng. |
| 1048 * | 1026 * |
| 1049 * @param source the source being scanned | 1027 * @param source the source being scanned |
| 1050 * @param string the string from which characters will be read | 1028 * @param string the string from which characters will be read |
| 1051 */ | 1029 */ |
| 1052 StringScanner(Source source, String string) : super(source) { | 1030 StringScanner(Source source, CharSequence string) : super(source) { |
| 1053 this._string = string; | 1031 this._string = string; |
| 1054 this._stringLength = string.length; | 1032 this._stringLength = string.length(); |
| 1055 this._charOffset = -1; | 1033 this._charOffset = -1; |
| 1056 } | 1034 } |
| 1057 | 1035 |
| 1058 int get offset => _charOffset; | 1036 int get offset => _charOffset; |
| 1059 | 1037 |
| 1060 void set offset(int offset) { | 1038 void set offset(int offset) { |
| 1061 _charOffset = offset; | 1039 _charOffset = offset; |
| 1062 } | 1040 } |
| 1063 | 1041 |
| 1064 int advance() { | 1042 int advance() { |
| 1065 if (++_charOffset < _stringLength) { | 1043 if (++_charOffset < _stringLength) { |
| 1066 return _string.codeUnitAt(_charOffset); | 1044 return _string.charAt(_charOffset); |
| 1067 } | 1045 } |
| 1068 _charOffset = _stringLength; | 1046 _charOffset = _stringLength; |
| 1069 return -1; | 1047 return -1; |
| 1070 } | 1048 } |
| 1071 | 1049 |
| 1072 String getString(int start, int endDelta) => _string.substring(start, _charOff
set + 1 + endDelta); | 1050 String getString(int start, int endDelta) => _string.subSequence(start, _charO
ffset + 1 + endDelta).toString(); |
| 1073 | 1051 |
| 1074 int peek() { | 1052 int peek() { |
| 1075 if (_charOffset + 1 < _stringLength) { | 1053 if (_charOffset + 1 < _stringLength) { |
| 1076 return _string.codeUnitAt(_charOffset + 1); | 1054 return _string.charAt(_charOffset + 1); |
| 1077 } | 1055 } |
| 1078 return -1; | 1056 return -1; |
| 1079 } | 1057 } |
| 1080 } | |
| 1081 | |
| 1082 /** | |
| 1083 * Instances of the class `CharBufferScanner` implement a scanner that reads fro
m a character | |
| 1084 * buffer. The scanning logic is in the superclass. | |
| 1085 * | |
| 1086 * @coverage dart.engine.html | |
| 1087 */ | |
| 1088 class CharBufferScanner extends AbstractScanner { | |
| 1089 /** | |
| 1090 * The buffer from which characters will be read. | |
| 1091 */ | |
| 1092 CharSequence _buffer; | |
| 1093 | |
| 1094 /** | |
| 1095 * The number of characters in the buffer. | |
| 1096 */ | |
| 1097 int _bufferLength = 0; | |
| 1098 | |
| 1099 /** | |
| 1100 * The index of the last character that was read. | |
| 1101 */ | |
| 1102 int _charOffset = 0; | |
| 1103 | |
| 1104 /** | |
| 1105 * Initialize a newly created scanner to scan the characters in the given char
acter buffer. | |
| 1106 * | |
| 1107 * @param source the source being scanned | |
| 1108 * @param buffer the buffer from which characters will be read | |
| 1109 */ | |
| 1110 CharBufferScanner(Source source, CharSequence buffer) : super(source) { | |
| 1111 this._buffer = buffer; | |
| 1112 this._bufferLength = buffer.length(); | |
| 1113 this._charOffset = -1; | |
| 1114 } | |
| 1115 | |
| 1116 int get offset => _charOffset; | |
| 1117 | |
| 1118 int advance() { | |
| 1119 if (++_charOffset < _bufferLength) { | |
| 1120 return _buffer.charAt(_charOffset); | |
| 1121 } | |
| 1122 _charOffset = _bufferLength; | |
| 1123 return -1; | |
| 1124 } | |
| 1125 | |
| 1126 String getString(int start, int endDelta) => _buffer.subSequence(start, _charO
ffset + 1 + endDelta).toString(); | |
| 1127 | |
| 1128 int peek() { | |
| 1129 if (_charOffset + 1 < _bufferLength) { | |
| 1130 return _buffer.charAt(_charOffset + 1); | |
| 1131 } | |
| 1132 return -1; | |
| 1133 } | |
| 1134 } | 1058 } |
| 1135 | 1059 |
| 1136 /** | 1060 /** |
| 1137 * Instances of the class `ToSourceVisitor` write a source representation of a v
isited XML | 1061 * Instances of the class `ToSourceVisitor` write a source representation of a v
isited XML |
| 1138 * node (and all of it's children) to a writer. | 1062 * node (and all of it's children) to a writer. |
| 1139 * | 1063 * |
| 1140 * @coverage dart.engine.html | 1064 * @coverage dart.engine.html |
| 1141 */ | 1065 */ |
| 1142 class ToSourceVisitor implements XmlVisitor<Object> { | 1066 class ToSourceVisitor implements XmlVisitor<Object> { |
| 1143 /** | 1067 /** |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 * | 1205 * |
| 1282 * @coverage dart.engine.html | 1206 * @coverage dart.engine.html |
| 1283 */ | 1207 */ |
| 1284 class XmlAttributeNode extends XmlNode { | 1208 class XmlAttributeNode extends XmlNode { |
| 1285 Token _name; | 1209 Token _name; |
| 1286 | 1210 |
| 1287 final Token equals; | 1211 final Token equals; |
| 1288 | 1212 |
| 1289 Token _value; | 1213 Token _value; |
| 1290 | 1214 |
| 1291 List<EmbeddedExpression> expressions = EmbeddedExpression.EMPTY_ARRAY; | 1215 List<XmlExpression> expressions = XmlExpression.EMPTY_ARRAY; |
| 1292 | 1216 |
| 1293 /** | 1217 /** |
| 1294 * Construct a new instance representing an XML attribute. | 1218 * Construct a new instance representing an XML attribute. |
| 1295 * | 1219 * |
| 1296 * @param name the name token (not `null`). This may be a zero length token if
the attribute | 1220 * @param name the name token (not `null`). This may be a zero length token if
the attribute |
| 1297 * is badly formed. | 1221 * is badly formed. |
| 1298 * @param equals the equals sign or `null` if none | 1222 * @param equals the equals sign or `null` if none |
| 1299 * @param value the value token (not `null`) | 1223 * @param value the value token (not `null`) |
| 1300 */ | 1224 */ |
| 1301 XmlAttributeNode(Token name, this.equals, Token value) { | 1225 XmlAttributeNode(Token name, this.equals, Token value) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 * | 1284 * |
| 1361 * @return the value token or `null` if this represents a badly formed attribu
te | 1285 * @return the value token or `null` if this represents a badly formed attribu
te |
| 1362 */ | 1286 */ |
| 1363 Token get valueToken => _value; | 1287 Token get valueToken => _value; |
| 1364 | 1288 |
| 1365 void visitChildren(XmlVisitor visitor) { | 1289 void visitChildren(XmlVisitor visitor) { |
| 1366 } | 1290 } |
| 1367 } | 1291 } |
| 1368 | 1292 |
| 1369 /** | 1293 /** |
| 1370 * Instances of the class `EmbeddedDartVisitor` implement a recursive visitor fo
r HTML files | |
| 1371 * that will invoke another visitor on all embedded dart scripts and expressions
. | |
| 1372 */ | |
| 1373 class EmbeddedDartVisitor<R> implements XmlVisitor<R> { | |
| 1374 /** | |
| 1375 * The visitor used to visit embedded Dart code. | |
| 1376 */ | |
| 1377 ASTVisitor<R> _dartVisitor; | |
| 1378 | |
| 1379 /** | |
| 1380 * Initialize a newly created visitor to visit all of the nodes in an HTML str
ucture and to use | |
| 1381 * the given visitor to visit all of the nodes representing any embedded scrip
ts or expressions. | |
| 1382 * | |
| 1383 * @param dartVisitor the visitor used to visit embedded Dart code | |
| 1384 */ | |
| 1385 EmbeddedDartVisitor(ASTVisitor<R> dartVisitor) { | |
| 1386 this._dartVisitor = dartVisitor; | |
| 1387 } | |
| 1388 | |
| 1389 R visitHtmlScriptTagNode(HtmlScriptTagNode node) { | |
| 1390 node.visitChildren(this); | |
| 1391 CompilationUnit script = node.script; | |
| 1392 if (script != null) { | |
| 1393 script.accept(_dartVisitor); | |
| 1394 } | |
| 1395 return null; | |
| 1396 } | |
| 1397 | |
| 1398 R visitHtmlUnit(HtmlUnit node) { | |
| 1399 node.visitChildren(this); | |
| 1400 return null; | |
| 1401 } | |
| 1402 | |
| 1403 R visitXmlAttributeNode(XmlAttributeNode node) { | |
| 1404 node.visitChildren(this); | |
| 1405 for (EmbeddedExpression expression in node.expressions) { | |
| 1406 expression.expression.accept(_dartVisitor); | |
| 1407 } | |
| 1408 return null; | |
| 1409 } | |
| 1410 | |
| 1411 R visitXmlTagNode(XmlTagNode node) { | |
| 1412 node.visitChildren(this); | |
| 1413 for (EmbeddedExpression expression in node.expressions) { | |
| 1414 expression.expression.accept(_dartVisitor); | |
| 1415 } | |
| 1416 return null; | |
| 1417 } | |
| 1418 } | |
| 1419 | |
| 1420 /** | |
| 1421 * The interface `XmlVisitor` defines the behavior of objects that can be used t
o visit an | 1294 * The interface `XmlVisitor` defines the behavior of objects that can be used t
o visit an |
| 1422 * [XmlNode] structure. | 1295 * [XmlNode] structure. |
| 1423 * | 1296 * |
| 1424 * @coverage dart.engine.html | 1297 * @coverage dart.engine.html |
| 1425 */ | 1298 */ |
| 1426 abstract class XmlVisitor<R> { | 1299 abstract class XmlVisitor<R> { |
| 1427 R visitHtmlScriptTagNode(HtmlScriptTagNode node); | 1300 R visitHtmlScriptTagNode(HtmlScriptTagNode node); |
| 1428 | 1301 |
| 1429 R visitHtmlUnit(HtmlUnit htmlUnit); | 1302 R visitHtmlUnit(HtmlUnit htmlUnit); |
| 1430 | 1303 |
| 1431 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); | 1304 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); |
| 1432 | 1305 |
| 1433 R visitXmlTagNode(XmlTagNode xmlTagNode); | 1306 R visitXmlTagNode(XmlTagNode xmlTagNode); |
| 1434 } | 1307 } |
| 1435 | 1308 |
| 1436 /** | 1309 /** |
| 1310 * Instances of the class `XmlExpression` represent an abstract expression embed
ded into |
| 1311 * [XmlNode]. |
| 1312 */ |
| 1313 abstract class XmlExpression { |
| 1314 /** |
| 1315 * An empty array of expressions. |
| 1316 */ |
| 1317 static List<XmlExpression> EMPTY_ARRAY = new List<XmlExpression>(0); |
| 1318 |
| 1319 /** |
| 1320 * Check if the given offset belongs to the expression's source range. |
| 1321 */ |
| 1322 bool contains(int offset) => this.offset <= offset && offset < end; |
| 1323 |
| 1324 /** |
| 1325 * Return the offset of the character immediately following the last character
of this |
| 1326 * expression's source range. This is equivalent to `getOffset() + getLength()
`. |
| 1327 * |
| 1328 * @return the offset of the character just past the expression's source range |
| 1329 */ |
| 1330 int get end; |
| 1331 |
| 1332 /** |
| 1333 * Return the number of characters in the expression's source range. |
| 1334 */ |
| 1335 int get length; |
| 1336 |
| 1337 /** |
| 1338 * Return the offset of the first character in the expression's source range. |
| 1339 */ |
| 1340 int get offset; |
| 1341 |
| 1342 /** |
| 1343 * Return the [Reference] at the given offset. |
| 1344 * |
| 1345 * @param offset the offset from the beginning of the file |
| 1346 * @return the [Reference] at the given offset, maybe `null` |
| 1347 */ |
| 1348 XmlExpression_Reference getReference(int offset); |
| 1349 } |
| 1350 |
| 1351 /** |
| 1352 * The reference to the [Element]. |
| 1353 */ |
| 1354 class XmlExpression_Reference { |
| 1355 Element element; |
| 1356 |
| 1357 int offset = 0; |
| 1358 |
| 1359 int length = 0; |
| 1360 |
| 1361 XmlExpression_Reference(Element element, int offset, int length) { |
| 1362 this.element = element; |
| 1363 this.offset = offset; |
| 1364 this.length = length; |
| 1365 } |
| 1366 } |
| 1367 |
| 1368 /** |
| 1437 * Instances of `HtmlScanner` receive and scan HTML content from a [Source].<br/
> | 1369 * Instances of `HtmlScanner` receive and scan HTML content from a [Source].<br/
> |
| 1438 * For example, the following code scans HTML source and returns the result: | 1370 * For example, the following code scans HTML source and returns the result: |
| 1439 * | 1371 * |
| 1440 * <pre> | 1372 * <pre> |
| 1441 * HtmlScanner scanner = new HtmlScanner(source); | 1373 * HtmlScanner scanner = new HtmlScanner(source); |
| 1442 * source.getContents(scanner); | 1374 * source.getContents(scanner); |
| 1443 * return scanner.getResult(); | 1375 * return scanner.getResult(); |
| 1444 * </pre> | 1376 * </pre> |
| 1445 * | 1377 * |
| 1446 * @coverage dart.engine.html | 1378 * @coverage dart.engine.html |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1470 | 1402 |
| 1471 /** | 1403 /** |
| 1472 * Construct a new instance to scan the specified source. | 1404 * Construct a new instance to scan the specified source. |
| 1473 * | 1405 * |
| 1474 * @param source the source to be scanned (not `null`) | 1406 * @param source the source to be scanned (not `null`) |
| 1475 */ | 1407 */ |
| 1476 HtmlScanner(Source source) { | 1408 HtmlScanner(Source source) { |
| 1477 this._source = source; | 1409 this._source = source; |
| 1478 } | 1410 } |
| 1479 | 1411 |
| 1480 void accept(CharBuffer contents, int modificationTime) { | 1412 void accept(CharSequence contents, int modificationTime) { |
| 1481 this._modificationTime = modificationTime; | |
| 1482 _scanner = new CharBufferScanner(_source, contents); | |
| 1483 _scanner.passThroughElements = _SCRIPT_TAG; | |
| 1484 _token = _scanner.tokenize(); | |
| 1485 } | |
| 1486 | |
| 1487 void accept2(String contents, int modificationTime) { | |
| 1488 this._modificationTime = modificationTime; | 1413 this._modificationTime = modificationTime; |
| 1489 _scanner = new StringScanner(_source, contents); | 1414 _scanner = new StringScanner(_source, contents); |
| 1490 _scanner.passThroughElements = _SCRIPT_TAG; | 1415 _scanner.passThroughElements = _SCRIPT_TAG; |
| 1491 _token = _scanner.tokenize(); | 1416 _token = _scanner.tokenize(); |
| 1492 } | 1417 } |
| 1493 | 1418 |
| 1494 /** | 1419 /** |
| 1495 * Answer the result of scanning the source | 1420 * Answer the result of scanning the source |
| 1496 * | 1421 * |
| 1497 * @return the result (not `null`) | 1422 * @return the result (not `null`) |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 final Token closingTag; | 1756 final Token closingTag; |
| 1832 | 1757 |
| 1833 /** | 1758 /** |
| 1834 * The ending [TokenType#GT] or [TokenType#SLASH_GT] token (not `null`). | 1759 * The ending [TokenType#GT] or [TokenType#SLASH_GT] token (not `null`). |
| 1835 */ | 1760 */ |
| 1836 final Token nodeEnd; | 1761 final Token nodeEnd; |
| 1837 | 1762 |
| 1838 /** | 1763 /** |
| 1839 * The expressions that are embedded in the tag's content. | 1764 * The expressions that are embedded in the tag's content. |
| 1840 */ | 1765 */ |
| 1841 List<EmbeddedExpression> expressions = EmbeddedExpression.EMPTY_ARRAY; | 1766 List<XmlExpression> expressions = XmlExpression.EMPTY_ARRAY; |
| 1842 | 1767 |
| 1843 /** | 1768 /** |
| 1844 * Construct a new instance representing an XML or HTML element | 1769 * Construct a new instance representing an XML or HTML element |
| 1845 * | 1770 * |
| 1846 * @param nodeStart the starting [TokenType#LT] token (not `null`) | 1771 * @param nodeStart the starting [TokenType#LT] token (not `null`) |
| 1847 * @param tag the [TokenType#TAG] token after the starting '<' (not `null`)
. | 1772 * @param tag the [TokenType#TAG] token after the starting '<' (not `null`)
. |
| 1848 * @param attributes the attributes associated with this element or [NO_ATTRIB
UTES] (not | 1773 * @param attributes the attributes associated with this element or [NO_ATTRIB
UTES] (not |
| 1849 * `null`, contains no `null`s) | 1774 * `null`, contains no `null`s) |
| 1850 * @param attributeEnd The [TokenType#GT] or [TokenType#SLASH_GT] token after
the | 1775 * @param attributeEnd The [TokenType#GT] or [TokenType#SLASH_GT] token after
the |
| 1851 * attributes (not `null`). The token may be the same token as [nodeE
nd] if | 1776 * attributes (not `null`). The token may be the same token as [nodeE
nd] if |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 * should always have a type of [TokenType.EOF]. | 2086 * should always have a type of [TokenType.EOF]. |
| 2162 */ | 2087 */ |
| 2163 final Token endToken; | 2088 final Token endToken; |
| 2164 | 2089 |
| 2165 /** | 2090 /** |
| 2166 * The tag nodes contained in the receiver (not `null`, contains no `null`s). | 2091 * The tag nodes contained in the receiver (not `null`, contains no `null`s). |
| 2167 */ | 2092 */ |
| 2168 List<XmlTagNode> _tagNodes; | 2093 List<XmlTagNode> _tagNodes; |
| 2169 | 2094 |
| 2170 /** | 2095 /** |
| 2171 * The element associated with Dart pieces in this HTML unit or `null` if the
receiver is | |
| 2172 * not resolved. | |
| 2173 */ | |
| 2174 CompilationUnitElement compilationUnitElement; | |
| 2175 | |
| 2176 /** | |
| 2177 * Construct a new instance representing the content of an HTML file. | 2096 * Construct a new instance representing the content of an HTML file. |
| 2178 * | 2097 * |
| 2179 * @param beginToken the first token in the file (not `null`) | 2098 * @param beginToken the first token in the file (not `null`) |
| 2180 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) | 2099 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) |
| 2181 * @param endToken the last token in the token stream which should be of type | 2100 * @param endToken the last token in the token stream which should be of type |
| 2182 * [TokenType.EOF] | 2101 * [TokenType.EOF] |
| 2183 */ | 2102 */ |
| 2184 HtmlUnit(this.beginToken, List<XmlTagNode> tagNodes, this.endToken) { | 2103 HtmlUnit(this.beginToken, List<XmlTagNode> tagNodes, this.endToken) { |
| 2185 this._tagNodes = becomeParentOf(tagNodes); | 2104 this._tagNodes = becomeParentOf(tagNodes); |
| 2186 } | 2105 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2208 } | 2127 } |
| 2209 super.element = element; | 2128 super.element = element; |
| 2210 } | 2129 } |
| 2211 | 2130 |
| 2212 void visitChildren(XmlVisitor visitor) { | 2131 void visitChildren(XmlVisitor visitor) { |
| 2213 for (XmlTagNode node in _tagNodes) { | 2132 for (XmlTagNode node in _tagNodes) { |
| 2214 node.accept(visitor); | 2133 node.accept(visitor); |
| 2215 } | 2134 } |
| 2216 } | 2135 } |
| 2217 } | 2136 } |
| OLD | NEW |