| OLD | NEW |
| 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 analyzer.test.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2541 _performPendingAnalysisTasks(); | 2541 _performPendingAnalysisTasks(); |
| 2542 expect(context.getErrors(sourceA).errors, hasLength(0)); | 2542 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2543 expect(context.getErrors(sourceB).errors, hasLength(0)); | 2543 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2544 // The a.dart's unit and element are the same. | 2544 // The a.dart's unit and element are the same. |
| 2545 { | 2545 { |
| 2546 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); | 2546 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2547 expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA)); | 2547 expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA)); |
| 2548 expect(unitA.element, same(unitElementA)); | 2548 expect(unitA.element, same(unitElementA)); |
| 2549 expect(unitElementA.library, same(libraryElementA)); | 2549 expect(unitElementA.library, same(libraryElementA)); |
| 2550 } | 2550 } |
| 2551 // Update a.dart, rename A to A2, invalidates b.dart, so | 2551 // Add method to a.dart. This invalidates b.dart, so |
| 2552 // we know that the previous update did not damage dependencies. | 2552 // we know that the previous update did not damage dependencies. |
| 2553 context.setContents( | 2553 context.setContents( |
| 2554 sourceA, | 2554 sourceA, |
| 2555 r''' | 2555 r''' |
| 2556 library lib_a; | 2556 library lib_a; |
| 2557 class A { | 2557 class A { |
| 2558 A(); | 2558 A(); |
| 2559 m() {} | 2559 m() {} |
| 2560 } | 2560 } |
| 2561 class B { | 2561 class B { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2753 '''); | 2753 '''); |
| 2754 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); | 2754 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2755 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); | 2755 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2756 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); | 2756 _assertInvalid(sourceC, LIBRARY_ERRORS_READY); |
| 2757 // No errors, "A.m" exists. | 2757 // No errors, "A.m" exists. |
| 2758 _performPendingAnalysisTasks(); | 2758 _performPendingAnalysisTasks(); |
| 2759 expect(context.getErrors(sourceC).errors, hasLength(0)); | 2759 expect(context.getErrors(sourceC).errors, hasLength(0)); |
| 2760 } | 2760 } |
| 2761 | 2761 |
| 2762 void _assertInvalid(AnalysisTarget target, ResultDescriptor descriptor) { | 2762 void _assertInvalid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 2763 CacheState state = analysisCache.getState(target, descriptor); | 2763 CacheState actual = analysisCache.getState(target, descriptor); |
| 2764 expect(state, CacheState.INVALID); | 2764 if (actual != CacheState.INVALID) { |
| 2765 fail("cache state of $target $descriptor: wanted INVALID, got: $actual"); |
| 2766 } |
| 2765 } | 2767 } |
| 2766 | 2768 |
| 2767 void _assertValid(AnalysisTarget target, ResultDescriptor descriptor) { | 2769 void _assertValid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 2768 CacheState state = analysisCache.getState(target, descriptor); | 2770 CacheState state = analysisCache.getState(target, descriptor); |
| 2769 expect(state, CacheState.VALID); | 2771 expect(state, CacheState.VALID); |
| 2770 } | 2772 } |
| 2771 | 2773 |
| 2772 void _performPendingAnalysisTasks([int maxTasks = 512]) { | 2774 void _performPendingAnalysisTasks([int maxTasks = 512]) { |
| 2773 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { | 2775 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { |
| 2774 if (i > maxTasks) { | 2776 if (i > maxTasks) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 * Initialize the visitor. | 2880 * Initialize the visitor. |
| 2879 */ | 2881 */ |
| 2880 _ElementGatherer(); | 2882 _ElementGatherer(); |
| 2881 | 2883 |
| 2882 @override | 2884 @override |
| 2883 void visitElement(Element element) { | 2885 void visitElement(Element element) { |
| 2884 elements[element] = element; | 2886 elements[element] = element; |
| 2885 super.visitElement(element); | 2887 super.visitElement(element); |
| 2886 } | 2888 } |
| 2887 } | 2889 } |
| OLD | NEW |