Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1529)

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2029053002: A different approach for resynthesizing enumerations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index ce69476cfafa3ed2206cd394e8634832bae77a0c..eaa34d1a168752b625c634adf08d6ee481bf8521 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -71,6 +71,11 @@ class ClassElementImpl extends ElementImpl
final UnlinkedClass _unlinkedClass;
/**
+ * The unlinked representation of the enumeration in the summary.
+ */
+ final UnlinkedEnum _unlinkedEnum;
+
+ /**
* A list containing all of the accessors (getters and setters) contained in
* this class.
*/
@@ -138,6 +143,7 @@ class ClassElementImpl extends ElementImpl
*/
ClassElementImpl(String name, int offset)
: _unlinkedClass = null,
+ _unlinkedEnum = null,
super(name, offset);
/**
@@ -145,20 +151,21 @@ class ClassElementImpl extends ElementImpl
*/
ClassElementImpl.forNode(Identifier name)
: _unlinkedClass = null,
+ _unlinkedEnum = null,
super.forNode(name);
/**
* Initialize using the given serialized information.
*/
- ClassElementImpl.forSerialized(
- this._unlinkedClass, CompilationUnitElementImpl enclosingUnit)
+ ClassElementImpl.forSerialized(this._unlinkedClass, this._unlinkedEnum,
+ CompilationUnitElementImpl enclosingUnit)
: super.forSerialized(enclosingUnit);
/**
* Set whether this class is abstract.
*/
void set abstract(bool isAbstract) {
- assert(_unlinkedClass == null);
+ assert(_unlinkedClass == null && _unlinkedEnum == null);
setModifier(Modifier.ABSTRACT, isAbstract);
}
@@ -187,6 +194,9 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass.codeRange?.length;
}
+ if (_unlinkedEnum != null) {
+ return _unlinkedEnum.codeRange?.length;
+ }
return super.codeLength;
}
@@ -195,6 +205,9 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass.codeRange?.offset;
}
+ if (_unlinkedEnum != null) {
+ return _unlinkedEnum.codeRange?.offset;
+ }
return super.codeOffset;
}
@@ -232,6 +245,12 @@ class ClassElementImpl extends ElementImpl
? new SourceRange(comment.offset, comment.length)
: null;
}
+ if (_unlinkedEnum != null) {
+ UnlinkedDocumentationComment comment = _unlinkedEnum.documentationComment;
+ return comment != null
+ ? new SourceRange(comment.offset, comment.length)
+ : null;
+ }
return super.docRange;
}
@@ -240,6 +259,9 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass?.documentationComment?.text;
}
+ if (_unlinkedEnum != null) {
+ return _unlinkedEnum?.documentationComment?.text;
+ }
return super.documentationComment;
}
@@ -294,6 +316,7 @@ class ClassElementImpl extends ElementImpl
* Set whether this class is defined by an enum declaration.
*/
void set enum2(bool isEnum) {
+ assert(_unlinkedClass == null && _unlinkedEnum == null);
setModifier(Modifier.ENUM, isEnum);
}
@@ -383,7 +406,7 @@ class ClassElementImpl extends ElementImpl
}
void set interfaces(List<InterfaceType> interfaces) {
- assert(_unlinkedClass == null);
+ assert(_unlinkedClass == null && _unlinkedEnum == null);
_interfaces = interfaces;
}
@@ -392,17 +415,31 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass.isAbstract;
}
+ if (_unlinkedEnum != null) {
+ return false;
+ }
return hasModifier(Modifier.ABSTRACT);
}
@override
- bool get isEnum => hasModifier(Modifier.ENUM);
+ bool get isEnum {
+ if (_unlinkedClass != null) {
+ return false;
+ }
+ if (_unlinkedEnum != null) {
+ return true;
+ }
+ return hasModifier(Modifier.ENUM);
+ }
@override
bool get isMixinApplication {
if (_unlinkedClass != null) {
return _unlinkedClass.isMixinApplication;
}
+ if (_unlinkedEnum != null) {
+ return false;
+ }
return hasModifier(Modifier.MIXIN_APPLICATION);
}
@@ -447,6 +484,10 @@ class ClassElementImpl extends ElementImpl
return _metadata ??=
_buildAnnotations(enclosingUnit, _unlinkedClass.annotations);
}
+ if (_unlinkedEnum != null) {
+ return _metadata ??=
+ _buildAnnotations(enclosingUnit, _unlinkedEnum.annotations);
+ }
return super.metadata;
}
@@ -457,6 +498,7 @@ class ClassElementImpl extends ElementImpl
* Set the methods contained in this class to the given [methods].
*/
void set methods(List<MethodElement> methods) {
+ assert(_unlinkedEnum == null);
for (MethodElement method in methods) {
(method as MethodElementImpl).enclosingElement = this;
}
@@ -483,7 +525,7 @@ class ClassElementImpl extends ElementImpl
}
void set mixins(List<InterfaceType> mixins) {
- assert(_unlinkedClass == null);
+ assert(_unlinkedClass == null && _unlinkedEnum == null);
_mixins = mixins;
}
@@ -492,6 +534,9 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass.name;
}
+ if (_unlinkedEnum != null) {
+ return _unlinkedEnum.name;
+ }
return super.name;
}
@@ -500,6 +545,9 @@ class ClassElementImpl extends ElementImpl
if (_unlinkedClass != null) {
return _unlinkedClass.nameOffset;
}
+ if (_unlinkedEnum != null) {
+ return _unlinkedEnum.nameOffset;
+ }
return super.nameOffset;
}
@@ -519,7 +567,7 @@ class ClassElementImpl extends ElementImpl
* [typeParameters].
*/
void set typeParameters(List<TypeParameterElement> typeParameters) {
- assert(_unlinkedClass == null);
+ assert(_unlinkedClass == null && _unlinkedEnum == null);
for (TypeParameterElement typeParameter in typeParameters) {
(typeParameter as TypeParameterElementImpl).enclosingElement = this;
}
@@ -527,8 +575,9 @@ class ClassElementImpl extends ElementImpl
}
@override
- List<UnlinkedTypeParam> get unlinkedTypeParams =>
- _unlinkedClass.typeParameters;
+ List<UnlinkedTypeParam> get unlinkedTypeParams {
+ return _unlinkedClass?.typeParameters ?? const <UnlinkedTypeParam>[];
+ }
@override
ConstructorElement get unnamedConstructor {
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698