Skip to content

Commit c1f0b35

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Remove unnecessary uses of new in analyzer_cli
Change-Id: Ib6d0123ae7c49814275b5829a1fd2676122dc540 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128842 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent 991f529 commit c1f0b35

22 files changed

+255
-264
lines changed

pkg/analyzer_cli/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ linter:
5151
- type_init_formals
5252
- unawaited_futures
5353
#- unnecessary_const # 2
54-
#- unnecessary_new # 258
54+
- unnecessary_new
5555
- unnecessary_null_in_if_null_operators
5656
#- unnecessary_this # 5
5757
#- unrelated_type_equality_checks # 2

pkg/analyzer_cli/bin/analyzer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:analyzer_cli/starter.dart';
1212
/// [sendPort] may be passed in when started in an isolate. If provided, it is
1313
/// used for bazel worker communication instead of stdin/stdout.
1414
main(List<String> args, [SendPort sendPort]) async {
15-
CommandLineStarter starter = new CommandLineStarter();
15+
CommandLineStarter starter = CommandLineStarter();
1616

1717
// Wait for the starter to complete.
1818
await starter.start(args, sendPort: sendPort);

pkg/analyzer_cli/lib/src/analyzer_impl.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import 'package:analyzer_cli/src/error_severity.dart';
2121
import 'package:analyzer_cli/src/options.dart';
2222
import 'package:path/path.dart' as path;
2323

24-
int get currentTimeMillis => new DateTime.now().millisecondsSinceEpoch;
24+
int get currentTimeMillis => DateTime.now().millisecondsSinceEpoch;
2525

2626
/// Analyzes single library [File].
2727
class AnalyzerImpl {
2828
static final PerformanceTag _prepareErrorsTag =
29-
new PerformanceTag("AnalyzerImpl.prepareErrors");
29+
PerformanceTag("AnalyzerImpl.prepareErrors");
3030
static final PerformanceTag _resolveLibraryTag =
31-
new PerformanceTag("AnalyzerImpl._resolveLibrary");
31+
PerformanceTag("AnalyzerImpl._resolveLibrary");
3232

3333
final CommandLineOptions options;
3434
final int startTime;
@@ -43,7 +43,7 @@ class AnalyzerImpl {
4343
final FileState libraryFile;
4444

4545
/// All files references by the analyzed library.
46-
final Set<String> files = new Set<String>();
46+
final Set<String> files = Set<String>();
4747

4848
/// All [AnalysisErrorInfo]s in the analyzed library.
4949
final List<ErrorsResult> errorsResults = [];
@@ -136,8 +136,8 @@ class AnalyzerImpl {
136136

137137
/// Fills [files].
138138
void prepareSources(LibraryElement library) {
139-
var units = new Set<CompilationUnitElement>();
140-
var libraries = new Set<LibraryElement>();
139+
var units = Set<CompilationUnitElement>();
140+
var libraries = Set<LibraryElement>();
141141
addLibrarySources(library, libraries, units);
142142
}
143143

pkg/analyzer_cli/lib/src/batch_mode.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class BatchRunner {
2323
/// use in unit testing.
2424
void runAsBatch(List<String> sharedArgs, BatchRunnerHandler handler) {
2525
outSink.writeln('>>> BATCH START');
26-
Stopwatch stopwatch = new Stopwatch();
26+
Stopwatch stopwatch = Stopwatch();
2727
stopwatch.start();
2828
int testsFailed = 0;
2929
int totalTests = 0;
3030
ErrorSeverity batchResult = ErrorSeverity.NONE;
3131
// Read line from stdin.
3232
Stream<String> cmdLine =
33-
stdin.transform(utf8.decoder).transform(new LineSplitter());
33+
stdin.transform(utf8.decoder).transform(LineSplitter());
3434
cmdLine.listen((String line) async {
3535
// TODO(brianwilkerson) Determine whether this await is necessary.
3636
await null;
@@ -42,8 +42,8 @@ class BatchRunner {
4242
exitCode = batchResult.ordinal;
4343
}
4444
// Prepare arguments.
45-
var lineArgs = line.split(new RegExp('\\s+'));
46-
var args = new List<String>();
45+
var lineArgs = line.split(RegExp('\\s+'));
46+
var args = List<String>();
4747
args.addAll(sharedArgs);
4848
args.addAll(lineArgs);
4949
args.remove('-b');

pkg/analyzer_cli/lib/src/build_mode.dart

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,33 @@ import 'package:convert/convert.dart';
4949
*/
5050
class AnalyzerWorkerLoop extends AsyncWorkerLoop {
5151
final ResourceProvider resourceProvider;
52-
final PerformanceLog logger = new PerformanceLog(null);
52+
final PerformanceLog logger = PerformanceLog(null);
5353
final String dartSdkPath;
5454
WorkerPackageBundleCache packageBundleCache;
5555

56-
final StringBuffer errorBuffer = new StringBuffer();
57-
final StringBuffer outBuffer = new StringBuffer();
56+
final StringBuffer errorBuffer = StringBuffer();
57+
final StringBuffer outBuffer = StringBuffer();
5858

5959
AnalyzerWorkerLoop(this.resourceProvider, AsyncWorkerConnection connection,
6060
{this.dartSdkPath})
6161
: super(connection: connection) {
62-
packageBundleCache = new WorkerPackageBundleCache(
63-
resourceProvider, logger, 256 * 1024 * 1024);
62+
packageBundleCache =
63+
WorkerPackageBundleCache(resourceProvider, logger, 256 * 1024 * 1024);
6464
}
6565

6666
factory AnalyzerWorkerLoop.sendPort(
6767
ResourceProvider resourceProvider, SendPort sendPort,
6868
{String dartSdkPath}) {
69-
AsyncWorkerConnection connection =
70-
new SendPortAsyncWorkerConnection(sendPort);
71-
return new AnalyzerWorkerLoop(resourceProvider, connection,
69+
AsyncWorkerConnection connection = SendPortAsyncWorkerConnection(sendPort);
70+
return AnalyzerWorkerLoop(resourceProvider, connection,
7271
dartSdkPath: dartSdkPath);
7372
}
7473

7574
factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider,
7675
{io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) {
77-
AsyncWorkerConnection connection = new StdAsyncWorkerConnection(
76+
AsyncWorkerConnection connection = StdAsyncWorkerConnection(
7877
inputStream: stdinStream, outputStream: stdoutStream);
79-
return new AnalyzerWorkerLoop(resourceProvider, connection,
78+
return AnalyzerWorkerLoop(resourceProvider, connection,
8079
dartSdkPath: dartSdkPath);
8180
}
8281

@@ -86,14 +85,10 @@ class AnalyzerWorkerLoop extends AsyncWorkerLoop {
8685
Future<void> analyze(
8786
CommandLineOptions options, Map<String, WorkerInput> inputs) async {
8887
var packageBundleProvider =
89-
new WorkerPackageBundleProvider(packageBundleCache, inputs);
90-
var buildMode = new BuildMode(
91-
resourceProvider,
92-
options,
93-
new AnalysisStats(),
94-
new ContextCache(resourceProvider, options, Driver.verbosePrint),
95-
logger: logger,
96-
packageBundleProvider: packageBundleProvider);
88+
WorkerPackageBundleProvider(packageBundleCache, inputs);
89+
var buildMode = BuildMode(resourceProvider, options, AnalysisStats(),
90+
ContextCache(resourceProvider, options, Driver.verbosePrint),
91+
logger: logger, packageBundleProvider: packageBundleProvider);
9792
await buildMode.analyze();
9893
AnalysisEngine.instance.clearCaches();
9994
}
@@ -110,7 +105,7 @@ class AnalyzerWorkerLoop extends AsyncWorkerLoop {
110105
// Prepare inputs with their digests.
111106
Map<String, WorkerInput> inputs = {};
112107
for (var input in request.inputs) {
113-
inputs[input.path] = new WorkerInput(input.path, input.digest);
108+
inputs[input.path] = WorkerInput(input.path, input.digest);
114109
}
115110

116111
// Add in the dart-sdk argument if `dartSdkPath` is not null,
@@ -124,19 +119,19 @@ class AnalyzerWorkerLoop extends AsyncWorkerLoop {
124119
// Prepare options.
125120
CommandLineOptions options =
126121
CommandLineOptions.parse(arguments, printAndFail: (String msg) {
127-
throw new ArgumentError(msg);
122+
throw ArgumentError(msg);
128123
});
129124

130125
// Analyze and respond.
131126
await analyze(options, inputs);
132127
String msg = _getErrorOutputBuffersText();
133-
return new WorkResponse()
128+
return WorkResponse()
134129
..exitCode = EXIT_CODE_OK
135130
..output = msg;
136131
} catch (e, st) {
137132
String msg = _getErrorOutputBuffersText();
138133
msg += '$e\n$st';
139-
return new WorkResponse()
134+
return WorkResponse()
140135
..exitCode = EXIT_CODE_ERROR
141136
..output = msg;
142137
}
@@ -151,7 +146,7 @@ class AnalyzerWorkerLoop extends AsyncWorkerLoop {
151146
errorSink = errorBuffer;
152147
outSink = outBuffer;
153148
exitHandler = (int exitCode) {
154-
throw new StateError('Exit called: $exitCode');
149+
throw StateError('Exit called: $exitCode');
155150
};
156151
await super.run();
157152
}
@@ -200,9 +195,9 @@ class BuildMode with HasContextMixin {
200195

201196
BuildMode(this.resourceProvider, this.options, this.stats, this.contextCache,
202197
{PerformanceLog logger, PackageBundleProvider packageBundleProvider})
203-
: logger = logger ?? new PerformanceLog(null),
198+
: logger = logger ?? PerformanceLog(null),
204199
packageBundleProvider = packageBundleProvider ??
205-
new DirectPackageBundleProvider(resourceProvider),
200+
DirectPackageBundleProvider(resourceProvider),
206201
dependencyTracker = options.summaryDepsOutput != null
207202
? DependencyTracker(options.summaryDepsOutput)
208203
: null;
@@ -256,12 +251,12 @@ class BuildMode with HasContextMixin {
256251
io.exitCode = ErrorSeverity.ERROR.ordinal;
257252
return ErrorSeverity.ERROR;
258253
}
259-
Source source = new FileSource(file, uri);
254+
Source source = FileSource(file, uri);
260255
explicitSources.add(source);
261256
}
262257

263258
// Write summary.
264-
assembler = new PackageBundleAssembler();
259+
assembler = PackageBundleAssembler();
265260
if (_shouldOutputSummary) {
266261
await logger.runAsync('Build and write output summary', () async {
267262
// Prepare all unlinked units.
@@ -277,13 +272,13 @@ class BuildMode with HasContextMixin {
277272
// Write the whole package bundle.
278273
PackageBundleBuilder bundle = assembler.assemble();
279274
if (options.buildSummaryOutput != null) {
280-
io.File file = new io.File(options.buildSummaryOutput);
275+
io.File file = io.File(options.buildSummaryOutput);
281276
file.writeAsBytesSync(bundle.toBuffer(),
282277
mode: io.FileMode.writeOnly);
283278
}
284279
if (options.buildSummaryOutputSemantic != null) {
285280
bundle.flushInformative();
286-
io.File file = new io.File(options.buildSummaryOutputSemantic);
281+
io.File file = io.File(options.buildSummaryOutputSemantic);
287282
file.writeAsBytesSync(bundle.toBuffer(),
288283
mode: io.FileMode.writeOnly);
289284
}
@@ -305,7 +300,7 @@ class BuildMode with HasContextMixin {
305300
}
306301

307302
if (dependencyTracker != null) {
308-
io.File file = new io.File(dependencyTracker.outputPath);
303+
io.File file = io.File(dependencyTracker.outputPath);
309304
file.writeAsStringSync(dependencyTracker.dependencies.join('\n'));
310305
}
311306

@@ -399,7 +394,7 @@ class BuildMode with HasContextMixin {
399394

400395
void _createAnalysisDriver() {
401396
// Read the summaries.
402-
summaryDataStore = new SummaryDataStore(<String>[]);
397+
summaryDataStore = SummaryDataStore(<String>[]);
403398

404399
// Adds a bundle at `path` to `summaryDataStore`.
405400
PackageBundle addBundle(String path) {
@@ -422,11 +417,11 @@ class BuildMode with HasContextMixin {
422417
PackageBundle sdkBundle;
423418
if (options.dartSdkSummaryPath != null) {
424419
SummaryBasedDartSdk summarySdk =
425-
new SummaryBasedDartSdk(options.dartSdkSummaryPath, true);
420+
SummaryBasedDartSdk(options.dartSdkSummaryPath, true);
426421
sdk = summarySdk;
427422
sdkBundle = summarySdk.bundle;
428423
} else {
429-
FolderBasedDartSdk dartSdk = new FolderBasedDartSdk(
424+
FolderBasedDartSdk dartSdk = FolderBasedDartSdk(
430425
resourceProvider, resourceProvider.getFolder(options.dartSdkPath));
431426
dartSdk.analysisOptions =
432427
createAnalysisOptionsForCommandLineOptions(options, rootPath);
@@ -439,30 +434,30 @@ class BuildMode with HasContextMixin {
439434
summaryDataStore.addBundle(null, sdkBundle);
440435
});
441436

442-
sourceFactory = new SourceFactory(<UriResolver>[
443-
new DartUriResolver(sdk),
444-
new TrackingInSummaryUriResolver(
445-
new InSummaryUriResolver(resourceProvider, summaryDataStore),
437+
sourceFactory = SourceFactory(<UriResolver>[
438+
DartUriResolver(sdk),
439+
TrackingInSummaryUriResolver(
440+
InSummaryUriResolver(resourceProvider, summaryDataStore),
446441
dependencyTracker),
447-
new ExplicitSourceResolver(uriToFileMap)
442+
ExplicitSourceResolver(uriToFileMap)
448443
]);
449444

450445
analysisOptions =
451446
createAnalysisOptionsForCommandLineOptions(options, rootPath);
452447

453-
AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger);
454-
analysisDriver = new AnalysisDriver(
448+
AnalysisDriverScheduler scheduler = AnalysisDriverScheduler(logger);
449+
analysisDriver = AnalysisDriver(
455450
scheduler,
456451
logger,
457452
resourceProvider,
458-
new MemoryByteStore(),
459-
new FileContentOverlay(),
453+
MemoryByteStore(),
454+
FileContentOverlay(),
460455
null,
461456
sourceFactory,
462457
analysisOptions,
463458
externalSummaries: summaryDataStore);
464459

465-
declaredVariables = new DeclaredVariables.fromMap(options.definedVariables);
460+
declaredVariables = DeclaredVariables.fromMap(options.definedVariables);
466461
analysisDriver.declaredVariables = declaredVariables;
467462

468463
_createLinkedElementFactory();
@@ -537,13 +532,13 @@ class BuildMode with HasContextMixin {
537532
*/
538533
Future<void> _printErrors({String outputPath}) async {
539534
await logger.runAsync('Compute and print analysis errors', () async {
540-
StringBuffer buffer = new StringBuffer();
535+
StringBuffer buffer = StringBuffer();
541536
var severityProcessor = (AnalysisError error) =>
542537
determineProcessedSeverity(error, options, analysisOptions);
543538
ErrorFormatter formatter = options.machineFormat
544-
? new MachineErrorFormatter(buffer, options, stats,
539+
? MachineErrorFormatter(buffer, options, stats,
545540
severityProcessor: severityProcessor)
546-
: new HumanErrorFormatter(buffer, options, stats,
541+
: HumanErrorFormatter(buffer, options, stats,
547542
severityProcessor: severityProcessor);
548543
for (Source source in explicitSources) {
549544
var result = await analysisDriver.getErrors(source.fullName);
@@ -557,7 +552,7 @@ class BuildMode with HasContextMixin {
557552
StringSink sink = options.machineFormat ? errorSink : outSink;
558553
sink.write(buffer);
559554
} else {
560-
new io.File(outputPath).writeAsStringSync(buffer.toString());
555+
io.File(outputPath).writeAsStringSync(buffer.toString());
561556
}
562557
});
563558
}
@@ -589,8 +584,8 @@ class DirectPackageBundleProvider implements PackageBundleProvider {
589584

590585
@override
591586
PackageBundle get(String path) {
592-
var bytes = new io.File(path).readAsBytesSync();
593-
return new PackageBundle.fromBuffer(bytes);
587+
var bytes = io.File(path).readAsBytesSync();
588+
return PackageBundle.fromBuffer(bytes);
594589
}
595590
}
596591

@@ -616,7 +611,7 @@ class ExplicitSourceResolver extends UriResolver {
616611
if (file == null) {
617612
return null;
618613
} else {
619-
return new FileSource(file, actualUri);
614+
return FileSource(file, actualUri);
620615
}
621616
}
622617

@@ -723,7 +718,7 @@ class WorkerPackageBundleCache {
723718
final Cache<WorkerInput, WorkerPackageBundle> _cache;
724719

725720
WorkerPackageBundleCache(this.resourceProvider, this.logger, int maxSizeBytes)
726-
: _cache = new Cache<WorkerInput, WorkerPackageBundle>(
721+
: _cache = Cache<WorkerInput, WorkerPackageBundle>(
727722
maxSizeBytes, (value) => value.size);
728723

729724
/**
@@ -738,14 +733,14 @@ class WorkerPackageBundleCache {
738733
if (input == null) {
739734
logger.writeln('Read $path outside of the inputs.');
740735
var bytes = resourceProvider.getFile(path).readAsBytesSync();
741-
return new PackageBundle.fromBuffer(bytes);
736+
return PackageBundle.fromBuffer(bytes);
742737
}
743738

744739
return _cache.get(input, () {
745740
logger.writeln('Read $input.');
746741
var bytes = resourceProvider.getFile(path).readAsBytesSync();
747-
var bundle = new PackageBundle.fromBuffer(bytes);
748-
return new WorkerPackageBundle(bytes, bundle);
742+
var bundle = PackageBundle.fromBuffer(bytes);
743+
return WorkerPackageBundle(bytes, bundle);
749744
}).bundle;
750745
}
751746
}

pkg/analyzer_cli/lib/src/context_cache.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class ContextCache {
2828
ContextCacheEntry forSource(String path) {
2929
path = _normalizeSourcePath(path);
3030
return _byDirectory.putIfAbsent(path, () {
31-
final builder = new ContextBuilder(resourceProvider, null, null,
31+
final builder = ContextBuilder(resourceProvider, null, null,
3232
options: clOptions.contextBuilderOptions);
33-
return new ContextCacheEntry(builder, path, clOptions, verbosePrint);
33+
return ContextCacheEntry(builder, path, clOptions, verbosePrint);
3434
});
3535
}
3636

0 commit comments

Comments
 (0)