From 5bcd357802dfbb194245f16bcdfe7a574556e221 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 30 Jun 2015 15:31:36 -0700 Subject: [PATCH] Invalidate both hints and lints on incremental resolution. We don't have new LINTS result descriptor yet, once we have, we need to update the new AnalysisContext implementation. R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org//1222433003. --- pkg/analyzer/lib/src/generated/engine.dart | 7 ++- .../src/generated/incremental_resolver.dart | 45 +++++-------------- .../generated/incremental_resolver_test.dart | 6 +-- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/pkg/analyzer/lib/src/generated/engine.dart b/pkg/analyzer/lib/src/generated/engine.dart index 7d3f7e68aad..8488ab4bf42 100644 --- a/pkg/analyzer/lib/src/generated/engine.dart +++ b/pkg/analyzer/lib/src/generated/engine.dart @@ -2222,7 +2222,7 @@ class AnalysisContextImpl implements InternalAnalysisContext { // Prepare sources to invalidate hints in. List sources = [librarySource]; sources.addAll(dartEntry.getValue(DartEntry.INCLUDED_PARTS)); - // Invalidate hints. + // Invalidate hints and lints. for (Source source in sources) { DartEntry dartEntry = _cache.get(source); if (dartEntry.getStateInLibrary(DartEntry.HINTS, librarySource) == @@ -2230,6 +2230,11 @@ class AnalysisContextImpl implements InternalAnalysisContext { dartEntry.setStateInLibrary( DartEntry.HINTS, librarySource, CacheState.INVALID); } + if (dartEntry.getStateInLibrary(DartEntry.LINTS, librarySource) == + CacheState.VALID) { + dartEntry.setStateInLibrary( + DartEntry.LINTS, librarySource, CacheState.INVALID); + } } } diff --git a/pkg/analyzer/lib/src/generated/incremental_resolver.dart b/pkg/analyzer/lib/src/generated/incremental_resolver.dart index 6f5480d992f..259cd030933 100644 --- a/pkg/analyzer/lib/src/generated/incremental_resolver.dart +++ b/pkg/analyzer/lib/src/generated/incremental_resolver.dart @@ -899,7 +899,6 @@ class IncrementalResolver { List _resolveErrors = AnalysisError.NO_ERRORS; List _verifyErrors = AnalysisError.NO_ERRORS; - List _lints = AnalysisError.NO_ERRORS; /** * Initialize a newly created incremental resolver to resolve a node in the @@ -941,7 +940,6 @@ class IncrementalResolver { // verify _verify(rootNode); _context.invalidateLibraryHints(_librarySource); - _generateLints(rootNode); // update entry errors _updateEntry(); // notify unit @@ -1053,24 +1051,6 @@ class IncrementalResolver { throw new AnalysisException("Cannot resolve node: no resolvable node"); } - void _generateLints(AstNode node) { - LoggingTimer timer = logger.startTimer(); - try { - if (_context.analysisOptions.lint) { - RecordingErrorListener errorListener = new RecordingErrorListener(); - CompilationUnit unit = node.getAncestor((n) => n is CompilationUnit); - LintGenerator lintGenerator = - new LintGenerator([unit], errorListener); - lintGenerator.generate(); - _lints = errorListener.getErrorsForSource(_source); - } else { - _lints = AnalysisError.NO_ERRORS; - } - } finally { - timer.stop('generate lints'); - } - } - /** * Return the element defined by [node], or `null` if the node does not * define an element. @@ -1201,21 +1181,8 @@ class IncrementalResolver { } void _updateEntry_OLD() { - { - List oldErrors = oldEntry.getValueInLibrary( - DartEntry.RESOLUTION_ERRORS, _librarySource); - List errors = _updateErrors(oldErrors, _resolveErrors); - oldEntry.setValueInLibrary( - DartEntry.RESOLUTION_ERRORS, _librarySource, errors); - } - { - List oldErrors = oldEntry.getValueInLibrary( - DartEntry.VERIFICATION_ERRORS, _librarySource); - List errors = _updateErrors(oldErrors, _verifyErrors); - oldEntry.setValueInLibrary( - DartEntry.VERIFICATION_ERRORS, _librarySource, errors); - } - oldEntry.setValueInLibrary(DartEntry.LINTS, _librarySource, _lints); + _updateErrors_OLD(DartEntry.RESOLUTION_ERRORS, _resolveErrors); + _updateErrors_OLD(DartEntry.VERIFICATION_ERRORS, _verifyErrors); } List _updateErrors( @@ -1249,6 +1216,14 @@ class IncrementalResolver { newUnitEntry.setValueIncremental(descriptor, errors); } + void _updateErrors_OLD(DataDescriptor> descriptor, + List newErrors) { + List oldErrors = + oldEntry.getValueInLibrary(descriptor, _librarySource); + List errors = _updateErrors(oldErrors, newErrors); + oldEntry.setValueInLibrary(descriptor, _librarySource, errors); + } + void _verify(AstNode node) { LoggingTimer timer = logger.startTimer(); try { diff --git a/pkg/analyzer/test/generated/incremental_resolver_test.dart b/pkg/analyzer/test/generated/incremental_resolver_test.dart index 98f6d237651..ed41b59a77f 100644 --- a/pkg/analyzer/test/generated/incremental_resolver_test.dart +++ b/pkg/analyzer/test/generated/incremental_resolver_test.dart @@ -2486,7 +2486,7 @@ class IncrementalResolverTest extends ResolverTestCase { void resetWithOptions(AnalysisOptions options) { if (AnalysisEngine.instance.useTaskModel) { analysisContext2 = - AnalysisContextFactory.contextWithCoreAndOptions(options); + AnalysisContextFactory.contextWithCoreAndOptions(options); } else { analysisContext2 = AnalysisContextFactory.oldContextWithCoreAndOptions(options); @@ -3711,7 +3711,7 @@ class A { expect(errors, isEmpty); } - void test_updateErrors_addNew_hint() { + void test_updateErrors_addNew_hint1() { _resolveUnit(r''' int main() { return 42; @@ -3723,7 +3723,7 @@ int main() { '''); } - void test_updateErrors_addNew_hints() { + void test_updateErrors_addNew_hint2() { _resolveUnit(r''' main() { int v = 0;