| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 /** | 669 /** |
| 670 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a | 670 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a |
| 671 * library. | 671 * library. |
| 672 * | 672 * |
| 673 * The result is only available for [Source]s representing a library. | 673 * The result is only available for [Source]s representing a library. |
| 674 */ | 674 */ |
| 675 final ResultDescriptor<bool> READY_RESOLVED_UNIT = | 675 final ResultDescriptor<bool> READY_RESOLVED_UNIT = |
| 676 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); | 676 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); |
| 677 | 677 |
| 678 /** | 678 /** |
| 679 * The names (resolved and not) referenced by a unit. | |
| 680 * | |
| 681 * The result is only available for [Source]s representing a compilation unit. | |
| 682 */ | |
| 683 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = | |
| 684 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); | |
| 685 | |
| 686 /** | |
| 687 * The sources of the Dart files that a library references. | 679 * The sources of the Dart files that a library references. |
| 688 * | 680 * |
| 689 * The list is the union of [IMPORTED_LIBRARIES], [EXPORTED_LIBRARIES] and | 681 * The list is the union of [IMPORTED_LIBRARIES], [EXPORTED_LIBRARIES] and |
| 690 * [UNITS] of the defining unit and [INCLUDED_PARTS]. Never empty or `null`. | 682 * [UNITS] of the defining unit and [INCLUDED_PARTS]. Never empty or `null`. |
| 691 * | 683 * |
| 692 * The result is only available for [Source]s representing a library. | 684 * The result is only available for [Source]s representing a library. |
| 693 */ | 685 */ |
| 694 final ListResultDescriptor<Source> REFERENCED_SOURCES = | 686 final ListResultDescriptor<Source> REFERENCED_SOURCES = |
| 695 new ListResultDescriptor<Source>('REFERENCED_SOURCES', Source.EMPTY_LIST); | 687 new ListResultDescriptor<Source>('REFERENCED_SOURCES', Source.EMPTY_LIST); |
| 696 | 688 |
| (...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3728 */ | 3720 */ |
| 3729 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 3721 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3730 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[ | 3722 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[ |
| 3731 EXPLICITLY_IMPORTED_LIBRARIES, | 3723 EXPLICITLY_IMPORTED_LIBRARIES, |
| 3732 EXPORTED_LIBRARIES, | 3724 EXPORTED_LIBRARIES, |
| 3733 IMPORTED_LIBRARIES, | 3725 IMPORTED_LIBRARIES, |
| 3734 INCLUDED_PARTS, | 3726 INCLUDED_PARTS, |
| 3735 LIBRARY_SPECIFIC_UNITS, | 3727 LIBRARY_SPECIFIC_UNITS, |
| 3736 PARSE_ERRORS, | 3728 PARSE_ERRORS, |
| 3737 PARSED_UNIT, | 3729 PARSED_UNIT, |
| 3738 REFERENCED_NAMES, | |
| 3739 REFERENCED_SOURCES, | 3730 REFERENCED_SOURCES, |
| 3740 SOURCE_KIND, | 3731 SOURCE_KIND, |
| 3741 UNITS, | 3732 UNITS, |
| 3742 ]); | 3733 ]); |
| 3743 | 3734 |
| 3744 /** | 3735 /** |
| 3745 * The source that is being parsed. | 3736 * The source that is being parsed. |
| 3746 */ | 3737 */ |
| 3747 Source _source; | 3738 Source _source; |
| 3748 | 3739 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3844 // | 3835 // |
| 3845 // Compute kind. | 3836 // Compute kind. |
| 3846 // | 3837 // |
| 3847 SourceKind sourceKind = SourceKind.LIBRARY; | 3838 SourceKind sourceKind = SourceKind.LIBRARY; |
| 3848 if (modificationTime == -1) { | 3839 if (modificationTime == -1) { |
| 3849 sourceKind = SourceKind.UNKNOWN; | 3840 sourceKind = SourceKind.UNKNOWN; |
| 3850 } else if (hasPartOfDirective && !hasNonPartOfDirective) { | 3841 } else if (hasPartOfDirective && !hasNonPartOfDirective) { |
| 3851 sourceKind = SourceKind.PART; | 3842 sourceKind = SourceKind.PART; |
| 3852 } | 3843 } |
| 3853 // | 3844 // |
| 3854 // Compute referenced names. | |
| 3855 // | |
| 3856 ReferencedNames referencedNames = new ReferencedNames(_source); | |
| 3857 new ReferencedNamesBuilder(referencedNames).build(unit); | |
| 3858 // | |
| 3859 // Compute source lists. | 3845 // Compute source lists. |
| 3860 // | 3846 // |
| 3861 List<Source> explicitlyImportedSources = | 3847 List<Source> explicitlyImportedSources = |
| 3862 explicitlyImportedSourceSet.toList(); | 3848 explicitlyImportedSourceSet.toList(); |
| 3863 List<Source> exportedSources = exportedSourceSet.toList(); | 3849 List<Source> exportedSources = exportedSourceSet.toList(); |
| 3864 List<Source> importedSources = importedSourceSet.toList(); | 3850 List<Source> importedSources = importedSourceSet.toList(); |
| 3865 List<Source> includedSources = includedSourceSet.toList(); | 3851 List<Source> includedSources = includedSourceSet.toList(); |
| 3866 List<Source> unitSources = <Source>[_source]..addAll(includedSourceSet); | 3852 List<Source> unitSources = <Source>[_source]..addAll(includedSourceSet); |
| 3867 List<LibrarySpecificUnit> librarySpecificUnits = | 3853 List<LibrarySpecificUnit> librarySpecificUnits = |
| 3868 unitSources.map((s) => new LibrarySpecificUnit(_source, s)).toList(); | 3854 unitSources.map((s) => new LibrarySpecificUnit(_source, s)).toList(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3885 // Record outputs. | 3871 // Record outputs. |
| 3886 // | 3872 // |
| 3887 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors); | 3873 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors); |
| 3888 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; | 3874 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; |
| 3889 outputs[EXPORTED_LIBRARIES] = exportedSources; | 3875 outputs[EXPORTED_LIBRARIES] = exportedSources; |
| 3890 outputs[IMPORTED_LIBRARIES] = importedSources; | 3876 outputs[IMPORTED_LIBRARIES] = importedSources; |
| 3891 outputs[INCLUDED_PARTS] = includedSources; | 3877 outputs[INCLUDED_PARTS] = includedSources; |
| 3892 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits; | 3878 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits; |
| 3893 outputs[PARSE_ERRORS] = parseErrors; | 3879 outputs[PARSE_ERRORS] = parseErrors; |
| 3894 outputs[PARSED_UNIT] = unit; | 3880 outputs[PARSED_UNIT] = unit; |
| 3895 outputs[REFERENCED_NAMES] = referencedNames; | |
| 3896 outputs[REFERENCED_SOURCES] = referencedSources.toList(); | 3881 outputs[REFERENCED_SOURCES] = referencedSources.toList(); |
| 3897 outputs[SOURCE_KIND] = sourceKind; | 3882 outputs[SOURCE_KIND] = sourceKind; |
| 3898 outputs[UNITS] = unitSources; | 3883 outputs[UNITS] = unitSources; |
| 3899 } | 3884 } |
| 3900 | 3885 |
| 3901 /** | 3886 /** |
| 3902 * Return the result of resolving the URI of the given URI-based [directive] | 3887 * Return the result of resolving the URI of the given URI-based [directive] |
| 3903 * against the URI of the given library, or `null` if the URI is not valid. | 3888 * against the URI of the given library, or `null` if the URI is not valid. |
| 3904 */ | 3889 */ |
| 3905 Source _resolveDirective(UriBasedDirective directive) { | 3890 Source _resolveDirective(UriBasedDirective directive) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4259 }; | 4244 }; |
| 4260 } | 4245 } |
| 4261 | 4246 |
| 4262 static ReadyResolvedUnitTask createTask( | 4247 static ReadyResolvedUnitTask createTask( |
| 4263 AnalysisContext context, AnalysisTarget target) { | 4248 AnalysisContext context, AnalysisTarget target) { |
| 4264 return new ReadyResolvedUnitTask(context, target); | 4249 return new ReadyResolvedUnitTask(context, target); |
| 4265 } | 4250 } |
| 4266 } | 4251 } |
| 4267 | 4252 |
| 4268 /** | 4253 /** |
| 4269 * Information about a Dart [source] - which names it uses, which names it | |
| 4270 * defines with their externally visible dependencies. | |
| 4271 */ | |
| 4272 class ReferencedNames { | |
| 4273 final Source source; | |
| 4274 | |
| 4275 /** | |
| 4276 * The mapping from the name of a class to the set of names of other classes | |
| 4277 * that extend, mix-in, or implement it. | |
| 4278 * | |
| 4279 * If the set of member of a class is changed, these changes might change | |
| 4280 * the list of unimplemented inherited members in the class and classes that | |
| 4281 * extend, mix-in, or implement it. So, we might need to report (or stop | |
| 4282 * reporting) the corresponding warning. | |
| 4283 */ | |
| 4284 final Map<String, Set<String>> superToSubs = <String, Set<String>>{}; | |
| 4285 | |
| 4286 /** | |
| 4287 * The names of extended classes for which the unnamed constructor is | |
| 4288 * invoked. Because we cannot use the name of the constructor to identify | |
| 4289 * whether the unit is affected, we need to use the class name. | |
| 4290 */ | |
| 4291 final Set<String> extendedUsedUnnamedConstructorNames = new Set<String>(); | |
| 4292 | |
| 4293 /** | |
| 4294 * The names of instantiated classes. | |
| 4295 * | |
| 4296 * If one of these classes changes its set of members, it might change | |
| 4297 * its list of unimplemented inherited members. So, we might need to report | |
| 4298 * (or stop reporting) the corresponding warning. | |
| 4299 */ | |
| 4300 final Set<String> instantiatedNames = new Set<String>(); | |
| 4301 | |
| 4302 /** | |
| 4303 * The set of names that are referenced by the library, both inside and | |
| 4304 * outside of method bodies. | |
| 4305 */ | |
| 4306 final Set<String> names = new Set<String>(); | |
| 4307 | |
| 4308 /** | |
| 4309 * The mapping from the name of a top-level element to the set of names that | |
| 4310 * the element uses in a way that is visible outside of the element, e.g. | |
| 4311 * the return type, or a parameter type. | |
| 4312 */ | |
| 4313 final Map<String, Set<String>> userToDependsOn = <String, Set<String>>{}; | |
| 4314 | |
| 4315 ReferencedNames(this.source); | |
| 4316 | |
| 4317 void addSubclass(String subName, String superName) { | |
| 4318 superToSubs.putIfAbsent(superName, () => new Set<String>()).add(subName); | |
| 4319 } | |
| 4320 } | |
| 4321 | |
| 4322 /** | |
| 4323 * A builder for creating [ReferencedNames]. | |
| 4324 */ | |
| 4325 class ReferencedNamesBuilder extends GeneralizingAstVisitor { | |
| 4326 final Set<String> importPrefixNames = new Set<String>(); | |
| 4327 final ReferencedNames names; | |
| 4328 | |
| 4329 String enclosingSuperClassName; | |
| 4330 ReferencedNamesScope scope = new ReferencedNamesScope(null); | |
| 4331 | |
| 4332 int localLevel = 0; | |
| 4333 Set<String> dependsOn; | |
| 4334 | |
| 4335 ReferencedNamesBuilder(this.names); | |
| 4336 | |
| 4337 ReferencedNames build(CompilationUnit unit) { | |
| 4338 unit.accept(this); | |
| 4339 return names; | |
| 4340 } | |
| 4341 | |
| 4342 @override | |
| 4343 visitBlock(Block node) { | |
| 4344 ReferencedNamesScope outerScope = scope; | |
| 4345 try { | |
| 4346 scope = new ReferencedNamesScope.forBlock(scope, node); | |
| 4347 super.visitBlock(node); | |
| 4348 } finally { | |
| 4349 scope = outerScope; | |
| 4350 } | |
| 4351 } | |
| 4352 | |
| 4353 @override | |
| 4354 visitClassDeclaration(ClassDeclaration node) { | |
| 4355 ReferencedNamesScope outerScope = scope; | |
| 4356 try { | |
| 4357 scope = new ReferencedNamesScope.forClass(scope, node); | |
| 4358 dependsOn = new Set<String>(); | |
| 4359 enclosingSuperClassName = | |
| 4360 _getSimpleName(node.extendsClause?.superclass?.name); | |
| 4361 super.visitClassDeclaration(node); | |
| 4362 String className = node.name.name; | |
| 4363 names.userToDependsOn[className] = dependsOn; | |
| 4364 _addSuperName(className, node.extendsClause?.superclass); | |
| 4365 _addSuperNames(className, node.withClause?.mixinTypes); | |
| 4366 _addSuperNames(className, node.implementsClause?.interfaces); | |
| 4367 } finally { | |
| 4368 enclosingSuperClassName = null; | |
| 4369 dependsOn = null; | |
| 4370 scope = outerScope; | |
| 4371 } | |
| 4372 } | |
| 4373 | |
| 4374 @override | |
| 4375 visitClassTypeAlias(ClassTypeAlias node) { | |
| 4376 ReferencedNamesScope outerScope = scope; | |
| 4377 try { | |
| 4378 scope = new ReferencedNamesScope.forClassTypeAlias(scope, node); | |
| 4379 dependsOn = new Set<String>(); | |
| 4380 super.visitClassTypeAlias(node); | |
| 4381 String className = node.name.name; | |
| 4382 names.userToDependsOn[className] = dependsOn; | |
| 4383 _addSuperName(className, node.superclass); | |
| 4384 _addSuperNames(className, node.withClause?.mixinTypes); | |
| 4385 _addSuperNames(className, node.implementsClause?.interfaces); | |
| 4386 } finally { | |
| 4387 dependsOn = null; | |
| 4388 scope = outerScope; | |
| 4389 } | |
| 4390 } | |
| 4391 | |
| 4392 @override | |
| 4393 visitComment(Comment node) { | |
| 4394 try { | |
| 4395 localLevel++; | |
| 4396 super.visitComment(node); | |
| 4397 } finally { | |
| 4398 localLevel--; | |
| 4399 } | |
| 4400 } | |
| 4401 | |
| 4402 @override | |
| 4403 visitConstructorName(ConstructorName node) { | |
| 4404 if (node.parent is! ConstructorDeclaration) { | |
| 4405 super.visitConstructorName(node); | |
| 4406 } | |
| 4407 } | |
| 4408 | |
| 4409 @override | |
| 4410 visitFunctionBody(FunctionBody node) { | |
| 4411 try { | |
| 4412 localLevel++; | |
| 4413 super.visitFunctionBody(node); | |
| 4414 } finally { | |
| 4415 localLevel--; | |
| 4416 } | |
| 4417 } | |
| 4418 | |
| 4419 @override | |
| 4420 visitFunctionDeclaration(FunctionDeclaration node) { | |
| 4421 if (localLevel == 0) { | |
| 4422 ReferencedNamesScope outerScope = scope; | |
| 4423 try { | |
| 4424 scope = new ReferencedNamesScope.forFunction(scope, node); | |
| 4425 dependsOn = new Set<String>(); | |
| 4426 super.visitFunctionDeclaration(node); | |
| 4427 names.userToDependsOn[node.name.name] = dependsOn; | |
| 4428 } finally { | |
| 4429 dependsOn = null; | |
| 4430 scope = outerScope; | |
| 4431 } | |
| 4432 } else { | |
| 4433 super.visitFunctionDeclaration(node); | |
| 4434 } | |
| 4435 } | |
| 4436 | |
| 4437 @override | |
| 4438 visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 4439 if (localLevel == 0) { | |
| 4440 ReferencedNamesScope outerScope = scope; | |
| 4441 try { | |
| 4442 scope = new ReferencedNamesScope.forFunctionTypeAlias(scope, node); | |
| 4443 dependsOn = new Set<String>(); | |
| 4444 super.visitFunctionTypeAlias(node); | |
| 4445 names.userToDependsOn[node.name.name] = dependsOn; | |
| 4446 } finally { | |
| 4447 dependsOn = null; | |
| 4448 scope = outerScope; | |
| 4449 } | |
| 4450 } else { | |
| 4451 super.visitFunctionTypeAlias(node); | |
| 4452 } | |
| 4453 } | |
| 4454 | |
| 4455 @override | |
| 4456 visitImportDirective(ImportDirective node) { | |
| 4457 if (node.prefix != null) { | |
| 4458 importPrefixNames.add(node.prefix.name); | |
| 4459 } | |
| 4460 super.visitImportDirective(node); | |
| 4461 } | |
| 4462 | |
| 4463 @override | |
| 4464 visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 4465 ConstructorName constructorName = node.constructorName; | |
| 4466 Identifier typeName = constructorName.type.name; | |
| 4467 if (typeName is SimpleIdentifier) { | |
| 4468 names.instantiatedNames.add(typeName.name); | |
| 4469 } | |
| 4470 if (typeName is PrefixedIdentifier) { | |
| 4471 String prefixName = typeName.prefix.name; | |
| 4472 if (importPrefixNames.contains(prefixName)) { | |
| 4473 names.instantiatedNames.add(typeName.identifier.name); | |
| 4474 } else { | |
| 4475 names.instantiatedNames.add(prefixName); | |
| 4476 } | |
| 4477 } | |
| 4478 super.visitInstanceCreationExpression(node); | |
| 4479 } | |
| 4480 | |
| 4481 @override | |
| 4482 visitMethodDeclaration(MethodDeclaration node) { | |
| 4483 ReferencedNamesScope outerScope = scope; | |
| 4484 try { | |
| 4485 scope = new ReferencedNamesScope.forMethod(scope, node); | |
| 4486 super.visitMethodDeclaration(node); | |
| 4487 } finally { | |
| 4488 scope = outerScope; | |
| 4489 } | |
| 4490 } | |
| 4491 | |
| 4492 @override | |
| 4493 visitSimpleIdentifier(SimpleIdentifier node) { | |
| 4494 // Ignore all declarations. | |
| 4495 if (node.inDeclarationContext()) { | |
| 4496 return; | |
| 4497 } | |
| 4498 // Ignore class names references from constructors. | |
| 4499 AstNode parent = node.parent; | |
| 4500 if (parent is ConstructorDeclaration && parent.returnType == node) { | |
| 4501 return; | |
| 4502 } | |
| 4503 // Prepare name. | |
| 4504 String name = node.name; | |
| 4505 // Ignore unqualified names shadowed by local elements. | |
| 4506 if (!node.isQualified) { | |
| 4507 if (scope.contains(name)) { | |
| 4508 return; | |
| 4509 } | |
| 4510 if (importPrefixNames.contains(name)) { | |
| 4511 return; | |
| 4512 } | |
| 4513 } | |
| 4514 // Do add the dependency. | |
| 4515 names.names.add(name); | |
| 4516 if (dependsOn != null && localLevel == 0) { | |
| 4517 dependsOn.add(name); | |
| 4518 } | |
| 4519 } | |
| 4520 | |
| 4521 @override | |
| 4522 visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 4523 if (node.constructorName == null && enclosingSuperClassName != null) { | |
| 4524 names.extendedUsedUnnamedConstructorNames.add(enclosingSuperClassName); | |
| 4525 } | |
| 4526 super.visitSuperConstructorInvocation(node); | |
| 4527 } | |
| 4528 | |
| 4529 @override | |
| 4530 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 4531 VariableDeclarationList variableList = node.variables; | |
| 4532 // Prepare type dependencies. | |
| 4533 Set<String> typeDependencies = new Set<String>(); | |
| 4534 dependsOn = typeDependencies; | |
| 4535 variableList.type?.accept(this); | |
| 4536 // Combine individual variable dependencies with the type dependencies. | |
| 4537 for (VariableDeclaration variable in variableList.variables) { | |
| 4538 dependsOn = new Set<String>(); | |
| 4539 variable.accept(this); | |
| 4540 dependsOn.addAll(typeDependencies); | |
| 4541 names.userToDependsOn[variable.name.name] = dependsOn; | |
| 4542 } | |
| 4543 dependsOn = null; | |
| 4544 } | |
| 4545 | |
| 4546 void _addSuperName(String className, TypeName type) { | |
| 4547 if (type != null) { | |
| 4548 Identifier typeName = type.name; | |
| 4549 if (typeName is SimpleIdentifier) { | |
| 4550 names.addSubclass(className, typeName.name); | |
| 4551 } | |
| 4552 if (typeName is PrefixedIdentifier) { | |
| 4553 names.addSubclass(className, typeName.identifier.name); | |
| 4554 } | |
| 4555 } | |
| 4556 } | |
| 4557 | |
| 4558 void _addSuperNames(String className, List<TypeName> types) { | |
| 4559 types?.forEach((type) => _addSuperName(className, type)); | |
| 4560 } | |
| 4561 | |
| 4562 static String _getSimpleName(Identifier identifier) { | |
| 4563 if (identifier is SimpleIdentifier) { | |
| 4564 return identifier.name; | |
| 4565 } | |
| 4566 if (identifier is PrefixedIdentifier) { | |
| 4567 return identifier.identifier.name; | |
| 4568 } | |
| 4569 return null; | |
| 4570 } | |
| 4571 } | |
| 4572 | |
| 4573 class ReferencedNamesScope { | |
| 4574 final ReferencedNamesScope enclosing; | |
| 4575 Set<String> names; | |
| 4576 | |
| 4577 ReferencedNamesScope(this.enclosing); | |
| 4578 | |
| 4579 factory ReferencedNamesScope.forBlock( | |
| 4580 ReferencedNamesScope enclosing, Block node) { | |
| 4581 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4582 for (Statement statement in node.statements) { | |
| 4583 if (statement is FunctionDeclarationStatement) { | |
| 4584 scope.add(statement.functionDeclaration.name.name); | |
| 4585 } else if (statement is VariableDeclarationStatement) { | |
| 4586 for (VariableDeclaration variable in statement.variables.variables) { | |
| 4587 scope.add(variable.name.name); | |
| 4588 } | |
| 4589 } | |
| 4590 } | |
| 4591 return scope; | |
| 4592 } | |
| 4593 | |
| 4594 factory ReferencedNamesScope.forClass( | |
| 4595 ReferencedNamesScope enclosing, ClassDeclaration node) { | |
| 4596 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4597 scope._addTypeParameters(node.typeParameters); | |
| 4598 for (ClassMember member in node.members) { | |
| 4599 if (member is FieldDeclaration) { | |
| 4600 for (VariableDeclaration variable in member.fields.variables) { | |
| 4601 scope.add(variable.name.name); | |
| 4602 } | |
| 4603 } else if (member is MethodDeclaration) { | |
| 4604 scope.add(member.name.name); | |
| 4605 } | |
| 4606 } | |
| 4607 return scope; | |
| 4608 } | |
| 4609 | |
| 4610 factory ReferencedNamesScope.forClassTypeAlias( | |
| 4611 ReferencedNamesScope enclosing, ClassTypeAlias node) { | |
| 4612 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4613 scope._addTypeParameters(node.typeParameters); | |
| 4614 return scope; | |
| 4615 } | |
| 4616 | |
| 4617 factory ReferencedNamesScope.forFunction( | |
| 4618 ReferencedNamesScope enclosing, FunctionDeclaration node) { | |
| 4619 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4620 scope._addTypeParameters(node.functionExpression.typeParameters); | |
| 4621 scope._addFormalParameters(node.functionExpression.parameters); | |
| 4622 return scope; | |
| 4623 } | |
| 4624 | |
| 4625 factory ReferencedNamesScope.forFunctionTypeAlias( | |
| 4626 ReferencedNamesScope enclosing, FunctionTypeAlias node) { | |
| 4627 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4628 scope._addTypeParameters(node.typeParameters); | |
| 4629 return scope; | |
| 4630 } | |
| 4631 | |
| 4632 factory ReferencedNamesScope.forMethod( | |
| 4633 ReferencedNamesScope enclosing, MethodDeclaration node) { | |
| 4634 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing); | |
| 4635 scope._addTypeParameters(node.typeParameters); | |
| 4636 scope._addFormalParameters(node.parameters); | |
| 4637 return scope; | |
| 4638 } | |
| 4639 | |
| 4640 void add(String name) { | |
| 4641 names ??= new Set<String>(); | |
| 4642 names.add(name); | |
| 4643 } | |
| 4644 | |
| 4645 bool contains(String name) { | |
| 4646 if (names != null && names.contains(name)) { | |
| 4647 return true; | |
| 4648 } | |
| 4649 if (enclosing != null) { | |
| 4650 return enclosing.contains(name); | |
| 4651 } | |
| 4652 return false; | |
| 4653 } | |
| 4654 | |
| 4655 void _addFormalParameters(FormalParameterList parameterList) { | |
| 4656 if (parameterList != null) { | |
| 4657 parameterList.parameters | |
| 4658 .map((p) => p is NormalFormalParameter ? p.identifier.name : '') | |
| 4659 .forEach(add); | |
| 4660 } | |
| 4661 } | |
| 4662 | |
| 4663 void _addTypeParameters(TypeParameterList typeParameterList) { | |
| 4664 if (typeParameterList != null) { | |
| 4665 typeParameterList.typeParameters.map((p) => p.name.name).forEach(add); | |
| 4666 } | |
| 4667 } | |
| 4668 } | |
| 4669 | |
| 4670 /** | |
| 4671 * A task that ensures that the expression AST for a constant is resolved and | 4254 * A task that ensures that the expression AST for a constant is resolved and |
| 4672 * sets the [CONSTANT_EXPRESSION_RESOLVED] result. | 4255 * sets the [CONSTANT_EXPRESSION_RESOLVED] result. |
| 4673 */ | 4256 */ |
| 4674 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask { | 4257 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask { |
| 4675 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 4258 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 4676 'ResolveConstantExpressionTask', | 4259 'ResolveConstantExpressionTask', |
| 4677 createTask, | 4260 createTask, |
| 4678 buildInputs, | 4261 buildInputs, |
| 4679 <ResultDescriptor>[CONSTANT_EXPRESSION_RESOLVED]); | 4262 <ResultDescriptor>[CONSTANT_EXPRESSION_RESOLVED]); |
| 4680 | 4263 |
| (...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6253 | 5836 |
| 6254 @override | 5837 @override |
| 6255 bool moveNext() { | 5838 bool moveNext() { |
| 6256 if (_newSources.isEmpty) { | 5839 if (_newSources.isEmpty) { |
| 6257 return false; | 5840 return false; |
| 6258 } | 5841 } |
| 6259 currentTarget = _newSources.removeLast(); | 5842 currentTarget = _newSources.removeLast(); |
| 6260 return true; | 5843 return true; |
| 6261 } | 5844 } |
| 6262 } | 5845 } |
| OLD | NEW |