Skip to content

Commit 11effd9

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Use collection elements and null-aware elements in TreeWriter
This is not a slam dunk, and I can abandon this if it is not deemed _more_ readable. Having a Map collection literal with a collection-if and a spread map literal inside (`if (foo) ...{ ... }`) isn't the most readable code. I change a programmatic filling of Maps to be declarative, with Map literals, collection elements like collection-if and collection-for. In particular, I think the null-aware elements nicely indicate nullable values, which might not be included in the Map. If something doesn't appear in the Insights pages from these property maps, it is more clear from the code that a value might be `null`, and might not appear. This simplifies the code all the way through `writeProperties` and `writeProperty`, which previously considered `null` values, but now only need to handle Objects. Change-Id: I64ab32cebbb3ed0b69d3e4005b9ad2c843030636 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465988 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 5b10311 commit 11effd9

File tree

3 files changed

+216
-242
lines changed

3 files changed

+216
-242
lines changed

pkg/analysis_server/lib/src/status/utilities/ast_writer.dart

Lines changed: 103 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -29,113 +29,109 @@ class AstWriter extends UnifyingAstVisitor<void> with TreeWriter {
2929

3030
/// Write a representation of the properties of the given [node] to the
3131
/// buffer.
32-
Map<String, Object?> _computeProperties(AstNode node) {
33-
var properties = <String, Object?>{};
34-
35-
properties['name'] = _getName(node);
36-
if (node is ArgumentListImpl) {
37-
properties['corresponding static parameters'] =
38-
node.correspondingStaticParameters;
39-
} else if (node is Annotation) {
40-
properties['element'] = node.element;
41-
properties['element annotation'] = node.elementAnnotation;
42-
} else if (node is BinaryExpression) {
43-
properties['element'] = node.element;
44-
properties['static type'] = node.staticType;
45-
} else if (node is ClassDeclaration) {
46-
properties['declared fragment'] = node.declaredFragment;
47-
properties['abstract keyword'] = node.abstractKeyword;
48-
} else if (node is ClassTypeAlias) {
49-
properties['declared fragment'] = node.declaredFragment;
50-
properties['abstract keyword'] = node.abstractKeyword;
51-
} else if (node is CompilationUnit) {
52-
properties['declared fragment'] = node.declaredFragment;
53-
} else if (node is Configuration) {
54-
properties['uriSource'] = node.resolvedUri;
55-
} else if (node is ConstructorName) {
56-
properties['element'] = node.element;
57-
} else if (node is DeclaredIdentifier) {
58-
properties['element'] = node.declaredFragment?.element;
59-
properties['keyword'] = node.keyword;
60-
} else if (node is ExportDirective) {
61-
properties['library export'] = node.libraryExport;
62-
} else if (node is FieldDeclaration) {
63-
properties['static keyword'] = node.staticKeyword;
64-
} else if (node is FormalParameter) {
65-
properties['declared fragment'] = node.declaredFragment;
66-
if (node.isRequiredPositional) {
67-
properties['kind'] = 'required-positional';
68-
} else if (node.isRequiredNamed) {
69-
properties['kind'] = 'required-named';
70-
} else if (node.isOptionalPositional) {
71-
properties['kind'] = 'optional-positional';
72-
} else if (node.isOptionalNamed) {
73-
properties['kind'] = 'optional-named';
74-
} else {
75-
properties['kind'] = 'unknown kind';
76-
}
77-
} else if (node is FunctionDeclaration) {
78-
properties['declared fragment'] = node.declaredFragment;
79-
properties['external keyword'] = node.externalKeyword;
80-
properties['property keyword'] = node.propertyKeyword;
81-
} else if (node is FunctionExpressionInvocation) {
82-
properties['element'] = node.element;
83-
properties['static invoke type'] = node.staticInvokeType;
84-
properties['static type'] = node.staticType;
85-
} else if (node is GenericFunctionType) {
86-
properties['type'] = node.type;
87-
} else if (node is ImportDirective) {
88-
properties['library import'] = node.libraryImport;
89-
} else if (node is IndexExpression) {
90-
properties['element'] = node.element;
91-
properties['static type'] = node.staticType;
92-
} else if (node is InstanceCreationExpression) {
93-
properties['static type'] = node.staticType;
94-
} else if (node is LibraryDirective) {
95-
properties['element'] = node.element;
96-
} else if (node is MethodDeclaration) {
97-
properties['declared fragment'] = node.declaredFragment;
98-
properties['external keyword'] = node.externalKeyword;
99-
properties['modifier keyword'] = node.modifierKeyword;
100-
properties['operator keyword'] = node.operatorKeyword;
101-
properties['property keyword'] = node.propertyKeyword;
102-
} else if (node is MethodInvocation) {
103-
properties['static invoke type'] = node.staticInvokeType;
104-
properties['static type'] = node.staticType;
105-
} else if (node is PartDirective) {
106-
properties['fragment include'] = node.partInclude;
107-
} else if (node is PostfixExpression) {
108-
properties['element'] = node.element;
109-
properties['static type'] = node.staticType;
110-
} else if (node is PrefixExpression) {
111-
properties['element'] = node.element;
112-
properties['static type'] = node.staticType;
113-
} else if (node is RedirectingConstructorInvocation) {
114-
properties['element'] = node.element;
115-
} else if (node is SimpleIdentifier) {
116-
properties['element'] = node.element;
117-
properties['static type'] = node.staticType;
118-
} else if (node is SimpleStringLiteral) {
119-
properties['value'] = node.value;
120-
} else if (node is SuperConstructorInvocation) {
121-
properties['element'] = node.element;
122-
} else if (node is TypeAnnotation) {
123-
properties['type'] = node.type;
124-
} else if (node is VariableDeclarationList) {
125-
properties['keyword'] = node.keyword;
126-
} else if (node is Declaration) {
127-
properties['declared fragment'] = node.declaredFragment;
128-
} else if (node is Expression) {
129-
properties['static type'] = node.staticType;
130-
} else if (node is FunctionBody) {
131-
properties['is asynchronous'] = node.isAsynchronous;
132-
properties['is generator'] = node.isGenerator;
133-
} else if (node is Identifier) {
134-
properties['element'] = node.element;
135-
properties['static type'] = node.staticType;
136-
}
137-
138-
return properties;
32+
Map<String, Object> _computeProperties(AstNode node) {
33+
return {
34+
'name': ?_getName(node),
35+
if (node is ArgumentListImpl)
36+
'corresponding static parameters': ?node.correspondingStaticParameters
37+
else if (node is Annotation) ...{
38+
'element': ?node.element,
39+
'element annotation': ?node.elementAnnotation,
40+
} else if (node is BinaryExpression) ...{
41+
'element': ?node.element,
42+
'static type': ?node.staticType,
43+
} else if (node is ClassDeclaration) ...{
44+
'declared fragment': ?node.declaredFragment,
45+
'abstract keyword': ?node.abstractKeyword,
46+
} else if (node is ClassTypeAlias) ...{
47+
'declared fragment': ?node.declaredFragment,
48+
'abstract keyword': ?node.abstractKeyword,
49+
} else if (node is CompilationUnit)
50+
'declared fragment': ?node.declaredFragment
51+
else if (node is Configuration)
52+
'uriSource': ?node.resolvedUri
53+
else if (node is ConstructorName)
54+
'element': ?node.element
55+
else if (node is DeclaredIdentifier) ...{
56+
'element': ?node.declaredFragment?.element,
57+
'keyword': ?node.keyword,
58+
} else if (node is ExportDirective)
59+
'library export': ?node.libraryExport
60+
else if (node is FieldDeclaration)
61+
'static keyword': ?node.staticKeyword
62+
else if (node is FormalParameter) ...{
63+
'declared fragment': ?node.declaredFragment,
64+
if (node.isRequiredPositional)
65+
'kind': 'required-positional'
66+
else if (node.isRequiredNamed)
67+
'kind': 'required-named'
68+
else if (node.isOptionalPositional)
69+
'kind': 'optional-positional'
70+
else if (node.isOptionalNamed)
71+
'kind': 'optional-named'
72+
else
73+
'kind': 'unknown kind',
74+
} else if (node is FunctionDeclaration) ...{
75+
'declared fragment': ?node.declaredFragment,
76+
'external keyword': ?node.externalKeyword,
77+
'property keyword': ?node.propertyKeyword,
78+
} else if (node is FunctionExpressionInvocation) ...{
79+
'element': ?node.element,
80+
'static invoke type': ?node.staticInvokeType,
81+
'static type': ?node.staticType,
82+
} else if (node is GenericFunctionType)
83+
'type': ?node.type
84+
else if (node is ImportDirective)
85+
'library import': ?node.libraryImport
86+
else if (node is IndexExpression) ...{
87+
'element': ?node.element,
88+
'static type': ?node.staticType,
89+
} else if (node is InstanceCreationExpression)
90+
'static type': ?node.staticType
91+
else if (node is LibraryDirective)
92+
'element': ?node.element
93+
else if (node is MethodDeclaration) ...{
94+
'declared fragment': ?node.declaredFragment,
95+
'external keyword': ?node.externalKeyword,
96+
'modifier keyword': ?node.modifierKeyword,
97+
'operator keyword': ?node.operatorKeyword,
98+
'property keyword': ?node.propertyKeyword,
99+
} else if (node is MethodInvocation) ...{
100+
'static invoke type': ?node.staticInvokeType,
101+
'static type': ?node.staticType,
102+
} else if (node is PartDirective)
103+
'fragment include': ?node.partInclude
104+
else if (node is PostfixExpression) ...{
105+
'element': ?node.element,
106+
'static type': ?node.staticType,
107+
} else if (node is PrefixExpression) ...{
108+
'element': ?node.element,
109+
'static type': ?node.staticType,
110+
} else if (node is RedirectingConstructorInvocation)
111+
'element': ?node.element
112+
else if (node is SimpleIdentifier) ...{
113+
'element': ?node.element,
114+
'static type': ?node.staticType,
115+
} else if (node is SimpleStringLiteral)
116+
'value': node.value
117+
else if (node is SuperConstructorInvocation)
118+
'element': ?node.element
119+
else if (node is TypeAnnotation)
120+
'type': ?node.type
121+
else if (node is VariableDeclarationList)
122+
'keyword': ?node.keyword
123+
else if (node is Declaration)
124+
'declared fragment': ?node.declaredFragment
125+
else if (node is Expression)
126+
'static type': ?node.staticType
127+
else if (node is FunctionBody) ...{
128+
'is asynchronous': node.isAsynchronous,
129+
'is generator': node.isGenerator,
130+
} else if (node is Identifier) ...{
131+
'element': ?node.element,
132+
'static type': ?node.staticType,
133+
},
134+
};
139135
}
140136

141137
/// Return the name of the given [node], or `null` if the given node is not a

0 commit comments

Comments
 (0)