Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include static member information for classes #1454

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 additions & 5 deletions dwds/lib/src/debugging/classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ClassHelper extends Domain {
"isStatic": false,
}
}
// TODO(jakemac): static fields once ddc supports them

var fields = sdkUtils.getFields(clazz);
var fieldNames = fields ? Object.keys(fields) : [];
descriptor['fields'] = {};
Expand All @@ -135,6 +135,34 @@ class ClassHelper extends Domain {
"classRefLibraryId" : field["type"][libraryUri],
}
}

// TODO(elliette): The following static member information is minimal and
// should be replaced once DDC provides full symbol information (see
// https://github.com/dart-lang/sdk/issues/40273):

descriptor['staticFields'] = {};
var staticFieldNames = sdkUtils.getStaticFields(clazz) ?? [];
for (const name of staticFieldNames) {
descriptor['staticFields'][name] = {
"isStatic": true,
// DDC only provides names of static members, we set isConst/isFinal
// to false even though they could be true.
"isConst": false,
"isFinal": false,
}
}

descriptor['staticMethods'] = {};
var staticMethodNames = sdkUtils.getStaticMethods(clazz) ?? [];
for (var name of staticMethodNames) {
descriptor['methods'][name] = {
// DDC only provides names of static members, we set isConst
// to false even though it could be true.
"isConst": false,
"isStatic": true,
}
}

return descriptor;
})()
''';
Expand All @@ -153,6 +181,9 @@ class ClassHelper extends Domain {
var classDescriptor = result.value as Map<String, dynamic>;
var methodRefs = <FuncRef>[];
var methodDescriptors = classDescriptor['methods'] as Map<String, dynamic>;
var staticMethodDescriptors =
classDescriptor['staticMethods'] as Map<String, dynamic>;
methodDescriptors.addAll(staticMethodDescriptors);
methodDescriptors.forEach((name, descriptor) {
var methodId = 'methods|${classRef.id}|$name';
methodRefs.add(FuncRef(
Expand All @@ -176,16 +207,39 @@ class ClassHelper extends Domain {
name: name,
owner: classRef,
declaredType: InstanceRef(
identityHashCode: createId().hashCode,
id: createId(),
kind: InstanceKind.kType,
classRef: classMetaData.classRef),
identityHashCode: createId().hashCode,
id: createId(),
kind: InstanceKind.kType,
// TODO(elliette): Is this the same as classRef?
classRef: classMetaData.classRef,
),
isConst: descriptor['isConst'] as bool,
isFinal: descriptor['isFinal'] as bool,
isStatic: descriptor['isStatic'] as bool,
id: createId()));
});

var staticFieldDescriptors =
classDescriptor['staticFields'] as Map<String, dynamic>;
staticFieldDescriptors.forEach((name, descriptor) async {
fieldRefs.add(
FieldRef(
name: name,
owner: classRef,
declaredType: InstanceRef(
identityHashCode: createId().hashCode,
id: createId(),
kind: InstanceKind.kType,
classRef: classRef,
),
isConst: descriptor['isConst'] as bool,
isFinal: descriptor['isFinal'] as bool,
isStatic: descriptor['isStatic'] as bool,
id: createId(),
),
);
});

// TODO: Implement the rest of these
// https://github.com/dart-lang/webdev/issues/176.
return Class(
Expand Down
7 changes: 7 additions & 0 deletions dwds/test/chrome_proxy_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ void main() {
expect(
testClass.functions,
unorderedEquals([
predicate((FuncRef f) => f.name == 'staticHello' && f.isStatic),
predicate((FuncRef f) => f.name == 'message' && !f.isStatic),
predicate((FuncRef f) => f.name == 'notFinal' && !f.isStatic),
predicate((FuncRef f) => f.name == 'hello' && !f.isStatic),
Expand All @@ -475,6 +476,12 @@ void main() {
!f.isStatic &&
!f.isConst &&
!f.isFinal),
predicate((FieldRef f) =>
f.name == 'staticMessage' &&
f.declaredType != null &&
f.isStatic &&
!f.isConst &&
!f.isFinal),
]));
});

Expand Down
4 changes: 4 additions & 0 deletions fixtures/_test/example/hello_world/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class MyTestClass {

String notFinal;

static final String staticMessage = 'static';

static String staticHello() => 'static hello';

MyTestClass({this.message = 'world'});

String hello() => message;
Expand Down