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

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

Issue 2654303003: Ignore files that are hidden by generated files. (Closed)
Patch Set: Created 3 years, 11 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:convert'; 5 import 'dart:convert';
6 import 'dart:typed_data'; 6 import 'dart:typed_data';
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 * Mapping from a URI to the corresponding [FileState]. 533 * Mapping from a URI to the corresponding [FileState].
534 */ 534 */
535 final Map<Uri, FileState> _uriToFile = {}; 535 final Map<Uri, FileState> _uriToFile = {};
536 536
537 /** 537 /**
538 * All known file paths. 538 * All known file paths.
539 */ 539 */
540 final Set<String> knownFilePaths = new Set<String>(); 540 final Set<String> knownFilePaths = new Set<String>();
541 541
542 /** 542 /**
543 * Mapping from a path to the flag whether there is a URI for the path.
544 */
545 final Map<String, bool> _hasUriForPath = {};
546
547 /**
543 * Mapping from a path to the corresponding [FileState]s, canonical or not. 548 * Mapping from a path to the corresponding [FileState]s, canonical or not.
544 */ 549 */
545 final Map<String, List<FileState>> _pathToFiles = {}; 550 final Map<String, List<FileState>> _pathToFiles = {};
546 551
547 /** 552 /**
548 * Mapping from a path to the corresponding canonical [FileState]. 553 * Mapping from a path to the corresponding canonical [FileState].
549 */ 554 */
550 final Map<String, FileState> _pathToCanonicalFile = {}; 555 final Map<String, FileState> _pathToCanonicalFile = {};
551 556
552 /** 557 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 */ 590 */
586 FileState getFileForPath(String path) { 591 FileState getFileForPath(String path) {
587 FileState file = _pathToCanonicalFile[path]; 592 FileState file = _pathToCanonicalFile[path];
588 if (file == null) { 593 if (file == null) {
589 File resource = _resourceProvider.getFile(path); 594 File resource = _resourceProvider.getFile(path);
590 Source fileSource = resource.createSource(); 595 Source fileSource = resource.createSource();
591 Uri uri = _sourceFactory.restoreUri(fileSource); 596 Uri uri = _sourceFactory.restoreUri(fileSource);
592 // Try to get the existing instance. 597 // Try to get the existing instance.
593 file = _uriToFile[uri]; 598 file = _uriToFile[uri];
594 // If we have a file, call it the canonical one and return it. 599 // If we have a file, call it the canonical one and return it.
595 if (file != null && file.path == path) { 600 if (file != null) {
596 _pathToCanonicalFile[path] = file; 601 _pathToCanonicalFile[path] = file;
597 return file; 602 return file;
598 } 603 }
599 // Create a new file. 604 // Create a new file.
600 FileSource uriSource = new FileSource(resource, uri); 605 FileSource uriSource = new FileSource(resource, uri);
601 file = new FileState._(this, path, uri, uriSource); 606 file = new FileState._(this, path, uri, uriSource);
602 _uriToFile[uri] = file; 607 _uriToFile[uri] = file;
603 _addFileWithPath(path, file); 608 _addFileWithPath(path, file);
604 _pathToCanonicalFile[path] = file; 609 _pathToCanonicalFile[path] = file;
605 file.refresh(); 610 file.refresh();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 List<FileState> allFiles = _pathToFiles[path].toList(); 646 List<FileState> allFiles = _pathToFiles[path].toList();
642 if (allFiles.length == 1) { 647 if (allFiles.length == 1) {
643 return allFiles; 648 return allFiles;
644 } 649 }
645 return allFiles 650 return allFiles
646 ..remove(canonicalFile) 651 ..remove(canonicalFile)
647 ..insert(0, canonicalFile); 652 ..insert(0, canonicalFile);
648 } 653 }
649 654
650 /** 655 /**
656 * Return `true` if there is a URI that can be resolved to the [path].
657 *
658 * When a file exists, but for the URI that corresponds to the file is
659 * resolved to another file, e.g. a generated one in Bazel, Gn, etc, we
660 * cannot analyze the original file.
661 */
662 bool hasUri(String path) {
663 bool flag = _hasUriForPath[path];
664 if (flag == null) {
665 File resource = _resourceProvider.getFile(path);
666 Source fileSource = resource.createSource();
667 Uri uri = _sourceFactory.restoreUri(fileSource);
668 Source uriSource = _sourceFactory.forUri2(uri);
669 flag = uriSource.fullName == path;
670 _hasUriForPath[path] = flag;
671 }
672 return flag;
673 }
674
675 /**
651 * Remove the file with the given [path]. 676 * Remove the file with the given [path].
652 */ 677 */
653 void removeFile(String path) { 678 void removeFile(String path) {
654 _uriToFile.clear(); 679 _uriToFile.clear();
655 knownFilePaths.clear(); 680 knownFilePaths.clear();
656 _pathToFiles.clear(); 681 _pathToFiles.clear();
657 _pathToCanonicalFile.clear(); 682 _pathToCanonicalFile.clear();
658 _partToLibraries.clear(); 683 _partToLibraries.clear();
659 } 684 }
660 685
(...skipping 19 matching lines...) Expand all
680 .where((f) => f._transitiveFiles == null) 705 .where((f) => f._transitiveFiles == null)
681 .toSet(); 706 .toSet();
682 } 707 }
683 708
684 Set<FileState> get filesWithoutTransitiveSignature { 709 Set<FileState> get filesWithoutTransitiveSignature {
685 return state._uriToFile.values 710 return state._uriToFile.values
686 .where((f) => f._transitiveSignature == null) 711 .where((f) => f._transitiveSignature == null)
687 .toSet(); 712 .toSet();
688 } 713 }
689 } 714 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698