| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 final Set<String> addedNames = new Set<String>(); | 1916 final Set<String> addedNames = new Set<String>(); |
| 1917 final Set<String> changedNames = new Set<String>(); | 1917 final Set<String> changedNames = new Set<String>(); |
| 1918 final Set<String> removedNames = new Set<String>(); | 1918 final Set<String> removedNames = new Set<String>(); |
| 1919 | 1919 |
| 1920 final Set<Source> invalidatedSources = new Set<Source>(); | 1920 final Set<Source> invalidatedSources = new Set<Source>(); |
| 1921 | 1921 |
| 1922 DartDelta(Source source) : super(source) { | 1922 DartDelta(Source source) : super(source) { |
| 1923 invalidatedSources.add(source); | 1923 invalidatedSources.add(source); |
| 1924 } | 1924 } |
| 1925 | 1925 |
| 1926 void elementAdded(Element element) { |
| 1927 addedNames.add(element.name); |
| 1928 } |
| 1929 |
| 1930 void elementChanged(Element element) { |
| 1931 changedNames.add(element.name); |
| 1932 } |
| 1933 |
| 1934 void elementRemoved(Element element) { |
| 1935 removedNames.add(element.name); |
| 1936 } |
| 1937 |
| 1938 bool isNameAffected(String name) { |
| 1939 return addedNames.contains(name) || |
| 1940 changedNames.contains(name) || |
| 1941 removedNames.contains(name); |
| 1942 } |
| 1943 |
| 1944 bool nameChanged(String name) { |
| 1945 return changedNames.add(name); |
| 1946 } |
| 1947 |
| 1926 @override | 1948 @override |
| 1927 bool affects(InternalAnalysisContext context, AnalysisTarget target, | 1949 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, |
| 1928 ResultDescriptor descriptor) { | 1950 ResultDescriptor descriptor) { |
| 1929 if (hasDirectiveChange) { | 1951 if (hasDirectiveChange) { |
| 1930 return true; | 1952 return DeltaResult.INVALIDATE; |
| 1931 } | 1953 } |
| 1954 // Prepare target source. |
| 1932 Source targetSource = null; | 1955 Source targetSource = null; |
| 1933 if (target is Source) { | 1956 if (target is Source) { |
| 1934 targetSource = target; | 1957 targetSource = target; |
| 1935 } | 1958 } |
| 1936 if (target is LibrarySpecificUnit) { | 1959 if (target is LibrarySpecificUnit) { |
| 1937 targetSource = target.library; | 1960 targetSource = target.library; |
| 1938 } | 1961 } |
| 1939 if (target is Element) { | 1962 if (target is Element) { |
| 1940 targetSource = target.source; | 1963 targetSource = target.source; |
| 1941 } | 1964 } |
| 1965 // Keep results that are updated incrementally. |
| 1966 // If we want to analyze only some references to the source being changed, |
| 1967 // we need to keep the same instances of CompilationUnitElement and |
| 1968 // LibraryElement. |
| 1942 if (targetSource == source) { | 1969 if (targetSource == source) { |
| 1943 return true; | 1970 if (ParseDartTask.DESCRIPTOR.results.contains(descriptor)) { |
| 1971 return DeltaResult.KEEP_CONTINUE; |
| 1972 } |
| 1973 if (BuildCompilationUnitElementTask.DESCRIPTOR.results |
| 1974 .contains(descriptor)) { |
| 1975 return DeltaResult.KEEP_CONTINUE; |
| 1976 } |
| 1977 if (BuildLibraryElementTask.DESCRIPTOR.results.contains(descriptor)) { |
| 1978 return DeltaResult.KEEP_CONTINUE; |
| 1979 } |
| 1980 return DeltaResult.INVALIDATE; |
| 1944 } | 1981 } |
| 1982 // Use the target library dependency information to decide whether |
| 1983 // the delta affects the library. |
| 1945 if (targetSource != null) { | 1984 if (targetSource != null) { |
| 1946 List<Source> librarySources = | 1985 List<Source> librarySources = |
| 1947 context.getLibrariesContaining(targetSource); | 1986 context.getLibrariesContaining(targetSource); |
| 1948 for (Source librarySource in librarySources) { | 1987 for (Source librarySource in librarySources) { |
| 1949 AnalysisCache cache = context.analysisCache; | 1988 AnalysisCache cache = context.analysisCache; |
| 1950 ReferencedNames referencedNames = | 1989 ReferencedNames referencedNames = |
| 1951 cache.getValue(librarySource, REFERENCED_NAMES); | 1990 cache.getValue(librarySource, REFERENCED_NAMES); |
| 1952 if (referencedNames == null) { | 1991 if (referencedNames == null) { |
| 1953 return true; | 1992 return DeltaResult.INVALIDATE; |
| 1954 } | 1993 } |
| 1955 referencedNames.addChangedElements(this); | 1994 referencedNames.addChangedElements(this); |
| 1956 if (referencedNames.isAffectedBy(this)) { | 1995 if (referencedNames.isAffectedBy(this)) { |
| 1957 return true; | 1996 return DeltaResult.INVALIDATE; |
| 1958 } | 1997 } |
| 1959 } | 1998 } |
| 1960 return false; | 1999 return DeltaResult.STOP; |
| 1961 } | 2000 } |
| 1962 return true; | 2001 // We don't know what to do with the given target, invalidate it. |
| 1963 } | 2002 return DeltaResult.INVALIDATE; |
| 1964 | |
| 1965 void elementAdded(Element element) { | |
| 1966 addedNames.add(element.name); | |
| 1967 } | |
| 1968 | |
| 1969 void elementChanged(Element element) { | |
| 1970 changedNames.add(element.name); | |
| 1971 } | |
| 1972 | |
| 1973 void elementRemoved(Element element) { | |
| 1974 removedNames.add(element.name); | |
| 1975 } | |
| 1976 | |
| 1977 bool isNameAffected(String name) { | |
| 1978 return addedNames.contains(name) || | |
| 1979 changedNames.contains(name) || | |
| 1980 removedNames.contains(name); | |
| 1981 } | |
| 1982 | |
| 1983 bool nameChanged(String name) { | |
| 1984 return changedNames.add(name); | |
| 1985 } | 2003 } |
| 1986 } | 2004 } |
| 1987 | 2005 |
| 1988 /** | 2006 /** |
| 1989 * A task that merges all of the errors for a single source into a single list | 2007 * A task that merges all of the errors for a single source into a single list |
| 1990 * of errors. | 2008 * of errors. |
| 1991 */ | 2009 */ |
| 1992 class DartErrorsTask extends SourceBasedAnalysisTask { | 2010 class DartErrorsTask extends SourceBasedAnalysisTask { |
| 1993 /** | 2011 /** |
| 1994 * The name of the [BUILD_DIRECTIVES_ERRORS] input. | 2012 * The name of the [BUILD_DIRECTIVES_ERRORS] input. |
| (...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3675 | 3693 |
| 3676 @override | 3694 @override |
| 3677 bool moveNext() { | 3695 bool moveNext() { |
| 3678 if (_newSources.isEmpty) { | 3696 if (_newSources.isEmpty) { |
| 3679 return false; | 3697 return false; |
| 3680 } | 3698 } |
| 3681 currentTarget = _newSources.removeLast(); | 3699 currentTarget = _newSources.removeLast(); |
| 3682 return true; | 3700 return true; |
| 3683 } | 3701 } |
| 3684 } | 3702 } |
| OLD | NEW |