Skip to content

Commit c1bb024

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Basic support for Container.alignment property.
[email protected] Change-Id: I509df0b9c5d97e00a2f6ec50f31db1d07396f4ea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109660 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 634aa46 commit c1bb024

File tree

4 files changed

+309
-6
lines changed

4 files changed

+309
-6
lines changed

pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analyzer/dart/analysis/results.dart';
1111
import 'package:analyzer/dart/ast/ast.dart';
1212
import 'package:analyzer/dart/element/element.dart';
1313
import 'package:analyzer/dart/element/type.dart';
14+
import 'package:analyzer/src/dart/analysis/session_helper.dart';
1415
import 'package:analyzer/src/dart/ast/utilities.dart';
1516
import 'package:analyzer/src/util/comment.dart';
1617

@@ -122,6 +123,9 @@ class _WidgetDescriptionComputer {
122123
/// The instance of [Flutter] support.
123124
final Flutter flutter;
124125

126+
ClassElement _classAlignment;
127+
ClassElement _classAlignmentDirectional;
128+
125129
_WidgetDescriptionComputer(
126130
this.classRegistry,
127131
this.resolvedUnit,
@@ -140,6 +144,8 @@ class _WidgetDescriptionComputer {
140144
return null;
141145
}
142146

147+
await _fetchClassElements();
148+
143149
var properties = <PropertyDescription>[];
144150
_addProperties(
145151
properties: properties,
@@ -343,6 +349,18 @@ class _WidgetDescriptionComputer {
343349
.toList();
344350
}
345351

352+
Future<void> _fetchClassElements() async {
353+
var sessionHelper = AnalysisSessionHelper(resolvedUnit.session);
354+
_classAlignment = await sessionHelper.getClass(
355+
flutter.widgetsUri,
356+
'Alignment',
357+
);
358+
_classAlignmentDirectional = await sessionHelper.getClass(
359+
flutter.widgetsUri,
360+
'AlignmentDirectional',
361+
);
362+
}
363+
346364
protocol.FlutterWidgetPropertyEditor _getEditor(DartType type) {
347365
if (type.isDartCoreBool) {
348366
return protocol.FlutterWidgetPropertyEditor(
@@ -372,6 +390,19 @@ class _WidgetDescriptionComputer {
372390
enumItems: _enumItemsForEnum(classElement),
373391
);
374392
}
393+
if (flutter.isExactAlignmentGeometry(classElement)) {
394+
var items = <protocol.FlutterWidgetPropertyValueEnumItem>[];
395+
items.addAll(
396+
_enumItemsForStaticFields(_classAlignment),
397+
);
398+
items.addAll(
399+
_enumItemsForStaticFields(_classAlignmentDirectional),
400+
);
401+
return protocol.FlutterWidgetPropertyEditor(
402+
protocol.FlutterWidgetPropertyEditorKind.ENUM,
403+
enumItems: items,
404+
);
405+
}
375406
}
376407
return null;
377408
}
@@ -406,7 +437,9 @@ class _WidgetDescriptionComputer {
406437
var field = element.variable;
407438
if (field is FieldElement && field.isStatic) {
408439
var enclosingClass = field.enclosingElement as ClassElement;
409-
if (field.isEnumConstant) {
440+
if (field.isEnumConstant ||
441+
flutter.isExactAlignment(enclosingClass) ||
442+
flutter.isExactAlignmentDirectional(enclosingClass)) {
410443
return protocol.FlutterWidgetPropertyValue(
411444
enumValue: _toEnumItem(field),
412445
);

pkg/analysis_server/lib/src/utilities/flutter.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Flutter {
3333
final String packageName;
3434
final String widgetsUri;
3535

36+
final Uri _uriAlignment;
3637
final Uri _uriAsync;
3738
final Uri _uriBasic;
3839
final Uri _uriContainer;
@@ -65,6 +66,7 @@ class Flutter {
6566

6667
Flutter._(this.packageName, String uriPrefix)
6768
: widgetsUri = '$uriPrefix/widgets.dart',
69+
_uriAlignment = Uri.parse('$uriPrefix/src/painting/alignment.dart'),
6870
_uriAsync = Uri.parse('$uriPrefix/src/widgets/async.dart'),
6971
_uriBasic = Uri.parse('$uriPrefix/src/widgets/basic.dart'),
7072
_uriContainer = Uri.parse('$uriPrefix/src/widgets/container.dart'),
@@ -321,6 +323,21 @@ class Flutter {
321323
bool isChildrenArgument(Expression argument) =>
322324
argument is NamedExpression && argument.name.label.name == 'children';
323325

326+
/// Return `true` if the [element] is the Flutter class `Alignment`.
327+
bool isExactAlignment(ClassElement element) {
328+
return _isExactWidget(element, 'Alignment', _uriAlignment);
329+
}
330+
331+
/// Return `true` if the [element] is the Flutter class `AlignmentDirectional`.
332+
bool isExactAlignmentDirectional(ClassElement element) {
333+
return _isExactWidget(element, 'AlignmentDirectional', _uriAlignment);
334+
}
335+
336+
/// Return `true` if the [element] is the Flutter class `AlignmentGeometry`.
337+
bool isExactAlignmentGeometry(ClassElement element) {
338+
return _isExactWidget(element, 'AlignmentGeometry', _uriAlignment);
339+
}
340+
324341
/**
325342
* Return `true` if the [node] is creation of `Container`.
326343
*/
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
var alignmentEditor = '''
6+
"editor": {
7+
"kind": "ENUM",
8+
"enumItems": $alignmentEnumItems
9+
}''';
10+
11+
var alignmentEnumItems = '''
12+
[
13+
{
14+
"libraryUri": "package:flutter/src/painting/alignment.dart",
15+
"className": "Alignment",
16+
"name": "topLeft"
17+
},
18+
{
19+
"libraryUri": "package:flutter/src/painting/alignment.dart",
20+
"className": "Alignment",
21+
"name": "topCenter"
22+
},
23+
{
24+
"libraryUri": "package:flutter/src/painting/alignment.dart",
25+
"className": "Alignment",
26+
"name": "topRight"
27+
},
28+
{
29+
"libraryUri": "package:flutter/src/painting/alignment.dart",
30+
"className": "Alignment",
31+
"name": "centerLeft"
32+
},
33+
{
34+
"libraryUri": "package:flutter/src/painting/alignment.dart",
35+
"className": "Alignment",
36+
"name": "center"
37+
},
38+
{
39+
"libraryUri": "package:flutter/src/painting/alignment.dart",
40+
"className": "Alignment",
41+
"name": "centerRight"
42+
},
43+
{
44+
"libraryUri": "package:flutter/src/painting/alignment.dart",
45+
"className": "Alignment",
46+
"name": "bottomLeft"
47+
},
48+
{
49+
"libraryUri": "package:flutter/src/painting/alignment.dart",
50+
"className": "Alignment",
51+
"name": "bottomCenter"
52+
},
53+
{
54+
"libraryUri": "package:flutter/src/painting/alignment.dart",
55+
"className": "Alignment",
56+
"name": "bottomRight"
57+
},
58+
{
59+
"libraryUri": "package:flutter/src/painting/alignment.dart",
60+
"className": "AlignmentDirectional",
61+
"name": "topStart"
62+
},
63+
{
64+
"libraryUri": "package:flutter/src/painting/alignment.dart",
65+
"className": "AlignmentDirectional",
66+
"name": "topCenter"
67+
},
68+
{
69+
"libraryUri": "package:flutter/src/painting/alignment.dart",
70+
"className": "AlignmentDirectional",
71+
"name": "topEnd"
72+
},
73+
{
74+
"libraryUri": "package:flutter/src/painting/alignment.dart",
75+
"className": "AlignmentDirectional",
76+
"name": "centerStart"
77+
},
78+
{
79+
"libraryUri": "package:flutter/src/painting/alignment.dart",
80+
"className": "AlignmentDirectional",
81+
"name": "center"
82+
},
83+
{
84+
"libraryUri": "package:flutter/src/painting/alignment.dart",
85+
"className": "AlignmentDirectional",
86+
"name": "centerEnd"
87+
},
88+
{
89+
"libraryUri": "package:flutter/src/painting/alignment.dart",
90+
"className": "AlignmentDirectional",
91+
"name": "bottomStart"
92+
},
93+
{
94+
"libraryUri": "package:flutter/src/painting/alignment.dart",
95+
"className": "AlignmentDirectional",
96+
"name": "bottomCenter"
97+
},
98+
{
99+
"libraryUri": "package:flutter/src/painting/alignment.dart",
100+
"className": "AlignmentDirectional",
101+
"name": "bottomEnd"
102+
}
103+
]''';

0 commit comments

Comments
 (0)