| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 static String _NAME = "name"; | 42 static String _NAME = "name"; |
| 43 | 43 |
| 44 static String _SELECTOR = "selector"; | 44 static String _SELECTOR = "selector"; |
| 45 | 45 |
| 46 static String _PUBLISH_AS = "publishAs"; | 46 static String _PUBLISH_AS = "publishAs"; |
| 47 | 47 |
| 48 static String _TEMPLATE_URL = "templateUrl"; | 48 static String _TEMPLATE_URL = "templateUrl"; |
| 49 | 49 |
| 50 static String _CSS_URL = "cssUrl"; | 50 static String _CSS_URL = "cssUrl"; |
| 51 | 51 |
| 52 static String _PREFIX_ATTR = "@"; | |
| 53 | |
| 54 static String _PREFIX_CALLBACK = "&"; | |
| 55 | |
| 56 static String _PREFIX_ONE_WAY = "=>"; | |
| 57 | |
| 58 static String _PREFIX_ONE_WAY_ONE_TIME = "=>!"; | |
| 59 | |
| 60 static String _PREFIX_TWO_WAY = "<=>"; | |
| 61 | |
| 62 static String _NG_ATTR = "NgAttr"; | 52 static String _NG_ATTR = "NgAttr"; |
| 63 | 53 |
| 64 static String _NG_CALLBACK = "NgCallback"; | 54 static String _NG_CALLBACK = "NgCallback"; |
| 65 | 55 |
| 66 static String _NG_ONE_WAY = "NgOneWay"; | 56 static String _NG_ONE_WAY = "NgOneWay"; |
| 67 | 57 |
| 68 static String _NG_ONE_WAY_ONE_TIME = "NgOneWayOneTime"; | 58 static String _NG_ONE_WAY_ONE_TIME = "NgOneWayOneTime"; |
| 69 | 59 |
| 70 static String _NG_TWO_WAY = "NgTwoWay"; | 60 static String _NG_TWO_WAY = "NgTwoWay"; |
| 71 | 61 |
| 62 /** |
| 63 * Returns the array of all top-level Angular elements that could be used in t
his library. |
| 64 * |
| 65 * @param libraryElement the [LibraryElement] to analyze |
| 66 * @return the array of all top-level Angular elements that could be used in t
his library |
| 67 */ |
| 68 static List<AngularElement> getAngularElements(LibraryElement libraryElement)
{ |
| 69 List<AngularElement> angularElements = []; |
| 70 // add Angular elements from current library |
| 71 for (CompilationUnitElement unit in libraryElement.units) { |
| 72 for (ClassElement type in unit.types) { |
| 73 addAngularElements(angularElements, type); |
| 74 } |
| 75 } |
| 76 // handle imports |
| 77 for (ImportElement importElement in libraryElement.imports) { |
| 78 Namespace namespace = new NamespaceBuilder().createImportNamespace(importE
lement); |
| 79 for (Element importedElement in namespace.definedNames.values) { |
| 80 addAngularElements(angularElements, importedElement); |
| 81 } |
| 82 } |
| 83 // done |
| 84 return new List.from(angularElements); |
| 85 } |
| 86 |
| 72 static Element getElement(ASTNode node, int offset) { | 87 static Element getElement(ASTNode node, int offset) { |
| 73 // maybe no node | 88 // maybe node is not SimpleStringLiteral |
| 74 if (node == null) { | 89 if (node is! SimpleStringLiteral) { |
| 75 return null; | 90 return null; |
| 76 } | 91 } |
| 77 // prepare enclosing ClassDeclaration | 92 // prepare enclosing ClassDeclaration |
| 78 ClassDeclaration classDeclaration = node.getAncestor(ClassDeclaration); | 93 ClassDeclaration classDeclaration = node.getAncestor(ClassDeclaration); |
| 79 if (classDeclaration == null) { | 94 if (classDeclaration == null) { |
| 80 return null; | 95 return null; |
| 81 } | 96 } |
| 82 // prepare ClassElement | 97 // prepare ClassElement |
| 83 ClassElement classElement = classDeclaration.element; | 98 ClassElement classElement = classDeclaration.element; |
| 84 if (classElement == null) { | 99 if (classElement == null) { |
| 85 return null; | 100 return null; |
| 86 } | 101 } |
| 87 // check toolkit objects | 102 // check toolkit objects |
| 88 for (ToolkitObjectElement toolkitObject in classElement.toolkitObjects) { | 103 for (ToolkitObjectElement toolkitObject in classElement.toolkitObjects) { |
| 89 List<AngularPropertyElement> properties = AngularPropertyElement.EMPTY_ARR
AY; | 104 List<AngularPropertyElement> properties = AngularPropertyElement.EMPTY_ARR
AY; |
| 105 // maybe name |
| 106 if (toolkitObject is AngularElement) { |
| 107 if (isNameCoveredByLiteral(toolkitObject, node)) { |
| 108 return toolkitObject; |
| 109 } |
| 110 } |
| 90 // try properties of AngularComponentElement | 111 // try properties of AngularComponentElement |
| 91 if (toolkitObject is AngularComponentElement) { | 112 if (toolkitObject is AngularComponentElement) { |
| 92 AngularComponentElement component = toolkitObject; | 113 AngularComponentElement component = toolkitObject; |
| 114 // try selector |
| 115 { |
| 116 AngularSelectorElement selector = component.selector; |
| 117 if (isNameCoveredByLiteral(selector, node)) { |
| 118 return selector; |
| 119 } |
| 120 } |
| 121 // try properties |
| 93 properties = component.properties; | 122 properties = component.properties; |
| 94 } | 123 } |
| 95 // try properties of AngularDirectiveElement | 124 // try properties of AngularDirectiveElement |
| 96 if (toolkitObject is AngularDirectiveElement) { | 125 if (toolkitObject is AngularDirectiveElement) { |
| 97 AngularDirectiveElement directive = toolkitObject; | 126 AngularDirectiveElement directive = toolkitObject; |
| 98 properties = directive.properties; | 127 properties = directive.properties; |
| 99 } | 128 } |
| 100 // check properties | 129 // check properties |
| 101 for (AngularPropertyElement property in properties) { | 130 for (AngularPropertyElement property in properties) { |
| 102 // property name (use complete node range) | 131 // property name (use complete node range) |
| 103 int propertyOffset = property.nameOffset; | 132 if (isNameCoveredByLiteral(property, node)) { |
| 104 int propertyEnd = propertyOffset + property.name.length; | |
| 105 if (node.offset <= propertyOffset && propertyEnd < node.end) { | |
| 106 return property; | 133 return property; |
| 107 } | 134 } |
| 108 // field name (use complete node range, including @, => and <=>) | 135 // field name (use complete node range, including @, => and <=>) |
| 109 FieldElement field = property.field; | 136 FieldElement field = property.field; |
| 110 if (field != null) { | 137 if (field != null) { |
| 111 int fieldOffset = property.fieldNameOffset; | 138 int fieldOffset = property.fieldNameOffset; |
| 112 int fieldEnd = fieldOffset + field.name.length; | 139 int fieldEnd = fieldOffset + field.name.length; |
| 113 if (node.offset <= fieldOffset && fieldEnd < node.end) { | 140 if (node.offset <= fieldOffset && fieldEnd < node.end) { |
| 114 return field; | 141 return field; |
| 115 } | 142 } |
| 116 } | 143 } |
| 117 } | 144 } |
| 118 } | 145 } |
| 119 // no Element | 146 // no Element |
| 120 return null; | 147 return null; |
| 121 } | 148 } |
| 122 | 149 |
| 123 /** | 150 /** |
| 124 * Checks if given [Type] is an Angular <code>Module</code> or its subclass. | |
| 125 */ | |
| 126 static bool isModule(Type2 type) { | |
| 127 if (type is! InterfaceType) { | |
| 128 return false; | |
| 129 } | |
| 130 InterfaceType interfaceType = type as InterfaceType; | |
| 131 // check hierarchy | |
| 132 Set<Type2> seenTypes = new Set(); | |
| 133 while (interfaceType != null) { | |
| 134 // check for recursion | |
| 135 if (!seenTypes.add(interfaceType)) { | |
| 136 return false; | |
| 137 } | |
| 138 // check for "Module" | |
| 139 if (interfaceType.element.name == "Module") { | |
| 140 return true; | |
| 141 } | |
| 142 // try supertype | |
| 143 interfaceType = interfaceType.superclass; | |
| 144 } | |
| 145 // no | |
| 146 return false; | |
| 147 } | |
| 148 | |
| 149 /** | |
| 150 * 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 |
| 151 * cannot parse. | 152 * cannot parse. |
| 152 */ | 153 */ |
| 153 static AngularSelectorElement parseSelector(int offset, String text) { | 154 static AngularSelectorElement parseSelector(int offset, String text) { |
| 154 if (text.startsWith("[") && text.endsWith("]")) { | 155 if (StringUtilities.startsWithChar(text, 0x5B) && StringUtilities.endsWithCh
ar(text, 0x5D)) { |
| 155 int nameOffset = offset + "[".length; | 156 int nameOffset = offset + "[".length; |
| 156 String attributeName = text.substring(1, text.length - 1); | 157 String attributeName = text.substring(1, text.length - 1); |
| 157 // TODO(scheglov) report warning if there are spaces between [ and identif
ier | 158 // TODO(scheglov) report warning if there are spaces between [ and identif
ier |
| 158 return new HasAttributeSelectorElementImpl(attributeName, nameOffset); | 159 return new HasAttributeSelectorElementImpl(attributeName, nameOffset); |
| 159 } | 160 } |
| 160 if (StringUtilities.isTagName(text)) { | 161 if (StringUtilities.isTagName(text)) { |
| 161 return new IsTagSelectorElementImpl(text, offset); | 162 return new IsTagSelectorElementImpl(text, offset); |
| 162 } | 163 } |
| 163 return null; | 164 return null; |
| 164 } | 165 } |
| 165 | 166 |
| 166 /** | 167 /** |
| 168 * Adds [AngularElement] declared by the given top-level [Element]. |
| 169 * |
| 170 * @param angularElements the list to fill with top-level [AngularElement]s |
| 171 * @param unitMember the top-level member of unit, such as [ClassElement], to
get |
| 172 * [AngularElement]s from |
| 173 */ |
| 174 static void addAngularElements(List<AngularElement> angularElements, Element u
nitMember) { |
| 175 if (unitMember is ClassElement) { |
| 176 ClassElement type = unitMember; |
| 177 for (ToolkitObjectElement toolkitObject in type.toolkitObjects) { |
| 178 if (toolkitObject is AngularElement) { |
| 179 angularElements.add(toolkitObject); |
| 180 } |
| 181 } |
| 182 } |
| 183 } |
| 184 |
| 185 /** |
| 167 * Returns the [FieldElement] of the first field in the given [FieldDeclaratio
n]. | 186 * Returns the [FieldElement] of the first field in the given [FieldDeclaratio
n]. |
| 168 */ | 187 */ |
| 169 static FieldElement getOnlyFieldElement(FieldDeclaration fieldDeclaration) { | 188 static FieldElement getOnlyFieldElement(FieldDeclaration fieldDeclaration) { |
| 170 NodeList<VariableDeclaration> fields = fieldDeclaration.fields.variables; | 189 NodeList<VariableDeclaration> fields = fieldDeclaration.fields.variables; |
| 171 return fields[0].element as FieldElement; | 190 return fields[0].element as FieldElement; |
| 172 } | 191 } |
| 173 | 192 |
| 174 /** | 193 /** |
| 175 * If given [Annotation] has one argument and it is [SimpleStringLiteral], ret
urns it, | 194 * If given [Annotation] has one argument and it is [SimpleStringLiteral], ret
urns it, |
| 176 * otherwise returns `null`. | 195 * otherwise returns `null`. |
| 177 */ | 196 */ |
| 178 static SimpleStringLiteral getOnlySimpleStringLiteralArgument(Annotation annot
ation) { | 197 static SimpleStringLiteral getOnlySimpleStringLiteralArgument(Annotation annot
ation) { |
| 179 SimpleStringLiteral nameLiteral = null; | 198 SimpleStringLiteral nameLiteral = null; |
| 180 ArgumentList argsNode = annotation.arguments; | 199 ArgumentList argsNode = annotation.arguments; |
| 181 if (argsNode != null) { | 200 if (argsNode != null) { |
| 182 NodeList<Expression> args = argsNode.arguments; | 201 NodeList<Expression> args = argsNode.arguments; |
| 183 if (args.length == 1) { | 202 if (args.length == 1) { |
| 184 Expression arg = args[0]; | 203 Expression arg = args[0]; |
| 185 if (arg is SimpleStringLiteral) { | 204 if (arg is SimpleStringLiteral) { |
| 186 nameLiteral = arg; | 205 nameLiteral = arg; |
| 187 } | 206 } |
| 188 } | 207 } |
| 189 } | 208 } |
| 190 return nameLiteral; | 209 return nameLiteral; |
| 191 } | 210 } |
| 192 | 211 |
| 193 /** | 212 /** |
| 194 * Checks if given [LocalVariableElement] is an Angular <code>Module</code>. | 213 * Checks if the name range of the given [Element] is completely covered by th
e given |
| 214 * [SimpleStringLiteral]. |
| 195 */ | 215 */ |
| 196 static bool isModule2(VariableDeclaration node) { | 216 static bool isNameCoveredByLiteral(Element element, ASTNode node) { |
| 197 Type2 type = node.name.bestType; | 217 if (element != null) { |
| 198 return isModule(type); | 218 String name = element.name; |
| 219 if (name != null) { |
| 220 int nameOffset = element.nameOffset; |
| 221 int nameEnd = nameOffset + name.length; |
| 222 return node.offset <= nameOffset && nameEnd < node.end; |
| 223 } |
| 224 } |
| 225 return false; |
| 199 } | 226 } |
| 200 | 227 |
| 201 /** | 228 /** |
| 202 * Parses given [SimpleStringLiteral] using [parseSelector]. | 229 * Parses given [SimpleStringLiteral] using [parseSelector]. |
| 203 */ | 230 */ |
| 204 static AngularSelectorElement parseSelector2(SimpleStringLiteral literal) { | 231 static AngularSelectorElement parseSelector2(SimpleStringLiteral literal) { |
| 205 int offset = literal.valueOffset; | 232 int offset = literal.valueOffset; |
| 206 String text = literal.stringValue; | 233 String text = literal.stringValue; |
| 207 return parseSelector(offset, text); | 234 return parseSelector(offset, text); |
| 208 } | 235 } |
| 209 | 236 |
| 210 /** | 237 /** |
| 211 * The source containing the unit that will be analyzed. | 238 * The [AnalysisContext] that performs analysis. |
| 212 */ | 239 */ |
| 213 Source _source; | 240 AnalysisContext _context; |
| 214 | 241 |
| 215 /** | 242 /** |
| 216 * The listener to which errors will be reported. | 243 * The listener to which errors will be reported. |
| 217 */ | 244 */ |
| 218 AnalysisErrorListener _errorListener; | 245 AnalysisErrorListener _errorListener; |
| 219 | 246 |
| 220 /** | 247 /** |
| 248 * The source containing the unit that will be analyzed. |
| 249 */ |
| 250 Source _source; |
| 251 |
| 252 /** |
| 221 * The [ClassDeclaration] that is currently being analyzed. | 253 * The [ClassDeclaration] that is currently being analyzed. |
| 222 */ | 254 */ |
| 223 ClassDeclaration _classDeclaration; | 255 ClassDeclaration _classDeclaration; |
| 224 | 256 |
| 225 /** | 257 /** |
| 226 * The [ClassElementImpl] that is currently being analyzed. | 258 * The [ClassElementImpl] that is currently being analyzed. |
| 227 */ | 259 */ |
| 228 ClassElementImpl _classElement; | 260 ClassElementImpl _classElement; |
| 229 | 261 |
| 230 /** | 262 /** |
| 231 * The [ToolkitObjectElement]s to set for [classElement]. | 263 * The [ToolkitObjectElement]s to set for [classElement]. |
| 232 */ | 264 */ |
| 233 List<ToolkitObjectElement> _classToolkitObjects = []; | 265 List<ToolkitObjectElement> _classToolkitObjects = []; |
| 234 | 266 |
| 235 /** | 267 /** |
| 236 * The [Annotation] that is currently being analyzed. | 268 * The [Annotation] that is currently being analyzed. |
| 237 */ | 269 */ |
| 238 Annotation _annotation; | 270 Annotation _annotation; |
| 239 | 271 |
| 240 /** | 272 /** |
| 241 * Initialize a newly created compilation unit element builder. | 273 * Initialize a newly created compilation unit element builder. |
| 242 * | 274 * |
| 243 * @param errorListener the listener to which errors will be reported. | 275 * @param errorListener the listener to which errors will be reported. |
| 244 * @param source the source containing the unit that will be analyzed | 276 * @param source the source containing the unit that will be analyzed |
| 245 */ | 277 */ |
| 246 AngularCompilationUnitBuilder(AnalysisErrorListener errorListener, Source sour
ce) { | 278 AngularCompilationUnitBuilder(AnalysisContext context, AnalysisErrorListener e
rrorListener, Source source) { |
| 279 this._context = context; |
| 247 this._errorListener = errorListener; | 280 this._errorListener = errorListener; |
| 248 this._source = source; | 281 this._source = source; |
| 249 } | 282 } |
| 250 | 283 |
| 251 /** | 284 /** |
| 252 * Builds Angular specific element models and adds them to the existing Dart e
lements. | 285 * Builds Angular specific element models and adds them to the existing Dart e
lements. |
| 253 * | 286 * |
| 254 * @param unit the compilation unit with built Dart element models | 287 * @param unit the compilation unit with built Dart element models |
| 255 */ | 288 */ |
| 256 void build(CompilationUnit unit) { | 289 void build(CompilationUnit unit) { |
| 257 // process classes | 290 // process classes |
| 258 for (CompilationUnitMember unitMember in unit.declarations) { | 291 for (CompilationUnitMember unitMember in unit.declarations) { |
| 259 if (unitMember is ClassDeclaration) { | 292 if (unitMember is ClassDeclaration) { |
| 260 this._classDeclaration = unitMember; | 293 this._classDeclaration = unitMember; |
| 261 this._classElement = _classDeclaration.element as ClassElementImpl; | 294 this._classElement = _classDeclaration.element as ClassElementImpl; |
| 262 this._classToolkitObjects.clear(); | 295 this._classToolkitObjects.clear(); |
| 263 parseModuleClass(); | |
| 264 // process annotations | 296 // process annotations |
| 265 NodeList<Annotation> annotations = _classDeclaration.metadata; | 297 NodeList<Annotation> annotations = _classDeclaration.metadata; |
| 266 for (Annotation annotation in annotations) { | 298 for (Annotation annotation in annotations) { |
| 267 // verify annotation | 299 // verify annotation |
| 268 if (annotation.arguments == null) { | 300 if (annotation.arguments == null) { |
| 269 continue; | 301 continue; |
| 270 } | 302 } |
| 271 this._annotation = annotation; | 303 this._annotation = annotation; |
| 272 // @NgFilter | 304 // @NgFilter |
| 273 if (isAngularAnnotation2(_NG_FILTER)) { | 305 if (isAngularAnnotation2(_NG_FILTER)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 290 continue; | 322 continue; |
| 291 } | 323 } |
| 292 } | 324 } |
| 293 // set toolkit objects | 325 // set toolkit objects |
| 294 if (!_classToolkitObjects.isEmpty) { | 326 if (!_classToolkitObjects.isEmpty) { |
| 295 List<ToolkitObjectElement> objects = _classToolkitObjects; | 327 List<ToolkitObjectElement> objects = _classToolkitObjects; |
| 296 _classElement.toolkitObjects = new List.from(objects); | 328 _classElement.toolkitObjects = new List.from(objects); |
| 297 } | 329 } |
| 298 } | 330 } |
| 299 } | 331 } |
| 300 // process modules in variables | |
| 301 parseModuleVariables(unit); | |
| 302 } | 332 } |
| 303 | 333 |
| 304 /** | 334 /** |
| 305 * Creates [AngularModuleElementImpl] for given information. | |
| 306 */ | |
| 307 AngularModuleElementImpl createModuleElement(List<AngularModuleElement> childM
odules, List<ClassElement> keyTypes) { | |
| 308 AngularModuleElementImpl module = new AngularModuleElementImpl(); | |
| 309 module.childModules = new List.from(childModules); | |
| 310 module.keyTypes = new List.from(keyTypes); | |
| 311 return module; | |
| 312 } | |
| 313 | |
| 314 /** | |
| 315 * @return the argument [Expression] with given name form [annotation], may be | 335 * @return the argument [Expression] with given name form [annotation], may be |
| 316 * `null` if not found. | 336 * `null` if not found. |
| 317 */ | 337 */ |
| 318 Expression getArgument(String name) { | 338 Expression getArgument(String name) { |
| 319 List<Expression> arguments = _annotation.arguments.arguments; | 339 List<Expression> arguments = _annotation.arguments.arguments; |
| 320 for (Expression argument in arguments) { | 340 for (Expression argument in arguments) { |
| 321 if (argument is NamedExpression) { | 341 if (argument is NamedExpression) { |
| 322 NamedExpression namedExpression = argument; | 342 NamedExpression namedExpression = argument; |
| 323 String argumentName = namedExpression.name.label.name; | 343 String argumentName = namedExpression.name.label.name; |
| 324 if (name == argumentName) { | 344 if (name == argumentName) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 return constructorElement.returnType.displayName == name; | 388 return constructorElement.returnType.displayName == name; |
| 369 } | 389 } |
| 370 return false; | 390 return false; |
| 371 } | 391 } |
| 372 | 392 |
| 373 /** | 393 /** |
| 374 * Checks if [annotation] is an annotation with required name. | 394 * Checks if [annotation] is an annotation with required name. |
| 375 */ | 395 */ |
| 376 bool isAngularAnnotation2(String name) => isAngularAnnotation(_annotation, nam
e); | 396 bool isAngularAnnotation2(String name) => isAngularAnnotation(_annotation, nam
e); |
| 377 | 397 |
| 378 /** | |
| 379 * Checks if [classElement] is an Angular <code>Module</code>. | |
| 380 */ | |
| 381 bool get isModule4 { | |
| 382 InterfaceType supertype = _classElement.supertype; | |
| 383 return isModule(supertype); | |
| 384 } | |
| 385 | |
| 386 /** | |
| 387 * Analyzes [classDeclaration] and if it is a module, creates [AngularModuleEl
ement] | |
| 388 * model for it. | |
| 389 */ | |
| 390 void parseModuleClass() { | |
| 391 if (!isModule4) { | |
| 392 return; | |
| 393 } | |
| 394 // check install(), type() and value() invocations | |
| 395 List<AngularModuleElement> childModules = []; | |
| 396 List<ClassElement> keyTypes = []; | |
| 397 _classDeclaration.accept(new RecursiveASTVisitor_AngularCompilationUnitBuild
er_parseModuleClass(this, childModules, keyTypes)); | |
| 398 // set module element | |
| 399 AngularModuleElementImpl module = createModuleElement(childModules, keyTypes
); | |
| 400 _classToolkitObjects.add(module); | |
| 401 } | |
| 402 | |
| 403 /** | |
| 404 * Checks if given [MethodInvocation] is an interesting <code>Module</code> me
thod | |
| 405 * invocation and remembers corresponding elements into lists. | |
| 406 */ | |
| 407 void parseModuleInvocation(MethodInvocation node, List<AngularModuleElement> c
hildModules, List<ClassElement> keyTypes) { | |
| 408 String methodName = node.methodName.name; | |
| 409 NodeList<Expression> arguments = node.argumentList.arguments; | |
| 410 // install() | |
| 411 if (arguments.length == 1 && methodName == "install") { | |
| 412 Type2 argType = arguments[0].bestType; | |
| 413 if (argType is InterfaceType) { | |
| 414 ClassElement argElement = argType.element; | |
| 415 List<ToolkitObjectElement> toolkitObjects = argElement.toolkitObjects; | |
| 416 for (ToolkitObjectElement toolkitObject in toolkitObjects) { | |
| 417 if (toolkitObject is AngularModuleElement) { | |
| 418 childModules.add(toolkitObject); | |
| 419 } | |
| 420 } | |
| 421 } | |
| 422 return; | |
| 423 } | |
| 424 // type() and value() | |
| 425 if (arguments.length >= 1 && (methodName == "type" || methodName == "value")
) { | |
| 426 Expression arg = arguments[0]; | |
| 427 if (arg is Identifier) { | |
| 428 Element argElement = arg.staticElement; | |
| 429 if (argElement is ClassElement) { | |
| 430 keyTypes.add(argElement); | |
| 431 } | |
| 432 } | |
| 433 return; | |
| 434 } | |
| 435 } | |
| 436 | |
| 437 /** | |
| 438 * Checks every local variable in the given unit to see if it is a <code>Modul
e</code> and creates | |
| 439 * [AngularModuleElement] for it. | |
| 440 */ | |
| 441 void parseModuleVariables(CompilationUnit unit) { | |
| 442 unit.accept(new RecursiveASTVisitor_AngularCompilationUnitBuilder_parseModul
eVariables(this)); | |
| 443 } | |
| 444 | |
| 445 void parseNgComponent() { | 398 void parseNgComponent() { |
| 446 bool isValid = true; | 399 bool isValid = true; |
| 447 // publishAs | 400 // publishAs |
| 448 if (!hasStringArgument(_PUBLISH_AS)) { | 401 if (!hasStringArgument(_PUBLISH_AS)) { |
| 449 reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []); | 402 reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []); |
| 450 isValid = false; | 403 isValid = false; |
| 451 } | 404 } |
| 452 // selector | 405 // selector |
| 453 AngularSelectorElement selector = null; | 406 AngularSelectorElement selector = null; |
| 454 if (!hasStringArgument(_SELECTOR)) { | 407 if (!hasStringArgument(_SELECTOR)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 477 String name = getStringArgument(_PUBLISH_AS); | 430 String name = getStringArgument(_PUBLISH_AS); |
| 478 int nameOffset = getStringArgumentOffset(_PUBLISH_AS); | 431 int nameOffset = getStringArgumentOffset(_PUBLISH_AS); |
| 479 String templateUri = getStringArgument(_TEMPLATE_URL); | 432 String templateUri = getStringArgument(_TEMPLATE_URL); |
| 480 int templateUriOffset = getStringArgumentOffset(_TEMPLATE_URL); | 433 int templateUriOffset = getStringArgumentOffset(_TEMPLATE_URL); |
| 481 String styleUri = getStringArgument(_CSS_URL); | 434 String styleUri = getStringArgument(_CSS_URL); |
| 482 int styleUriOffset = getStringArgumentOffset(_CSS_URL); | 435 int styleUriOffset = getStringArgumentOffset(_CSS_URL); |
| 483 AngularComponentElementImpl element = new AngularComponentElementImpl(name
, nameOffset); | 436 AngularComponentElementImpl element = new AngularComponentElementImpl(name
, nameOffset); |
| 484 element.selector = selector; | 437 element.selector = selector; |
| 485 element.templateUri = templateUri; | 438 element.templateUri = templateUri; |
| 486 element.templateUriOffset = templateUriOffset; | 439 element.templateUriOffset = templateUriOffset; |
| 440 // resolve template URI |
| 441 // TODO(scheglov) resolve to HtmlElement to allow F3 ? |
| 442 { |
| 443 try { |
| 444 parseUriWithException(templateUri); |
| 445 // TODO(scheglov) think if there is better solution |
| 446 if (templateUri.startsWith("packages/")) { |
| 447 templateUri = "package:${templateUri.substring("packages/".length)}"
; |
| 448 } |
| 449 Source templateSource = _context.sourceFactory.resolveUri(_source, tem
plateUri); |
| 450 if (templateSource == null || !templateSource.exists()) { |
| 451 reportErrorForArgument(_TEMPLATE_URL, AngularCode.URI_DOES_NOT_EXIST
, [templateUri]); |
| 452 } |
| 453 element.templateSource = templateSource; |
| 454 } on URISyntaxException catch (exception) { |
| 455 reportErrorForArgument(_TEMPLATE_URL, AngularCode.INVALID_URI, [templa
teUri]); |
| 456 } |
| 457 } |
| 487 element.styleUri = styleUri; | 458 element.styleUri = styleUri; |
| 488 element.styleUriOffset = styleUriOffset; | 459 element.styleUriOffset = styleUriOffset; |
| 489 element.properties = parseNgComponentProperties(true); | 460 element.properties = parseNgComponentProperties(true); |
| 490 _classToolkitObjects.add(element); | 461 _classToolkitObjects.add(element); |
| 491 } | 462 } |
| 492 } | 463 } |
| 493 | 464 |
| 494 /** | 465 /** |
| 495 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration]. | 466 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration]. |
| 496 */ | 467 */ |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 Expression specExpression = entry.value; | 542 Expression specExpression = entry.value; |
| 572 if (specExpression is! SimpleStringLiteral) { | 543 if (specExpression is! SimpleStringLiteral) { |
| 573 reportError(specExpression, AngularCode.INVALID_PROPERTY_SPEC, []); | 544 reportError(specExpression, AngularCode.INVALID_PROPERTY_SPEC, []); |
| 574 continue; | 545 continue; |
| 575 } | 546 } |
| 576 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral; | 547 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral; |
| 577 String spec = specLiteral.value; | 548 String spec = specLiteral.value; |
| 578 // parse binding kind and field name | 549 // parse binding kind and field name |
| 579 AngularPropertyKind kind; | 550 AngularPropertyKind kind; |
| 580 int fieldNameOffset; | 551 int fieldNameOffset; |
| 581 if (spec.startsWith(_PREFIX_ATTR)) { | 552 if (StringUtilities.startsWithChar(spec, 0x40)) { |
| 582 kind = AngularPropertyKind.ATTR; | 553 kind = AngularPropertyKind.ATTR; |
| 583 fieldNameOffset = 1; | 554 fieldNameOffset = 1; |
| 584 } else if (spec.startsWith(_PREFIX_CALLBACK)) { | 555 } else if (StringUtilities.startsWithChar(spec, 0x26)) { |
| 585 kind = AngularPropertyKind.CALLBACK; | 556 kind = AngularPropertyKind.CALLBACK; |
| 586 fieldNameOffset = 1; | 557 fieldNameOffset = 1; |
| 587 } else if (spec.startsWith(_PREFIX_ONE_WAY_ONE_TIME)) { | 558 } else if (StringUtilities.startsWith3(spec, 0, 0x3D, 0x3E, 0x21)) { |
| 588 kind = AngularPropertyKind.ONE_WAY_ONE_TIME; | 559 kind = AngularPropertyKind.ONE_WAY_ONE_TIME; |
| 589 fieldNameOffset = 3; | 560 fieldNameOffset = 3; |
| 590 } else if (spec.startsWith(_PREFIX_ONE_WAY)) { | 561 } else if (StringUtilities.startsWith2(spec, 0, 0x3D, 0x3E)) { |
| 591 kind = AngularPropertyKind.ONE_WAY; | 562 kind = AngularPropertyKind.ONE_WAY; |
| 592 fieldNameOffset = 2; | 563 fieldNameOffset = 2; |
| 593 } else if (spec.startsWith(_PREFIX_TWO_WAY)) { | 564 } else if (StringUtilities.startsWith3(spec, 0, 0x3C, 0x3D, 0x3E)) { |
| 594 kind = AngularPropertyKind.TWO_WAY; | 565 kind = AngularPropertyKind.TWO_WAY; |
| 595 fieldNameOffset = 3; | 566 fieldNameOffset = 3; |
| 596 } else { | 567 } else { |
| 597 reportError(specLiteral, AngularCode.INVALID_PROPERTY_KIND, [spec]); | 568 reportError(specLiteral, AngularCode.INVALID_PROPERTY_KIND, [spec]); |
| 598 continue; | 569 continue; |
| 599 } | 570 } |
| 600 String fieldName = spec.substring(fieldNameOffset); | 571 String fieldName = spec.substring(fieldNameOffset); |
| 601 fieldNameOffset += specLiteral.valueOffset; | 572 fieldNameOffset += specLiteral.valueOffset; |
| 602 // prepare field | 573 // prepare field |
| 603 FieldElement field = _classElement.getField(fieldName); | 574 FieldElement field = _classElement.getField(fieldName); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 void reportErrorForAnnotation(ErrorCode errorCode, List<Object> arguments) { | 668 void reportErrorForAnnotation(ErrorCode errorCode, List<Object> arguments) { |
| 698 reportError(_annotation, errorCode, arguments); | 669 reportError(_annotation, errorCode, arguments); |
| 699 } | 670 } |
| 700 | 671 |
| 701 void reportErrorForArgument(String argumentName, ErrorCode errorCode, List<Obj
ect> arguments) { | 672 void reportErrorForArgument(String argumentName, ErrorCode errorCode, List<Obj
ect> arguments) { |
| 702 Expression argument = getArgument(argumentName); | 673 Expression argument = getArgument(argumentName); |
| 703 reportError(argument, errorCode, arguments); | 674 reportError(argument, errorCode, arguments); |
| 704 } | 675 } |
| 705 } | 676 } |
| 706 | 677 |
| 707 class RecursiveASTVisitor_AngularCompilationUnitBuilder_parseModuleClass extends
RecursiveASTVisitor<Object> { | |
| 708 final AngularCompilationUnitBuilder AngularCompilationUnitBuilder_this; | |
| 709 | |
| 710 List<AngularModuleElement> childModules; | |
| 711 | |
| 712 List<ClassElement> keyTypes; | |
| 713 | |
| 714 RecursiveASTVisitor_AngularCompilationUnitBuilder_parseModuleClass(this.Angula
rCompilationUnitBuilder_this, this.childModules, this.keyTypes) : super(); | |
| 715 | |
| 716 Object visitMethodInvocation(MethodInvocation node) { | |
| 717 if (node.target == null) { | |
| 718 AngularCompilationUnitBuilder_this.parseModuleInvocation(node, childModule
s, keyTypes); | |
| 719 } | |
| 720 return null; | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 class RecursiveASTVisitor_AngularCompilationUnitBuilder_parseModuleVariables ext
ends RecursiveASTVisitor<Object> { | |
| 725 final AngularCompilationUnitBuilder AngularCompilationUnitBuilder_this; | |
| 726 | |
| 727 RecursiveASTVisitor_AngularCompilationUnitBuilder_parseModuleVariables(this.An
gularCompilationUnitBuilder_this) : super(); | |
| 728 | |
| 729 LocalVariableElementImpl _variable = null; | |
| 730 | |
| 731 Expression _variableInit = null; | |
| 732 | |
| 733 List<AngularModuleElement> _childModules = []; | |
| 734 | |
| 735 List<ClassElement> _keyTypes = []; | |
| 736 | |
| 737 Object visitClassDeclaration(ClassDeclaration node) => null; | |
| 738 | |
| 739 Object visitFunctionDeclaration(FunctionDeclaration node) { | |
| 740 _childModules.clear(); | |
| 741 _keyTypes.clear(); | |
| 742 super.visitFunctionDeclaration(node); | |
| 743 if (_variable != null) { | |
| 744 AngularModuleElementImpl module = AngularCompilationUnitBuilder_this.creat
eModuleElement(_childModules, _keyTypes); | |
| 745 _variable.toolkitObjects = <ToolkitObjectElement> [module]; | |
| 746 } | |
| 747 return null; | |
| 748 } | |
| 749 | |
| 750 Object visitMethodInvocation(MethodInvocation node) { | |
| 751 if (_variable != null) { | |
| 752 if (isVariableInvocation(node)) { | |
| 753 AngularCompilationUnitBuilder_this.parseModuleInvocation(node, _childMod
ules, _keyTypes); | |
| 754 } | |
| 755 } | |
| 756 return null; | |
| 757 } | |
| 758 | |
| 759 Object visitVariableDeclaration(VariableDeclaration node) { | |
| 760 VariableElement element = node.element; | |
| 761 if (element is LocalVariableElementImpl && AngularCompilationUnitBuilder.isM
odule2(node)) { | |
| 762 _variable = element; | |
| 763 _variableInit = node.initializer; | |
| 764 } | |
| 765 return super.visitVariableDeclaration(node); | |
| 766 } | |
| 767 | |
| 768 bool isVariableInvocation(MethodInvocation node) { | |
| 769 Expression target = node.realTarget; | |
| 770 // var module = new Module()..type(t1)..type(t2); | |
| 771 if (_variableInit is CascadeExpression && target != null && identical(target
.parent, _variableInit)) { | |
| 772 return true; | |
| 773 } | |
| 774 // var module = new Module(); | |
| 775 // module.type(t); | |
| 776 if (target is Identifier) { | |
| 777 Element targetElement = target.staticElement; | |
| 778 return identical(targetElement, _variable); | |
| 779 } | |
| 780 // no | |
| 781 return false; | |
| 782 } | |
| 783 } | |
| 784 | |
| 785 /** | 678 /** |
| 786 * Instances of the class `CompilationUnitBuilder` build an element model for a
single | 679 * Instances of the class `CompilationUnitBuilder` build an element model for a
single |
| 787 * compilation unit. | 680 * compilation unit. |
| 788 * | 681 * |
| 789 * @coverage dart.engine.resolver | 682 * @coverage dart.engine.resolver |
| 790 */ | 683 */ |
| 791 class CompilationUnitBuilder { | 684 class CompilationUnitBuilder { |
| 792 /** | 685 /** |
| 793 * Build the compilation unit element for the given source. | 686 * Build the compilation unit element for the given source. |
| 794 * | 687 * |
| (...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2766 CatchClause catchClause = catchClauses[i]; | 2659 CatchClause catchClause = catchClauses[i]; |
| 2767 if (catchClause.onKeyword != null) { | 2660 if (catchClause.onKeyword != null) { |
| 2768 // on-catch clause found, verify that the exception type is not a subtyp
e of a previous | 2661 // on-catch clause found, verify that the exception type is not a subtyp
e of a previous |
| 2769 // on-catch exception type | 2662 // on-catch exception type |
| 2770 TypeName typeName = catchClause.exceptionType; | 2663 TypeName typeName = catchClause.exceptionType; |
| 2771 if (typeName != null && typeName.type != null) { | 2664 if (typeName != null && typeName.type != null) { |
| 2772 Type2 currentType = typeName.type; | 2665 Type2 currentType = typeName.type; |
| 2773 if (currentType.isObject) { | 2666 if (currentType.isObject) { |
| 2774 // Found catch clause clause that has Object as an exception type, t
his is equivalent to | 2667 // Found catch clause clause that has Object as an exception type, t
his is equivalent to |
| 2775 // having a catch clause that doesn't have an exception type, visit
the block, but | 2668 // having a catch clause that doesn't have an exception type, visit
the block, but |
| 2776 // generate an error on any following catch clauses (and don't visit
them). | 2669 // generate an error on any following catch clauses (and don't visi
t them). |
| 2777 safelyVisit(catchClause); | 2670 safelyVisit(catchClause); |
| 2778 if (i + 1 != numOfCatchClauses) { | 2671 if (i + 1 != numOfCatchClauses) { |
| 2779 // this catch clause is not the last in the try statement | 2672 // this catch clause is not the last in the try statement |
| 2780 CatchClause nextCatchClause = catchClauses[i + 1]; | 2673 CatchClause nextCatchClause = catchClauses[i + 1]; |
| 2781 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2674 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 2782 int offset = nextCatchClause.offset; | 2675 int offset = nextCatchClause.offset; |
| 2783 int length = lastCatchClause.end - offset; | 2676 int length = lastCatchClause.end - offset; |
| 2784 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT
CH, offset, length, []); | 2677 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT
CH, offset, length, []); |
| 2785 return null; | 2678 return null; |
| 2786 } | 2679 } |
| 2787 } | 2680 } |
| 2788 for (Type2 type in visitedTypes) { | 2681 for (Type2 type in visitedTypes) { |
| 2789 if (currentType.isSubtypeOf(type)) { | 2682 if (currentType.isSubtypeOf(type)) { |
| 2790 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2683 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 2791 int offset = catchClause.offset; | 2684 int offset = catchClause.offset; |
| 2792 int length = lastCatchClause.end - offset; | 2685 int length = lastCatchClause.end - offset; |
| 2793 _errorReporter.reportError5(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o
ffset, length, [currentType.displayName, type.displayName]); | 2686 _errorReporter.reportError5(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o
ffset, length, [currentType.displayName, type.displayName]); |
| 2794 return null; | 2687 return null; |
| 2795 } | 2688 } |
| 2796 } | 2689 } |
| 2797 visitedTypes.add(currentType); | 2690 visitedTypes.add(currentType); |
| 2798 } | 2691 } |
| 2799 safelyVisit(catchClause); | 2692 safelyVisit(catchClause); |
| 2800 } else { | 2693 } else { |
| 2801 // Found catch clause clause that doesn't have an exception type, visit
the block, but | 2694 // Found catch clause clause that doesn't have an exception type, visit
the block, but |
| 2802 // generate an error on any following catch clauses (and don't visit the
m). | 2695 // generate an error on any following catch clauses (and don't visit the
m). |
| 2803 safelyVisit(catchClause); | 2696 safelyVisit(catchClause); |
| 2804 if (i + 1 != numOfCatchClauses) { | 2697 if (i + 1 != numOfCatchClauses) { |
| 2805 // this catch clause is not the last in the try statement | 2698 // this catch clause is not the last in the try statement |
| 2806 CatchClause nextCatchClause = catchClauses[i + 1]; | 2699 CatchClause nextCatchClause = catchClauses[i + 1]; |
| 2807 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2700 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 2808 int offset = nextCatchClause.offset; | 2701 int offset = nextCatchClause.offset; |
| 2809 int length = lastCatchClause.end - offset; | 2702 int length = lastCatchClause.end - offset; |
| 2810 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
offset, length, []); | 2703 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
offset, length, []); |
| 2811 return null; | 2704 return null; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2845 ValidResult getConstantBooleanValue(Expression expression) { | 2738 ValidResult getConstantBooleanValue(Expression expression) { |
| 2846 if (expression is BooleanLiteral) { | 2739 if (expression is BooleanLiteral) { |
| 2847 if (expression.value) { | 2740 if (expression.value) { |
| 2848 return new ValidResult(new DartObjectImpl(null, BoolState.from(true))); | 2741 return new ValidResult(new DartObjectImpl(null, BoolState.from(true))); |
| 2849 } else { | 2742 } else { |
| 2850 return new ValidResult(new DartObjectImpl(null, BoolState.from(false))); | 2743 return new ValidResult(new DartObjectImpl(null, BoolState.from(false))); |
| 2851 } | 2744 } |
| 2852 } | 2745 } |
| 2853 // Don't consider situations where we could evaluate to a constant boolean e
xpression with the | 2746 // Don't consider situations where we could evaluate to a constant boolean e
xpression with the |
| 2854 // ConstantVisitor | 2747 // ConstantVisitor |
| 2855 // else { | 2748 // |
| 2856 // EvaluationResultImpl result = expression.accept(new ConstantVisitor(
)); | 2749 // else { |
| 2857 // if (result == ValidResult.RESULT_TRUE) { | 2750 // |
| 2858 // return ValidResult.RESULT_TRUE; | 2751 // EvaluationResultImpl result = expression.accept(new ConstantVisitor(
)); |
| 2859 // } else if (result == ValidResult.RESULT_FALSE) { | 2752 // |
| 2860 // return ValidResult.RESULT_FALSE; | 2753 // if (result == ValidResult.RESULT_TRUE) { |
| 2861 // } | 2754 // |
| 2862 // return null; | 2755 // return ValidResult.RESULT_TRUE; |
| 2863 // } | 2756 // |
| 2757 // } else if (result == ValidResult.RESULT_FALSE) { |
| 2758 // |
| 2759 // return ValidResult.RESULT_FALSE; |
| 2760 // |
| 2761 // } |
| 2762 // |
| 2763 // return null; |
| 2764 // |
| 2765 // } |
| 2864 return null; | 2766 return null; |
| 2865 } | 2767 } |
| 2866 | 2768 |
| 2867 /** | 2769 /** |
| 2868 * Return `true` if and only if the passed expression is resolved to a constan
t variable. | 2770 * Return `true` if and only if the passed expression is resolved to a constan
t variable. |
| 2869 * | 2771 * |
| 2870 * @param expression some conditional expression | 2772 * @param expression some conditional expression |
| 2871 * @return `true` if and only if the passed expression is resolved to a consta
nt variable | 2773 * @return `true` if and only if the passed expression is resolved to a consta
nt variable |
| 2872 */ | 2774 */ |
| 2873 bool isDebugConstant(Expression expression) { | 2775 bool isDebugConstant(Expression expression) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2893 * @param node the node to be visited | 2795 * @param node the node to be visited |
| 2894 */ | 2796 */ |
| 2895 void safelyVisit(ASTNode node) { | 2797 void safelyVisit(ASTNode node) { |
| 2896 if (node != null) { | 2798 if (node != null) { |
| 2897 node.accept(this); | 2799 node.accept(this); |
| 2898 } | 2800 } |
| 2899 } | 2801 } |
| 2900 } | 2802 } |
| 2901 | 2803 |
| 2902 /** | 2804 /** |
| 2805 * Instances of the class `ExitDetector` determine whether the visited AST node
is guaranteed |
| 2806 * to terminate by executing a `return` statement, `throw` expression, `rethrow` |
| 2807 * expression, or simple infinite loop such as `while(true)`. |
| 2808 */ |
| 2809 class ExitDetector extends GeneralizingASTVisitor<bool> { |
| 2810 bool visitArgumentList(ArgumentList node) => visitExpressions(node.arguments); |
| 2811 |
| 2812 bool visitAsExpression(AsExpression node) => node.expression.accept(this); |
| 2813 |
| 2814 bool visitAssertStatement(AssertStatement node) => node.condition.accept(this)
; |
| 2815 |
| 2816 bool visitAssignmentExpression(AssignmentExpression node) => node.leftHandSide
.accept(this) || node.rightHandSide.accept(this); |
| 2817 |
| 2818 bool visitBinaryExpression(BinaryExpression node) { |
| 2819 Expression lhsExpression = node.leftOperand; |
| 2820 sc.TokenType operatorType = node.operator.type; |
| 2821 // If the operator is || and the left hand side is false literal, don't cons
ider the RHS of the |
| 2822 // binary expression. |
| 2823 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} |
| 2824 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? |
| 2825 if (identical(operatorType, sc.TokenType.BAR_BAR)) { |
| 2826 if (lhsExpression is BooleanLiteral) { |
| 2827 BooleanLiteral booleanLiteral = lhsExpression; |
| 2828 if (!booleanLiteral.value) { |
| 2829 return false; |
| 2830 } |
| 2831 } |
| 2832 } |
| 2833 // If the operator is && and the left hand side is true literal, don't consi
der the RHS of the |
| 2834 // binary expression. |
| 2835 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) { |
| 2836 if (lhsExpression is BooleanLiteral) { |
| 2837 BooleanLiteral booleanLiteral = lhsExpression; |
| 2838 if (booleanLiteral.value) { |
| 2839 return false; |
| 2840 } |
| 2841 } |
| 2842 } |
| 2843 return lhsExpression.accept(this) || node.rightOperand.accept(this); |
| 2844 } |
| 2845 |
| 2846 bool visitBlock(Block node) => visitStatements(node.statements); |
| 2847 |
| 2848 bool visitBlockFunctionBody(BlockFunctionBody node) => node.block.accept(this)
; |
| 2849 |
| 2850 bool visitBreakStatement(BreakStatement node) => false; |
| 2851 |
| 2852 bool visitCascadeExpression(CascadeExpression node) { |
| 2853 Expression target = node.target; |
| 2854 if (target.accept(this)) { |
| 2855 return true; |
| 2856 } |
| 2857 return visitExpressions(node.cascadeSections); |
| 2858 } |
| 2859 |
| 2860 bool visitConditionalExpression(ConditionalExpression node) { |
| 2861 Expression conditionExpression = node.condition; |
| 2862 Expression thenStatement = node.thenExpression; |
| 2863 Expression elseStatement = node.elseExpression; |
| 2864 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} |
| 2865 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? |
| 2866 if (conditionExpression.accept(this)) { |
| 2867 return true; |
| 2868 } |
| 2869 if (thenStatement == null || elseStatement == null) { |
| 2870 return false; |
| 2871 } |
| 2872 return thenStatement.accept(this) && elseStatement.accept(this); |
| 2873 } |
| 2874 |
| 2875 bool visitContinueStatement(ContinueStatement node) => false; |
| 2876 |
| 2877 bool visitDoStatement(DoStatement node) { |
| 2878 Expression conditionExpression = node.condition; |
| 2879 if (conditionExpression.accept(this)) { |
| 2880 return true; |
| 2881 } |
| 2882 // TODO(jwren) Do we want to take all constant expressions into account? |
| 2883 if (conditionExpression is BooleanLiteral) { |
| 2884 BooleanLiteral booleanLiteral = conditionExpression; |
| 2885 if (booleanLiteral.value) { |
| 2886 return node.body.accept(this); |
| 2887 } |
| 2888 } |
| 2889 return false; |
| 2890 } |
| 2891 |
| 2892 bool visitEmptyStatement(EmptyStatement node) => false; |
| 2893 |
| 2894 bool visitExpressionStatement(ExpressionStatement node) => node.expression.acc
ept(this); |
| 2895 |
| 2896 bool visitForEachStatement(ForEachStatement node) => node.iterator.accept(this
); |
| 2897 |
| 2898 bool visitForStatement(ForStatement node) { |
| 2899 if (node.variables != null && visitVariableDeclarations(node.variables.varia
bles)) { |
| 2900 return true; |
| 2901 } |
| 2902 if (node.initialization != null && node.initialization.accept(this)) { |
| 2903 return true; |
| 2904 } |
| 2905 if (node.condition != null && node.condition.accept(this)) { |
| 2906 return true; |
| 2907 } |
| 2908 return visitExpressions(node.updaters); |
| 2909 } |
| 2910 |
| 2911 bool visitFunctionDeclarationStatement(FunctionDeclarationStatement node) => f
alse; |
| 2912 |
| 2913 bool visitFunctionExpression(FunctionExpression node) => false; |
| 2914 |
| 2915 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 2916 if (node.function.accept(this)) { |
| 2917 return true; |
| 2918 } |
| 2919 return node.argumentList.accept(this); |
| 2920 } |
| 2921 |
| 2922 bool visitIdentifier(Identifier node) => false; |
| 2923 |
| 2924 bool visitIfStatement(IfStatement node) { |
| 2925 Expression conditionExpression = node.condition; |
| 2926 Statement thenStatement = node.thenStatement; |
| 2927 Statement elseStatement = node.elseStatement; |
| 2928 // TODO(jwren) Do we want to take constant expressions into account, evaluat
e if(false) {} |
| 2929 // differently than if(<condition>), when <condition> evaluates to a constan
t false value? |
| 2930 if (conditionExpression.accept(this)) { |
| 2931 return true; |
| 2932 } |
| 2933 if (thenStatement == null || elseStatement == null) { |
| 2934 return false; |
| 2935 } |
| 2936 return thenStatement.accept(this) && elseStatement.accept(this); |
| 2937 } |
| 2938 |
| 2939 bool visitIndexExpression(IndexExpression node) { |
| 2940 Expression target = node.target; |
| 2941 if (target != null && target.accept(this)) { |
| 2942 return true; |
| 2943 } |
| 2944 if (node.index.accept(this)) { |
| 2945 return true; |
| 2946 } |
| 2947 return false; |
| 2948 } |
| 2949 |
| 2950 bool visitInstanceCreationExpression(InstanceCreationExpression node) => node.
argumentList.accept(this); |
| 2951 |
| 2952 bool visitIsExpression(IsExpression node) => node.expression.accept(this); |
| 2953 |
| 2954 bool visitLabel(Label node) => false; |
| 2955 |
| 2956 bool visitLabeledStatement(LabeledStatement node) => node.statement.accept(thi
s); |
| 2957 |
| 2958 bool visitLiteral(Literal node) => false; |
| 2959 |
| 2960 bool visitMethodInvocation(MethodInvocation node) { |
| 2961 Expression target = node.target; |
| 2962 if (target != null && target.accept(this)) { |
| 2963 return true; |
| 2964 } |
| 2965 return node.argumentList.accept(this); |
| 2966 } |
| 2967 |
| 2968 bool visitNamedExpression(NamedExpression node) => node.expression.accept(this
); |
| 2969 |
| 2970 bool visitParenthesizedExpression(ParenthesizedExpression node) => node.expres
sion.accept(this); |
| 2971 |
| 2972 bool visitPostfixExpression(PostfixExpression node) => false; |
| 2973 |
| 2974 bool visitPrefixExpression(PrefixExpression node) => false; |
| 2975 |
| 2976 bool visitPropertyAccess(PropertyAccess node) => node.target.accept(this); |
| 2977 |
| 2978 bool visitRethrowExpression(RethrowExpression node) => true; |
| 2979 |
| 2980 bool visitReturnStatement(ReturnStatement node) => true; |
| 2981 |
| 2982 bool visitSuperExpression(SuperExpression node) => false; |
| 2983 |
| 2984 bool visitSwitchCase(SwitchCase node) => visitStatements(node.statements); |
| 2985 |
| 2986 bool visitSwitchDefault(SwitchDefault node) => visitStatements(node.statements
); |
| 2987 |
| 2988 bool visitSwitchStatement(SwitchStatement node) { |
| 2989 bool hasDefault = false; |
| 2990 for (SwitchMember member in node.members) { |
| 2991 if (!member.accept(this)) { |
| 2992 return false; |
| 2993 } |
| 2994 if (member is SwitchDefault) { |
| 2995 hasDefault = true; |
| 2996 } |
| 2997 } |
| 2998 return hasDefault; |
| 2999 } |
| 3000 |
| 3001 bool visitThisExpression(ThisExpression node) => false; |
| 3002 |
| 3003 bool visitThrowExpression(ThrowExpression node) => true; |
| 3004 |
| 3005 bool visitTryStatement(TryStatement node) { |
| 3006 if (node.body.accept(this)) { |
| 3007 return true; |
| 3008 } |
| 3009 Block finallyBlock = node.finallyBlock; |
| 3010 if (finallyBlock != null && finallyBlock.accept(this)) { |
| 3011 return true; |
| 3012 } |
| 3013 return false; |
| 3014 } |
| 3015 |
| 3016 bool visitTypeName(TypeName node) => false; |
| 3017 |
| 3018 bool visitVariableDeclaration(VariableDeclaration node) { |
| 3019 Expression initializer = node.initializer; |
| 3020 if (initializer != null) { |
| 3021 return initializer.accept(this); |
| 3022 } |
| 3023 return false; |
| 3024 } |
| 3025 |
| 3026 bool visitVariableDeclarationList(VariableDeclarationList node) => visitVariab
leDeclarations(node.variables); |
| 3027 |
| 3028 bool visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 3029 NodeList<VariableDeclaration> variables = node.variables.variables; |
| 3030 for (int i = 0; i < variables.length; i++) { |
| 3031 if (variables[i].accept(this)) { |
| 3032 return true; |
| 3033 } |
| 3034 } |
| 3035 return false; |
| 3036 } |
| 3037 |
| 3038 bool visitWhileStatement(WhileStatement node) { |
| 3039 Expression conditionExpression = node.condition; |
| 3040 if (conditionExpression.accept(this)) { |
| 3041 return true; |
| 3042 } |
| 3043 // TODO(jwren) Do we want to take all constant expressions into account? |
| 3044 if (conditionExpression is BooleanLiteral) { |
| 3045 BooleanLiteral booleanLiteral = conditionExpression; |
| 3046 if (booleanLiteral.value) { |
| 3047 return node.body.accept(this); |
| 3048 } |
| 3049 } |
| 3050 return false; |
| 3051 } |
| 3052 |
| 3053 bool visitExpressions(NodeList<Expression> expressions) { |
| 3054 for (int i = expressions.length - 1; i >= 0; i--) { |
| 3055 if (expressions[i].accept(this)) { |
| 3056 return true; |
| 3057 } |
| 3058 } |
| 3059 return false; |
| 3060 } |
| 3061 |
| 3062 bool visitStatements(NodeList<Statement> statements) { |
| 3063 for (int i = statements.length - 1; i >= 0; i--) { |
| 3064 if (statements[i].accept(this)) { |
| 3065 return true; |
| 3066 } |
| 3067 } |
| 3068 return false; |
| 3069 } |
| 3070 |
| 3071 bool visitVariableDeclarations(NodeList<VariableDeclaration> variableDeclarati
ons) { |
| 3072 for (int i = variableDeclarations.length - 1; i >= 0; i--) { |
| 3073 if (variableDeclarations[i].accept(this)) { |
| 3074 return true; |
| 3075 } |
| 3076 } |
| 3077 return false; |
| 3078 } |
| 3079 } |
| 3080 |
| 3081 /** |
| 2903 * Instances of the class `HintGenerator` traverse a library's worth of dart cod
e at a time to | 3082 * Instances of the class `HintGenerator` traverse a library's worth of dart cod
e at a time to |
| 2904 * generate hints over the set of sources. | 3083 * generate hints over the set of sources. |
| 2905 * | 3084 * |
| 2906 * @see HintCode | 3085 * @see HintCode |
| 2907 * @coverage dart.engine.resolver | 3086 * @coverage dart.engine.resolver |
| 2908 */ | 3087 */ |
| 2909 class HintGenerator { | 3088 class HintGenerator { |
| 2910 List<CompilationUnit> _compilationUnits; | 3089 List<CompilationUnit> _compilationUnits; |
| 2911 | 3090 |
| 2912 AnalysisContext _context; | 3091 AnalysisContext _context; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3327 * @param path the file path being verified (not `null`) | 3506 * @param path the file path being verified (not `null`) |
| 3328 * @return `true` if and only if an error code is generated on the passed node | 3507 * @return `true` if and only if an error code is generated on the passed node |
| 3329 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE | 3508 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE |
| 3330 */ | 3509 */ |
| 3331 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { | 3510 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { |
| 3332 Source source = getSource(uriLiteral); | 3511 Source source = getSource(uriLiteral); |
| 3333 String fullName = getSourceFullName(source); | 3512 String fullName = getSourceFullName(source); |
| 3334 if (fullName != null) { | 3513 if (fullName != null) { |
| 3335 int pathIndex = 0; | 3514 int pathIndex = 0; |
| 3336 int fullNameIndex = fullName.length; | 3515 int fullNameIndex = fullName.length; |
| 3337 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { | 3516 while (pathIndex < path.length && StringUtilities.startsWith3(path, pathIn
dex, 0x2E, 0x2E, 0x2F)) { |
| 3338 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); | 3517 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); |
| 3339 if (fullNameIndex < 4) { | 3518 if (fullNameIndex < 4) { |
| 3340 return false; | 3519 return false; |
| 3341 } | 3520 } |
| 3342 // Check for "/lib" at a specified place in the fullName | 3521 // Check for "/lib" at a specified place in the fullName |
| 3343 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) { | 3522 if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, 0x2F, 0x6C,
0x69, 0x62)) { |
| 3344 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP
EC_YAML; | 3523 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP
EC_YAML; |
| 3345 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat
ivePubspecPath); | 3524 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat
ivePubspecPath); |
| 3346 if (pubspecSource != null && pubspecSource.exists()) { | 3525 if (pubspecSource != null && pubspecSource.exists()) { |
| 3347 // Files inside the lib directory hierarchy should not reference fil
es outside | 3526 // Files inside the lib directory hierarchy should not reference fil
es outside |
| 3348 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB
_REFERENCES_FILE_OUTSIDE, uriLiteral, []); | 3527 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB
_REFERENCES_FILE_OUTSIDE, uriLiteral, []); |
| 3349 } | 3528 } |
| 3350 return true; | 3529 return true; |
| 3351 } | 3530 } |
| 3352 pathIndex += 3; | 3531 pathIndex += 3; |
| 3353 } | 3532 } |
| 3354 } | 3533 } |
| 3355 return false; | 3534 return false; |
| 3356 } | 3535 } |
| 3357 | 3536 |
| 3358 /** | 3537 /** |
| 3359 * This verifies that the passed file import directive is not contained in a s
ource outside a | 3538 * This verifies that the passed file import directive is not contained in a s
ource outside a |
| 3360 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory | 3539 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory |
| 3361 * hierarchy. | 3540 * hierarchy. |
| 3362 * | 3541 * |
| 3363 * @param uriLiteral the import URL (not `null`) | 3542 * @param uriLiteral the import URL (not `null`) |
| 3364 * @param path the file path being verified (not `null`) | 3543 * @param path the file path being verified (not `null`) |
| 3365 * @return `true` if and only if an error code is generated on the passed node | 3544 * @return `true` if and only if an error code is generated on the passed node |
| 3366 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE | 3545 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE |
| 3367 */ | 3546 */ |
| 3368 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { | 3547 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { |
| 3369 if (path.startsWith("lib/")) { | 3548 if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) { |
| 3370 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { | 3549 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { |
| 3371 return true; | 3550 return true; |
| 3372 } | 3551 } |
| 3373 } | 3552 } |
| 3374 int pathIndex = path.indexOf("/lib/"); | 3553 int pathIndex = StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x
2F); |
| 3375 while (pathIndex != -1) { | 3554 while (pathIndex != -1) { |
| 3376 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa
thIndex + 1)) { | 3555 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa
thIndex + 1)) { |
| 3377 return true; | 3556 return true; |
| 3378 } | 3557 } |
| 3379 pathIndex = JavaString.indexOf(path, "/lib/", pathIndex + 4); | 3558 pathIndex = StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69
, 0x62, 0x2F); |
| 3380 } | 3559 } |
| 3381 return false; | 3560 return false; |
| 3382 } | 3561 } |
| 3383 | 3562 |
| 3384 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera
l, String path, int pathIndex) { | 3563 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera
l, String path, int pathIndex) { |
| 3385 Source source = getSource(uriLiteral); | 3564 Source source = getSource(uriLiteral); |
| 3386 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; | 3565 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; |
| 3387 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub
specPath); | 3566 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub
specPath); |
| 3388 if (pubspecSource == null || !pubspecSource.exists()) { | 3567 if (pubspecSource == null || !pubspecSource.exists()) { |
| 3389 return false; | 3568 return false; |
| 3390 } | 3569 } |
| 3391 String fullName = getSourceFullName(source); | 3570 String fullName = getSourceFullName(source); |
| 3392 if (fullName != null) { | 3571 if (fullName != null) { |
| 3393 if (!fullName.contains("/lib/")) { | 3572 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) <
0) { |
| 3394 // Files outside the lib directory hierarchy should not reference files
inside | 3573 // Files outside the lib directory hierarchy should not reference files
inside |
| 3395 // ... use package: url instead | 3574 // ... use package: url instead |
| 3396 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); | 3575 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); |
| 3397 return true; | 3576 return true; |
| 3398 } | 3577 } |
| 3399 } | 3578 } |
| 3400 return false; | 3579 return false; |
| 3401 } | 3580 } |
| 3402 | 3581 |
| 3403 /** | 3582 /** |
| 3404 * This verifies that the passed package import directive does not contain "..
" | 3583 * This verifies that the passed package import directive does not contain "..
" |
| 3405 * | 3584 * |
| 3406 * @param uriLiteral the import URL (not `null`) | 3585 * @param uriLiteral the import URL (not `null`) |
| 3407 * @param path the path to be validated (not `null`) | 3586 * @param path the path to be validated (not `null`) |
| 3408 * @return `true` if and only if an error code is generated on the passed node | 3587 * @return `true` if and only if an error code is generated on the passed node |
| 3409 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 3588 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 3410 */ | 3589 */ |
| 3411 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { | 3590 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { |
| 3412 if (path.startsWith("../") || path.contains("/../")) { | 3591 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || StringUtilitie
s.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { |
| 3413 // Package import should not to contain ".." | 3592 // Package import should not to contain ".." |
| 3414 _errorReporter.reportError3(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); | 3593 _errorReporter.reportError3(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); |
| 3415 return true; | 3594 return true; |
| 3416 } | 3595 } |
| 3417 return false; | 3596 return false; |
| 3418 } | 3597 } |
| 3419 | 3598 |
| 3420 /** | 3599 /** |
| 3421 * Answer the source associated with the compilation unit containing the given
AST node. | 3600 * Answer the source associated with the compilation unit containing the given
AST node. |
| 3422 * | 3601 * |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3447 String fullName = source.fullName; | 3626 String fullName = source.fullName; |
| 3448 if (fullName != null) { | 3627 if (fullName != null) { |
| 3449 return fullName.replaceAll(r'\', '/'); | 3628 return fullName.replaceAll(r'\', '/'); |
| 3450 } | 3629 } |
| 3451 } | 3630 } |
| 3452 return null; | 3631 return null; |
| 3453 } | 3632 } |
| 3454 } | 3633 } |
| 3455 | 3634 |
| 3456 /** | 3635 /** |
| 3457 * Instances of the class `ReturnDetector` determine whether the visited AST nod
e is | |
| 3458 * guaranteed (modulo exceptions) to terminate by executing a return statement. | |
| 3459 */ | |
| 3460 class ReturnDetector extends UnifyingASTVisitor<bool> { | |
| 3461 bool visitBlock(Block node) => visitStatements(node.statements); | |
| 3462 | |
| 3463 bool visitBlockFunctionBody(BlockFunctionBody node) => node.block.accept(this)
; | |
| 3464 | |
| 3465 bool visitIfStatement(IfStatement node) { | |
| 3466 Statement thenStatement = node.thenStatement; | |
| 3467 Statement elseStatement = node.elseStatement; | |
| 3468 if (thenStatement == null || elseStatement == null) { | |
| 3469 return false; | |
| 3470 } | |
| 3471 return thenStatement.accept(this) && elseStatement.accept(this); | |
| 3472 } | |
| 3473 | |
| 3474 bool visitNode(ASTNode node) => false; | |
| 3475 | |
| 3476 bool visitReturnStatement(ReturnStatement node) => true; | |
| 3477 | |
| 3478 bool visitSwitchCase(SwitchCase node) => visitStatements(node.statements); | |
| 3479 | |
| 3480 bool visitSwitchDefault(SwitchDefault node) => visitStatements(node.statements
); | |
| 3481 | |
| 3482 bool visitSwitchStatement(SwitchStatement node) { | |
| 3483 bool hasDefault = false; | |
| 3484 for (SwitchMember member in node.members) { | |
| 3485 if (!member.accept(this)) { | |
| 3486 return false; | |
| 3487 } | |
| 3488 if (member is SwitchDefault) { | |
| 3489 hasDefault = true; | |
| 3490 } | |
| 3491 } | |
| 3492 return hasDefault; | |
| 3493 } | |
| 3494 | |
| 3495 bool visitStatements(NodeList<Statement> statements) { | |
| 3496 for (int i = statements.length - 1; i >= 0; i--) { | |
| 3497 if (statements[i].accept(this)) { | |
| 3498 return true; | |
| 3499 } | |
| 3500 } | |
| 3501 return false; | |
| 3502 } | |
| 3503 } | |
| 3504 | |
| 3505 /** | |
| 3506 * Instances of the class `ToDoFinder` find to-do comments in Dart code. | 3636 * Instances of the class `ToDoFinder` find to-do comments in Dart code. |
| 3507 */ | 3637 */ |
| 3508 class ToDoFinder { | 3638 class ToDoFinder { |
| 3509 /** | 3639 /** |
| 3510 * The error reporter by which to-do comments will be reported. | 3640 * The error reporter by which to-do comments will be reported. |
| 3511 */ | 3641 */ |
| 3512 ErrorReporter _errorReporter; | 3642 ErrorReporter _errorReporter; |
| 3513 | 3643 |
| 3514 /** | 3644 /** |
| 3515 * Initialize a newly created to-do finder to report to-do comments to the giv
en reporter. | 3645 * Initialize a newly created to-do finder to report to-do comments to the giv
en reporter. |
| (...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4943 } | 5073 } |
| 4944 } | 5074 } |
| 4945 } | 5075 } |
| 4946 return null; | 5076 return null; |
| 4947 } | 5077 } |
| 4948 | 5078 |
| 4949 Object visitBreakStatement(BreakStatement node) { | 5079 Object visitBreakStatement(BreakStatement node) { |
| 4950 SimpleIdentifier labelNode = node.label; | 5080 SimpleIdentifier labelNode = node.label; |
| 4951 LabelElementImpl labelElement = lookupLabel(node, labelNode); | 5081 LabelElementImpl labelElement = lookupLabel(node, labelNode); |
| 4952 if (labelElement != null && labelElement.isOnSwitchMember) { | 5082 if (labelElement != null && labelElement.isOnSwitchMember) { |
| 4953 _resolver.reportError7(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab
elNode, []); | 5083 _resolver.reportError8(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab
elNode, []); |
| 4954 } | 5084 } |
| 4955 return null; | 5085 return null; |
| 4956 } | 5086 } |
| 4957 | 5087 |
| 4958 Object visitClassDeclaration(ClassDeclaration node) { | 5088 Object visitClassDeclaration(ClassDeclaration node) { |
| 4959 setMetadata(node.element, node); | 5089 setMetadata(node.element, node); |
| 4960 return null; | 5090 return null; |
| 4961 } | 5091 } |
| 4962 | 5092 |
| 4963 Object visitClassTypeAlias(ClassTypeAlias node) { | 5093 Object visitClassTypeAlias(ClassTypeAlias node) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5069 } | 5199 } |
| 5070 return null; | 5200 return null; |
| 5071 } | 5201 } |
| 5072 | 5202 |
| 5073 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 5203 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 5074 SimpleIdentifier fieldName = node.fieldName; | 5204 SimpleIdentifier fieldName = node.fieldName; |
| 5075 ClassElement enclosingClass = _resolver.enclosingClass; | 5205 ClassElement enclosingClass = _resolver.enclosingClass; |
| 5076 FieldElement fieldElement = enclosingClass.getField(fieldName.name); | 5206 FieldElement fieldElement = enclosingClass.getField(fieldName.name); |
| 5077 fieldName.staticElement = fieldElement; | 5207 fieldName.staticElement = fieldElement; |
| 5078 if (fieldElement == null || fieldElement.isSynthetic) { | 5208 if (fieldElement == null || fieldElement.isSynthetic) { |
| 5079 _resolver.reportError7(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F
IELD, node, [fieldName]); | 5209 _resolver.reportError8(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F
IELD, node, [fieldName]); |
| 5080 } else if (fieldElement.isStatic) { | 5210 } else if (fieldElement.isStatic) { |
| 5081 _resolver.reportError7(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD,
node, [fieldName]); | 5211 _resolver.reportError8(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD,
node, [fieldName]); |
| 5082 } | 5212 } |
| 5083 return null; | 5213 return null; |
| 5084 } | 5214 } |
| 5085 | 5215 |
| 5086 Object visitConstructorName(ConstructorName node) { | 5216 Object visitConstructorName(ConstructorName node) { |
| 5087 Type2 type = node.type.type; | 5217 Type2 type = node.type.type; |
| 5088 if (type != null && type.isDynamic) { | 5218 if (type != null && type.isDynamic) { |
| 5089 return null; | 5219 return null; |
| 5090 } else if (type is! InterfaceType) { | 5220 } else if (type is! InterfaceType) { |
| 5091 // TODO(brianwilkerson) Report these errors. | 5221 // TODO(brianwilkerson) Report these errors. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5109 name.staticElement = constructor; | 5239 name.staticElement = constructor; |
| 5110 } | 5240 } |
| 5111 node.staticElement = constructor; | 5241 node.staticElement = constructor; |
| 5112 return null; | 5242 return null; |
| 5113 } | 5243 } |
| 5114 | 5244 |
| 5115 Object visitContinueStatement(ContinueStatement node) { | 5245 Object visitContinueStatement(ContinueStatement node) { |
| 5116 SimpleIdentifier labelNode = node.label; | 5246 SimpleIdentifier labelNode = node.label; |
| 5117 LabelElementImpl labelElement = lookupLabel(node, labelNode); | 5247 LabelElementImpl labelElement = lookupLabel(node, labelNode); |
| 5118 if (labelElement != null && labelElement.isOnSwitchStatement) { | 5248 if (labelElement != null && labelElement.isOnSwitchStatement) { |
| 5119 _resolver.reportError7(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo
de, []); | 5249 _resolver.reportError8(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo
de, []); |
| 5120 } | 5250 } |
| 5121 return null; | 5251 return null; |
| 5122 } | 5252 } |
| 5123 | 5253 |
| 5124 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 5254 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 5125 setMetadata(node.element, node); | 5255 setMetadata(node.element, node); |
| 5126 return null; | 5256 return null; |
| 5127 } | 5257 } |
| 5128 | 5258 |
| 5129 Object visitExportDirective(ExportDirective node) { | 5259 Object visitExportDirective(ExportDirective node) { |
| 5130 Element element = node.element; | 5260 Element element = node.element; |
| 5131 if (element is ExportElement) { | 5261 if (element is ExportElement) { |
| 5132 // The element is null when the URI is invalid | 5262 // The element is null when the URI is invalid |
| 5133 // TODO(brianwilkerson) Figure out whether the element can ever be somethi
ng other than an | 5263 // TODO(brianwilkerson) Figure out whether the element can ever be somethi
ng other than an |
| 5134 // ExportElement | 5264 // ExportElement |
| 5135 resolveCombinators(element.exportedLibrary, node.combinators); | 5265 resolveCombinators(element.exportedLibrary, node.combinators); |
| 5136 setMetadata(element, node); | 5266 setMetadata(element, node); |
| 5137 } | 5267 } |
| 5138 return null; | 5268 return null; |
| 5139 } | 5269 } |
| 5140 | 5270 |
| 5141 Object visitFieldFormalParameter(FieldFormalParameter node) { | 5271 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 5142 String fieldName = node.identifier.name; | 5272 String fieldName = node.identifier.name; |
| 5143 ClassElement classElement = _resolver.enclosingClass; | 5273 ClassElement classElement = _resolver.enclosingClass; |
| 5144 if (classElement != null) { | 5274 if (classElement != null) { |
| 5145 FieldElement fieldElement = classElement.getField(fieldName); | 5275 FieldElement fieldElement = classElement.getField(fieldName); |
| 5146 if (fieldElement == null) { | 5276 if (fieldElement == null) { |
| 5147 _resolver.reportError7(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_
EXISTANT_FIELD, node, [fieldName]); | 5277 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_
EXISTANT_FIELD, node, [fieldName]); |
| 5148 } else { | 5278 } else { |
| 5149 ParameterElement parameterElement = node.element; | 5279 ParameterElement parameterElement = node.element; |
| 5150 if (parameterElement is FieldFormalParameterElementImpl) { | 5280 if (parameterElement is FieldFormalParameterElementImpl) { |
| 5151 FieldFormalParameterElementImpl fieldFormal = parameterElement; | 5281 FieldFormalParameterElementImpl fieldFormal = parameterElement; |
| 5152 fieldFormal.field = fieldElement; | 5282 fieldFormal.field = fieldElement; |
| 5153 Type2 declaredType = fieldFormal.type; | 5283 Type2 declaredType = fieldFormal.type; |
| 5154 Type2 fieldType = fieldElement.type; | 5284 Type2 fieldType = fieldElement.type; |
| 5155 if (node.type == null) { | 5285 if (node.type == null) { |
| 5156 fieldFormal.type = fieldType; | 5286 fieldFormal.type = fieldType; |
| 5157 } | 5287 } |
| 5158 if (fieldElement.isSynthetic) { | 5288 if (fieldElement.isSynthetic) { |
| 5159 _resolver.reportError7(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
NON_EXISTANT_FIELD, node, [fieldName]); | 5289 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
NON_EXISTANT_FIELD, node, [fieldName]); |
| 5160 } else if (fieldElement.isStatic) { | 5290 } else if (fieldElement.isStatic) { |
| 5161 _resolver.reportError7(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
STATIC_FIELD, node, [fieldName]); | 5291 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
STATIC_FIELD, node, [fieldName]); |
| 5162 } else if (declaredType != null && fieldType != null && !declaredType.
isAssignableTo(fieldType)) { | 5292 } else if (declaredType != null && fieldType != null && !declaredType.
isAssignableTo(fieldType)) { |
| 5163 // TODO(brianwilkerson) We should implement a displayName() method f
or types that will | 5293 // TODO(brianwilkerson) We should implement a displayName() method f
or types that will |
| 5164 // work nicely with function types and then use that below. | 5294 // work nicely with function types and then use that below. |
| 5165 _resolver.reportError7(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N
OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]); | 5295 _resolver.reportError8(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N
OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]); |
| 5166 } | 5296 } |
| 5167 } else { | 5297 } else { |
| 5168 if (fieldElement.isSynthetic) { | 5298 if (fieldElement.isSynthetic) { |
| 5169 _resolver.reportError7(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
NON_EXISTANT_FIELD, node, [fieldName]); | 5299 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
NON_EXISTANT_FIELD, node, [fieldName]); |
| 5170 } else if (fieldElement.isStatic) { | 5300 } else if (fieldElement.isStatic) { |
| 5171 _resolver.reportError7(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
STATIC_FIELD, node, [fieldName]); | 5301 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_
STATIC_FIELD, node, [fieldName]); |
| 5172 } | 5302 } |
| 5173 } | 5303 } |
| 5174 } | 5304 } |
| 5175 } | 5305 } |
| 5176 // else { | 5306 // else { |
| 5177 // // TODO(jwren) Report error, constructor initializer variable is a top
level element | 5307 // // TODO(jwren) Report error, constructor initializer variable is a top
level element |
| 5178 // // (Either here or in ErrorVerifier#checkForAllFinalInitializedErrorCo
des) | 5308 // // (Either here or in ErrorVerifier#checkForAllFinalInitializedErrorCo
des) |
| 5179 // } | 5309 // } |
| 5310 setMetadata2(node.element, node); |
| 5180 return super.visitFieldFormalParameter(node); | 5311 return super.visitFieldFormalParameter(node); |
| 5181 } | 5312 } |
| 5182 | 5313 |
| 5183 Object visitFunctionDeclaration(FunctionDeclaration node) { | 5314 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 5184 setMetadata(node.element, node); | 5315 setMetadata(node.element, node); |
| 5185 return null; | 5316 return null; |
| 5186 } | 5317 } |
| 5187 | 5318 |
| 5188 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 5319 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 5189 // TODO(brianwilkerson) Can we ever resolve the function being invoked? | 5320 // TODO(brianwilkerson) Can we ever resolve the function being invoked? |
| 5190 Expression expression = node.function; | 5321 Expression expression = node.function; |
| 5191 if (expression is FunctionExpression) { | 5322 if (expression is FunctionExpression) { |
| 5192 FunctionExpression functionExpression = expression; | 5323 FunctionExpression functionExpression = expression; |
| 5193 ExecutableElement functionElement = functionExpression.element; | 5324 ExecutableElement functionElement = functionExpression.element; |
| 5194 ArgumentList argumentList = node.argumentList; | 5325 ArgumentList argumentList = node.argumentList; |
| 5195 List<ParameterElement> parameters = resolveArgumentsToParameters(false, ar
gumentList, functionElement); | 5326 List<ParameterElement> parameters = resolveArgumentsToParameters(false, ar
gumentList, functionElement); |
| 5196 if (parameters != null) { | 5327 if (parameters != null) { |
| 5197 argumentList.correspondingStaticParameters = parameters; | 5328 argumentList.correspondingStaticParameters = parameters; |
| 5198 } | 5329 } |
| 5199 } | 5330 } |
| 5200 return null; | 5331 return null; |
| 5201 } | 5332 } |
| 5202 | 5333 |
| 5203 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 5334 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 5204 setMetadata(node.element, node); | 5335 setMetadata(node.element, node); |
| 5205 return null; | 5336 return null; |
| 5206 } | 5337 } |
| 5207 | 5338 |
| 5339 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 5340 setMetadata2(node.element, node); |
| 5341 return null; |
| 5342 } |
| 5343 |
| 5208 Object visitImportDirective(ImportDirective node) { | 5344 Object visitImportDirective(ImportDirective node) { |
| 5209 SimpleIdentifier prefixNode = node.prefix; | 5345 SimpleIdentifier prefixNode = node.prefix; |
| 5210 if (prefixNode != null) { | 5346 if (prefixNode != null) { |
| 5211 String prefixName = prefixNode.name; | 5347 String prefixName = prefixNode.name; |
| 5212 for (PrefixElement prefixElement in _definingLibrary.prefixes) { | 5348 for (PrefixElement prefixElement in _definingLibrary.prefixes) { |
| 5213 if (prefixElement.displayName == prefixName) { | 5349 if (prefixElement.displayName == prefixName) { |
| 5214 prefixNode.staticElement = prefixElement; | 5350 prefixNode.staticElement = prefixElement; |
| 5215 break; | 5351 break; |
| 5216 } | 5352 } |
| 5217 } | 5353 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5381 } | 5517 } |
| 5382 } | 5518 } |
| 5383 } | 5519 } |
| 5384 } | 5520 } |
| 5385 generatedWithTypePropagation = true; | 5521 generatedWithTypePropagation = true; |
| 5386 } | 5522 } |
| 5387 if (errorCode == null) { | 5523 if (errorCode == null) { |
| 5388 return null; | 5524 return null; |
| 5389 } | 5525 } |
| 5390 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ | 5526 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ |
| 5391 _resolver.reportError7(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m
ethodName, [methodName.name]); | 5527 _resolver.reportError8(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m
ethodName, [methodName.name]); |
| 5392 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { | 5528 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { |
| 5393 _resolver.reportError7(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); | 5529 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); |
| 5394 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { | 5530 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { |
| 5395 String targetTypeName; | 5531 String targetTypeName; |
| 5396 if (target == null) { | 5532 if (target == null) { |
| 5397 ClassElement enclosingClass = _resolver.enclosingClass; | 5533 ClassElement enclosingClass = _resolver.enclosingClass; |
| 5398 targetTypeName = enclosingClass.displayName; | 5534 targetTypeName = enclosingClass.displayName; |
| 5399 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; | 5535 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; |
| 5400 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); | 5536 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); |
| 5401 } else { | 5537 } else { |
| 5402 // ignore Function "call" | 5538 // ignore Function "call" |
| 5403 // (if we are about to create a hint using type propagation, then we can
use type | 5539 // (if we are about to create a hint using type propagation, then we can
use type |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5419 } | 5555 } |
| 5420 targetTypeName = targetType == null ? null : targetType.displayName; | 5556 targetTypeName = targetType == null ? null : targetType.displayName; |
| 5421 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; | 5557 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; |
| 5422 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p
roxyErrorCode, methodName, [methodName.name, targetTypeName]); | 5558 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p
roxyErrorCode, methodName, [methodName.name, targetTypeName]); |
| 5423 } | 5559 } |
| 5424 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { | 5560 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { |
| 5425 // Generate the type name. | 5561 // Generate the type name. |
| 5426 // The error code will never be generated via type propagation | 5562 // The error code will never be generated via type propagation |
| 5427 Type2 targetType = getStaticType(target); | 5563 Type2 targetType = getStaticType(target); |
| 5428 String targetTypeName = targetType == null ? null : targetType.name; | 5564 String targetTypeName = targetType == null ? null : targetType.name; |
| 5429 _resolver.reportError7(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho
dName, [methodName.name, targetTypeName]); | 5565 _resolver.reportError8(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho
dName, [methodName.name, targetTypeName]); |
| 5430 } | 5566 } |
| 5431 return null; | 5567 return null; |
| 5432 } | 5568 } |
| 5433 | 5569 |
| 5434 Object visitPartDirective(PartDirective node) { | 5570 Object visitPartDirective(PartDirective node) { |
| 5435 setMetadata(node.element, node); | 5571 setMetadata(node.element, node); |
| 5436 return null; | 5572 return null; |
| 5437 } | 5573 } |
| 5438 | 5574 |
| 5439 Object visitPartOfDirective(PartOfDirective node) { | 5575 Object visitPartOfDirective(PartOfDirective node) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5477 // First, check to see whether the prefix is really a prefix. | 5613 // First, check to see whether the prefix is really a prefix. |
| 5478 // | 5614 // |
| 5479 Element prefixElement = prefix.staticElement; | 5615 Element prefixElement = prefix.staticElement; |
| 5480 if (prefixElement is PrefixElement) { | 5616 if (prefixElement is PrefixElement) { |
| 5481 Element element = _resolver.nameScope.lookup(node, _definingLibrary); | 5617 Element element = _resolver.nameScope.lookup(node, _definingLibrary); |
| 5482 if (element == null && identifier.inSetterContext()) { | 5618 if (element == null && identifier.inSetterContext()) { |
| 5483 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti
fier("${node.name}="), _definingLibrary); | 5619 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti
fier("${node.name}="), _definingLibrary); |
| 5484 } | 5620 } |
| 5485 if (element == null) { | 5621 if (element == null) { |
| 5486 if (identifier.inSetterContext()) { | 5622 if (identifier.inSetterContext()) { |
| 5487 _resolver.reportError7(StaticWarningCode.UNDEFINED_SETTER, identifier,
[identifier.name, prefixElement.name]); | 5623 _resolver.reportError8(StaticWarningCode.UNDEFINED_SETTER, identifier,
[identifier.name, prefixElement.name]); |
| 5488 } else if (node.parent is Annotation) { | 5624 } else if (node.parent is Annotation) { |
| 5489 Annotation annotation = node.parent as Annotation; | 5625 Annotation annotation = node.parent as Annotation; |
| 5490 _resolver.reportError7(CompileTimeErrorCode.INVALID_ANNOTATION, annota
tion, []); | 5626 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annota
tion, []); |
| 5491 return null; | 5627 return null; |
| 5492 } else { | 5628 } else { |
| 5493 _resolver.reportError7(StaticWarningCode.UNDEFINED_GETTER, identifier,
[identifier.name, prefixElement.name]); | 5629 _resolver.reportError8(StaticWarningCode.UNDEFINED_GETTER, identifier,
[identifier.name, prefixElement.name]); |
| 5494 } | 5630 } |
| 5495 return null; | 5631 return null; |
| 5496 } | 5632 } |
| 5497 if (element is PropertyAccessorElement && identifier.inSetterContext()) { | 5633 if (element is PropertyAccessorElement && identifier.inSetterContext()) { |
| 5498 PropertyInducingElement variable = (element as PropertyAccessorElement).
variable; | 5634 PropertyInducingElement variable = (element as PropertyAccessorElement).
variable; |
| 5499 if (variable != null) { | 5635 if (variable != null) { |
| 5500 PropertyAccessorElement setter = variable.setter; | 5636 PropertyAccessorElement setter = variable.setter; |
| 5501 if (setter != null) { | 5637 if (setter != null) { |
| 5502 element = setter; | 5638 element = setter; |
| 5503 } | 5639 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5592 } | 5728 } |
| 5593 node.staticElement = element; | 5729 node.staticElement = element; |
| 5594 ArgumentList argumentList = node.argumentList; | 5730 ArgumentList argumentList = node.argumentList; |
| 5595 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu
mentList, element); | 5731 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu
mentList, element); |
| 5596 if (parameters != null) { | 5732 if (parameters != null) { |
| 5597 argumentList.correspondingStaticParameters = parameters; | 5733 argumentList.correspondingStaticParameters = parameters; |
| 5598 } | 5734 } |
| 5599 return null; | 5735 return null; |
| 5600 } | 5736 } |
| 5601 | 5737 |
| 5738 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 5739 setMetadata2(node.element, node); |
| 5740 return null; |
| 5741 } |
| 5742 |
| 5602 Object visitSimpleIdentifier(SimpleIdentifier node) { | 5743 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 5603 // | 5744 // |
| 5604 // Synthetic identifiers have been already reported during parsing. | 5745 // Synthetic identifiers have been already reported during parsing. |
| 5605 // | 5746 // |
| 5606 if (node.isSynthetic) { | 5747 if (node.isSynthetic) { |
| 5607 return null; | 5748 return null; |
| 5608 } | 5749 } |
| 5609 // | 5750 // |
| 5610 // We ignore identifiers that have already been resolved, such as identifier
s representing the | 5751 // We ignore identifiers that have already been resolved, such as identifier
s representing the |
| 5611 // name in a declaration. | 5752 // name in a declaration. |
| 5612 // | 5753 // |
| 5613 if (node.staticElement != null) { | 5754 if (node.staticElement != null) { |
| 5614 return null; | 5755 return null; |
| 5615 } | 5756 } |
| 5616 // | 5757 // |
| 5617 // The name dynamic denotes a Type object even though dynamic is not a class
. | 5758 // The name dynamic denotes a Type object even though dynamic is not a class
. |
| 5618 // | 5759 // |
| 5619 if (node.name == _dynamicType.name) { | 5760 if (node.name == _dynamicType.name) { |
| 5620 node.staticElement = _dynamicType.element; | 5761 node.staticElement = _dynamicType.element; |
| 5621 node.staticType = _typeType; | 5762 node.staticType = _typeType; |
| 5622 return null; | 5763 return null; |
| 5623 } | 5764 } |
| 5624 // | 5765 // |
| 5625 // Otherwise, the node should be resolved. | 5766 // Otherwise, the node should be resolved. |
| 5626 // | 5767 // |
| 5627 Element element = resolveSimpleIdentifier(node); | 5768 Element element = resolveSimpleIdentifier(node); |
| 5628 ClassElement enclosingClass = _resolver.enclosingClass; | 5769 ClassElement enclosingClass = _resolver.enclosingClass; |
| 5629 if (isFactoryConstructorReturnType(node) && element != enclosingClass) { | 5770 if (isFactoryConstructorReturnType(node) && element != enclosingClass) { |
| 5630 _resolver.reportError7(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA
SS, node, []); | 5771 _resolver.reportError8(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA
SS, node, []); |
| 5631 } else if (isConstructorReturnType(node) && element != enclosingClass) { | 5772 } else if (isConstructorReturnType(node) && element != enclosingClass) { |
| 5632 _resolver.reportError7(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node
, []); | 5773 _resolver.reportError8(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node
, []); |
| 5633 element = null; | 5774 element = null; |
| 5634 } else if (element == null || (element is PrefixElement && !isValidAsPrefix(
node))) { | 5775 } else if (element == null || (element is PrefixElement && !isValidAsPrefix(
node))) { |
| 5635 // TODO(brianwilkerson) Recover from this error. | 5776 // TODO(brianwilkerson) Recover from this error. |
| 5636 if (isConstructorReturnType(node)) { | 5777 if (isConstructorReturnType(node)) { |
| 5637 _resolver.reportError7(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no
de, []); | 5778 _resolver.reportError8(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no
de, []); |
| 5638 } else if (node.parent is Annotation) { | 5779 } else if (node.parent is Annotation) { |
| 5639 Annotation annotation = node.parent as Annotation; | 5780 Annotation annotation = node.parent as Annotation; |
| 5640 _resolver.reportError7(CompileTimeErrorCode.INVALID_ANNOTATION, annotati
on, []); | 5781 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotati
on, []); |
| 5641 } else { | 5782 } else { |
| 5642 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); | 5783 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); |
| 5643 } | 5784 } |
| 5644 } | 5785 } |
| 5645 node.staticElement = element; | 5786 node.staticElement = element; |
| 5646 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu
ll) { | 5787 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu
ll) { |
| 5647 InterfaceType enclosingType = enclosingClass.type; | 5788 InterfaceType enclosingType = enclosingClass.type; |
| 5648 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n
ull, enclosingType, node.name), null); | 5789 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n
ull, enclosingType, node.name), null); |
| 5649 node.auxiliaryElements = auxiliaryElements; | 5790 node.auxiliaryElements = auxiliaryElements; |
| 5650 } | 5791 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5667 InterfaceType superType = enclosingClass.supertype; | 5808 InterfaceType superType = enclosingClass.supertype; |
| 5668 if (superType == null) { | 5809 if (superType == null) { |
| 5669 // TODO(brianwilkerson) Report this error. | 5810 // TODO(brianwilkerson) Report this error. |
| 5670 return null; | 5811 return null; |
| 5671 } | 5812 } |
| 5672 SimpleIdentifier name = node.constructorName; | 5813 SimpleIdentifier name = node.constructorName; |
| 5673 String superName = name != null ? name.name : null; | 5814 String superName = name != null ? name.name : null; |
| 5674 ConstructorElement element = superType.lookUpConstructor(superName, _definin
gLibrary); | 5815 ConstructorElement element = superType.lookUpConstructor(superName, _definin
gLibrary); |
| 5675 if (element == null) { | 5816 if (element == null) { |
| 5676 if (name != null) { | 5817 if (name != null) { |
| 5677 _resolver.reportError7(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI
TIALIZER, node, [superType.displayName, name]); | 5818 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI
TIALIZER, node, [superType.displayName, name]); |
| 5678 } else { | 5819 } else { |
| 5679 _resolver.reportError7(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI
TIALIZER_DEFAULT, node, [superType.displayName]); | 5820 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI
TIALIZER_DEFAULT, node, [superType.displayName]); |
| 5680 } | 5821 } |
| 5681 return null; | 5822 return null; |
| 5682 } else { | 5823 } else { |
| 5683 if (element.isFactory) { | 5824 if (element.isFactory) { |
| 5684 _resolver.reportError7(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
node, [element]); | 5825 _resolver.reportError8(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
node, [element]); |
| 5685 } | 5826 } |
| 5686 } | 5827 } |
| 5687 if (name != null) { | 5828 if (name != null) { |
| 5688 name.staticElement = element; | 5829 name.staticElement = element; |
| 5689 } | 5830 } |
| 5690 node.staticElement = element; | 5831 node.staticElement = element; |
| 5691 ArgumentList argumentList = node.argumentList; | 5832 ArgumentList argumentList = node.argumentList; |
| 5692 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo
nstructor, argumentList, element); | 5833 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo
nstructor, argumentList, element); |
| 5693 if (parameters != null) { | 5834 if (parameters != null) { |
| 5694 argumentList.correspondingStaticParameters = parameters; | 5835 argumentList.correspondingStaticParameters = parameters; |
| 5695 } | 5836 } |
| 5696 return null; | 5837 return null; |
| 5697 } | 5838 } |
| 5698 | 5839 |
| 5699 Object visitSuperExpression(SuperExpression node) { | 5840 Object visitSuperExpression(SuperExpression node) { |
| 5700 if (!isSuperInValidContext(node)) { | 5841 if (!isSuperInValidContext(node)) { |
| 5701 _resolver.reportError7(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node
, []); | 5842 _resolver.reportError8(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node
, []); |
| 5702 } | 5843 } |
| 5703 return super.visitSuperExpression(node); | 5844 return super.visitSuperExpression(node); |
| 5704 } | 5845 } |
| 5705 | 5846 |
| 5706 Object visitTypeParameter(TypeParameter node) { | 5847 Object visitTypeParameter(TypeParameter node) { |
| 5707 TypeName bound = node.bound; | 5848 TypeName bound = node.bound; |
| 5708 if (bound != null) { | 5849 if (bound != null) { |
| 5709 TypeParameterElementImpl typeParameter = node.name.staticElement as TypePa
rameterElementImpl; | 5850 TypeParameterElementImpl typeParameter = node.name.staticElement as TypePa
rameterElementImpl; |
| 5710 if (typeParameter != null) { | 5851 if (typeParameter != null) { |
| 5711 typeParameter.bound = bound.type; | 5852 typeParameter.bound = bound.type; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6254 if (labelElement == null) { | 6395 if (labelElement == null) { |
| 6255 } | 6396 } |
| 6256 // | 6397 // |
| 6257 // The label element that was returned was a marker for look-up and isn'
t stored in the | 6398 // The label element that was returned was a marker for look-up and isn'
t stored in the |
| 6258 // element model. | 6399 // element model. |
| 6259 // | 6400 // |
| 6260 labelElement = null; | 6401 labelElement = null; |
| 6261 } | 6402 } |
| 6262 } else { | 6403 } else { |
| 6263 if (labelScope == null) { | 6404 if (labelScope == null) { |
| 6264 _resolver.reportError7(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode,
[labelNode.name]); | 6405 _resolver.reportError8(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode,
[labelNode.name]); |
| 6265 } else { | 6406 } else { |
| 6266 labelElement = labelScope.lookup(labelNode) as LabelElementImpl; | 6407 labelElement = labelScope.lookup(labelNode) as LabelElementImpl; |
| 6267 if (labelElement == null) { | 6408 if (labelElement == null) { |
| 6268 _resolver.reportError7(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode
, [labelNode.name]); | 6409 _resolver.reportError8(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode
, [labelNode.name]); |
| 6269 } else { | 6410 } else { |
| 6270 labelNode.staticElement = labelElement; | 6411 labelNode.staticElement = labelElement; |
| 6271 } | 6412 } |
| 6272 } | 6413 } |
| 6273 } | 6414 } |
| 6274 if (labelElement != null) { | 6415 if (labelElement != null) { |
| 6275 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem
ent); | 6416 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem
ent); |
| 6276 if (labelContainer != _resolver.enclosingFunction) { | 6417 if (labelContainer != _resolver.enclosingFunction) { |
| 6277 _resolver.reportError7(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN
ode, [labelNode.name]); | 6418 _resolver.reportError8(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN
ode, [labelNode.name]); |
| 6278 labelElement = null; | 6419 labelElement = null; |
| 6279 } | 6420 } |
| 6280 } | 6421 } |
| 6281 return labelElement; | 6422 return labelElement; |
| 6282 } | 6423 } |
| 6283 | 6424 |
| 6284 /** | 6425 /** |
| 6285 * Look up the method with the given name in the given type. Return the elemen
t representing the | 6426 * Look up the method with the given name in the given type. Return the elemen
t representing the |
| 6286 * method that was found, or `null` if there is no method with the given name. | 6427 * method that was found, or `null` if there is no method with the given name. |
| 6287 * | 6428 * |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6592 resolveAnnotationElementGetter(annotation, getter); | 6733 resolveAnnotationElementGetter(annotation, getter); |
| 6593 return; | 6734 return; |
| 6594 } | 6735 } |
| 6595 // prefix.Class.constructor(args) | 6736 // prefix.Class.constructor(args) |
| 6596 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor
(name3, _definingLibrary); | 6737 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor
(name3, _definingLibrary); |
| 6597 nameNode3.staticElement = constructor; | 6738 nameNode3.staticElement = constructor; |
| 6598 } | 6739 } |
| 6599 } | 6740 } |
| 6600 // we need constructor | 6741 // we need constructor |
| 6601 if (constructor == null) { | 6742 if (constructor == null) { |
| 6602 _resolver.reportError7(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); | 6743 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); |
| 6603 return; | 6744 return; |
| 6604 } | 6745 } |
| 6605 // record element | 6746 // record element |
| 6606 annotation.element = constructor; | 6747 annotation.element = constructor; |
| 6607 // resolve arguments | 6748 // resolve arguments |
| 6608 resolveAnnotationConstructorInvocationArguments(annotation, constructor); | 6749 resolveAnnotationConstructorInvocationArguments(annotation, constructor); |
| 6609 } | 6750 } |
| 6610 | 6751 |
| 6611 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle
ment accessorElement) { | 6752 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle
ment accessorElement) { |
| 6612 // accessor should be synthetic | 6753 // accessor should be synthetic |
| 6613 if (!accessorElement.isSynthetic) { | 6754 if (!accessorElement.isSynthetic) { |
| 6614 _resolver.reportError7(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); | 6755 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); |
| 6615 return; | 6756 return; |
| 6616 } | 6757 } |
| 6617 // variable should be constant | 6758 // variable should be constant |
| 6618 VariableElement variableElement = accessorElement.variable; | 6759 VariableElement variableElement = accessorElement.variable; |
| 6619 if (!variableElement.isConst) { | 6760 if (!variableElement.isConst) { |
| 6620 _resolver.reportError7(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); | 6761 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation
, []); |
| 6621 } | 6762 } |
| 6622 // OK | 6763 // OK |
| 6623 return; | 6764 return; |
| 6624 } | 6765 } |
| 6625 | 6766 |
| 6626 /** | 6767 /** |
| 6627 * Given a list of arguments and the element that will be invoked using those
argument, compute | 6768 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 6628 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 6769 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
| 6629 * correspond to the arguments, or `null` if no correspondence could be comput
ed. | 6770 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| 6630 * | 6771 * |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6677 int positionalArgumentCount = 0; | 6818 int positionalArgumentCount = 0; |
| 6678 Set<String> usedNames = new Set<String>(); | 6819 Set<String> usedNames = new Set<String>(); |
| 6679 for (int i = 0; i < argumentCount; i++) { | 6820 for (int i = 0; i < argumentCount; i++) { |
| 6680 Expression argument = arguments[i]; | 6821 Expression argument = arguments[i]; |
| 6681 if (argument is NamedExpression) { | 6822 if (argument is NamedExpression) { |
| 6682 SimpleIdentifier nameNode = argument.name.label; | 6823 SimpleIdentifier nameNode = argument.name.label; |
| 6683 String name = nameNode.name; | 6824 String name = nameNode.name; |
| 6684 ParameterElement element = namedParameters[name]; | 6825 ParameterElement element = namedParameters[name]; |
| 6685 if (element == null) { | 6826 if (element == null) { |
| 6686 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA
MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; | 6827 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA
MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; |
| 6687 _resolver.reportError7(errorCode, nameNode, [name]); | 6828 _resolver.reportError8(errorCode, nameNode, [name]); |
| 6688 } else { | 6829 } else { |
| 6689 resolvedParameters[i] = element; | 6830 resolvedParameters[i] = element; |
| 6690 nameNode.staticElement = element; | 6831 nameNode.staticElement = element; |
| 6691 } | 6832 } |
| 6692 if (!usedNames.add(name)) { | 6833 if (!usedNames.add(name)) { |
| 6693 _resolver.reportError7(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT,
nameNode, [name]); | 6834 _resolver.reportError8(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT,
nameNode, [name]); |
| 6694 } | 6835 } |
| 6695 } else { | 6836 } else { |
| 6696 positionalArgumentCount++; | 6837 positionalArgumentCount++; |
| 6697 if (unnamedIndex < unnamedParameterCount) { | 6838 if (unnamedIndex < unnamedParameterCount) { |
| 6698 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; | 6839 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; |
| 6699 } | 6840 } |
| 6700 } | 6841 } |
| 6701 } | 6842 } |
| 6702 if (positionalArgumentCount < requiredParameters.length) { | 6843 if (positionalArgumentCount < requiredParameters.length) { |
| 6703 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI
RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode; | 6844 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI
RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode; |
| 6704 _resolver.reportError7(errorCode, argumentList, [requiredParameters.length
, positionalArgumentCount]); | 6845 _resolver.reportError8(errorCode, argumentList, [requiredParameters.length
, positionalArgumentCount]); |
| 6705 } else if (positionalArgumentCount > unnamedParameterCount) { | 6846 } else if (positionalArgumentCount > unnamedParameterCount) { |
| 6706 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode; | 6847 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode; |
| 6707 _resolver.reportError7(errorCode, argumentList, [unnamedParameterCount, po
sitionalArgumentCount]); | 6848 _resolver.reportError8(errorCode, argumentList, [unnamedParameterCount, po
sitionalArgumentCount]); |
| 6708 } | 6849 } |
| 6709 return resolvedParameters; | 6850 return resolvedParameters; |
| 6710 } | 6851 } |
| 6711 | 6852 |
| 6712 /** | 6853 /** |
| 6713 * Resolve the names in the given combinators in the scope of the given librar
y. | 6854 * Resolve the names in the given combinators in the scope of the given librar
y. |
| 6714 * | 6855 * |
| 6715 * @param library the library that defines the names | 6856 * @param library the library that defines the names |
| 6716 * @param combinators the combinators containing the names to be resolved | 6857 * @param combinators the combinators containing the names to be resolved |
| 6717 */ | 6858 */ |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7024 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; | 7165 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; |
| 7025 addAnnotations(annotationList, variableDeclaration.metadata); | 7166 addAnnotations(annotationList, variableDeclaration.metadata); |
| 7026 } | 7167 } |
| 7027 } | 7168 } |
| 7028 if (!annotationList.isEmpty) { | 7169 if (!annotationList.isEmpty) { |
| 7029 (element as ElementImpl).metadata = new List.from(annotationList); | 7170 (element as ElementImpl).metadata = new List.from(annotationList); |
| 7030 } | 7171 } |
| 7031 } | 7172 } |
| 7032 | 7173 |
| 7033 /** | 7174 /** |
| 7175 * Given a node that can have annotations associated with it and the element t
o which that node |
| 7176 * has been resolved, create the annotations in the element model representing
the annotations on |
| 7177 * the node. |
| 7178 * |
| 7179 * @param element the element to which the node has been resolved |
| 7180 * @param node the node that can have annotations associated with it |
| 7181 */ |
| 7182 void setMetadata2(Element element, NormalFormalParameter node) { |
| 7183 if (element is! ElementImpl) { |
| 7184 return; |
| 7185 } |
| 7186 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl>
(); |
| 7187 addAnnotations(annotationList, node.metadata); |
| 7188 if (!annotationList.isEmpty) { |
| 7189 (element as ElementImpl).metadata = new List.from(annotationList); |
| 7190 } |
| 7191 } |
| 7192 |
| 7193 /** |
| 7034 * Return `true` if we should report an error as a result of looking up a memb
er in the | 7194 * Return `true` if we should report an error as a result of looking up a memb
er in the |
| 7035 * given type and not finding any member. | 7195 * given type and not finding any member. |
| 7036 * | 7196 * |
| 7037 * @param type the type in which we attempted to perform the look-up | 7197 * @param type the type in which we attempted to perform the look-up |
| 7038 * @param member the result of the look-up | 7198 * @param member the result of the look-up |
| 7039 * @return `true` if we should report an error | 7199 * @return `true` if we should report an error |
| 7040 */ | 7200 */ |
| 7041 bool shouldReportMissingMember(Type2 type, Element member) { | 7201 bool shouldReportMissingMember(Type2 type, Element member) { |
| 7042 if (member != null || type == null || type.isDynamic || type.isBottom) { | 7202 if (member != null || type == null || type.isDynamic || type.isBottom) { |
| 7043 return false; | 7203 return false; |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7850 * AST structures. | 8010 * AST structures. |
| 7851 */ | 8011 */ |
| 7852 Map<Source, ResolvableCompilationUnit> _astMap = new Map<Source, ResolvableCom
pilationUnit>(); | 8012 Map<Source, ResolvableCompilationUnit> _astMap = new Map<Source, ResolvableCom
pilationUnit>(); |
| 7853 | 8013 |
| 7854 /** | 8014 /** |
| 7855 * The library scope used when resolving elements within this library's compil
ation units. | 8015 * The library scope used when resolving elements within this library's compil
ation units. |
| 7856 */ | 8016 */ |
| 7857 LibraryScope _libraryScope; | 8017 LibraryScope _libraryScope; |
| 7858 | 8018 |
| 7859 /** | 8019 /** |
| 8020 * An array of all top-level Angular elements that could be used in this libra
ry. |
| 8021 */ |
| 8022 List<AngularElement> angularElements; |
| 8023 |
| 8024 /** |
| 7860 * An empty array that can be used to initialize lists of libraries. | 8025 * An empty array that can be used to initialize lists of libraries. |
| 7861 */ | 8026 */ |
| 7862 static List<Library> _EMPTY_ARRAY = new List<Library>(0); | 8027 static List<Library> _EMPTY_ARRAY = new List<Library>(0); |
| 7863 | 8028 |
| 7864 /** | 8029 /** |
| 7865 * The prefix of a URI using the dart-ext scheme to reference a native code li
brary. | 8030 * The prefix of a URI using the dart-ext scheme to reference a native code li
brary. |
| 7866 */ | 8031 */ |
| 7867 static String _DART_EXT_SCHEME = "dart-ext:"; | 8032 static String _DART_EXT_SCHEME = "dart-ext:"; |
| 7868 | 8033 |
| 7869 /** | 8034 /** |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8039 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, "
${uriBase}.dll"); | 8204 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, "
${uriBase}.dll"); |
| 8040 if (source == null || !source.exists()) { | 8205 if (source == null || !source.exists()) { |
| 8041 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${uri
Base}.so"); | 8206 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${uri
Base}.so"); |
| 8042 if (source == null || !source.exists()) { | 8207 if (source == null || !source.exists()) { |
| 8043 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${u
riBase}.dylib"); | 8208 source = _analysisContext.sourceFactory.resolveUri(librarySource, "${u
riBase}.dylib"); |
| 8044 if (source == null || !source.exists()) { | 8209 if (source == null || !source.exists()) { |
| 8045 _errorListener.onError(new AnalysisError.con2(librarySource, uriLite
ral.offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriCont
ent])); | 8210 _errorListener.onError(new AnalysisError.con2(librarySource, uriLite
ral.offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriCont
ent])); |
| 8046 } | 8211 } |
| 8047 } | 8212 } |
| 8048 } | 8213 } |
| 8214 _libraryElement.hasExtUri2 = true; |
| 8049 return null; | 8215 return null; |
| 8050 } | 8216 } |
| 8051 try { | 8217 try { |
| 8052 parseUriWithException(uriContent); | 8218 parseUriWithException(uriContent); |
| 8053 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, u
riContent); | 8219 Source source = _analysisContext.sourceFactory.resolveUri(librarySource, u
riContent); |
| 8054 if (source == null || !source.exists()) { | 8220 if (source == null || !source.exists()) { |
| 8055 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.
offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]
)); | 8221 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.
offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]
)); |
| 8056 } | 8222 } |
| 8057 return source; | 8223 return source; |
| 8058 } on URISyntaxException catch (exception) { | 8224 } on URISyntaxException catch (exception) { |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8999 } | 9165 } |
| 9000 } | 9166 } |
| 9001 } finally { | 9167 } finally { |
| 9002 timeCounter.stop(); | 9168 timeCounter.stop(); |
| 9003 } | 9169 } |
| 9004 // Angular | 9170 // Angular |
| 9005 timeCounter = PerformanceStatistics.angular.start(); | 9171 timeCounter = PerformanceStatistics.angular.start(); |
| 9006 try { | 9172 try { |
| 9007 for (Source source in library.compilationUnitSources) { | 9173 for (Source source in library.compilationUnitSources) { |
| 9008 CompilationUnit ast = library.getAST(source); | 9174 CompilationUnit ast = library.getAST(source); |
| 9009 new AngularCompilationUnitBuilder(_errorListener, source).build(ast); | 9175 new AngularCompilationUnitBuilder(analysisContext, _errorListener, sourc
e).build(ast); |
| 9010 } | 9176 } |
| 9177 // remember accessible Angular elements |
| 9178 LibraryElementImpl libraryElement = library.libraryElement; |
| 9179 library.angularElements = AngularCompilationUnitBuilder.getAngularElements
(libraryElement); |
| 9011 } finally { | 9180 } finally { |
| 9012 timeCounter.stop(); | 9181 timeCounter.stop(); |
| 9013 } | 9182 } |
| 9014 } | 9183 } |
| 9015 | 9184 |
| 9016 /** | 9185 /** |
| 9017 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 9186 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 9018 * given library, or `null` if the URI is not valid. | 9187 * given library, or `null` if the URI is not valid. |
| 9019 * | 9188 * |
| 9020 * @param librarySource the source representing the library containing the dir
ective | 9189 * @param librarySource the source representing the library containing the dir
ective |
| (...skipping 1887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10908 */ | 11077 */ |
| 10909 Scope get nameScope => _nameScope; | 11078 Scope get nameScope => _nameScope; |
| 10910 | 11079 |
| 10911 /** | 11080 /** |
| 10912 * Report an error with the given error code and arguments. | 11081 * Report an error with the given error code and arguments. |
| 10913 * | 11082 * |
| 10914 * @param errorCode the error code of the error to be reported | 11083 * @param errorCode the error code of the error to be reported |
| 10915 * @param node the node specifying the location of the error | 11084 * @param node the node specifying the location of the error |
| 10916 * @param arguments the arguments to the error, used to compose the error mess
age | 11085 * @param arguments the arguments to the error, used to compose the error mess
age |
| 10917 */ | 11086 */ |
| 10918 void reportError7(ErrorCode errorCode, ASTNode node, List<Object> arguments) { | 11087 void reportError8(ErrorCode errorCode, ASTNode node, List<Object> arguments) { |
| 10919 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng
th, errorCode, arguments)); | 11088 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng
th, errorCode, arguments)); |
| 10920 } | 11089 } |
| 10921 | 11090 |
| 10922 /** | 11091 /** |
| 10923 * Report an error with the given error code and arguments. | 11092 * Report an error with the given error code and arguments. |
| 10924 * | 11093 * |
| 10925 * @param errorCode the error code of the error to be reported | 11094 * @param errorCode the error code of the error to be reported |
| 10926 * @param offset the offset of the location of the error | 11095 * @param offset the offset of the location of the error |
| 10927 * @param length the length of the location of the error | 11096 * @param length the length of the location of the error |
| 10928 * @param arguments the arguments to the error, used to compose the error mess
age | 11097 * @param arguments the arguments to the error, used to compose the error mess
age |
| 10929 */ | 11098 */ |
| 10930 void reportError8(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { | 11099 void reportError9(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { |
| 10931 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC
ode, arguments)); | 11100 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC
ode, arguments)); |
| 10932 } | 11101 } |
| 10933 | 11102 |
| 10934 /** | 11103 /** |
| 10935 * Report an error with the given error code and arguments. | 11104 * Report an error with the given error code and arguments. |
| 10936 * | 11105 * |
| 10937 * @param errorCode the error code of the error to be reported | 11106 * @param errorCode the error code of the error to be reported |
| 10938 * @param token the token specifying the location of the error | 11107 * @param token the token specifying the location of the error |
| 10939 * @param arguments the arguments to the error, used to compose the error mess
age | 11108 * @param arguments the arguments to the error, used to compose the error mess
age |
| 10940 */ | 11109 */ |
| 10941 void reportError9(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ | 11110 void reportError10(ErrorCode errorCode, sc.Token token, List<Object> arguments
) { |
| 10942 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le
ngth, errorCode, arguments)); | 11111 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le
ngth, errorCode, arguments)); |
| 10943 } | 11112 } |
| 10944 | 11113 |
| 10945 /** | 11114 /** |
| 10946 * Visit the given AST node if it is not null. | 11115 * Visit the given AST node if it is not null. |
| 10947 * | 11116 * |
| 10948 * @param node the node to be visited | 11117 * @param node the node to be visited |
| 10949 */ | 11118 */ |
| 10950 void safelyVisit(ASTNode node) { | 11119 void safelyVisit(ASTNode node) { |
| 10951 if (node != null) { | 11120 if (node != null) { |
| (...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12419 * @param argumentList the list of arguments from which a type is to be extrac
ted | 12588 * @param argumentList the list of arguments from which a type is to be extrac
ted |
| 12420 * @return the type specified by the first argument in the argument list | 12589 * @return the type specified by the first argument in the argument list |
| 12421 */ | 12590 */ |
| 12422 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { | 12591 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { |
| 12423 String argumentValue = getFirstArgumentAsString(argumentList); | 12592 String argumentValue = getFirstArgumentAsString(argumentList); |
| 12424 if (argumentValue != null) { | 12593 if (argumentValue != null) { |
| 12425 // | 12594 // |
| 12426 // If the query has spaces, full parsing is required because it might be: | 12595 // If the query has spaces, full parsing is required because it might be: |
| 12427 // E[text='warning text'] | 12596 // E[text='warning text'] |
| 12428 // | 12597 // |
| 12429 if (argumentValue.contains(" ")) { | 12598 if (StringUtilities.indexOf1(argumentValue, 0, 0x20) >= 0) { |
| 12430 return null; | 12599 return null; |
| 12431 } | 12600 } |
| 12432 // | 12601 // |
| 12433 // Otherwise, try to extract the tag based on http://www.w3.org/TR/CSS2/se
lector.html. | 12602 // Otherwise, try to extract the tag based on http://www.w3.org/TR/CSS2/se
lector.html. |
| 12434 // | 12603 // |
| 12435 String tag = argumentValue; | 12604 String tag = argumentValue; |
| 12436 tag = StringUtilities.substringBefore(tag, ":"); | 12605 tag = StringUtilities.substringBeforeChar(tag, 0x3A); |
| 12437 tag = StringUtilities.substringBefore(tag, "["); | 12606 tag = StringUtilities.substringBeforeChar(tag, 0x5B); |
| 12438 tag = StringUtilities.substringBefore(tag, "."); | 12607 tag = StringUtilities.substringBeforeChar(tag, 0x2E); |
| 12439 tag = StringUtilities.substringBefore(tag, "#"); | 12608 tag = StringUtilities.substringBeforeChar(tag, 0x23); |
| 12440 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; | 12609 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; |
| 12441 ClassElement returnType = library.getType(tag); | 12610 ClassElement returnType = library.getType(tag); |
| 12442 if (returnType != null) { | 12611 if (returnType != null) { |
| 12443 return returnType.type; | 12612 return returnType.type; |
| 12444 } | 12613 } |
| 12445 } | 12614 } |
| 12446 return null; | 12615 return null; |
| 12447 } | 12616 } |
| 12448 | 12617 |
| 12449 /** | 12618 /** |
| (...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13814 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen
tList == null) { | 13983 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen
tList == null) { |
| 13815 ConstructorName name = parent; | 13984 ConstructorName name = parent; |
| 13816 if (name.name == null) { | 13985 if (name.name == null) { |
| 13817 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier
; | 13986 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier
; |
| 13818 SimpleIdentifier prefix = prefixedIdentifier.prefix; | 13987 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 13819 element = nameScope.lookup(prefix, definingLibrary); | 13988 element = nameScope.lookup(prefix, definingLibrary); |
| 13820 if (element is PrefixElement) { | 13989 if (element is PrefixElement) { |
| 13821 if (parent.parent is InstanceCreationExpression && (parent.parent as
InstanceCreationExpression).isConst) { | 13990 if (parent.parent is InstanceCreationExpression && (parent.parent as
InstanceCreationExpression).isConst) { |
| 13822 // If, if this is a const expression, then generate a | 13991 // If, if this is a const expression, then generate a |
| 13823 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. | 13992 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. |
| 13824 reportError7(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde
ntifier.identifier, [prefixedIdentifier.identifier.name]); | 13993 reportError8(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde
ntifier.identifier, [prefixedIdentifier.identifier.name]); |
| 13825 } else { | 13994 } else { |
| 13826 // Else, if this expression is a new expression, report a NEW_WITH
_NON_TYPE warning. | 13995 // Else, if this expression is a new expression, report a NEW_WITH
_NON_TYPE warning. |
| 13827 reportError7(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi
er.identifier, [prefixedIdentifier.identifier.name]); | 13996 reportError8(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi
er.identifier, [prefixedIdentifier.identifier.name]); |
| 13828 } | 13997 } |
| 13829 setElement(prefix, element); | 13998 setElement(prefix, element); |
| 13830 return null; | 13999 return null; |
| 13831 } else if (element != null) { | 14000 } else if (element != null) { |
| 13832 // | 14001 // |
| 13833 // Rewrite the constructor name. The parser, when it sees a construc
tor named "a.b", | 14002 // Rewrite the constructor name. The parser, when it sees a construc
tor named "a.b", |
| 13834 // cannot tell whether "a" is a prefix and "b" is a class name, or w
hether "a" is a | 14003 // cannot tell whether "a" is a prefix and "b" is a class name, or w
hether "a" is a |
| 13835 // class name and "b" is a constructor name. It arbitrarily chooses
the former, but | 14004 // class name and "b" is a constructor name. It arbitrarily chooses
the former, but |
| 13836 // in this case was wrong. | 14005 // in this case was wrong. |
| 13837 // | 14006 // |
| 13838 name.name = prefixedIdentifier.identifier; | 14007 name.name = prefixedIdentifier.identifier; |
| 13839 name.period = prefixedIdentifier.period; | 14008 name.period = prefixedIdentifier.period; |
| 13840 node.name = prefix; | 14009 node.name = prefix; |
| 13841 typeName = prefix; | 14010 typeName = prefix; |
| 13842 } | 14011 } |
| 13843 } | 14012 } |
| 13844 } | 14013 } |
| 13845 } | 14014 } |
| 13846 // check element | 14015 // check element |
| 13847 bool elementValid = element is! MultiplyDefinedElement; | 14016 bool elementValid = element is! MultiplyDefinedElement; |
| 13848 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation
Expression(node)) { | 14017 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation
Expression(node)) { |
| 13849 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); | 14018 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); |
| 13850 InstanceCreationExpression creation = node.parent.parent as InstanceCreati
onExpression; | 14019 InstanceCreationExpression creation = node.parent.parent as InstanceCreati
onExpression; |
| 13851 if (creation.isConst) { | 14020 if (creation.isConst) { |
| 13852 if (element == null) { | 14021 if (element == null) { |
| 13853 reportError7(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty
peName]); | 14022 reportError8(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty
peName]); |
| 13854 } else { | 14023 } else { |
| 13855 reportError7(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple,
[typeName]); | 14024 reportError8(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple,
[typeName]); |
| 13856 } | 14025 } |
| 13857 elementValid = false; | 14026 elementValid = false; |
| 13858 } else { | 14027 } else { |
| 13859 if (element != null) { | 14028 if (element != null) { |
| 13860 reportError7(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ
eName]); | 14029 reportError8(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ
eName]); |
| 13861 elementValid = false; | 14030 elementValid = false; |
| 13862 } | 14031 } |
| 13863 } | 14032 } |
| 13864 } | 14033 } |
| 13865 if (elementValid && element == null) { | 14034 if (elementValid && element == null) { |
| 13866 // We couldn't resolve the type name. | 14035 // We couldn't resolve the type name. |
| 13867 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN
_IDENTIFIER_AS_TYPE | 14036 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN
_IDENTIFIER_AS_TYPE |
| 13868 // from the ErrorVerifier, so that we don't have two errors on a built in
identifier being | 14037 // from the ErrorVerifier, so that we don't have two errors on a built in
identifier being |
| 13869 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi
erAsType(). | 14038 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi
erAsType(). |
| 13870 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); | 14039 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); |
| 13871 RedirectingConstructorKind redirectingConstructorKind; | 14040 RedirectingConstructorKind redirectingConstructorKind; |
| 13872 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) { | 14041 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) { |
| 13873 reportError7(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName,
[typeName.name]); | 14042 reportError8(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName,
[typeName.name]); |
| 13874 } else if (typeNameSimple.name == "boolean") { | 14043 } else if (typeNameSimple.name == "boolean") { |
| 13875 reportError7(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple,
[]); | 14044 reportError8(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple,
[]); |
| 13876 } else if (isTypeNameInCatchClause(node)) { | 14045 } else if (isTypeNameInCatchClause(node)) { |
| 13877 reportError7(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type
Name.name]); | 14046 reportError8(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type
Name.name]); |
| 13878 } else if (isTypeNameInAsExpression(node)) { | 14047 } else if (isTypeNameInAsExpression(node)) { |
| 13879 reportError7(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam
e]); | 14048 reportError8(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam
e]); |
| 13880 } else if (isTypeNameInIsExpression(node)) { | 14049 } else if (isTypeNameInIsExpression(node)) { |
| 13881 reportError7(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n
ame]); | 14050 reportError8(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n
ame]); |
| 13882 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod
e)) != null) { | 14051 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod
e)) != null) { |
| 13883 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting
ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn
ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; | 14052 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting
ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn
ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; |
| 13884 reportError7(errorCode, typeName, [typeName.name]); | 14053 reportError8(errorCode, typeName, [typeName.name]); |
| 13885 } else if (isTypeNameInTypeArgumentList(node)) { | 14054 } else if (isTypeNameInTypeArgumentList(node)) { |
| 13886 reportError7(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName,
[typeName.name]); | 14055 reportError8(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName,
[typeName.name]); |
| 13887 } else { | 14056 } else { |
| 13888 reportError7(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name
]); | 14057 reportError8(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name
]); |
| 13889 } | 14058 } |
| 13890 elementValid = false; | 14059 elementValid = false; |
| 13891 } | 14060 } |
| 13892 if (!elementValid) { | 14061 if (!elementValid) { |
| 13893 if (element is MultiplyDefinedElement) { | 14062 if (element is MultiplyDefinedElement) { |
| 13894 setElement(typeName, element); | 14063 setElement(typeName, element); |
| 13895 } else { | 14064 } else { |
| 13896 setElement(typeName, this._dynamicType.element); | 14065 setElement(typeName, this._dynamicType.element); |
| 13897 } | 14066 } |
| 13898 typeName.staticType = this._dynamicType; | 14067 typeName.staticType = this._dynamicType; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 13914 } else if (element is MultiplyDefinedElement) { | 14083 } else if (element is MultiplyDefinedElement) { |
| 13915 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl
ements; | 14084 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl
ements; |
| 13916 type = getType(elements); | 14085 type = getType(elements); |
| 13917 if (type != null) { | 14086 if (type != null) { |
| 13918 node.type = type; | 14087 node.type = type; |
| 13919 } | 14088 } |
| 13920 } else { | 14089 } else { |
| 13921 // The name does not represent a type. | 14090 // The name does not represent a type. |
| 13922 RedirectingConstructorKind redirectingConstructorKind; | 14091 RedirectingConstructorKind redirectingConstructorKind; |
| 13923 if (isTypeNameInCatchClause(node)) { | 14092 if (isTypeNameInCatchClause(node)) { |
| 13924 reportError7(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type
Name.name]); | 14093 reportError8(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type
Name.name]); |
| 13925 } else if (isTypeNameInAsExpression(node)) { | 14094 } else if (isTypeNameInAsExpression(node)) { |
| 13926 reportError7(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam
e]); | 14095 reportError8(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam
e]); |
| 13927 } else if (isTypeNameInIsExpression(node)) { | 14096 } else if (isTypeNameInIsExpression(node)) { |
| 13928 reportError7(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n
ame]); | 14097 reportError8(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n
ame]); |
| 13929 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod
e)) != null) { | 14098 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod
e)) != null) { |
| 13930 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting
ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn
ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; | 14099 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting
ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn
ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; |
| 13931 reportError7(errorCode, typeName, [typeName.name]); | 14100 reportError8(errorCode, typeName, [typeName.name]); |
| 13932 } else if (isTypeNameInTypeArgumentList(node)) { | 14101 } else if (isTypeNameInTypeArgumentList(node)) { |
| 13933 reportError7(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName,
[typeName.name]); | 14102 reportError8(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName,
[typeName.name]); |
| 13934 } else { | 14103 } else { |
| 13935 ASTNode parent = typeName.parent; | 14104 ASTNode parent = typeName.parent; |
| 13936 while (parent is TypeName) { | 14105 while (parent is TypeName) { |
| 13937 parent = parent.parent; | 14106 parent = parent.parent; |
| 13938 } | 14107 } |
| 13939 if (parent is ExtendsClause || parent is ImplementsClause || parent is W
ithClause || parent is ClassTypeAlias) { | 14108 if (parent is ExtendsClause || parent is ImplementsClause || parent is W
ithClause || parent is ClassTypeAlias) { |
| 13940 } else { | 14109 } else { |
| 13941 reportError7(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); | 14110 reportError8(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); |
| 13942 } | 14111 } |
| 13943 } | 14112 } |
| 13944 setElement(typeName, this._dynamicType.element); | 14113 setElement(typeName, this._dynamicType.element); |
| 13945 typeName.staticType = this._dynamicType; | 14114 typeName.staticType = this._dynamicType; |
| 13946 node.type = this._dynamicType; | 14115 node.type = this._dynamicType; |
| 13947 return null; | 14116 return null; |
| 13948 } | 14117 } |
| 13949 if (argumentList != null) { | 14118 if (argumentList != null) { |
| 13950 NodeList<TypeName> arguments = argumentList.arguments; | 14119 NodeList<TypeName> arguments = argumentList.arguments; |
| 13951 int argumentCount = arguments.length; | 14120 int argumentCount = arguments.length; |
| 13952 List<Type2> parameters = getTypeArguments(type); | 14121 List<Type2> parameters = getTypeArguments(type); |
| 13953 int parameterCount = parameters.length; | 14122 int parameterCount = parameters.length; |
| 13954 int count = Math.min(argumentCount, parameterCount); | 14123 int count = Math.min(argumentCount, parameterCount); |
| 13955 List<Type2> typeArguments = new List<Type2>(); | 14124 List<Type2> typeArguments = new List<Type2>(); |
| 13956 for (int i = 0; i < count; i++) { | 14125 for (int i = 0; i < count; i++) { |
| 13957 Type2 argumentType = getType3(arguments[i]); | 14126 Type2 argumentType = getType3(arguments[i]); |
| 13958 if (argumentType != null) { | 14127 if (argumentType != null) { |
| 13959 typeArguments.add(argumentType); | 14128 typeArguments.add(argumentType); |
| 13960 } | 14129 } |
| 13961 } | 14130 } |
| 13962 if (argumentCount != parameterCount) { | 14131 if (argumentCount != parameterCount) { |
| 13963 reportError7(getInvalidTypeParametersErrorCode(node), node, [typeName.na
me, parameterCount, argumentCount]); | 14132 reportError8(getInvalidTypeParametersErrorCode(node), node, [typeName.na
me, parameterCount, argumentCount]); |
| 13964 } | 14133 } |
| 13965 argumentCount = typeArguments.length; | 14134 argumentCount = typeArguments.length; |
| 13966 if (argumentCount < parameterCount) { | 14135 if (argumentCount < parameterCount) { |
| 13967 // | 14136 // |
| 13968 // If there were too many arguments, we already handled it by not adding
the values of the | 14137 // If there were too many arguments, we already handled it by not adding
the values of the |
| 13969 // extra arguments to the list. If there are too few, we handle it by ad
ding 'dynamic' | 14138 // extra arguments to the list. If there are too few, we handle it by ad
ding 'dynamic' |
| 13970 // enough times to make the count equal. | 14139 // enough times to make the count equal. |
| 13971 // | 14140 // |
| 13972 for (int i = argumentCount; i < parameterCount; i++) { | 14141 for (int i = argumentCount; i < parameterCount; i++) { |
| 13973 typeArguments.add(this._dynamicType); | 14142 typeArguments.add(this._dynamicType); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14326 TypeName typeName = typeNames[i]; | 14495 TypeName typeName = typeNames[i]; |
| 14327 if (!detectedRepeatOnIndex[i]) { | 14496 if (!detectedRepeatOnIndex[i]) { |
| 14328 Element element = typeName.name.staticElement; | 14497 Element element = typeName.name.staticElement; |
| 14329 for (int j = i + 1; j < typeNames.length; j++) { | 14498 for (int j = i + 1; j < typeNames.length; j++) { |
| 14330 TypeName typeName2 = typeNames[j]; | 14499 TypeName typeName2 = typeNames[j]; |
| 14331 Identifier identifier2 = typeName2.name; | 14500 Identifier identifier2 = typeName2.name; |
| 14332 String name2 = identifier2.name; | 14501 String name2 = identifier2.name; |
| 14333 Element element2 = identifier2.staticElement; | 14502 Element element2 = identifier2.staticElement; |
| 14334 if (element != null && element == element2) { | 14503 if (element != null && element == element2) { |
| 14335 detectedRepeatOnIndex[j] = true; | 14504 detectedRepeatOnIndex[j] = true; |
| 14336 reportError7(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2,
[name2]); | 14505 reportError8(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2,
[name2]); |
| 14337 } | 14506 } |
| 14338 } | 14507 } |
| 14339 } | 14508 } |
| 14340 } | 14509 } |
| 14341 } | 14510 } |
| 14342 } | 14511 } |
| 14343 | 14512 |
| 14344 /** | 14513 /** |
| 14345 * Return the type specified by the given name. | 14514 * Return the type specified by the given name. |
| 14346 * | 14515 * |
| 14347 * @param typeName the type name specifying the type to be returned | 14516 * @param typeName the type name specifying the type to be returned |
| 14348 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 14517 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 14349 * a type | 14518 * a type |
| 14350 * @param dynamicTypeError the error to produce if the type name is "dynamic" | 14519 * @param dynamicTypeError the error to produce if the type name is "dynamic" |
| 14351 * @return the type specified by the type name | 14520 * @return the type specified by the type name |
| 14352 */ | 14521 */ |
| 14353 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode
dynamicTypeError) { | 14522 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode
dynamicTypeError) { |
| 14354 Type2 type = typeName.type; | 14523 Type2 type = typeName.type; |
| 14355 if (type is InterfaceType) { | 14524 if (type is InterfaceType) { |
| 14356 return type; | 14525 return type; |
| 14357 } | 14526 } |
| 14358 // If the type is not an InterfaceType, then visitTypeName() sets the type t
o be a DynamicTypeImpl | 14527 // If the type is not an InterfaceType, then visitTypeName() sets the type t
o be a DynamicTypeImpl |
| 14359 Identifier name = typeName.name; | 14528 Identifier name = typeName.name; |
| 14360 if (name.name == sc.Keyword.DYNAMIC.syntax) { | 14529 if (name.name == sc.Keyword.DYNAMIC.syntax) { |
| 14361 reportError7(dynamicTypeError, name, [name.name]); | 14530 reportError8(dynamicTypeError, name, [name.name]); |
| 14362 } else { | 14531 } else { |
| 14363 reportError7(nonTypeError, name, [name.name]); | 14532 reportError8(nonTypeError, name, [name.name]); |
| 14364 } | 14533 } |
| 14365 return null; | 14534 return null; |
| 14366 } | 14535 } |
| 14367 | 14536 |
| 14368 /** | 14537 /** |
| 14369 * Resolve the types in the given list of type names. | 14538 * Resolve the types in the given list of type names. |
| 14370 * | 14539 * |
| 14371 * @param typeNames the type names to be resolved | 14540 * @param typeNames the type names to be resolved |
| 14372 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 14541 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 14373 * a type | 14542 * a type |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15368 /** | 15537 /** |
| 15369 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver | 15538 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver |
| 15370 * to determine which names are visible at any given point in the code. | 15539 * to determine which names are visible at any given point in the code. |
| 15371 * | 15540 * |
| 15372 * @coverage dart.engine.resolver | 15541 * @coverage dart.engine.resolver |
| 15373 */ | 15542 */ |
| 15374 abstract class Scope { | 15543 abstract class Scope { |
| 15375 /** | 15544 /** |
| 15376 * The prefix used to mark an identifier as being private to its library. | 15545 * The prefix used to mark an identifier as being private to its library. |
| 15377 */ | 15546 */ |
| 15378 static String PRIVATE_NAME_PREFIX = "_"; | 15547 static int PRIVATE_NAME_PREFIX = 0x5F; |
| 15379 | 15548 |
| 15380 /** | 15549 /** |
| 15381 * The suffix added to the declared name of a setter when looking up the sette
r. Used to | 15550 * The suffix added to the declared name of a setter when looking up the sette
r. Used to |
| 15382 * disambiguate between a getter and a setter that have the same name. | 15551 * disambiguate between a getter and a setter that have the same name. |
| 15383 */ | 15552 */ |
| 15384 static String SETTER_SUFFIX = "="; | 15553 static String SETTER_SUFFIX = "="; |
| 15385 | 15554 |
| 15386 /** | 15555 /** |
| 15387 * The name used to look up the method used to implement the unary minus opera
tor. Used to | 15556 * The name used to look up the method used to implement the unary minus opera
tor. Used to |
| 15388 * disambiguate between the unary and binary operators. | 15557 * disambiguate between the unary and binary operators. |
| 15389 */ | 15558 */ |
| 15390 static String UNARY_MINUS = "unary-"; | 15559 static String UNARY_MINUS = "unary-"; |
| 15391 | 15560 |
| 15392 /** | 15561 /** |
| 15393 * Return `true` if the given name is a library-private name. | 15562 * Return `true` if the given name is a library-private name. |
| 15394 * | 15563 * |
| 15395 * @param name the name being tested | 15564 * @param name the name being tested |
| 15396 * @return `true` if the given name is a library-private name | 15565 * @return `true` if the given name is a library-private name |
| 15397 */ | 15566 */ |
| 15398 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); | 15567 static bool isPrivateName(String name) => name != null && StringUtilities.star
tsWithChar(name, PRIVATE_NAME_PREFIX); |
| 15399 | 15568 |
| 15400 /** | 15569 /** |
| 15401 * A table mapping names that are defined in this scope to the element represe
nting the thing | 15570 * A table mapping names that are defined in this scope to the element represe
nting the thing |
| 15402 * declared with that name. | 15571 * declared with that name. |
| 15403 */ | 15572 */ |
| 15404 Map<String, Element> _definedNames = new Map<String, Element>(); | 15573 Map<String, Element> _definedNames = new Map<String, Element>(); |
| 15405 | 15574 |
| 15406 /** | 15575 /** |
| 15407 * A flag indicating whether there are any names defined in this scope. | 15576 * A flag indicating whether there are any names defined in this scope. |
| 15408 */ | 15577 */ |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16117 * with a [MethodDeclaration] in the AST structure. | 16286 * with a [MethodDeclaration] in the AST structure. |
| 16118 */ | 16287 */ |
| 16119 bool _isInStaticMethod = false; | 16288 bool _isInStaticMethod = false; |
| 16120 | 16289 |
| 16121 /** | 16290 /** |
| 16122 * This is set to `true` iff the visitor is currently visiting code in the SDK
. | 16291 * This is set to `true` iff the visitor is currently visiting code in the SDK
. |
| 16123 */ | 16292 */ |
| 16124 bool _isInSystemLibrary = false; | 16293 bool _isInSystemLibrary = false; |
| 16125 | 16294 |
| 16126 /** | 16295 /** |
| 16296 * A flag indicating whether the current library contains at least one import
directive with a URI |
| 16297 * that uses the "dart-ext" scheme. |
| 16298 */ |
| 16299 bool _hasExtUri = false; |
| 16300 |
| 16301 /** |
| 16127 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of | 16302 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of |
| 16128 * a class. | 16303 * a class. |
| 16129 */ | 16304 */ |
| 16130 ClassElement _enclosingClass; | 16305 ClassElement _enclosingClass; |
| 16131 | 16306 |
| 16132 /** | 16307 /** |
| 16133 * The method or function that we are currently visiting, or `null` if we are
not inside a | 16308 * The method or function that we are currently visiting, or `null` if we are
not inside a |
| 16134 * method or function. | 16309 * method or function. |
| 16135 */ | 16310 */ |
| 16136 ExecutableElement _enclosingFunction; | 16311 ExecutableElement _enclosingFunction; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16186 /** | 16361 /** |
| 16187 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS]
and | 16362 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS]
and |
| 16188 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. | 16363 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. |
| 16189 */ | 16364 */ |
| 16190 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 16365 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
| 16191 | 16366 |
| 16192 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { | 16367 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { |
| 16193 this._errorReporter = errorReporter; | 16368 this._errorReporter = errorReporter; |
| 16194 this._currentLibrary = currentLibrary; | 16369 this._currentLibrary = currentLibrary; |
| 16195 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; | 16370 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; |
| 16371 this._hasExtUri = currentLibrary.hasExtUri(); |
| 16196 this._typeProvider = typeProvider; | 16372 this._typeProvider = typeProvider; |
| 16197 this._inheritanceManager = inheritanceManager; | 16373 this._inheritanceManager = inheritanceManager; |
| 16198 _isEnclosingConstructorConst = false; | 16374 _isEnclosingConstructorConst = false; |
| 16199 _isInCatchClause = false; | 16375 _isInCatchClause = false; |
| 16200 _isInStaticVariableDeclaration = false; | 16376 _isInStaticVariableDeclaration = false; |
| 16201 _isInInstanceVariableDeclaration = false; | 16377 _isInInstanceVariableDeclaration = false; |
| 16202 _isInInstanceVariableInitializer = false; | 16378 _isInInstanceVariableInitializer = false; |
| 16203 _isInConstructorInitializer = false; | 16379 _isInConstructorInitializer = false; |
| 16204 _isInStaticMethod = false; | 16380 _isInStaticMethod = false; |
| 16205 _boolType = typeProvider.boolType; | 16381 _boolType = typeProvider.boolType; |
| (...skipping 2921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19127 if (counterpartAccessor != null && identical(counterpartAccessor.enclosing
Element, propertyAccessorElement.enclosingElement)) { | 19303 if (counterpartAccessor != null && identical(counterpartAccessor.enclosing
Element, propertyAccessorElement.enclosingElement)) { |
| 19128 return false; | 19304 return false; |
| 19129 } | 19305 } |
| 19130 } | 19306 } |
| 19131 if (counterpartAccessor == null) { | 19307 if (counterpartAccessor == null) { |
| 19132 // If the accessor is declared in a class, check the superclasses. | 19308 // If the accessor is declared in a class, check the superclasses. |
| 19133 if (_enclosingClass != null) { | 19309 if (_enclosingClass != null) { |
| 19134 // Figure out the correct identifier to lookup in the inheritance graph,
if 'x', then 'x=', | 19310 // Figure out the correct identifier to lookup in the inheritance graph,
if 'x', then 'x=', |
| 19135 // or if 'x=', then 'x'. | 19311 // or if 'x=', then 'x'. |
| 19136 String lookupIdentifier = propertyAccessorElement.name; | 19312 String lookupIdentifier = propertyAccessorElement.name; |
| 19137 if (lookupIdentifier.endsWith("=")) { | 19313 if (StringUtilities.endsWithChar(lookupIdentifier, 0x3D)) { |
| 19138 lookupIdentifier = lookupIdentifier.substring(0, lookupIdentifier.leng
th - 1); | 19314 lookupIdentifier = lookupIdentifier.substring(0, lookupIdentifier.leng
th - 1); |
| 19139 } else { | 19315 } else { |
| 19140 lookupIdentifier += "="; | 19316 lookupIdentifier += "="; |
| 19141 } | 19317 } |
| 19142 // lookup with the identifier. | 19318 // lookup with the identifier. |
| 19143 ExecutableElement elementFromInheritance = _inheritanceManager.lookupInh
eritance(_enclosingClass, lookupIdentifier); | 19319 ExecutableElement elementFromInheritance = _inheritanceManager.lookupInh
eritance(_enclosingClass, lookupIdentifier); |
| 19144 // Verify that we found something, and that it is an accessor | 19320 // Verify that we found something, and that it is an accessor |
| 19145 if (elementFromInheritance != null && elementFromInheritance is Property
AccessorElement) { | 19321 if (elementFromInheritance != null && elementFromInheritance is Property
AccessorElement) { |
| 19146 enclosingClassForCounterpart = elementFromInheritance.enclosingElement
as ClassElement; | 19322 enclosingClassForCounterpart = elementFromInheritance.enclosingElement
as ClassElement; |
| 19147 counterpartAccessor = elementFromInheritance; | 19323 counterpartAccessor = elementFromInheritance; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19271 } | 19447 } |
| 19272 | 19448 |
| 19273 /** | 19449 /** |
| 19274 * Checks to ensure that native function bodies can only in SDK code. | 19450 * Checks to ensure that native function bodies can only in SDK code. |
| 19275 * | 19451 * |
| 19276 * @param node the native function body to test | 19452 * @param node the native function body to test |
| 19277 * @return `true` if and only if an error code is generated on the passed node | 19453 * @return `true` if and only if an error code is generated on the passed node |
| 19278 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE | 19454 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE |
| 19279 */ | 19455 */ |
| 19280 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { | 19456 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { |
| 19281 // TODO(brianwilkerson) Figure out the right rule for when 'native' is allow
ed. | 19457 if (!_isInSystemLibrary && !_hasExtUri) { |
| 19282 if (!_isInSystemLibrary) { | |
| 19283 _errorReporter.reportError3(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); | 19458 _errorReporter.reportError3(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); |
| 19284 return true; | 19459 return true; |
| 19285 } | 19460 } |
| 19286 return false; | 19461 return false; |
| 19287 } | 19462 } |
| 19288 | 19463 |
| 19289 /** | 19464 /** |
| 19290 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. | 19465 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. |
| 19291 * | 19466 * |
| 19292 * This method assumes that the instance creation was tested to be 'new' befor
e being called. | 19467 * This method assumes that the instance creation was tested to be 'new' befor
e being called. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19655 * @return `true` if and only if an error code is generated on the passed node | 19830 * @return `true` if and only if an error code is generated on the passed node |
| 19656 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER | 19831 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER |
| 19657 */ | 19832 */ |
| 19658 bool checkForPrivateOptionalParameter(FormalParameter node) { | 19833 bool checkForPrivateOptionalParameter(FormalParameter node) { |
| 19659 // should be named parameter | 19834 // should be named parameter |
| 19660 if (node.kind != ParameterKind.NAMED) { | 19835 if (node.kind != ParameterKind.NAMED) { |
| 19661 return false; | 19836 return false; |
| 19662 } | 19837 } |
| 19663 // name should start with '_' | 19838 // name should start with '_' |
| 19664 SimpleIdentifier name = node.identifier; | 19839 SimpleIdentifier name = node.identifier; |
| 19665 if (name.isSynthetic || !name.name.startsWith("_")) { | 19840 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) { |
| 19666 return false; | 19841 return false; |
| 19667 } | 19842 } |
| 19668 // report problem | 19843 // report problem |
| 19669 _errorReporter.reportError3(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER,
node, []); | 19844 _errorReporter.reportError3(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER,
node, []); |
| 19670 return true; | 19845 return true; |
| 19671 } | 19846 } |
| 19672 | 19847 |
| 19673 /** | 19848 /** |
| 19674 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and | 19849 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and |
| 19675 * references itself directly or indirectly. | 19850 * references itself directly or indirectly. |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20841 | 21016 |
| 20842 /** | 21017 /** |
| 20843 * The template used to create the message to be displayed for this error. | 21018 * The template used to create the message to be displayed for this error. |
| 20844 */ | 21019 */ |
| 20845 final String message; | 21020 final String message; |
| 20846 | 21021 |
| 20847 /** | 21022 /** |
| 20848 * The template used to create the correction to be displayed for this error,
or `null` if | 21023 * The template used to create the correction to be displayed for this error,
or `null` if |
| 20849 * there is no correction information for this error. | 21024 * there is no correction information for this error. |
| 20850 */ | 21025 */ |
| 20851 String correction10; | 21026 String correction9; |
| 20852 | 21027 |
| 20853 /** | 21028 /** |
| 20854 * Initialize a newly created error code to have the given type and message. | 21029 * Initialize a newly created error code to have the given type and message. |
| 20855 * | 21030 * |
| 20856 * @param type the type of this error | 21031 * @param type the type of this error |
| 20857 * @param message the message template used to create the message to be displa
yed for the error | 21032 * @param message the message template used to create the message to be displa
yed for the error |
| 20858 */ | 21033 */ |
| 20859 ResolverErrorCode.con1(String name, int ordinal, this.type, this.message) : su
per(name, ordinal); | 21034 ResolverErrorCode.con1(String name, int ordinal, this.type, this.message) : su
per(name, ordinal); |
| 20860 | 21035 |
| 20861 /** | 21036 /** |
| 20862 * Initialize a newly created error code to have the given type, message and c
orrection. | 21037 * Initialize a newly created error code to have the given type, message and c
orrection. |
| 20863 * | 21038 * |
| 20864 * @param type the type of this error | 21039 * @param type the type of this error |
| 20865 * @param message the template used to create the message to be displayed for
the error | 21040 * @param message the template used to create the message to be displayed for
the error |
| 20866 * @param correction the template used to create the correction to be displaye
d for the error | 21041 * @param correction the template used to create the correction to be displaye
d for the error |
| 20867 */ | 21042 */ |
| 20868 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri
ng correction) : super(name, ordinal) { | 21043 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri
ng correction) : super(name, ordinal) { |
| 20869 this.correction10 = correction; | 21044 this.correction9 = correction; |
| 20870 } | 21045 } |
| 20871 | 21046 |
| 20872 String get correction => correction10; | 21047 String get correction => correction9; |
| 20873 | 21048 |
| 20874 ErrorSeverity get errorSeverity => type.severity; | 21049 ErrorSeverity get errorSeverity => type.severity; |
| 20875 } | 21050 } |
| OLD | NEW |