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

Unified Diff: pkg/analyzer/lib/src/dart/constant/value.dart

Issue 2772943002: store constructor and arguments for constant values (Closed)
Patch Set: clean up pubspec Created 3 years, 9 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
Index: pkg/analyzer/lib/src/dart/constant/value.dart
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index a927df61a25e54153166a5a6ec2f78c9bf38275f..91d79cf9b931def496abd7b8dd53e623c6a71172 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -136,6 +136,29 @@ class BoolState extends InstanceState {
}
/**
+ * Information about a const constructor invocation.
+ */
+class ConstructorInvocation {
+ /**
+ * The constructor that was called.
+ */
+ final ConstructorElement constructor;
+
+ /**
+ * The positional arguments passed to the constructor.
+ */
+ final List<DartObjectImpl> positionalArguments;
+
+ /**
+ * The named arguments passed to the constructor.
+ */
+ final Map<String, DartObjectImpl> namedArguments;
+
+ ConstructorInvocation(
+ this.constructor, this.positionalArguments, this.namedArguments);
+}
+
+/**
* A representation of an instance of a Dart class.
*/
class DartObjectImpl implements DartObject {
@@ -375,6 +398,16 @@ class DartObjectImpl implements DartObject {
return null;
}
+ /// Gets the constructor that was called to create this value, if this is a
+ /// const constructor invocation. Otherwise returns null.
+ ConstructorInvocation getInvocation() {
+ InstanceState state = _state;
+ if (state is GenericState) {
+ return state.invocation;
+ }
+ return null;
+ }
+
/**
* Return the result of invoking the '&gt;' operator on this object with the
* [rightOperand]. The [typeProvider] is the type provider used to find known
@@ -1322,10 +1355,15 @@ class GenericState extends InstanceState {
final HashMap<String, DartObjectImpl> _fieldMap;
/**
+ * Information about the constructor invoked to generate this instance.
+ */
+ final ConstructorInvocation invocation;
+
+ /**
* Initialize a newly created state to represent a newly created object. The
* [fieldMap] contains the values of the fields of the instance.
*/
- GenericState(this._fieldMap);
+ GenericState(this._fieldMap, {this.invocation});
@override
HashMap<String, DartObjectImpl> get fields => _fieldMap;
« no previous file with comments | « pkg/analyzer/lib/src/dart/constant/evaluation.dart ('k') | pkg/analyzer/test/src/dart/constant/evaluation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698