Restore UriReferencedElement and its uri/uriOffset/uriEnd properties.

This is a partial rollback of bdd69ccd6c,
it restores APIs and implementations, but does not restore its usages
in analyzer or analysis_server. Should be enough to make clients
temporary OK, but also keeps resynthesizing from Kernel working.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review-Url: https://codereview.chromium.org/2991453002 .
This commit is contained in:
Konstantin Shcheglov 2017-07-21 16:59:50 -07:00
parent f334284967
commit ce4d7b1891
6 changed files with 260 additions and 21 deletions

View file

@ -412,7 +412,7 @@ abstract class ClassMemberElement implements Element {
*
* Clients may not extend, implement or mix-in this class.
*/
abstract class CompilationUnitElement implements Element {
abstract class CompilationUnitElement implements Element, UriReferencedElement {
/**
* An empty list of compilation unit elements.
*/
@ -1161,7 +1161,7 @@ abstract class ExecutableElement implements FunctionTypedElement {
*
* Clients may not extend, implement or mix-in this class.
*/
abstract class ExportElement implements Element {
abstract class ExportElement implements Element, UriReferencedElement {
/**
* An empty list of export elements.
*/
@ -1349,7 +1349,7 @@ abstract class HideElementCombinator implements NamespaceCombinator {
*
* Clients may not extend, implement or mix-in this class.
*/
abstract class ImportElement implements Element {
abstract class ImportElement implements Element, UriReferencedElement {
/**
* An empty list of import elements.
*/
@ -1948,6 +1948,31 @@ abstract class TypeParameterizedElement implements Element {
*/
abstract class UndefinedElement implements Element {}
/**
* An element included into a library using some URI.
*
* Clients may not extend, implement or mix-in this class.
*/
abstract class UriReferencedElement implements Element {
/**
* Return the URI that is used to include this element into the enclosing
* library, or `null` if this is the defining compilation unit of a library.
*/
String get uri;
/**
* Return the offset of the character immediately following the last character
* of this node's URI, or `-1` for synthetic import.
*/
int get uriEnd;
/**
* Return the offset of the URI in the file, or `-1` if this element is
* synthetic.
*/
int get uriOffset;
}
/**
* A variable. There are more specific subclasses for more specific kinds of
* variables.

View file

@ -890,6 +890,11 @@ class DirectiveElementBuilder extends SimpleAstVisitor<Object> {
ExportElementImpl exportElement = new ExportElementImpl(node.offset);
exportElement.metadata = _getElementAnnotations(node.metadata);
StringLiteral uriLiteral = node.uri;
if (uriLiteral != null) {
exportElement.uriOffset = uriLiteral.offset;
exportElement.uriEnd = uriLiteral.end;
}
exportElement.uri = node.selectedUriContent;
exportElement.combinators = _buildCombinators(node);
exportElement.exportedLibrary = exportedLibrary;
setElementDocumentationComment(exportElement, node);
@ -930,6 +935,11 @@ class DirectiveElementBuilder extends SimpleAstVisitor<Object> {
ImportElementImpl importElement = new ImportElementImpl(node.offset);
importElement.metadata = _getElementAnnotations(node.metadata);
StringLiteral uriLiteral = node.uri;
if (uriLiteral != null) {
importElement.uriOffset = uriLiteral.offset;
importElement.uriEnd = uriLiteral.end;
}
importElement.uri = node.selectedUriContent;
importElement.deferred = node.deferredKeyword != null;
importElement.combinators = _buildCombinators(node);
importElement.importedLibrary = importedLibrary;

View file

@ -1419,7 +1419,7 @@ class ClassElementImpl extends AbstractClassElementImpl
/**
* A concrete implementation of a [CompilationUnitElement].
*/
class CompilationUnitElementImpl extends ElementImpl
class CompilationUnitElementImpl extends UriReferencedElementImpl
implements CompilationUnitElement {
/**
* The context in which this unit is resynthesized, or `null` if the
@ -3417,17 +3417,6 @@ abstract class ElementImpl implements Element {
}
}
String _selectUri(
String defaultUri, List<UnlinkedConfiguration> configurations) {
for (UnlinkedConfiguration configuration in configurations) {
if (context.declaredVariables.get(configuration.name) ==
configuration.value) {
return configuration.uri;
}
}
return defaultUri;
}
static int findElementIndexUsingIdentical(List items, Object item) {
int length = items.length;
for (int i = 0; i < length; i++) {
@ -4252,7 +4241,8 @@ abstract class ExecutableElementImpl extends ElementImpl
/**
* A concrete implementation of an [ExportElement].
*/
class ExportElementImpl extends ElementImpl implements ExportElement {
class ExportElementImpl extends UriReferencedElementImpl
implements ExportElement {
/**
* The unlinked representation of the export in the summary.
*/
@ -4311,11 +4301,8 @@ class ExportElementImpl extends ElementImpl implements ExportElement {
@override
LibraryElement get exportedLibrary {
if (_unlinkedExportNonPublic != null && _exportedLibrary == null) {
_selectedUri ??= _selectUri(
_unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
LibraryElementImpl library = enclosingElement as LibraryElementImpl;
_exportedLibrary =
library.resynthesizerContext.buildExportedLibrary(_selectedUri);
_exportedLibrary = library.resynthesizerContext.buildExportedLibrary(uri);
}
return _exportedLibrary;
}
@ -4355,6 +4342,49 @@ class ExportElementImpl extends ElementImpl implements ExportElement {
return offset;
}
@override
String get uri {
if (_unlinkedExportPublic != null) {
return _selectedUri ??= _selectUri(
_unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
}
return super.uri;
}
@override
void set uri(String uri) {
_assertNotResynthesized(_unlinkedExportPublic);
super.uri = uri;
}
@override
int get uriEnd {
if (_unlinkedExportNonPublic != null) {
return _unlinkedExportNonPublic.uriEnd;
}
return super.uriEnd;
}
@override
void set uriEnd(int uriEnd) {
_assertNotResynthesized(_unlinkedExportNonPublic);
super.uriEnd = uriEnd;
}
@override
int get uriOffset {
if (_unlinkedExportNonPublic != null) {
return _unlinkedExportNonPublic.uriOffset;
}
return super.uriOffset;
}
@override
void set uriOffset(int uriOffset) {
_assertNotResynthesized(_unlinkedExportNonPublic);
super.uriOffset = uriOffset;
}
@override
T accept<T>(ElementVisitor<T> visitor) => visitor.visitExportElement(this);
@ -5539,7 +5569,8 @@ class HideElementCombinatorImpl implements HideElementCombinator {
/**
* A concrete implementation of an [ImportElement].
*/
class ImportElementImpl extends ElementImpl implements ImportElement {
class ImportElementImpl extends UriReferencedElementImpl
implements ImportElement {
/**
* The unlinked representation of the import in the summary.
*/
@ -5578,6 +5609,11 @@ class ImportElementImpl extends ElementImpl implements ImportElement {
*/
PrefixElement _prefix;
/**
* The URI that was selected based on the [context] declared variables.
*/
String _selectedUri;
/**
* Initialize a newly created import element at the given [offset].
* The offset may be `-1` if the import is synthetic.
@ -5731,6 +5767,58 @@ class ImportElementImpl extends ElementImpl implements ImportElement {
_prefixOffset = prefixOffset;
}
@override
String get uri {
if (_unlinkedImport != null) {
if (_unlinkedImport.isImplicit) {
return null;
}
return _selectedUri ??=
_selectUri(_unlinkedImport.uri, _unlinkedImport.configurations);
}
return super.uri;
}
@override
void set uri(String uri) {
_assertNotResynthesized(_unlinkedImport);
super.uri = uri;
}
@override
int get uriEnd {
if (_unlinkedImport != null) {
if (_unlinkedImport.isImplicit) {
return -1;
}
return _unlinkedImport.uriEnd;
}
return super.uriEnd;
}
@override
void set uriEnd(int uriEnd) {
_assertNotResynthesized(_unlinkedImport);
super.uriEnd = uriEnd;
}
@override
int get uriOffset {
if (_unlinkedImport != null) {
if (_unlinkedImport.isImplicit) {
return -1;
}
return _unlinkedImport.uriOffset;
}
return super.uriOffset;
}
@override
void set uriOffset(int uriOffset) {
_assertNotResynthesized(_unlinkedImport);
super.uriOffset = uriOffset;
}
@override
T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this);
@ -9218,6 +9306,89 @@ class UnitExplicitTopLevelVariables {
: const <TopLevelVariableElementImpl>[];
}
/**
* A concrete implementation of a [UriReferencedElement].
*/
abstract class UriReferencedElementImpl extends ElementImpl
implements UriReferencedElement {
/**
* The offset of the URI in the file, or `-1` if this node is synthetic.
*/
int _uriOffset = -1;
/**
* The offset of the character immediately following the last character of
* this node's URI, or `-1` if this node is synthetic.
*/
int _uriEnd = -1;
/**
* The URI that is specified by this directive.
*/
String _uri;
/**
* Initialize a newly created import element to have the given [name] and
* [offset]. The offset may be `-1` if the element is synthetic.
*/
UriReferencedElementImpl(String name, int offset) : super(name, offset);
/**
* Initialize using the given serialized information.
*/
UriReferencedElementImpl.forSerialized(ElementImpl enclosingElement)
: super.forSerialized(enclosingElement);
/**
* Return the URI that is specified by this directive.
*/
String get uri => _uri;
/**
* Set the URI that is specified by this directive to be the given [uri].
*/
void set uri(String uri) {
_uri = uri;
}
/**
* Return the offset of the character immediately following the last character
* of this node's URI, or `-1` if this node is synthetic.
*/
int get uriEnd => _uriEnd;
/**
* Set the offset of the character immediately following the last character of
* this node's URI to the given [offset].
*/
void set uriEnd(int offset) {
_uriEnd = offset;
}
/**
* Return the offset of the URI in the file, or `-1` if this node is synthetic.
*/
int get uriOffset => _uriOffset;
/**
* Set the offset of the URI in the file to the given [offset].
*/
void set uriOffset(int offset) {
_uriOffset = offset;
}
String _selectUri(
String defaultUri, List<UnlinkedConfiguration> configurations) {
for (UnlinkedConfiguration configuration in configurations) {
if (context.declaredVariables.get(configuration.name) ==
configuration.value) {
return configuration.uri;
}
}
return defaultUri;
}
}
/**
* A concrete implementation of a [VariableElement].
*/

View file

@ -221,6 +221,15 @@ class CompilationUnitElementHandle extends ElementHandle
@override
List<ClassElement> get types => actualElement.types;
@override
String get uri => actualElement.uri;
@override
int get uriEnd => actualElement.uriEnd;
@override
int get uriOffset => actualElement.uriOffset;
@override
CompilationUnit computeNode() => actualElement.computeNode();
@ -532,6 +541,15 @@ class ExportElementHandle extends ElementHandle implements ExportElement {
@override
ElementKind get kind => ElementKind.EXPORT;
@override
String get uri => actualElement.uri;
@override
int get uriEnd => actualElement.uriEnd;
@override
int get uriOffset => actualElement.uriOffset;
}
/**
@ -710,6 +728,15 @@ class ImportElementHandle extends ElementHandle implements ImportElement {
@override
int get prefixOffset => actualElement.prefixOffset;
@override
String get uri => actualElement.uri;
@override
int get uriEnd => actualElement.uriEnd;
@override
int get uriOffset => actualElement.uriOffset;
}
/**

View file

@ -1038,8 +1038,11 @@ class _LibraryResynthesizer {
_UnitResynthesizer partResynthesizer =
createUnitResynthesizer(unitNum, unitSource, partDecl);
CompilationUnitElementImpl partUnit = partResynthesizer.unit;
partUnit.uriOffset = partDecl.uriOffset;
partUnit.uriEnd = partDecl.uriEnd;
partUnit.source = unitSource;
partUnit.librarySource = librarySource;
partUnit.uri = uri;
return partResynthesizer;
}

View file

@ -1551,6 +1551,9 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
CompilationUnit partUnit = partUnitMap[partSource];
if (partUnit != null) {
CompilationUnitElementImpl partElement = partUnit.element;
partElement.uriOffset = partUri.offset;
partElement.uriEnd = partUri.end;
partElement.uri = directive.uriContent;
//
// Validate that the part source is unique in the library.
//