Skip to content

Commit

Permalink
Make private fields final where possible
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Dec 17, 2019
1 parent b1afe2d commit 2d332ee
Show file tree
Hide file tree
Showing 36 changed files with 196 additions and 275 deletions.
11 changes: 11 additions & 0 deletions pkg/analyzer/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ analyzer:
errors:
# Increase the severity of the unused_import hint.
unused_import: warning
# There are currently 140 violations in lib/.
always_declare_return_types: ignore
# There are currently 230 violations in lib/.
annotate_overrides: ignore
# There are currently 5500 violations in lib/. This just does not fit well
# with the analyzer team's style.
omit_local_variable_types: ignore
# There are currently 3360 violations in lib/.
prefer_single_quotes: ignore
# Ignoring "style" lint rules from pedantic for now. There are pre-existing
# violations that need to be cleaned up. Each one can be cleaned up and
# enabled according to the value provided.
# TODO(srawlins): At the time of writing, 2600 violations in lib/. The fix
# is mechanical, via `dartfmt --fix-doc-comments`, but not worth the churn
# today.
slash_for_doc_comments: ignore
# There are currently 1980 violations in lib/.
unnecessary_this: ignore

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/dart/analysis/declared_variables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
/// Clients may not extend, implement or mix-in this class.
class DeclaredVariables {
/// A table mapping the names of declared variables to their values.
Map<String, String> _declaredVariables = <String, String>{};
final Map<String, String> _declaredVariables = <String, String>{};

/// Initialize a newly created set of declared variables in which there are no
/// variables.
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/dart/ast/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import 'package:analyzer/dart/ast/ast.dart';
class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
/// A queue holding the nodes that have not yet been visited in the order in
/// which they ought to be visited.
Queue<AstNode> _queue = Queue<AstNode>();
final Queue<AstNode> _queue = Queue<AstNode>();

/// A visitor, used to visit the children of the current node, that will add
/// the nodes it visits to the [_queue].
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/instrumentation/log_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InstrumentationLogAdapter implements InstrumentationService {
static const String TAG_WATCH_EVENT = 'Watch';

/// A logger used to log instrumentation in string format.
InstrumentationLogger _instrumentationLogger;
final InstrumentationLogger _instrumentationLogger;

/// Initialize a newly created instrumentation service to communicate with the
/// given [_instrumentationLogger].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReferenceCollector {
/// The list of names that are referenced using an import prefix.
///
/// It is filled by [addImportPrefix] and shared across all nodes.
List<_ReferencedImportPrefixedNames> _importPrefixedReferences = [];
final List<_ReferencedImportPrefixedNames> _importPrefixedReferences = [];

/// The list of names that are referenced with `super`.
_NameSet _superReferences = _NameSet();
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/library_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LibraryContext {
/// The size of the linked data that is loaded by this context.
/// When it reaches [_maxLinkedDataInBytes] the whole context is thrown away.
/// We use it as an approximation for the heap size of elements.
int _linkedDataInBytes = 0;
final int _linkedDataInBytes = 0;

AnalysisContextImpl analysisContext;
LinkedElementFactory elementFactory;
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ class ChildEntities
with IterableMixin<SyntacticEntity>
implements Iterable<SyntacticEntity> {
/// The list of child entities to be iterated over.
List<SyntacticEntity> _entities = [];
final List<SyntacticEntity> _entities = [];

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

/// The URI referenced by this directive.
StringLiteralImpl _uri;
Expand Down
19 changes: 8 additions & 11 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2498,12 +2498,12 @@ class NodeLocator extends UnifyingAstVisitor<void> {
/**
* The start offset of the range used to identify the node.
*/
int _startOffset = 0;
final int _startOffset;

/**
* The end offset of the range used to identify the node.
*/
int _endOffset = 0;
final int _endOffset;

/**
* The element that was found that corresponds to the given source range, or
Expand Down Expand Up @@ -2601,15 +2601,11 @@ class NodeLocator extends UnifyingAstVisitor<void> {
* encompasses the specified range.
*/
class NodeLocator2 extends UnifyingAstVisitor<void> {
/**
* The inclusive start offset of the range used to identify the node.
*/
int _startOffset = 0;
/// The inclusive start offset of the range used to identify the node.
final int _startOffset;

/**
* The inclusive end offset of the range used to identify the node.
*/
int _endOffset = 0;
/// The inclusive end offset of the range used to identify the node.
final int _endOffset;

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

AstNode _immediateChild;

Map<String, SimpleIdentifier> _locals = HashMap<String, SimpleIdentifier>();
final Map<String, SimpleIdentifier> _locals =
HashMap<String, SimpleIdentifier>();

final int _position;

Expand Down
10 changes: 5 additions & 5 deletions pkg/analyzer/lib/src/dart/constant/evaluation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ import 'package:analyzer/src/task/api/model.dart';
/// constant instance creation expressions.
class ConstantEvaluationEngine {
/// Parameter to "fromEnvironment" methods that denotes the default value.
static String _DEFAULT_VALUE_PARAM = "defaultValue";
static const String _DEFAULT_VALUE_PARAM = "defaultValue";

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

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

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

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

/// The type provider used to access the known types.
Expand Down
49 changes: 25 additions & 24 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2353,88 +2353,89 @@ class DynamicElementImpl extends ElementImpl implements TypeDefiningElement {
class ElementAnnotationImpl implements ElementAnnotation {
/// The name of the top-level variable used to mark that a function always
/// throws, for dead code purposes.
static String _ALWAYS_THROWS_VARIABLE_NAME = "alwaysThrows";
static const String _ALWAYS_THROWS_VARIABLE_NAME = "alwaysThrows";

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

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

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

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

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

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

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

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

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

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

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

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

/// The name of `angular.meta` library, used to define angular analysis
/// annotations.
static String _NG_META_LIB_NAME = "angular.meta";
static const String _NG_META_LIB_NAME = "angular.meta";

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

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

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

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

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

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

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

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

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

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

/// The path to the element whose location is represented by this object.
List<String> _components;
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/resolver/exit_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExitDetector extends GeneralizingAstVisitor<bool> {
bool _enclosingBlockContainsContinue = false;

/// Add node when a labelled `break` is encountered.
Set<AstNode> _enclosingBlockBreaksLabel = <AstNode>{};
final Set<AstNode> _enclosingBlockBreaksLabel = <AstNode>{};

@override
bool visitArgumentList(ArgumentList node) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:analyzer/src/dart/element/type.dart';
/// nodes, have legacy types, and asserts that the legacy types are deep legacy
/// types.
class LegacyTypeAsserter extends GeneralizingAstVisitor {
Set<DartType> _visitedTypes = {};
final Set<DartType> _visitedTypes = {};

LegacyTypeAsserter({bool requireIsDebug = true}) {
if (requireIsDebug) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/resolver/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class LibraryImportScope extends Scope {
* A scope containing all of the names defined in a given library.
*/
class LibraryScope extends EnclosedScope {
List<ExtensionElement> _extensions = <ExtensionElement>[];
final List<ExtensionElement> _extensions = <ExtensionElement>[];

/**
* Initialize a newly created scope representing the names defined in the
Expand Down
Loading

0 comments on commit 2d332ee

Please sign in to comment.