Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2d332ee

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Make private fields final where possible
Change-Id: I16ee52f1b23e8d708e40cb482c5150f1e04d2417 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128524 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent b1afe2d commit 2d332ee

36 files changed

+196
-275
lines changed

pkg/analyzer/analysis_options.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@ analyzer:
77
errors:
88
# Increase the severity of the unused_import hint.
99
unused_import: warning
10+
# There are currently 140 violations in lib/.
11+
always_declare_return_types: ignore
12+
# There are currently 230 violations in lib/.
13+
annotate_overrides: ignore
14+
# There are currently 5500 violations in lib/. This just does not fit well
15+
# with the analyzer team's style.
16+
omit_local_variable_types: ignore
17+
# There are currently 3360 violations in lib/.
18+
prefer_single_quotes: ignore
1019
# Ignoring "style" lint rules from pedantic for now. There are pre-existing
1120
# violations that need to be cleaned up. Each one can be cleaned up and
1221
# enabled according to the value provided.
1322
# TODO(srawlins): At the time of writing, 2600 violations in lib/. The fix
1423
# is mechanical, via `dartfmt --fix-doc-comments`, but not worth the churn
1524
# today.
1625
slash_for_doc_comments: ignore
26+
# There are currently 1980 violations in lib/.
27+
unnecessary_this: ignore
1728

1829
linter:
1930
rules:

