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 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 void test_isServerLibrary_html() { | 1456 void test_isServerLibrary_html() { |
1457 Source source = addSource("/test.html", "<html></html>"); | 1457 Source source = addSource("/test.html", "<html></html>"); |
1458 expect(context.isServerLibrary(source), isFalse); | 1458 expect(context.isServerLibrary(source), isFalse); |
1459 } | 1459 } |
1460 | 1460 |
1461 void test_isServerLibrary_unknown() { | 1461 void test_isServerLibrary_unknown() { |
1462 Source source = newSource("/test.dart"); | 1462 Source source = newSource("/test.dart"); |
1463 expect(context.isServerLibrary(source), isFalse); | 1463 expect(context.isServerLibrary(source), isFalse); |
1464 } | 1464 } |
1465 | 1465 |
| 1466 void test_onResultInvalidated_removeSource() { |
| 1467 Source source = addSource('/test.dart', 'main() {}'); |
| 1468 _analyzeAll_assertFinished(); |
| 1469 // listen for changes |
| 1470 bool listenerInvoked = false; |
| 1471 context.onResultChanged(RESOLVED_UNIT).listen((ResultChangedEvent event) { |
| 1472 Source eventSource = event.target.source; |
| 1473 expect(event.wasComputed, isFalse); |
| 1474 expect(event.wasInvalidated, isTrue); |
| 1475 expect(event.descriptor, RESOLVED_UNIT); |
| 1476 expect(eventSource, source); |
| 1477 listenerInvoked = true; |
| 1478 }); |
| 1479 // apply changes |
| 1480 expect(listenerInvoked, false); |
| 1481 context.applyChanges(new ChangeSet()..removedSource(source)); |
| 1482 // verify |
| 1483 expect(listenerInvoked, isTrue); |
| 1484 } |
| 1485 |
| 1486 void test_onResultInvalidated_setContents() { |
| 1487 Source source = addSource('/test.dart', 'main() {}'); |
| 1488 _analyzeAll_assertFinished(); |
| 1489 // listen for changes |
| 1490 bool listenerInvoked = false; |
| 1491 context.onResultChanged(RESOLVED_UNIT).listen((ResultChangedEvent event) { |
| 1492 Source eventSource = event.target.source; |
| 1493 expect(event.wasComputed, isFalse); |
| 1494 expect(event.wasInvalidated, isTrue); |
| 1495 expect(event.descriptor, RESOLVED_UNIT); |
| 1496 expect(eventSource, source); |
| 1497 listenerInvoked = true; |
| 1498 }); |
| 1499 // apply changes |
| 1500 expect(listenerInvoked, false); |
| 1501 context.setContents(source, 'class B {}'); |
| 1502 // verify |
| 1503 expect(listenerInvoked, isTrue); |
| 1504 } |
| 1505 |
1466 void test_parseCompilationUnit_errors() { | 1506 void test_parseCompilationUnit_errors() { |
1467 Source source = addSource("/lib.dart", "library {"); | 1507 Source source = addSource("/lib.dart", "library {"); |
1468 CompilationUnit compilationUnit = context.parseCompilationUnit(source); | 1508 CompilationUnit compilationUnit = context.parseCompilationUnit(source); |
1469 expect(compilationUnit, isNotNull); | 1509 expect(compilationUnit, isNotNull); |
1470 var errorInfo = context.getErrors(source); | 1510 var errorInfo = context.getErrors(source); |
1471 expect(errorInfo, isNotNull); | 1511 expect(errorInfo, isNotNull); |
1472 List<AnalysisError> errors = errorInfo.errors; | 1512 List<AnalysisError> errors = errorInfo.errors; |
1473 expect(errors, isNotNull); | 1513 expect(errors, isNotNull); |
1474 expect(errors.length > 0, isTrue); | 1514 expect(errors.length > 0, isTrue); |
1475 } | 1515 } |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 // while (initialTime == JavaSystem.currentTimeMillis()) { | 1963 // while (initialTime == JavaSystem.currentTimeMillis()) { |
1924 // Thread.sleep(1); | 1964 // Thread.sleep(1); |
1925 // // Force the modification time to be different. | 1965 // // Force the modification time to be different. |
1926 // } | 1966 // } |
1927 // _context.setContents(source, "library test;"); | 1967 // _context.setContents(source, "library test;"); |
1928 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour
ce)); | 1968 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour
ce)); |
1929 // _analyzeAll_assertFinished(); | 1969 // _analyzeAll_assertFinished(); |
1930 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e
lement model", _context.getLibraryElement(source)); | 1970 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e
lement model", _context.getLibraryElement(source)); |
1931 } | 1971 } |
1932 | 1972 |
1933 void test_performAnalysisTask_onResultComputed() { | 1973 void test_performAnalysisTask_onResultChanged() { |
1934 Set<String> libraryElementUris = new Set<String>(); | 1974 Set<String> libraryElementUris = new Set<String>(); |
1935 Set<String> parsedUnitUris = new Set<String>(); | 1975 Set<String> parsedUnitUris = new Set<String>(); |
1936 Set<String> resolvedUnitUris = new Set<String>(); | 1976 Set<String> resolvedUnitUris = new Set<String>(); |
1937 // listen | 1977 // listen |
1938 context.onResultComputed(LIBRARY_ELEMENT).listen((event) { | 1978 context.onResultChanged(LIBRARY_ELEMENT).listen((event) { |
| 1979 expect(event.wasComputed, isTrue); |
| 1980 expect(event.wasInvalidated, isFalse); |
1939 Source librarySource = event.target; | 1981 Source librarySource = event.target; |
1940 libraryElementUris.add(librarySource.uri.toString()); | 1982 libraryElementUris.add(librarySource.uri.toString()); |
1941 }); | 1983 }); |
1942 context.onResultComputed(PARSED_UNIT).listen((event) { | 1984 context.onResultChanged(PARSED_UNIT).listen((event) { |
| 1985 expect(event.wasComputed, isTrue); |
| 1986 expect(event.wasInvalidated, isFalse); |
1943 Source source = event.target; | 1987 Source source = event.target; |
1944 parsedUnitUris.add(source.uri.toString()); | 1988 parsedUnitUris.add(source.uri.toString()); |
1945 }); | 1989 }); |
1946 context.onResultComputed(RESOLVED_UNIT).listen((event) { | 1990 context.onResultChanged(RESOLVED_UNIT).listen((event) { |
| 1991 expect(event.wasComputed, isTrue); |
| 1992 expect(event.wasInvalidated, isFalse); |
1947 LibrarySpecificUnit target = event.target; | 1993 LibrarySpecificUnit target = event.target; |
1948 Source librarySource = target.library; | 1994 Source librarySource = target.library; |
1949 resolvedUnitUris.add(librarySource.uri.toString()); | 1995 resolvedUnitUris.add(librarySource.uri.toString()); |
1950 }); | 1996 }); |
1951 // analyze | 1997 // analyze |
1952 addSource('/test.dart', 'main() {}'); | 1998 addSource('/test.dart', 'main() {}'); |
1953 _analyzeAll_assertFinished(); | 1999 _analyzeAll_assertFinished(); |
1954 // verify | 2000 // verify |
1955 expect(libraryElementUris, contains('file:///test.dart')); | 2001 expect(libraryElementUris, contains('file:///test.dart')); |
1956 expect(parsedUnitUris, contains('file:///test.dart')); | 2002 expect(parsedUnitUris, contains('file:///test.dart')); |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2880 * Initialize the visitor. | 2926 * Initialize the visitor. |
2881 */ | 2927 */ |
2882 _ElementGatherer(); | 2928 _ElementGatherer(); |
2883 | 2929 |
2884 @override | 2930 @override |
2885 void visitElement(Element element) { | 2931 void visitElement(Element element) { |
2886 elements[element] = element; | 2932 elements[element] = element; |
2887 super.visitElement(element); | 2933 super.visitElement(element); |
2888 } | 2934 } |
2889 } | 2935 } |
OLD | NEW |