Skip to content

Commit

Permalink
Switch on null-aware operators by default in analyzer.
Browse files Browse the repository at this point in the history
Patches to update analyzer_cli and analysis_server will follow once a
new version of analyzer has been published.

BUG=dartbug.com/23793
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org//1239513005 .
  • Loading branch information
stereotype441 committed Jul 13, 2015
1 parent 2f6ebaa commit 4b83219
Show file tree
Hide file tree
Showing 26 changed files with 12 additions and 139 deletions.
3 changes: 0 additions & 3 deletions pkg/analyzer/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
(this._options.hint && !options.hint) ||
(this._options.lint && !options.lint) ||
this._options.preserveComments != options.preserveComments ||
this._options.enableNullAwareOperators !=
options.enableNullAwareOperators ||
this._options.enableStrictCallChecks != options.enableStrictCallChecks;
int cacheSize = options.cacheSize;
if (this._options.cacheSize != cacheSize) {
Expand All @@ -251,7 +249,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.generateImplicitErrors = options.generateImplicitErrors;
this._options.generateSdkErrors = options.generateSdkErrors;
this._options.dart2jsHint = options.dart2jsHint;
this._options.enableNullAwareOperators = options.enableNullAwareOperators;
this._options.enableStrictCallChecks = options.enableStrictCallChecks;
this._options.hint = options.hint;
this._options.incremental = options.incremental;
Expand Down
22 changes: 10 additions & 12 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.dart2jsHint != options.dart2jsHint ||
(this._options.hint && !options.hint) ||
this._options.preserveComments != options.preserveComments ||
this._options.enableNullAwareOperators !=
options.enableNullAwareOperators ||
this._options.enableStrictCallChecks != options.enableStrictCallChecks;
int cacheSize = options.cacheSize;
if (this._options.cacheSize != cacheSize) {
Expand All @@ -1129,7 +1127,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.generateImplicitErrors = options.generateImplicitErrors;
this._options.generateSdkErrors = options.generateSdkErrors;
this._options.dart2jsHint = options.dart2jsHint;
this._options.enableNullAwareOperators = options.enableNullAwareOperators;
this._options.enableStrictCallChecks = options.enableStrictCallChecks;
this._options.hint = options.hint;
this._options.incremental = options.incremental;
Expand Down Expand Up @@ -6102,6 +6099,7 @@ abstract class AnalysisOptions {
/**
* Return `true` to enable null-aware operators (DEP 9).
*/
@deprecated // Always true
bool get enableNullAwareOperators;

/**
Expand Down Expand Up @@ -6202,11 +6200,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
*/
bool enableGenericMethods = false;

/**
* A flag indicating whether null-aware operators should be parsed (DEP 9).
*/
bool enableNullAwareOperators = false;

/**
* A flag indicating whether analysis is to strictly follow the specification
* when generating warnings on "call" methods (fixes dartbug.com/21938).
Expand Down Expand Up @@ -6273,7 +6266,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate;
cacheSize = options.cacheSize;
dart2jsHint = options.dart2jsHint;
enableNullAwareOperators = options.enableNullAwareOperators;
enableStrictCallChecks = options.enableStrictCallChecks;
generateImplicitErrors = options.generateImplicitErrors;
generateSdkErrors = options.generateSdkErrors;
Expand All @@ -6293,7 +6285,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate;
cacheSize = options.cacheSize;
dart2jsHint = options.dart2jsHint;
enableNullAwareOperators = options.enableNullAwareOperators;
enableStrictCallChecks = options.enableStrictCallChecks;
generateImplicitErrors = options.generateImplicitErrors;
generateSdkErrors = options.generateSdkErrors;
Expand Down Expand Up @@ -6362,6 +6353,15 @@ class AnalysisOptionsImpl implements AnalysisOptions {
// Enum support cannot be disabled
}

@deprecated
@override
bool get enableNullAwareOperators => true;

@deprecated
void set enableNullAwareOperators(bool enable) {
// Null-aware operator support cannot be disabled
}

/**
* Predicate used for [analyzeFunctionBodiesPredicate] when
* [analyzeFunctionBodies] is set to `true`.
Expand Down Expand Up @@ -10996,8 +10996,6 @@ class ScanDartTask extends AnalysisTask {
Scanner scanner = new Scanner(
source, new CharSequenceReader(_content), errorListener);
scanner.preserveComments = context.analysisOptions.preserveComments;
scanner.enableNullAwareOperators =
context.analysisOptions.enableNullAwareOperators;
_tokenStream = scanner.tokenize();
_lineInfo = new LineInfo(scanner.lineStarts);
_errors = errorListener.getErrorsForSource(source);
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/generated/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ class HtmlParser extends XmlParser {
LineInfo_Location location = _lineInfo.getLocation(contentOffset);
sc.Scanner scanner = new sc.Scanner(source,
new sc.SubSequenceReader(contents, contentOffset), _errorListener);
scanner.enableNullAwareOperators = _options.enableNullAwareOperators;
scanner.setSourceStart(location.lineNumber, location.columnNumber);
sc.Token firstToken = scanner.tokenize();
Parser parser = new Parser(source, _errorListener);
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/generated/incremental_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,6 @@ class PoorMansIncrementalResolver {
RecordingErrorListener errorListener = new RecordingErrorListener();
CharSequenceReader reader = new CharSequenceReader(code);
Scanner scanner = new Scanner(_unitSource, reader, errorListener);
scanner.enableNullAwareOperators = _options.enableNullAwareOperators;
Token token = scanner.tokenize();
_newScanErrors = errorListener.errors;
return token;
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/generated/incremental_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ class IncrementalScanner {
Token _scanRange(int start, int end) {
Scanner scanner = new Scanner(
source, new CharacterRangeReader(reader, start, end), errorListener);
scanner.enableNullAwareOperators = _options.enableNullAwareOperators;
return scanner.tokenize();
}

Expand Down
10 changes: 2 additions & 8 deletions pkg/analyzer/lib/src/generated/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,6 @@ class Scanner {
*/
bool _hasUnmatchedGroups = false;

/**
* A flag indicating whether null-aware operators ('?.', '??', and '??=')
* should be tokenized.
*/
bool enableNullAwareOperators = false;

/**
* Initialize a newly created scanner to scan characters from the given
* [source]. The given character [_reader] will be used to read the characters
Expand Down Expand Up @@ -1664,11 +1658,11 @@ class Scanner {
int _tokenizeQuestion() {
// ? ?. ?? ??=
int next = _reader.advance();
if (enableNullAwareOperators && next == 0x2E) {
if (next == 0x2E) {
// '.'
_appendTokenOfType(TokenType.QUESTION_PERIOD);
return _reader.advance();
} else if (enableNullAwareOperators && next == 0x3F) {
} else if (next == 0x3F) {
// '?'
next = _reader.advance();
if (next == 0x3D) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/analyzer/lib/src/task/dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3115,8 +3115,6 @@ class ScanDartTask extends SourceBasedAnalysisTask {
errorListener);
scanner.setSourceStart(fragment.line, fragment.column);
scanner.preserveComments = context.analysisOptions.preserveComments;
scanner.enableNullAwareOperators =
context.analysisOptions.enableNullAwareOperators;

outputs[TOKEN_STREAM] = scanner.tokenize();
outputs[LINE_INFO] = new LineInfo(scanner.lineStarts);
Expand All @@ -3127,8 +3125,6 @@ class ScanDartTask extends SourceBasedAnalysisTask {
Scanner scanner =
new Scanner(source, new CharSequenceReader(content), errorListener);
scanner.preserveComments = context.analysisOptions.preserveComments;
scanner.enableNullAwareOperators =
context.analysisOptions.enableNullAwareOperators;

outputs[TOKEN_STREAM] = scanner.tokenize();
outputs[LINE_INFO] = new LineInfo(scanner.lineStarts);
Expand Down
21 changes: 0 additions & 21 deletions pkg/analyzer/test/generated/compile_time_error_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4757,9 +4757,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_call() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
g() {}
Expand All @@ -4777,9 +4774,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_call_loadLibrary() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
''');
Expand All @@ -4796,9 +4790,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_get() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
var x;
Expand All @@ -4816,9 +4807,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_get_loadLibrary() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
''');
Expand All @@ -4835,9 +4823,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_set() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
var x;
Expand All @@ -4855,9 +4840,6 @@ f() {
}

void test_prefix_conditionalPropertyAccess_set_loadLibrary() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
''');
Expand Down Expand Up @@ -4988,9 +4970,6 @@ f() {
}

void test_prefixNotFollowedByDot_conditionalMethodInvocation() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
addNamedSource('/lib.dart', '''
library lib;
g() {}
Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer/test/generated/engine_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,6 @@ class AnalysisOptionsImplTest extends EngineTestCase {
options.analyzeFunctionBodies = booleanValue;
options.cacheSize = i;
options.dart2jsHint = booleanValue;
options.enableNullAwareOperators = booleanValue;
options.enableStrictCallChecks = booleanValue;
options.generateImplicitErrors = booleanValue;
options.generateSdkErrors = booleanValue;
Expand All @@ -2252,7 +2251,6 @@ class AnalysisOptionsImplTest extends EngineTestCase {
expect(copy.analyzeFunctionBodies, options.analyzeFunctionBodies);
expect(copy.cacheSize, options.cacheSize);
expect(copy.dart2jsHint, options.dart2jsHint);
expect(copy.enableNullAwareOperators, options.enableNullAwareOperators);
expect(copy.enableStrictCallChecks, options.enableStrictCallChecks);
expect(copy.generateImplicitErrors, options.generateImplicitErrors);
expect(copy.generateSdkErrors, options.generateSdkErrors);
Expand Down
12 changes: 0 additions & 12 deletions pkg/analyzer/test/generated/non_error_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2372,9 +2372,6 @@ f([String x = '0']) {
}

void test_invalidAssignment_ifNullAssignment_compatibleType() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
Source source = addSource('''
void f(int i) {
num n;
Expand All @@ -2387,9 +2384,6 @@ void f(int i) {
}

void test_invalidAssignment_ifNullAssignment_sameType() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
Source source = addSource('''
void f(int i) {
int j;
Expand Down Expand Up @@ -5011,9 +5005,6 @@ class Bar extends Foo {
void test_undefinedGetter_typeLiteral_conditionalAccess() {
// When applied to a type literal, the conditional access operator '?.' can
// be used to access instance getters of Type.
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
Source source = addSource('''
class A {}
f() => A?.hashCode;
Expand Down Expand Up @@ -5101,9 +5092,6 @@ main() {
void test_undefinedMethod_typeLiteral_conditionalAccess() {
// When applied to a type literal, the conditional access operator '?.' can
// be used to access instance methods of Type.
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableNullAwareOperators = true;
resetWithOptions(options);
Source source = addSource('''
class A {}
f() => A?.toString();
Expand Down
Loading

0 comments on commit 4b83219

Please sign in to comment.