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

Side by Side Diff: pkg/analysis_server/lib/src/context_manager.dart

Issue 1852113002: More strong mode changes in analysis_server (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library context.directory.manager; 5 library context.directory.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:core' hide Resource; 10 import 'dart:core' hide Resource;
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (options == null && !optionsRemoved) { 585 if (options == null && !optionsRemoved) {
586 return; 586 return;
587 } 587 }
588 588
589 // In case options files are removed, revert to defaults. 589 // In case options files are removed, revert to defaults.
590 if (optionsRemoved) { 590 if (optionsRemoved) {
591 // Start with defaults. 591 // Start with defaults.
592 info.context.analysisOptions = new AnalysisOptionsImpl(); 592 info.context.analysisOptions = new AnalysisOptionsImpl();
593 593
594 // Apply inherited options. 594 // Apply inherited options.
595 options = _getEmbeddedOptions(info.context); 595 options = _toStringMap(_getEmbeddedOptions(info.context));
596 if (options != null) { 596 if (options != null) {
597 configureContextOptions(info.context, options); 597 configureContextOptions(info.context, options);
598 } 598 }
599 } else { 599 } else {
600 // Check for embedded options. 600 // Check for embedded options.
601 YamlMap embeddedOptions = _getEmbeddedOptions(info.context); 601 YamlMap embeddedOptions = _getEmbeddedOptions(info.context);
602 if (embeddedOptions != null) { 602 if (embeddedOptions != null) {
603 options = new Merger().merge(embeddedOptions, options); 603 options = _toStringMap(new Merger().merge(embeddedOptions, options));
604 } 604 }
605 } 605 }
606 606
607 // Notify options processors. 607 // Notify options processors.
608 AnalysisEngine.instance.optionsPlugin.optionsProcessors 608 AnalysisEngine.instance.optionsPlugin.optionsProcessors
609 .forEach((OptionsProcessor p) { 609 .forEach((OptionsProcessor p) {
610 try { 610 try {
611 p.optionsProcessed(info.context, options); 611 p.optionsProcessed(info.context, options);
612 } catch (e, stacktrace) { 612 } catch (e, stacktrace) {
613 AnalysisEngine.instance.logger.logError( 613 AnalysisEngine.instance.logger.logError(
614 'Error processing .analysis_options', 614 'Error processing .analysis_options',
615 new CaughtException(e, stacktrace)); 615 new CaughtException(e, stacktrace));
616 } 616 }
617 }); 617 });
618 618
619 configureContextOptions(info.context, options); 619 configureContextOptions(info.context, options);
620 620
621 // Nothing more to do. 621 // Nothing more to do.
622 if (options == null) { 622 if (options == null) {
623 return; 623 return;
624 } 624 }
625 625
626 var analyzer = options[AnalyzerOptions.analyzer]; 626 var analyzer = options[AnalyzerOptions.analyzer];
627 if (analyzer is Map) { 627 if (analyzer is Map) {
628 // Set ignore patterns. 628 // Set ignore patterns.
629 YamlList exclude = analyzer[AnalyzerOptions.exclude]; 629 YamlList exclude = analyzer[AnalyzerOptions.exclude];
630 if (exclude is List<String>) { 630 List<String> excludeList = _toStringList(exclude);
631 setIgnorePatternsForContext(info, exclude); 631 if (excludeList != null) {
632 setIgnorePatternsForContext(info, excludeList);
632 } 633 }
633 } 634 }
634 } 635 }
635 636
636 /** 637 /**
637 * Return the options from the analysis options file in the given [folder] 638 * Return the options from the analysis options file in the given [folder]
638 * if exists, or in one of the parent folders, or `null` if no analysis 639 * if exists, or in one of the parent folders, or `null` if no analysis
639 * options file is found or if the contents of the file are not valid YAML. 640 * options file is found or if the contents of the file are not valid YAML.
640 */ 641 */
641 Map<String, Object> readOptions(Folder folder) { 642 Map<String, Object> readOptions(Folder folder) {
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to 1554 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to
1554 // the non-existent file 'username@hostname.pid'. To avoid these dummy 1555 // the non-existent file 'username@hostname.pid'. To avoid these dummy
1555 // links causing the analyzer to thrash, just ignore links to 1556 // links causing the analyzer to thrash, just ignore links to
1556 // non-existent files. 1557 // non-existent files.
1557 return file.exists; 1558 return file.exists;
1558 } 1559 }
1559 } 1560 }
1560 return false; 1561 return false;
1561 } 1562 }
1562 1563
1564 /**
1565 * If all of the elements of [list] are strings, return a list of strings
1566 * containing the same elements. Otherwise, return `null`.
1567 */
1568 List<String> _toStringList(YamlList list) {
1569 if (list == null) {
1570 return null;
1571 }
1572 List<String> stringList = <String>[];
1573 for (var element in list) {
1574 if (element is String) {
1575 stringList.add(element);
1576 } else {
1577 return null;
1578 }
1579 }
1580 return stringList;
1581 }
1582
1583 /**
1584 * If the given [object] is a map, and all of the keys in the map are strings,
1585 * return a map containing the same mappings. Otherwise, return `null`.
1586 */
1587 Map<String, Object> _toStringMap(Object object) {
1588 if (object is Map) {
1589 Map<String, Object> stringMap = new HashMap<String, Object>();
1590 for (var key in object.keys) {
1591 if (key is String) {
1592 stringMap[key] = object[key];
1593 } else {
1594 return null;
1595 }
1596 }
1597 return stringMap;
1598 }
1599 return null;
1600 }
1601
1563 void _updateContextPackageUriResolver( 1602 void _updateContextPackageUriResolver(
1564 Folder contextFolder, FolderDisposition disposition) { 1603 Folder contextFolder, FolderDisposition disposition) {
1565 AnalysisContext context = folderMap[contextFolder]; 1604 AnalysisContext context = folderMap[contextFolder];
1566 context.sourceFactory = _createSourceFactory( 1605 context.sourceFactory = _createSourceFactory(
1567 context, context.analysisOptions, disposition, contextFolder); 1606 context, context.analysisOptions, disposition, contextFolder);
1568 callbacks.updateContextPackageUriResolver(context); 1607 callbacks.updateContextPackageUriResolver(context);
1569 } 1608 }
1570 1609
1571 /** 1610 /**
1572 * Create and return a source representing the given [file] within the given 1611 * Create and return a source representing the given [file] within the given
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 ResourceProvider resourceProvider) { 1795 ResourceProvider resourceProvider) {
1757 if (packages != null) { 1796 if (packages != null) {
1758 // Construct package map for the SdkExtUriResolver. 1797 // Construct package map for the SdkExtUriResolver.
1759 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); 1798 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider);
1760 return <UriResolver>[new SdkExtUriResolver(packageMap)]; 1799 return <UriResolver>[new SdkExtUriResolver(packageMap)];
1761 } else { 1800 } else {
1762 return const <UriResolver>[]; 1801 return const <UriResolver>[];
1763 } 1802 }
1764 } 1803 }
1765 } 1804 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698