Index: pkg/analyzer/test/src/context/context_test.dart |
diff --git a/pkg/analyzer/test/src/context/context_test.dart b/pkg/analyzer/test/src/context/context_test.dart |
index 24071a99c4737f0bf128ba8756f33279e25eb67c..252ed6268b8220d00f4ef3ad90e5b9e48d35d2a9 100644 |
--- a/pkg/analyzer/test/src/context/context_test.dart |
+++ b/pkg/analyzer/test/src/context/context_test.dart |
@@ -2892,64 +2892,56 @@ class B extends A {} |
_assertInvalid(b, LIBRARY_ERRORS_READY); |
} |
- void test_class_private_member() { |
+ void test_class_method_remove_notUsed_instantiated() { |
Source a = addSource( |
'/a.dart', |
r''' |
-class A { |
- A(); |
- A._privateConstructor(); |
- |
- foo() {} |
- |
- int _privateField; |
- _privateMethod() {} |
- int get _privateGetter => null; |
- void set _privateSetter(_) {} |
+abstract class I { |
+ void foo(); |
+} |
+class A implements I { |
+ void foo() {} |
} |
'''); |
Source b = addSource( |
'/b.dart', |
r''' |
import 'a.dart'; |
-main(A a) { |
- a.foo(); |
+main() { |
+ new A(); |
} |
'''); |
_performPendingAnalysisTasks(); |
- // Update a.dart: rename private members of A |
- // b.dart is valid, it cannot see these private members. |
+ // Update a.dart: remove 'A.foo'. |
+ // b.dart is valid because it does not reference 'foo'. |
+ // The class 'A' has a warning, but it is still not abstract. |
context.setContents( |
a, |
r''' |
-class A { |
- A(); |
- A._privateConstructor2(); |
- |
- foo() {} |
- |
- int _privateField2; |
- _privateMethod2() {} |
- int get _privateGetter2 => null; |
- void set _privateSetter2(_) {} |
+abstract class I { |
+ void fo(); |
+} |
+class A implements I { |
} |
'''); |
_assertValidForChangedLibrary(a); |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
+ |
_assertValidForDependentLibrary(b); |
_assertValidAllLibraryUnitResults(b); |
- _assertValid(b, LIBRARY_ERRORS_READY); |
+ _assertValidAllResolution(b); |
+ _assertValidAllErrors(b); |
} |
- void test_class_super_makeAbstract_instantiate() { |
+ void test_class_method_remove_subclass() { |
Source a = addSource( |
'/a.dart', |
r''' |
abstract class I { |
- void m(); |
+ void foo(); |
} |
class A implements I { |
- void m() {} |
+ void foo() {} |
} |
'''); |
Source b = addSource( |
@@ -2958,35 +2950,77 @@ class A implements I { |
import 'a.dart'; |
class B extends A {} |
'''); |
- Source c = addSource( |
- '/c.dart', |
- r''' |
-import 'b.dart'; |
-main() { |
- new B(); |
-} |
-'''); |
_performPendingAnalysisTasks(); |
// Update a.dart: remove A.bar, add A.bar2. |
- // b.dart is valid, because it doesn't references 'bar' or 'bar2'. |
+ // b.dart |
+ // Resolution is valid because 'foo' is not referenced. |
+ // HINTS are invalid because 'B' might have invalid @override. |
+ // VERIFY_ERRORS are invalid because 'B' might not implement something. |
+ // Other errors are also invalid. |
context.setContents( |
a, |
r''' |
abstract class I { |
- void m(); |
+ void foo(); |
} |
class A implements I { |
- void m2() {} |
} |
'''); |
_assertValidForChangedLibrary(a); |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
_assertValidForDependentLibrary(b); |
- _assertInvalid(b, LIBRARY_ERRORS_READY); |
+ _assertValidAllResolution(b); |
+ _assertInvalidHintsVerifyErrors(b); |
+ } |
- _assertValidForDependentLibrary(c); |
- _assertInvalid(c, LIBRARY_ERRORS_READY); |
+ void test_class_private_member() { |
+ Source a = addSource( |
+ '/a.dart', |
+ r''' |
+class A { |
+ A(); |
+ A._privateConstructor(); |
+ |
+ foo() {} |
+ |
+ int _privateField; |
+ _privateMethod() {} |
+ int get _privateGetter => null; |
+ void set _privateSetter(_) {} |
+} |
+'''); |
+ Source b = addSource( |
+ '/b.dart', |
+ r''' |
+import 'a.dart'; |
+main(A a) { |
+ a.foo(); |
+} |
+'''); |
+ _performPendingAnalysisTasks(); |
+ // Update a.dart: rename private members of A |
+ // b.dart is valid, it cannot see these private members. |
+ context.setContents( |
+ a, |
+ r''' |
+class A { |
+ A(); |
+ A._privateConstructor2(); |
+ |
+ foo() {} |
+ |
+ int _privateField2; |
+ _privateMethod2() {} |
+ int get _privateGetter2 => null; |
+ void set _privateSetter2(_) {} |
+} |
+'''); |
+ _assertValidForChangedLibrary(a); |
+ _assertInvalid(a, LIBRARY_ERRORS_READY); |
+ _assertValidForDependentLibrary(b); |
+ _assertValidAllLibraryUnitResults(b); |
+ _assertValid(b, LIBRARY_ERRORS_READY); |
} |
void test_private_class() { |
@@ -3166,8 +3200,8 @@ class A { |
_assertValidForChangedLibrary(a); |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
_assertValidForDependentLibrary(b); |
- _assertInvalid(b, LIBRARY_ERRORS_READY); |
- _assertInvalidUnits(b, RESOLVED_UNIT4); |
+ _assertValidAllResolution(b); |
+ _assertInvalidHintsVerifyErrors(b); |
_performPendingAnalysisTasks(); |
expect(context.getErrors(b).errors, hasLength(1)); |
@@ -3342,8 +3376,8 @@ class B { |
_assertValidForChangedLibrary(a); |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
_assertValidForDependentLibrary(b); |
- _assertInvalid(b, LIBRARY_ERRORS_READY); |
- _assertInvalidUnits(b, RESOLVED_UNIT4); |
+ _assertValidAllResolution(b); |
+ _assertValidAllErrors(b); |
// The a.dart's unit and element are the same. |
{ |
LibrarySpecificUnit target = new LibrarySpecificUnit(a, a); |
@@ -3612,8 +3646,8 @@ main() { |
'''); |
_performPendingAnalysisTasks(); |
// Update a.dart: remove A.m, add A.m2. |
- // b.dart is invalid, because B extends A. |
- // c.dart is invalid, because 'main' references B. |
+ // b.dart has valid resolution, and invalid errors. |
+ // c.dart is invalid, because 'main' references 'm'. |
context.setContents( |
a, |
r''' |
@@ -3625,9 +3659,8 @@ class A { |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
_assertValidForDependentLibrary(b); |
- _assertInvalidLibraryElements(b, LIBRARY_ELEMENT4); |
- _assertInvalidUnits(b, RESOLVED_UNIT4); |
- _assertInvalid(b, LIBRARY_ERRORS_READY); |
+ _assertValidAllResolution(b); |
+ _assertInvalidHintsVerifyErrors(b); |
_assertValidForDependentLibrary(c); |
_assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); |
@@ -3675,12 +3708,9 @@ class A { |
'''); |
_assertInvalid(a, LIBRARY_ERRORS_READY); |
- // TODO(scheglov) In theory b.dart is not affected, because it does not |
- // call A.m, does not override it, etc. |
_assertValidForDependentLibrary(b); |
- _assertInvalidLibraryElements(b, LIBRARY_ELEMENT4); |
- _assertInvalidUnits(b, RESOLVED_UNIT4); |
- _assertInvalid(b, LIBRARY_ERRORS_READY); |
+ _assertValidAllResolution(b); |
+ _assertInvalidHintsVerifyErrors(b); |
_assertValidForDependentLibrary(c); |
_assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); |
@@ -3696,6 +3726,18 @@ class A { |
} |
/** |
+ * Assert that [VERIFY_ERRORS] and other error results that include it, |
+ * are invalid. |
+ */ |
+ void _assertInvalidHintsVerifyErrors(Source unit) { |
+ _assertUnitInvalid(unit, HINTS); |
+ _assertUnitInvalid(unit, VERIFY_ERRORS); |
+ _assertUnitInvalid(unit, LIBRARY_UNIT_ERRORS); |
+ _assertInvalid(unit, DART_ERRORS); |
+ _assertInvalid(unit, LIBRARY_ERRORS_READY); |
+ } |
+ |
+ /** |
* Assert that [LIBRARY_ELEMENT_RESULTS] for [first] and after it are invalid. |
*/ |
void _assertInvalidLibraryElements( |
@@ -3749,6 +3791,18 @@ class A { |
reason: '$descriptor in $target'); |
} |
+ /** |
+ * Assert that all error results for the given [unit] are valid. |
+ */ |
+ void _assertValidAllErrors(Source unit) { |
+ for (ListResultDescriptor<AnalysisError> result in ERROR_SOURCE_RESULTS) { |
+ _assertValid(unit, result); |
+ } |
+ for (ListResultDescriptor<AnalysisError> result in ERROR_UNIT_RESULTS) { |
+ _assertUnitValid(unit, result); |
+ } |
+ } |
+ |
void _assertValidAllLibraryUnitResults(Source source, {Source library}) { |
for (ResultDescriptor<LibraryElement> result in LIBRARY_ELEMENT_RESULTS) { |
_assertValid(source, result); |
@@ -3760,6 +3814,14 @@ class A { |
} |
} |
+ void _assertValidAllResolution(Source unit) { |
+ _assertValidUnits(unit, null); |
+ _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); |
+ _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); |
+ _assertValidTaskResults(unit, ResolveLibraryReferencesTask.DESCRIPTOR); |
+ _assertValidTaskResults(unit, ResolveLibraryTask.DESCRIPTOR); |
+ } |
+ |
void _assertValidForAnyLibrary(Source source) { |
// Source results. |
_assertValidTaskResults(source, ScanDartTask.DESCRIPTOR); |
@@ -3793,6 +3855,18 @@ class A { |
} |
} |
+ void _assertValidUnits(Source unit, ResultDescriptor<CompilationUnit> last, |
+ {Source library}) { |
+ var target = new LibrarySpecificUnit(library ?? unit, unit); |
+ bool foundLast = false; |
+ for (ResultDescriptor<CompilationUnit> result in RESOLVED_UNIT_RESULTS) { |
+ if (!foundLast) { |
+ _assertValid(target, result); |
+ } |
+ foundLast = foundLast || result == last; |
+ } |
+ } |
+ |
void _performPendingAnalysisTasks([int maxTasks = 512]) { |
for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { |
if (i > maxTasks) { |