pkg/analyzer/lib/dart/analysis/declared_variables.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
1212
/// Clients may not extend, implement or mix-in this class.
1313
class DeclaredVariables {
1414
/// A table mapping the names of declared variables to their values.
15-
Map<String, String> _declaredVariables = <String, String>{};
15+
final Map<String, String> _declaredVariables = <String, String>{};
1616

1717
/// Initialize a newly created set of declared variables in which there are no
1818
/// variables.

pkg/analyzer/lib/dart/ast/visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import 'package:analyzer/dart/ast/ast.dart';
4949
class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
5050
/// A queue holding the nodes that have not yet been visited in the order in
5151
/// which they ought to be visited.
52-
Queue<AstNode> _queue = Queue<AstNode>();
52+
final Queue<AstNode> _queue = Queue<AstNode>();
5353

5454
/// A visitor, used to visit the children of the current node, that will add
5555
/// the nodes it visits to the [_queue].

pkg/analyzer/lib/instrumentation/log_adapter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InstrumentationLogAdapter implements InstrumentationService {
2525
static const String TAG_WATCH_EVENT = 'Watch';
2626

2727
/// A logger used to log instrumentation in string format.
28-
InstrumentationLogger _instrumentationLogger;
28+
final InstrumentationLogger _instrumentationLogger;
2929

3030
/// Initialize a newly created instrumentation service to communicate with the
3131
/// given [_instrumentationLogger].

pkg/analyzer/lib/src/dart/analysis/dependency/reference_collector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ReferenceCollector {
2929
/// The list of names that are referenced using an import prefix.
3030
///
3131
/// It is filled by [addImportPrefix] and shared across all nodes.
32-
List<_ReferencedImportPrefixedNames> _importPrefixedReferences = [];
32+
final List<_ReferencedImportPrefixedNames> _importPrefixedReferences = [];
3333

3434
/// The list of names that are referenced with `super`.
3535
_NameSet _superReferences = _NameSet();

pkg/analyzer/lib/src/dart/analysis/library_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LibraryContext {
5050
/// The size of the linked data that is loaded by this context.
5151
/// When it reaches [_maxLinkedDataInBytes] the whole context is thrown away.
5252
/// We use it as an approximation for the heap size of elements.
53-
int _linkedDataInBytes = 0;
53+
final int _linkedDataInBytes = 0;
5454

5555
AnalysisContextImpl analysisContext;
5656
LinkedElementFactory elementFactory;

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ class ChildEntities
13861386
with IterableMixin<SyntacticEntity>
13871387
implements Iterable<SyntacticEntity> {
13881388
/// The list of child entities to be iterated over.
1389-
List<SyntacticEntity> _entities = [];
1389+
final List<SyntacticEntity> _entities = [];
13901390

13911391
@override
13921392
Iterator<SyntacticEntity> get iterator => _entities.iterator;
@@ -10133,7 +10133,7 @@ abstract class UriBasedDirectiveImpl extends DirectiveImpl
1013310133
implements UriBasedDirective {
1013410134
/// The prefix of a URI using the `dart-ext` scheme to reference a native code
1013510135
/// library.
10136-
static String _DART_EXT_SCHEME = "dart-ext:";
10136+
static const String _DART_EXT_SCHEME = "dart-ext:";
1013710137

1013810138
/// The URI referenced by this directive.
1013910139
StringLiteralImpl _uri;

pkg/analyzer/lib/src/dart/ast/utilities.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,12 +2498,12 @@ class NodeLocator extends UnifyingAstVisitor<void> {
24982498
/**
24992499
* The start offset of the range used to identify the node.
25002500
*/
2501-
int _startOffset = 0;
2501+
final int _startOffset;
25022502

25032503
/**
25042504
* The end offset of the range used to identify the node.
25052505
*/
2506-
int _endOffset = 0;
2506+
final int _endOffset;
25072507

25082508
/**
25092509
* The element that was found that corresponds to the given source range, or
@@ -2601,15 +2601,11 @@ class NodeLocator extends UnifyingAstVisitor<void> {
26012601
* encompasses the specified range.
26022602
*/
26032603
class NodeLocator2 extends UnifyingAstVisitor<void> {
2604-
/**
2605-
* The inclusive start offset of the range used to identify the node.
2606-
*/
2607-
int _startOffset = 0;
2604+
/// The inclusive start offset of the range used to identify the node.
2605+
final int _startOffset;
26082606

2609-
/**
2610-
* The inclusive end offset of the range used to identify the node.
2611-
*/
2612-
int _endOffset = 0;
2607+
/// The inclusive end offset of the range used to identify the node.
2608+
final int _endOffset;
26132609

26142610
/**
26152611
* The found node or `null` if there is no such node.
@@ -5633,7 +5629,8 @@ class ScopedNameFinder extends GeneralizingAstVisitor<void> {
56335629

56345630
AstNode _immediateChild;
56355631

5636-
Map<String, SimpleIdentifier> _locals = HashMap<String, SimpleIdentifier>();
5632+
final Map<String, SimpleIdentifier> _locals =
5633+
HashMap<String, SimpleIdentifier>();
56375634

56385635
final int _position;
56395636

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ import 'package:analyzer/src/task/api/model.dart';
3434
/// constant instance creation expressions.
3535
class ConstantEvaluationEngine {
3636
/// Parameter to "fromEnvironment" methods that denotes the default value.
37-
static String _DEFAULT_VALUE_PARAM = "defaultValue";
37+
static const String _DEFAULT_VALUE_PARAM = "defaultValue";
3838

3939
/// Source of RegExp matching declarable operator names.
4040
/// From sdk/lib/internal/symbol.dart.
41-
static String _OPERATOR_RE =
41+
static const String _OPERATOR_RE =
4242
"(?:[\\-+*/%&|^]|\\[\\]=?|==|~/?|<[<=]?|>[>=]?|unary-)";
4343

4444
/// Source of RegExp matching Dart reserved words.
4545
/// From sdk/lib/internal/symbol.dart.
46-
static String _RESERVED_WORD_RE =
46+
static const String _RESERVED_WORD_RE =
4747
"(?:assert|break|c(?:a(?:se|tch)|lass|on(?:st|tinue))|"
4848
"d(?:efault|o)|e(?:lse|num|xtends)|f(?:alse|inal(?:ly)?|or)|"
4949
"i[fns]|n(?:ew|ull)|ret(?:hrow|urn)|s(?:uper|witch)|t(?:h(?:is|row)|"
5050
"r(?:ue|y))|v(?:ar|oid)|w(?:hile|ith))";
5151

5252
/// Source of RegExp matching any public identifier.
5353
/// From sdk/lib/internal/symbol.dart.
54-
static String _PUBLIC_IDENTIFIER_RE =
54+
static const String _PUBLIC_IDENTIFIER_RE =
5555
"(?!$_RESERVED_WORD_RE\\b(?!\\\$))[a-zA-Z\$][\\w\$]*";
5656

5757
/// RegExp that validates a non-empty non-private symbol.
5858
/// From sdk/lib/internal/symbol.dart.
59-
static RegExp _PUBLIC_SYMBOL_PATTERN = RegExp(
59+
static final RegExp _PUBLIC_SYMBOL_PATTERN = RegExp(
6060
"^(?:$_OPERATOR_RE\$|$_PUBLIC_IDENTIFIER_RE(?:=?\$|[.](?!\$)))+?\$");
6161

6262
/// The type provider used to access the known types.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,88 +2353,89 @@ class DynamicElementImpl extends ElementImpl implements TypeDefiningElement {
23532353
class ElementAnnotationImpl implements ElementAnnotation {
23542354
/// The name of the top-level variable used to mark that a function always
23552355
/// throws, for dead code purposes.
2356-
static String _ALWAYS_THROWS_VARIABLE_NAME = "alwaysThrows";
2356+
static const String _ALWAYS_THROWS_VARIABLE_NAME = "alwaysThrows";
23572357

23582358
/// The name of the class used to mark an element as being deprecated.
2359-
static String _DEPRECATED_CLASS_NAME = "Deprecated";
2359+
static const String _DEPRECATED_CLASS_NAME = "Deprecated";
23602360

23612361
/// The name of the top-level variable used to mark an element as being
23622362
/// deprecated.
2363-
static String _DEPRECATED_VARIABLE_NAME = "deprecated";
2363+
static const String _DEPRECATED_VARIABLE_NAME = "deprecated";
23642364

23652365
/// The name of the top-level variable used to mark a method as being a
23662366
/// factory.
2367-
static String _FACTORY_VARIABLE_NAME = "factory";
2367+
static const String _FACTORY_VARIABLE_NAME = "factory";
23682368

23692369
/// The name of the top-level variable used to mark a class and its subclasses
23702370
/// as being immutable.
2371-
static String _IMMUTABLE_VARIABLE_NAME = "immutable";
2371+
static const String _IMMUTABLE_VARIABLE_NAME = "immutable";
23722372

23732373
/// The name of the top-level variable used to mark a constructor as being
23742374
/// literal.
2375-
static String _LITERAL_VARIABLE_NAME = "literal";
2375+
static const String _LITERAL_VARIABLE_NAME = "literal";
23762376

23772377
/// The name of the top-level variable used to mark a type as having
23782378
/// "optional" type arguments.
2379-
static String _OPTIONAL_TYPE_ARGS_VARIABLE_NAME = "optionalTypeArgs";
2379+
static const String _OPTIONAL_TYPE_ARGS_VARIABLE_NAME = "optionalTypeArgs";
23802380

23812381
/// The name of the top-level variable used to mark a function as running
23822382
/// a single test.
2383-
static String _IS_TEST_VARIABLE_NAME = "isTest";
2383+
static const String _IS_TEST_VARIABLE_NAME = "isTest";
23842384

23852385
/// The name of the top-level variable used to mark a function as running
23862386
/// a test group.
2387-
static String _IS_TEST_GROUP_VARIABLE_NAME = "isTestGroup";
2387+
static const String _IS_TEST_GROUP_VARIABLE_NAME = "isTestGroup";
23882388

23892389
/// The name of the class used to JS annotate an element.
2390-
static String _JS_CLASS_NAME = "JS";
2390+
static const String _JS_CLASS_NAME = "JS";
23912391

23922392
/// The name of `js` library, used to define JS annotations.
2393-
static String _JS_LIB_NAME = "js";
2393+
static const String _JS_LIB_NAME = "js";
23942394

23952395
/// The name of `meta` library, used to define analysis annotations.
2396-
static String _META_LIB_NAME = "meta";
2396+
static const String _META_LIB_NAME = "meta";
23972397

23982398
/// The name of the top-level variable used to mark a method as requiring
23992399
/// overriders to call super.
2400-
static String _MUST_CALL_SUPER_VARIABLE_NAME = "mustCallSuper";
2400+
static const String _MUST_CALL_SUPER_VARIABLE_NAME = "mustCallSuper";
24012401

24022402
/// The name of `angular.meta` library, used to define angular analysis
24032403
/// annotations.
2404-
static String _NG_META_LIB_NAME = "angular.meta";
2404+
static const String _NG_META_LIB_NAME = "angular.meta";
24052405

24062406
/// The name of the top-level variable used to mark a member as being nonVirtual.
2407-
static String _NON_VIRTUAL_VARIABLE_NAME = "nonVirtual";
2407+
static const String _NON_VIRTUAL_VARIABLE_NAME = "nonVirtual";
24082408

24092409
/// The name of the top-level variable used to mark a method as being expected
24102410
/// to override an inherited method.
2411-
static String _OVERRIDE_VARIABLE_NAME = "override";
2411+
static const String _OVERRIDE_VARIABLE_NAME = "override";
24122412

24132413
/// The name of the top-level variable used to mark a method as being
24142414
/// protected.
2415-
static String _PROTECTED_VARIABLE_NAME = "protected";
2415+
static const String _PROTECTED_VARIABLE_NAME = "protected";
24162416

24172417
/// The name of the top-level variable used to mark a class as implementing a
24182418
/// proxy object.
2419-
static String PROXY_VARIABLE_NAME = "proxy";
2419+
static const String PROXY_VARIABLE_NAME = "proxy";
24202420

24212421
/// The name of the class used to mark a parameter as being required.
2422-
static String _REQUIRED_CLASS_NAME = "Required";
2422+
static const String _REQUIRED_CLASS_NAME = "Required";
24232423

24242424
/// The name of the top-level variable used to mark a parameter as being
24252425
/// required.
2426-
static String _REQUIRED_VARIABLE_NAME = "required";
2426+
static const String _REQUIRED_VARIABLE_NAME = "required";
24272427

24282428
/// The name of the top-level variable used to mark a class as being sealed.
2429-
static String _SEALED_VARIABLE_NAME = "sealed";
2429+
static const String _SEALED_VARIABLE_NAME = "sealed";
24302430

24312431
/// The name of the top-level variable used to mark a method as being
24322432
/// visible for templates.
2433-
static String _VISIBLE_FOR_TEMPLATE_VARIABLE_NAME = "visibleForTemplate";
2433+
static const String _VISIBLE_FOR_TEMPLATE_VARIABLE_NAME =
2434+
"visibleForTemplate";
24342435

24352436
/// The name of the top-level variable used to mark a method as being
24362437
/// visible for testing.
2437-
static String _VISIBLE_FOR_TESTING_VARIABLE_NAME = "visibleForTesting";
2438+
static const String _VISIBLE_FOR_TESTING_VARIABLE_NAME = "visibleForTesting";
24382439

24392440
/// The element representing the field, variable, or constructor being used as
24402441
/// an annotation.
@@ -3196,7 +3197,7 @@ abstract class ElementImpl implements Element {
31963197
/// A concrete implementation of an [ElementLocation].
31973198
class ElementLocationImpl implements ElementLocation {
31983199
/// The character used to separate components in the encoded form.
3199-
static int _SEPARATOR_CHAR = 0x3B;
3200+
static const int _SEPARATOR_CHAR = 0x3B;
32003201

32013202
/// The path to the element whose location is represented by this object.
32023203
List<String> _components;

0 commit comments

Comments
 (0)