Skip to content

Commit ff8a5df

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 40689. Add isStatic to available Declaration.
I did not use it yet, but filtered out all not top-level declarations that are not CONSTRUCTOR or ENUM_CONSTANT. But isStatic might be used if we decide to suggest static getters. [email protected], [email protected] Bug: #40689 Change-Id: I1c86754d9dbbc1422defc06a8fe6a47fa0bf6f98 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136410 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 34cdc81 commit ff8a5df

File tree

6 files changed

+411
-58
lines changed

6 files changed

+411
-58
lines changed

pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,18 @@ String _getRelativeFileUri(ResolvedUnitResult unit, Uri what) {
183183
protocol.AvailableSuggestion _protocolAvailableSuggestion(
184184
Declaration declaration) {
185185
var label = declaration.name;
186-
if (declaration.kind == DeclarationKind.CONSTRUCTOR) {
187-
label = declaration.parent.name;
188-
if (declaration.name.isNotEmpty) {
189-
label += '.${declaration.name}';
186+
if (declaration.parent != null) {
187+
if (declaration.kind == DeclarationKind.CONSTRUCTOR) {
188+
label = declaration.parent.name;
189+
if (declaration.name.isNotEmpty) {
190+
label += '.${declaration.name}';
191+
}
192+
} else if (declaration.kind == DeclarationKind.ENUM_CONSTANT) {
193+
label = '${declaration.parent.name}.${declaration.name}';
194+
} else {
195+
return null;
190196
}
191197
}
192-
if (declaration.kind == DeclarationKind.ENUM_CONSTANT) {
193-
label = '${declaration.parent.name}.${declaration.name}';
194-
}
195198

196199
String declaringLibraryUri;
197200
if (declaration.parent == null) {
@@ -227,7 +230,9 @@ protocol.AvailableSuggestionSet _protocolAvailableSuggestionSet(
227230

228231
void addItem(Declaration declaration) {
229232
var suggestion = _protocolAvailableSuggestion(declaration);
230-
items.add(suggestion);
233+
if (suggestion != null) {
234+
items.add(suggestion);
235+
}
231236
declaration.children.forEach(addItem);
232237
}
233238

@@ -260,8 +265,9 @@ int _protocolElementFlags(Declaration declaration) {
260265
return protocol.Element.makeFlags(
261266
isAbstract: declaration.isAbstract,
262267
isConst: declaration.isConst,
263-
isFinal: declaration.isFinal,
264268
isDeprecated: declaration.isDeprecated,
269+
isFinal: declaration.isFinal,
270+
isStatic: declaration.isStatic,
265271
);
266272
}
267273

pkg/analyzer/lib/src/services/available_declarations.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Declaration {
4545
final bool isConst;
4646
final bool isDeprecated;
4747
final bool isFinal;
48+
final bool isStatic;
4849
final DeclarationKind kind;
4950
final LineInfo lineInfo;
5051
final int locationOffset;
@@ -75,6 +76,7 @@ class Declaration {
7576
@required this.isConst,
7677
@required this.isDeprecated,
7778
@required this.isFinal,
79+
@required this.isStatic,
7880
@required this.kind,
7981
@required this.lineInfo,
8082
@required this.locationOffset,
@@ -925,6 +927,7 @@ class _DeclarationStorage {
925927
isConst: d.isConst,
926928
isDeprecated: d.isDeprecated,
927929
isFinal: d.isFinal,
930+
isStatic: d.isStatic,
928931
kind: kind,
929932
lineInfo: lineInfo,
930933
locationOffset: d.locationOffset,
@@ -1049,6 +1052,7 @@ class _DeclarationStorage {
10491052
isConst: d.isConst,
10501053
isDeprecated: d.isDeprecated,
10511054
isFinal: d.isFinal,
1055+
isStatic: d.isStatic,
10521056
kind: idlKind,
10531057
locationOffset: d.locationOffset,
10541058
locationStartColumn: d.locationStartColumn,
@@ -1105,7 +1109,7 @@ class _ExportCombinator {
11051109

11061110
class _File {
11071111
/// The version of data format, should be incremented on every format change.
1108-
static const int DATA_VERSION = 14;
1112+
static const int DATA_VERSION = 15;
11091113

11101114
/// The next value for [id].
11111115
static int _nextId = 0;
@@ -1318,6 +1322,7 @@ class _File {
13181322
bool isConst = false,
13191323
bool isDeprecated = false,
13201324
bool isFinal = false,
1325+
bool isStatic = false,
13211326
@required DeclarationKind kind,
13221327
@required Identifier name,
13231328
String parameters,
@@ -1347,6 +1352,7 @@ class _File {
13471352
isConst: isConst,
13481353
isDeprecated: isDeprecated,
13491354
isFinal: isFinal,
1355+
isStatic: isStatic,
13501356
kind: kind,
13511357
lineInfo: lineInfo,
13521358
locationOffset: locationOffset,
@@ -1413,6 +1419,7 @@ class _File {
14131419
);
14141420
hasConstructor = true;
14151421
} else if (classMember is FieldDeclaration) {
1422+
var isStatic = classMember.isStatic;
14161423
var isConst = classMember.fields.isConst;
14171424
var isFinal = classMember.fields.isFinal;
14181425
for (var field in classMember.fields.variables) {
@@ -1421,6 +1428,7 @@ class _File {
14211428
isConst: isConst,
14221429
isDeprecated: isDeprecated,
14231430
isFinal: isFinal,
1431+
isStatic: isStatic,
14241432
kind: DeclarationKind.FIELD,
14251433
name: field.name,
14261434
parent: parent,
@@ -1429,10 +1437,12 @@ class _File {
14291437
);
14301438
}
14311439
} else if (classMember is MethodDeclaration) {
1440+
var isStatic = classMember.isStatic;
14321441
var parameters = classMember.parameters;
14331442
if (classMember.isGetter) {
14341443
addDeclaration(
14351444
isDeprecated: isDeprecated,
1445+
isStatic: isStatic,
14361446
kind: DeclarationKind.GETTER,
14371447
name: classMember.name,
14381448
parent: parent,
@@ -1441,6 +1451,7 @@ class _File {
14411451
} else if (classMember.isSetter) {
14421452
addDeclaration(
14431453
isDeprecated: isDeprecated,
1454+
isStatic: isStatic,
14441455
kind: DeclarationKind.SETTER,
14451456
name: classMember.name,
14461457
parameters: parameters.toSource(),
@@ -1456,6 +1467,7 @@ class _File {
14561467
defaultArgumentListString: defaultArguments?.text,
14571468
defaultArgumentListTextRanges: defaultArguments?.ranges,
14581469
isDeprecated: isDeprecated,
1470+
isStatic: isStatic,
14591471
kind: DeclarationKind.METHOD,
14601472
name: classMember.name,
14611473
parameters: parameters.toSource(),
@@ -1496,6 +1508,7 @@ class _File {
14961508
isConst: false,
14971509
isDeprecated: false,
14981510
isFinal: false,
1511+
isStatic: false,
14991512
kind: DeclarationKind.CONSTRUCTOR,
15001513
locationOffset: -1,
15011514
locationPath: path,

pkg/analyzer/lib/src/summary/format.dart

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,7 @@ class AvailableDeclarationBuilder extends Object
21582158
bool _isConst;
21592159
bool _isDeprecated;
21602160
bool _isFinal;
2161+
bool _isStatic;
21612162
idl.AvailableDeclarationKind _kind;
21622163
int _locationOffset;
21632164
int _locationStartColumn;
@@ -2261,6 +2262,13 @@ class AvailableDeclarationBuilder extends Object
22612262
this._isFinal = value;
22622263
}
22632264

2265+
@override
2266+
bool get isStatic => _isStatic ??= false;
2267+
2268+
set isStatic(bool value) {
2269+
this._isStatic = value;
2270+
}
2271+
22642272
@override
22652273
idl.AvailableDeclarationKind get kind =>
22662274
_kind ??= idl.AvailableDeclarationKind.CLASS;
@@ -2370,6 +2378,7 @@ class AvailableDeclarationBuilder extends Object
23702378
bool isConst,
23712379
bool isDeprecated,
23722380
bool isFinal,
2381+
bool isStatic,
23732382
idl.AvailableDeclarationKind kind,
23742383
int locationOffset,
23752384
int locationStartColumn,
@@ -2394,6 +2403,7 @@ class AvailableDeclarationBuilder extends Object
23942403
_isConst = isConst,
23952404
_isDeprecated = isDeprecated,
23962405
_isFinal = isFinal,
2406+
_isStatic = isStatic,
23972407
_kind = kind,
23982408
_locationOffset = locationOffset,
23992409
_locationStartColumn = locationStartColumn,
@@ -2440,6 +2450,7 @@ class AvailableDeclarationBuilder extends Object
24402450
signature.addBool(this._isConst == true);
24412451
signature.addBool(this._isDeprecated == true);
24422452
signature.addBool(this._isFinal == true);
2453+
signature.addBool(this._isStatic == true);
24432454
signature.addInt(this._kind == null ? 0 : this._kind.index);
24442455
signature.addInt(this._locationOffset ?? 0);
24452456
signature.addInt(this._locationStartColumn ?? 0);
@@ -2568,41 +2579,44 @@ class AvailableDeclarationBuilder extends Object
25682579
if (_isFinal == true) {
25692580
fbBuilder.addBool(11, true);
25702581
}
2582+
if (_isStatic == true) {
2583+
fbBuilder.addBool(12, true);
2584+
}
25712585
if (_kind != null && _kind != idl.AvailableDeclarationKind.CLASS) {
2572-
fbBuilder.addUint8(12, _kind.index);
2586+
fbBuilder.addUint8(13, _kind.index);
25732587
}
25742588
if (_locationOffset != null && _locationOffset != 0) {
2575-
fbBuilder.addUint32(13, _locationOffset);
2589+
fbBuilder.addUint32(14, _locationOffset);
25762590
}
25772591
if (_locationStartColumn != null && _locationStartColumn != 0) {
2578-
fbBuilder.addUint32(14, _locationStartColumn);
2592+
fbBuilder.addUint32(15, _locationStartColumn);
25792593
}
25802594
if (_locationStartLine != null && _locationStartLine != 0) {
2581-
fbBuilder.addUint32(15, _locationStartLine);
2595+
fbBuilder.addUint32(16, _locationStartLine);
25822596
}
25832597
if (offset_name != null) {
2584-
fbBuilder.addOffset(16, offset_name);
2598+
fbBuilder.addOffset(17, offset_name);
25852599
}
25862600
if (offset_parameterNames != null) {
2587-
fbBuilder.addOffset(17, offset_parameterNames);
2601+
fbBuilder.addOffset(18, offset_parameterNames);
25882602
}
25892603
if (offset_parameters != null) {
2590-
fbBuilder.addOffset(18, offset_parameters);
2604+
fbBuilder.addOffset(19, offset_parameters);
25912605
}
25922606
if (offset_parameterTypes != null) {
2593-
fbBuilder.addOffset(19, offset_parameterTypes);
2607+
fbBuilder.addOffset(20, offset_parameterTypes);
25942608
}
25952609
if (offset_relevanceTags != null) {
2596-
fbBuilder.addOffset(20, offset_relevanceTags);
2610+
fbBuilder.addOffset(21, offset_relevanceTags);
25972611
}
25982612
if (_requiredParameterCount != null && _requiredParameterCount != 0) {
2599-
fbBuilder.addUint32(21, _requiredParameterCount);
2613+
fbBuilder.addUint32(22, _requiredParameterCount);
26002614
}
26012615
if (offset_returnType != null) {
2602-
fbBuilder.addOffset(22, offset_returnType);
2616+
fbBuilder.addOffset(23, offset_returnType);
26032617
}
26042618
if (offset_typeParameters != null) {
2605-
fbBuilder.addOffset(23, offset_typeParameters);
2619+
fbBuilder.addOffset(24, offset_typeParameters);
26062620
}
26072621
return fbBuilder.endTable();
26082622
}
@@ -2637,6 +2651,7 @@ class _AvailableDeclarationImpl extends Object
26372651
bool _isConst;
26382652
bool _isDeprecated;
26392653
bool _isFinal;
2654+
bool _isStatic;
26402655
idl.AvailableDeclarationKind _kind;
26412656
int _locationOffset;
26422657
int _locationStartColumn;
@@ -2727,84 +2742,90 @@ class _AvailableDeclarationImpl extends Object
27272742
return _isFinal;
27282743
}
27292744

2745+
@override
2746+
bool get isStatic {
2747+
_isStatic ??= const fb.BoolReader().vTableGet(_bc, _bcOffset, 12, false);
2748+
return _isStatic;
2749+
}
2750+
27302751
@override
27312752
idl.AvailableDeclarationKind get kind {
27322753
_kind ??= const _AvailableDeclarationKindReader()
2733-
.vTableGet(_bc, _bcOffset, 12, idl.AvailableDeclarationKind.CLASS);
2754+
.vTableGet(_bc, _bcOffset, 13, idl.AvailableDeclarationKind.CLASS);
27342755
return _kind;
27352756
}
27362757

27372758
@override
27382759
int get locationOffset {
27392760
_locationOffset ??=
2740-
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 13, 0);
2761+
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 14, 0);
27412762
return _locationOffset;
27422763
}
27432764

27442765
@override
27452766
int get locationStartColumn {
27462767
_locationStartColumn ??=
2747-
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 14, 0);
2768+
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 15, 0);
27482769
return _locationStartColumn;
27492770
}
27502771

27512772
@override
27522773
int get locationStartLine {
27532774
_locationStartLine ??=
2754-
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 15, 0);
2775+
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 16, 0);
27552776
return _locationStartLine;
27562777
}
27572778

27582779
@override
27592780
String get name {
2760-
_name ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 16, '');
2781+
_name ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 17, '');
27612782
return _name;
27622783
}
27632784

27642785
@override
27652786
List<String> get parameterNames {
27662787
_parameterNames ??= const fb.ListReader<String>(fb.StringReader())
2767-
.vTableGet(_bc, _bcOffset, 17, const <String>[]);
2788+
.vTableGet(_bc, _bcOffset, 18, const <String>[]);
27682789
return _parameterNames;
27692790
}
27702791

27712792
@override
27722793
String get parameters {
2773-
_parameters ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 18, '');
2794+
_parameters ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 19, '');
27742795
return _parameters;
27752796
}
27762797

27772798
@override
27782799
List<String> get parameterTypes {
27792800
_parameterTypes ??= const fb.ListReader<String>(fb.StringReader())
2780-
.vTableGet(_bc, _bcOffset, 19, const <String>[]);
2801+
.vTableGet(_bc, _bcOffset, 20, const <String>[]);
27812802
return _parameterTypes;
27822803
}
27832804

27842805
@override
27852806
List<String> get relevanceTags {
27862807
_relevanceTags ??= const fb.ListReader<String>(fb.StringReader())
2787-
.vTableGet(_bc, _bcOffset, 20, const <String>[]);
2808+
.vTableGet(_bc, _bcOffset, 21, const <String>[]);
27882809
return _relevanceTags;
27892810
}
27902811

27912812
@override
27922813
int get requiredParameterCount {
27932814
_requiredParameterCount ??=
2794-
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 21, 0);
2815+
const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 22, 0);
27952816
return _requiredParameterCount;
27962817
}
27972818

27982819
@override
27992820
String get returnType {
2800-
_returnType ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 22, '');
2821+
_returnType ??= const fb.StringReader().vTableGet(_bc, _bcOffset, 23, '');
28012822
return _returnType;
28022823
}
28032824

28042825
@override
28052826
String get typeParameters {
28062827
_typeParameters ??=
2807-
const fb.StringReader().vTableGet(_bc, _bcOffset, 23, '');
2828+
const fb.StringReader().vTableGet(_bc, _bcOffset, 24, '');
28082829
return _typeParameters;
28092830
}
28102831
}
@@ -2849,6 +2870,9 @@ abstract class _AvailableDeclarationMixin implements idl.AvailableDeclaration {
28492870
if (isFinal != false) {
28502871
_result["isFinal"] = isFinal;
28512872
}
2873+
if (isStatic != false) {
2874+
_result["isStatic"] = isStatic;
2875+
}
28522876
if (kind != idl.AvailableDeclarationKind.CLASS) {
28532877
_result["kind"] = kind.toString().split('.')[1];
28542878
}
@@ -2902,6 +2926,7 @@ abstract class _AvailableDeclarationMixin implements idl.AvailableDeclaration {
29022926
"isConst": isConst,
29032927
"isDeprecated": isDeprecated,
29042928
"isFinal": isFinal,
2929+
"isStatic": isStatic,
29052930
"kind": kind,
29062931
"locationOffset": locationOffset,
29072932
"locationStartColumn": locationStartColumn,

0 commit comments

Comments
 (0)