Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2933753002: Run the sorter to reduce code churn (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 27 matching lines...) Expand all
38 import 'package:front_end/src/incremental/byte_store.dart'; 38 import 'package:front_end/src/incremental/byte_store.dart';
39 import 'package:meta/meta.dart'; 39 import 'package:meta/meta.dart';
40 40
41 /** 41 /**
42 * [FileContentOverlay] is used to temporary override content of files. 42 * [FileContentOverlay] is used to temporary override content of files.
43 */ 43 */
44 class FileContentOverlay { 44 class FileContentOverlay {
45 final _map = <String, String>{}; 45 final _map = <String, String>{};
46 46
47 /** 47 /**
48 * Return the paths currently being overridden.
49 */
50 Iterable<String> get paths => _map.keys;
51
52 /**
48 * Return the content of the file with the given [path], or `null` the 53 * Return the content of the file with the given [path], or `null` the
49 * overlay does not override the content of the file. 54 * overlay does not override the content of the file.
50 * 55 *
51 * The [path] must be absolute and normalized. 56 * The [path] must be absolute and normalized.
52 */ 57 */
53 String operator [](String path) => _map[path]; 58 String operator [](String path) => _map[path];
54 59
55 /** 60 /**
56 * Return the new [content] of the file with the given [path]. 61 * Return the new [content] of the file with the given [path].
57 * 62 *
58 * The [path] must be absolute and normalized. 63 * The [path] must be absolute and normalized.
59 */ 64 */
60 void operator []=(String path, String content) { 65 void operator []=(String path, String content) {
61 if (content == null) { 66 if (content == null) {
62 _map.remove(path); 67 _map.remove(path);
63 } else { 68 } else {
64 _map[path] = content; 69 _map[path] = content;
65 } 70 }
66 } 71 }
67
68 /**
69 * Return the paths currently being overridden.
70 */
71 Iterable<String> get paths => _map.keys;
72 } 72 }
73 73
74 /** 74 /**
75 * Information about a file being analyzed, explicitly or implicitly. 75 * Information about a file being analyzed, explicitly or implicitly.
76 * 76 *
77 * It provides a consistent view on its properties. 77 * It provides a consistent view on its properties.
78 * 78 *
79 * The properties are not guaranteed to represent the most recent state 79 * The properties are not guaranteed to represent the most recent state
80 * of the file system. To update the file to the most recent state, [refresh] 80 * of the file system. To update the file to the most recent state, [refresh]
81 * should be called. 81 * should be called.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 /** 380 /**
381 * Return a new parsed unresolved [CompilationUnit]. 381 * Return a new parsed unresolved [CompilationUnit].
382 */ 382 */
383 CompilationUnit parse(AnalysisErrorListener errorListener) { 383 CompilationUnit parse(AnalysisErrorListener errorListener) {
384 return PerformanceStatistics.parse.makeCurrentWhile(() { 384 return PerformanceStatistics.parse.makeCurrentWhile(() {
385 return _parse(errorListener); 385 return _parse(errorListener);
386 }); 386 });
387 } 387 }
388 388
389 CompilationUnit _parse(AnalysisErrorListener errorListener) {
390 AnalysisOptions analysisOptions = _fsState._analysisOptions;
391
392 if (USE_FASTA_PARSER) {
393 try {
394 fasta.ScannerResult scanResult =
395 PerformanceStatistics.scan.makeCurrentWhile(() {
396 return fasta.scan(
397 _contentBytes,
398 includeComments: true,
399 scanGenericMethodComments: analysisOptions.strongMode,
400 );
401 });
402
403 var astBuilder = new fasta.AstBuilder(
404 new ErrorReporter(errorListener, source),
405 null,
406 null,
407 new _FastaElementStoreProxy(),
408 new fasta.Scope.top(isModifiable: true),
409 true,
410 uri);
411 astBuilder.parseGenericMethodComments = analysisOptions.strongMode;
412
413 var parser = new fasta.Parser(astBuilder);
414 astBuilder.parser = parser;
415 parser.parseUnit(scanResult.tokens);
416 var unit = astBuilder.pop() as CompilationUnit;
417
418 LineInfo lineInfo = new LineInfo(scanResult.lineStarts);
419 unit.lineInfo = lineInfo;
420 return unit;
421 } catch (e, st) {
422 print(e);
423 print(st);
424 rethrow;
425 }
426 } else {
427 CharSequenceReader reader = new CharSequenceReader(content);
428 Scanner scanner = new Scanner(source, reader, errorListener);
429 scanner.scanGenericMethodComments = analysisOptions.strongMode;
430 Token token = PerformanceStatistics.scan.makeCurrentWhile(() {
431 return scanner.tokenize();
432 });
433 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
434
435 Parser parser = new Parser(source, errorListener);
436 parser.enableAssertInitializer = analysisOptions.enableAssertInitializer;
437 parser.parseGenericMethodComments = analysisOptions.strongMode;
438 CompilationUnit unit = parser.parseCompilationUnit(token);
439 unit.lineInfo = lineInfo;
440 return unit;
441 }
442 }
443
444 /** 389 /**
445 * Read the file content and ensure that all of the file properties are 390 * Read the file content and ensure that all of the file properties are
446 * consistent with the read content, including API signature. 391 * consistent with the read content, including API signature.
447 * 392 *
448 * Return `true` if the API signature changed since the last refresh. 393 * Return `true` if the API signature changed since the last refresh.
449 */ 394 */
450 bool refresh() { 395 bool refresh() {
451 // Read the content. 396 // Read the content.
452 try { 397 try {
453 _content = _fsState._contentOverlay[path]; 398 _content = _fsState._contentOverlay[path];
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 Uri absoluteUri; 550 Uri absoluteUri;
606 try { 551 try {
607 absoluteUri = resolveRelativeUri(uri, Uri.parse(relativeUri)); 552 absoluteUri = resolveRelativeUri(uri, Uri.parse(relativeUri));
608 } on FormatException { 553 } on FormatException {
609 return _fsState.unresolvedFile; 554 return _fsState.unresolvedFile;
610 } 555 }
611 556
612 return _fsState.getFileForUri(absoluteUri); 557 return _fsState.getFileForUri(absoluteUri);
613 } 558 }
614 559
560 CompilationUnit _parse(AnalysisErrorListener errorListener) {
561 AnalysisOptions analysisOptions = _fsState._analysisOptions;
562
563 if (USE_FASTA_PARSER) {
564 try {
565 fasta.ScannerResult scanResult =
566 PerformanceStatistics.scan.makeCurrentWhile(() {
567 return fasta.scan(
568 _contentBytes,
569 includeComments: true,
570 scanGenericMethodComments: analysisOptions.strongMode,
571 );
572 });
573
574 var astBuilder = new fasta.AstBuilder(
575 new ErrorReporter(errorListener, source),
576 null,
577 null,
578 new _FastaElementStoreProxy(),
579 new fasta.Scope.top(isModifiable: true),
580 true,
581 uri);
582 astBuilder.parseGenericMethodComments = analysisOptions.strongMode;
583
584 var parser = new fasta.Parser(astBuilder);
585 astBuilder.parser = parser;
586 parser.parseUnit(scanResult.tokens);
587 var unit = astBuilder.pop() as CompilationUnit;
588
589 LineInfo lineInfo = new LineInfo(scanResult.lineStarts);
590 unit.lineInfo = lineInfo;
591 return unit;
592 } catch (e, st) {
593 print(e);
594 print(st);
595 rethrow;
596 }
597 } else {
598 CharSequenceReader reader = new CharSequenceReader(content);
599 Scanner scanner = new Scanner(source, reader, errorListener);
600 scanner.scanGenericMethodComments = analysisOptions.strongMode;
601 Token token = PerformanceStatistics.scan.makeCurrentWhile(() {
602 return scanner.tokenize();
603 });
604 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
605
606 Parser parser = new Parser(source, errorListener);
607 parser.enableAssertInitializer = analysisOptions.enableAssertInitializer;
608 parser.parseGenericMethodComments = analysisOptions.strongMode;
609 CompilationUnit unit = parser.parseCompilationUnit(token);
610 unit.lineInfo = lineInfo;
611 return unit;
612 }
613 }
614
615 /** 615 /**
616 * Return `true` if the given byte lists are equal. 616 * Return `true` if the given byte lists are equal.
617 */ 617 */
618 static bool _equalByteLists(List<int> a, List<int> b) { 618 static bool _equalByteLists(List<int> a, List<int> b) {
619 if (a == null) { 619 if (a == null) {
620 return b == null; 620 return b == null;
621 } else if (b == null) { 621 } else if (b == null) {
622 return false; 622 return false;
623 } 623 }
624 if (a.length != b.length) { 624 if (a.length != b.length) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 _FastaElementProxy operator [](fasta.Builder builder) => 945 _FastaElementProxy operator [](fasta.Builder builder) =>
946 _elements.putIfAbsent(builder, () => new _FastaElementProxy()); 946 _elements.putIfAbsent(builder, () => new _FastaElementProxy());
947 947
948 @override 948 @override
949 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 949 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
950 } 950 }
951 951
952 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType { 952 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType {
953 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 953 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
954 } 954 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/command_line/arguments.dart ('k') | pkg/analyzer/lib/src/dart/scanner/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698