| 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 library analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 3958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3969 */ | 3969 */ |
| 3970 Namespace _exportNamespace; | 3970 Namespace _exportNamespace; |
| 3971 | 3971 |
| 3972 /** | 3972 /** |
| 3973 * The public [Namespace] of this library, `null` if it has not been | 3973 * The public [Namespace] of this library, `null` if it has not been |
| 3974 * computed yet. | 3974 * computed yet. |
| 3975 */ | 3975 */ |
| 3976 Namespace _publicNamespace; | 3976 Namespace _publicNamespace; |
| 3977 | 3977 |
| 3978 /** | 3978 /** |
| 3979 * A bit-encoded form of the capabilities associated with this library. |
| 3980 */ |
| 3981 int _resolutionCapabilities = 0; |
| 3982 |
| 3983 /** |
| 3979 * Initialize a newly created library element in the given [context] to have | 3984 * Initialize a newly created library element in the given [context] to have |
| 3980 * the given [name] and [offset]. | 3985 * the given [name] and [offset]. |
| 3981 */ | 3986 */ |
| 3982 LibraryElementImpl(this.context, String name, int offset, this.nameLength) | 3987 LibraryElementImpl(this.context, String name, int offset, this.nameLength) |
| 3983 : resynthesizerContext = null, | 3988 : resynthesizerContext = null, |
| 3984 _unlinkedDefiningUnit = null, | 3989 _unlinkedDefiningUnit = null, |
| 3985 super(name, offset); | 3990 super(name, offset); |
| 3986 | 3991 |
| 3987 /** | 3992 /** |
| 3988 * Initialize a newly created library element in the given [context] to have | 3993 * Initialize a newly created library element in the given [context] to have |
| 3989 * the given [name]. | 3994 * the given [name]. |
| 3990 */ | 3995 */ |
| 3991 LibraryElementImpl.forNode(this.context, LibraryIdentifier name) | 3996 LibraryElementImpl.forNode(this.context, LibraryIdentifier name) |
| 3992 : nameLength = name != null ? name.length : 0, | 3997 : nameLength = name != null ? name.length : 0, |
| 3993 resynthesizerContext = null, | 3998 resynthesizerContext = null, |
| 3994 _unlinkedDefiningUnit = null, | 3999 _unlinkedDefiningUnit = null, |
| 3995 super.forNode(name); | 4000 super.forNode(name); |
| 3996 | 4001 |
| 3997 /** | 4002 /** |
| 3998 * Initialize using the given serialized information. | 4003 * Initialize using the given serialized information. |
| 3999 */ | 4004 */ |
| 4000 LibraryElementImpl.forSerialized(this.context, String name, int offset, | 4005 LibraryElementImpl.forSerialized(this.context, String name, int offset, |
| 4001 this.nameLength, this.resynthesizerContext, this._unlinkedDefiningUnit) | 4006 this.nameLength, this.resynthesizerContext, this._unlinkedDefiningUnit) |
| 4002 : super.forSerialized(null) { | 4007 : super.forSerialized(null) { |
| 4003 _name = name; | 4008 _name = name; |
| 4004 _nameOffset = offset; | 4009 _nameOffset = offset; |
| 4010 setResolutionCapability( |
| 4011 LibraryResolutionCapability.resolvedTypeNames, true); |
| 4012 setResolutionCapability( |
| 4013 LibraryResolutionCapability.constantExpressions, true); |
| 4005 } | 4014 } |
| 4006 | 4015 |
| 4007 @override | 4016 @override |
| 4008 int get codeLength { | 4017 int get codeLength { |
| 4009 CompilationUnitElement unit = _definingCompilationUnit; | 4018 CompilationUnitElement unit = _definingCompilationUnit; |
| 4010 if (unit is CompilationUnitElementImpl) { | 4019 if (unit is CompilationUnitElementImpl) { |
| 4011 return unit.codeLength; | 4020 return unit.codeLength; |
| 4012 } | 4021 } |
| 4013 return null; | 4022 return null; |
| 4014 } | 4023 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4500 } | 4509 } |
| 4501 invalidate(this); | 4510 invalidate(this); |
| 4502 } | 4511 } |
| 4503 | 4512 |
| 4504 @override | 4513 @override |
| 4505 bool isUpToDate(int timeStamp) { | 4514 bool isUpToDate(int timeStamp) { |
| 4506 Set<LibraryElement> visitedLibraries = new Set(); | 4515 Set<LibraryElement> visitedLibraries = new Set(); |
| 4507 return _safeIsUpToDate(this, timeStamp, visitedLibraries); | 4516 return _safeIsUpToDate(this, timeStamp, visitedLibraries); |
| 4508 } | 4517 } |
| 4509 | 4518 |
| 4519 /** |
| 4520 * Set whether the library has the given [capability] to |
| 4521 * correspond to the given [value]. |
| 4522 */ |
| 4523 void setResolutionCapability( |
| 4524 LibraryResolutionCapability capability, bool value) { |
| 4525 _resolutionCapabilities = |
| 4526 BooleanArray.set(_resolutionCapabilities, capability.index, value); |
| 4527 } |
| 4528 |
| 4510 @override | 4529 @override |
| 4511 void visitChildren(ElementVisitor visitor) { | 4530 void visitChildren(ElementVisitor visitor) { |
| 4512 super.visitChildren(visitor); | 4531 super.visitChildren(visitor); |
| 4513 _definingCompilationUnit?.accept(visitor); | 4532 _definingCompilationUnit?.accept(visitor); |
| 4514 safelyVisitChildren(_exports, visitor); | 4533 safelyVisitChildren(_exports, visitor); |
| 4515 safelyVisitChildren(_imports, visitor); | 4534 safelyVisitChildren(_imports, visitor); |
| 4516 safelyVisitChildren(_parts, visitor); | 4535 safelyVisitChildren(_parts, visitor); |
| 4517 } | 4536 } |
| 4518 | 4537 |
| 4519 /** | 4538 /** |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4540 LibraryElement exportedLibrary = exportElement.exportedLibrary; | 4559 LibraryElement exportedLibrary = exportElement.exportedLibrary; |
| 4541 if (exportedLibrary != null) { | 4560 if (exportedLibrary != null) { |
| 4542 (exportedLibrary as LibraryElementImpl) | 4561 (exportedLibrary as LibraryElementImpl) |
| 4543 ._addVisibleLibraries(visibleLibraries, true); | 4562 ._addVisibleLibraries(visibleLibraries, true); |
| 4544 } | 4563 } |
| 4545 } | 4564 } |
| 4546 } | 4565 } |
| 4547 } | 4566 } |
| 4548 | 4567 |
| 4549 /** | 4568 /** |
| 4569 * Return `true` if the [library] has the given [capability]. |
| 4570 */ |
| 4571 static bool hasResolutionCapability( |
| 4572 LibraryElement library, LibraryResolutionCapability capability) { |
| 4573 return library is LibraryElementImpl && |
| 4574 BooleanArray.get(library._resolutionCapabilities, capability.index); |
| 4575 } |
| 4576 |
| 4577 /** |
| 4550 * Return `true` if the given [library] is up to date with respect to the | 4578 * Return `true` if the given [library] is up to date with respect to the |
| 4551 * given [timeStamp]. The set of [visitedLibraries] is used to prevent | 4579 * given [timeStamp]. The set of [visitedLibraries] is used to prevent |
| 4552 * infinite recursion in the case of mutually dependent libraries. | 4580 * infinite recursion in the case of mutually dependent libraries. |
| 4553 */ | 4581 */ |
| 4554 static bool _safeIsUpToDate(LibraryElement library, int timeStamp, | 4582 static bool _safeIsUpToDate(LibraryElement library, int timeStamp, |
| 4555 Set<LibraryElement> visitedLibraries) { | 4583 Set<LibraryElement> visitedLibraries) { |
| 4556 if (!visitedLibraries.contains(library)) { | 4584 if (!visitedLibraries.contains(library)) { |
| 4557 visitedLibraries.add(library); | 4585 visitedLibraries.add(library); |
| 4558 AnalysisContext context = library.context; | 4586 AnalysisContext context = library.context; |
| 4559 // Check the defining compilation unit. | 4587 // Check the defining compilation unit. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4579 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { | 4607 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { |
| 4580 return false; | 4608 return false; |
| 4581 } | 4609 } |
| 4582 } | 4610 } |
| 4583 } | 4611 } |
| 4584 return true; | 4612 return true; |
| 4585 } | 4613 } |
| 4586 } | 4614 } |
| 4587 | 4615 |
| 4588 /** | 4616 /** |
| 4617 * Enum of possible resolution capabilities that a [LibraryElementImpl] has. |
| 4618 */ |
| 4619 enum LibraryResolutionCapability { |
| 4620 /** |
| 4621 * All elements have their types resolved. |
| 4622 */ |
| 4623 resolvedTypeNames, |
| 4624 |
| 4625 /** |
| 4626 * All (potentially) constants expressions are set into corresponding |
| 4627 * elements. |
| 4628 */ |
| 4629 constantExpressions, |
| 4630 } |
| 4631 |
| 4632 /** |
| 4589 * The context in which the library is resynthesized. | 4633 * The context in which the library is resynthesized. |
| 4590 */ | 4634 */ |
| 4591 abstract class LibraryResynthesizerContext { | 4635 abstract class LibraryResynthesizerContext { |
| 4592 /** | 4636 /** |
| 4593 * Return the export namespace of the library. | 4637 * Return the export namespace of the library. |
| 4594 */ | 4638 */ |
| 4595 Namespace buildExportNamespace(); | 4639 Namespace buildExportNamespace(); |
| 4596 | 4640 |
| 4597 LibraryElement buildImportedLibrary(int dependency); | 4641 LibraryElement buildImportedLibrary(int dependency); |
| 4598 | 4642 |
| (...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6547 | 6591 |
| 6548 @override | 6592 @override |
| 6549 void visitElement(Element element) { | 6593 void visitElement(Element element) { |
| 6550 int offset = element.nameOffset; | 6594 int offset = element.nameOffset; |
| 6551 if (offset != -1) { | 6595 if (offset != -1) { |
| 6552 map[offset] = element; | 6596 map[offset] = element; |
| 6553 } | 6597 } |
| 6554 super.visitElement(element); | 6598 super.visitElement(element); |
| 6555 } | 6599 } |
| 6556 } | 6600 } |
| OLD | NEW |