diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart index 6cd2ef6954c..922f2adfc71 100644 --- a/pkg/analysis_server/lib/src/analysis_server.dart +++ b/pkg/analysis_server/lib/src/analysis_server.dart @@ -257,6 +257,7 @@ class AnalysisServer { analysisServerOptions.enableIncrementalResolutionApi; contextDirectoryManager.defaultOptions.incrementalValidation = analysisServerOptions.enableIncrementalResolutionValidation; + contextDirectoryManager.defaultOptions.generateImplicitErrors = false; _noErrorNotification = analysisServerOptions.noErrorNotification; AnalysisEngine.instance.logger = new AnalysisLogger(); _onAnalysisStartedController = new StreamController.broadcast(); diff --git a/pkg/analysis_server/lib/src/get_handler.dart b/pkg/analysis_server/lib/src/get_handler.dart index e58e4289c6b..aa4c2a2d2e7 100644 --- a/pkg/analysis_server/lib/src/get_handler.dart +++ b/pkg/analysis_server/lib/src/get_handler.dart @@ -1010,7 +1010,10 @@ class GetHandler { _writeOption(buffer, 'Cache size', options.cacheSize); _writeOption(buffer, 'Generate hints', options.hint); _writeOption(buffer, 'Generate dart2js hints', options.dart2jsHint); - _writeOption(buffer, 'Generate SDK errors', options.generateSdkErrors); + _writeOption(buffer, 'Generate errors in implicit files', + options.generateImplicitErrors); + _writeOption( + buffer, 'Generate errors in SDK files', options.generateSdkErrors); _writeOption(buffer, 'Incremental resolution', options.incremental); _writeOption(buffer, 'Incremental resolution with API changes', options.incrementalApi); diff --git a/pkg/analyzer/lib/src/analyzer_impl.dart b/pkg/analyzer/lib/src/analyzer_impl.dart index 222aad7f1a1..849356fd033 100644 --- a/pkg/analyzer/lib/src/analyzer_impl.dart +++ b/pkg/analyzer/lib/src/analyzer_impl.dart @@ -150,7 +150,7 @@ class AnalyzerImpl { new DartUriResolver(sdk), new FileUriResolver() ]; - // may be add package resolver + // maybe add package resolver { JavaFile packageDirectory; if (options.packageRootPath != null) { @@ -187,6 +187,8 @@ class AnalyzerImpl { contextOptions.hint = !options.disableHints; contextOptions.analyzeFunctionBodiesPredicate = _analyzeFunctionBodiesPredicate; + contextOptions.generateImplicitErrors = options.showPackageWarnings; + contextOptions.generateSdkErrors = options.showSdkWarnings; context.analysisOptions = contextOptions; // Create and add a ChangeSet diff --git a/pkg/analyzer/lib/src/generated/engine.dart b/pkg/analyzer/lib/src/generated/engine.dart index 2a9bbf82f25..d90a771f9ff 100644 --- a/pkg/analyzer/lib/src/generated/engine.dart +++ b/pkg/analyzer/lib/src/generated/engine.dart @@ -965,8 +965,14 @@ class AnalysisContextImpl implements InternalAnalysisContext { AnalysisOptionsImpl _options = new AnalysisOptionsImpl(); /** - * A flag indicating whether errors related to sources in the SDK should be generated and - * reported. + * A flag indicating whether errors related to implicitly analyzed sources + * should be generated and reported. + */ + bool _generateImplicitErrors = true; + + /** + * A flag indicating whether errors related to sources in the SDK should be + * generated and reported. */ bool _generateSdkErrors = true; @@ -1121,6 +1127,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { void set analysisOptions(AnalysisOptions options) { bool needsRecompute = this._options.analyzeFunctionBodiesPredicate != options.analyzeFunctionBodiesPredicate || + this._options.generateImplicitErrors != options.generateImplicitErrors || this._options.generateSdkErrors != options.generateSdkErrors || this._options.dart2jsHint != options.dart2jsHint || (this._options.hint && !options.hint) || @@ -1146,6 +1153,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { } this._options.analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; + this._options.generateImplicitErrors = options.generateImplicitErrors; this._options.generateSdkErrors = options.generateSdkErrors; this._options.dart2jsHint = options.dart2jsHint; this._options.hint = options.hint; @@ -1154,6 +1162,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { this._options.incrementalValidation = options.incrementalValidation; this._options.lint = options.lint; this._options.preserveComments = options.preserveComments; + _generateImplicitErrors = options.generateImplicitErrors; _generateSdkErrors = options.generateSdkErrors; if (needsRecompute) { _invalidateAllLocalResolutionInformation(false); @@ -2590,6 +2599,12 @@ class AnalysisContextImpl implements InternalAnalysisContext { // These values are not currently being computed, so their state // is not interesting. continue; + } else if (!sourceEntry.explicitlyAdded && + !_generateImplicitErrors && + (descriptor == DartEntry.VERIFICATION_ERRORS || + descriptor == DartEntry.HINTS || + descriptor == DartEntry.LINTS)) { + continue; } else if (source.isInSystemLibrary && !_generateSdkErrors && (descriptor == DartEntry.VERIFICATION_ERRORS || @@ -2609,6 +2624,20 @@ class AnalysisContextImpl implements InternalAnalysisContext { } } + /** + * Return `true` if errors should be produced for the given [source]. The + * [dartEntry] associated with the source is passed in for efficiency. + */ + bool _shouldErrorsBeAnalyzed(Source source, DartEntry dartEntry) { + if (source.isInSystemLibrary) { + return _generateSdkErrors; + } else if (!dartEntry.explicitlyAdded) { + return _generateImplicitErrors; + } else { + return true; + } + } + /** * Visit all entries of the content cache. */ @@ -3852,7 +3881,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { return new AnalysisContextImpl_TaskData( new ResolveDartLibraryTask(this, source, librarySource), false); } - if (_generateSdkErrors || !source.isInSystemLibrary) { + if (_shouldErrorsBeAnalyzed(source, dartEntry)) { CacheState verificationErrorsState = dartEntry.getStateInLibrary( DartEntry.VERIFICATION_ERRORS, librarySource); if (verificationErrorsState == CacheState.INVALID || @@ -4068,7 +4097,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { return; } } - if (_generateSdkErrors || !source.isInSystemLibrary) { + if (_shouldErrorsBeAnalyzed(source, dartEntry)) { CacheState verificationErrorsState = dartEntry.getStateInLibrary( DartEntry.VERIFICATION_ERRORS, librarySource); if (verificationErrorsState == CacheState.INVALID || @@ -6301,8 +6330,8 @@ abstract class AnalysisListener { class AnalysisNotScheduledError implements Exception {} /** - * The interface `AnalysisOptions` defines the behavior of objects that provide access to a - * set of analysis options used to control the behavior of an analysis context. + * A set of analysis options used to control the behavior of an analysis + * context. */ abstract class AnalysisOptions { /** @@ -6314,7 +6343,7 @@ abstract class AnalysisOptions { * This getter is deprecated; consider using [analyzeFunctionBodiesPredicate] * instead. */ - @deprecated + @deprecated // Use this.analyzeFunctionBodiesPredicate bool get analyzeFunctionBodies; /** @@ -6324,61 +6353,54 @@ abstract class AnalysisOptions { AnalyzeFunctionBodiesPredicate get analyzeFunctionBodiesPredicate; /** - * Return the maximum number of sources for which AST structures should be kept in the cache. - * - * @return the maximum number of sources for which AST structures should be kept in the cache + * Return the maximum number of sources for which AST structures should be + * kept in the cache. */ int get cacheSize; /** * Return `true` if analysis is to generate dart2js related hint results. - * - * @return `true` if analysis is to generate dart2js related hint results */ bool get dart2jsHint; /** * Return `true` if analysis is to include the new async support. */ - @deprecated + @deprecated // Always true bool get enableAsync; /** * Return `true` if analysis is to include the new deferred loading support. - * - * @return `true` if analysis is to include the new deferred loading support */ - @deprecated + @deprecated // Always true bool get enableDeferredLoading; /** * Return `true` if analysis is to include the new enum support. - * - * @return `true` if analysis is to include the new enum support */ - @deprecated + @deprecated // Always true bool get enableEnum; /** - * Return `true` if errors, warnings and hints should be generated for sources in the SDK. - * The default value is `false`. - * - * @return `true` if errors, warnings and hints should be generated for the SDK + * Return `true` if errors, warnings and hints should be generated for sources + * that are implicitly being analyzed. The default value is `true`. + */ + bool get generateImplicitErrors; + + /** + * Return `true` if errors, warnings and hints should be generated for sources + * in the SDK. The default value is `false`. */ bool get generateSdkErrors; /** - * Return `true` if analysis is to generate hint results (e.g. type inference based - * information and pub best practices). - * - * @return `true` if analysis is to generate hint results + * Return `true` if analysis is to generate hint results (e.g. type inference + * based information and pub best practices). */ bool get hint; /** * Return `true` if incremental analysis should be used. - * - * @return `true` if incremental analysis should be used */ bool get incremental; @@ -6396,22 +6418,18 @@ abstract class AnalysisOptions { /** * Return `true` if analysis is to generate lint warnings. - * - * @return `true` if analysis is to generate lint warnings */ bool get lint; /** * Return `true` if analysis is to parse comments. - * - * @return `true` if analysis is to parse comments */ bool get preserveComments; } /** - * Instances of the class `AnalysisOptions` represent a set of analysis options used to - * control the behavior of an analysis context. + * A set of analysis options used to control the behavior of an analysis + * context. */ class AnalysisOptionsImpl implements AnalysisOptions { /** @@ -6439,24 +6457,32 @@ class AnalysisOptionsImpl implements AnalysisOptions { _analyzeAllFunctionBodies; /** - * The maximum number of sources for which AST structures should be kept in the cache. + * The maximum number of sources for which AST structures should be kept in + * the cache. */ int cacheSize = DEFAULT_CACHE_SIZE; /** - * A flag indicating whether analysis is to generate dart2js related hint results. + * A flag indicating whether analysis is to generate dart2js related hint + * results. */ bool dart2jsHint = true; /** - * A flag indicating whether errors, warnings and hints should be generated for sources in the - * SDK. + * A flag indicating whether errors, warnings and hints should be generated + * for sources that are implicitly being analyzed. */ - bool _generateSdkErrors = false; + bool generateImplicitErrors = true; /** - * A flag indicating whether analysis is to generate hint results (e.g. type inference based - * information and pub best practices). + * A flag indicating whether errors, warnings and hints should be generated + * for sources in the SDK. + */ + bool generateSdkErrors = false; + + /** + * A flag indicating whether analysis is to generate hint results (e.g. type + * inference based information and pub best practices). */ bool hint = true; @@ -6488,21 +6514,21 @@ class AnalysisOptionsImpl implements AnalysisOptions { bool preserveComments = true; /** - * Initialize a newly created set of analysis options to have their default values. + * Initialize a newly created set of analysis options to have their default + * values. */ AnalysisOptionsImpl(); /** - * Initialize a newly created set of analysis options to have the same values as those in the - * given set of analysis options. - * - * @param options the analysis options whose values are being copied + * Initialize a newly created set of analysis options to have the same values + * as those in the given set of analysis [options]. */ AnalysisOptionsImpl.con1(AnalysisOptions options) { analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; cacheSize = options.cacheSize; dart2jsHint = options.dart2jsHint; - _generateSdkErrors = options.generateSdkErrors; + generateImplicitErrors = options.generateImplicitErrors; + generateSdkErrors = options.generateSdkErrors; hint = options.hint; incremental = options.incremental; incrementalApi = options.incrementalApi; @@ -6568,20 +6594,6 @@ class AnalysisOptionsImpl implements AnalysisOptions { // Enum support cannot be disabled } - @override - bool get generateSdkErrors => _generateSdkErrors; - - /** - * Set whether errors, warnings and hints should be generated for sources in the SDK to match the - * given value. - * - * @param generate `true` if errors, warnings and hints should be generated for sources in - * the SDK - */ - void set generateSdkErrors(bool generate) { - _generateSdkErrors = generate; - } - /** * Predicate used for [analyzeFunctionBodiesPredicate] when * [analyzeFunctionBodies] is set to `true`. diff --git a/pkg/analyzer/test/generated/engine_test.dart b/pkg/analyzer/test/generated/engine_test.dart index 57ee31a2bf9..35e96603d76 100644 --- a/pkg/analyzer/test/generated/engine_test.dart +++ b/pkg/analyzer/test/generated/engine_test.dart @@ -2198,6 +2198,7 @@ class AnalysisOptionsImplTest extends EngineTestCase { options.analyzeFunctionBodies = booleanValue; options.cacheSize = i; options.dart2jsHint = booleanValue; + options.generateImplicitErrors = booleanValue; options.generateSdkErrors = booleanValue; options.hint = booleanValue; options.incremental = booleanValue; @@ -2206,6 +2207,7 @@ class AnalysisOptionsImplTest extends EngineTestCase { expect(copy.analyzeFunctionBodies, options.analyzeFunctionBodies); expect(copy.cacheSize, options.cacheSize); expect(copy.dart2jsHint, options.dart2jsHint); + expect(copy.generateImplicitErrors, options.generateImplicitErrors); expect(copy.generateSdkErrors, options.generateSdkErrors); expect(copy.hint, options.hint); expect(copy.incremental, options.incremental); @@ -2213,14 +2215,14 @@ class AnalysisOptionsImplTest extends EngineTestCase { } } - void test_getAnalyzeFunctionBodies() { + void test_analyzeFunctionBodies() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.analyzeFunctionBodies; options.analyzeFunctionBodies = value; expect(options.analyzeFunctionBodies, value); } - void test_getCacheSize() { + void test_cacheSize() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); expect(options.cacheSize, AnalysisOptionsImpl.DEFAULT_CACHE_SIZE); int value = options.cacheSize + 1; @@ -2228,35 +2230,42 @@ class AnalysisOptionsImplTest extends EngineTestCase { expect(options.cacheSize, value); } - void test_getDart2jsHint() { + void test_dart2jsHint() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.dart2jsHint; options.dart2jsHint = value; expect(options.dart2jsHint, value); } - void test_getGenerateSdkErrors() { + void test_generateImplicitErrors() { + AnalysisOptionsImpl options = new AnalysisOptionsImpl(); + bool value = !options.generateImplicitErrors; + options.generateImplicitErrors = value; + expect(options.generateImplicitErrors, value); + } + + void test_generateSdkErrors() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.generateSdkErrors; options.generateSdkErrors = value; expect(options.generateSdkErrors, value); } - void test_getHint() { + void test_hint() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.hint; options.hint = value; expect(options.hint, value); } - void test_getIncremental() { + void test_incremental() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.incremental; options.incremental = value; expect(options.incremental, value); } - void test_getPreserveComments() { + void test_preserveComments() { AnalysisOptionsImpl options = new AnalysisOptionsImpl(); bool value = !options.preserveComments; options.preserveComments = value; diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart index 89f83f120bf..ca1eb930ec7 100644 --- a/pkg/analyzer/test/generated/resolver_test.dart +++ b/pkg/analyzer/test/generated/resolver_test.dart @@ -362,6 +362,8 @@ class AnalysisContextForTests extends AnalysisContextImpl { AnalysisOptions currentOptions = analysisOptions; bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != options.analyzeFunctionBodiesPredicate || + currentOptions.generateImplicitErrors != + options.generateImplicitErrors || currentOptions.generateSdkErrors != options.generateSdkErrors || currentOptions.dart2jsHint != options.dart2jsHint || (currentOptions.hint && !options.hint) ||