OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 Source source = addSource("/test.dart", "library lib;"); | 776 Source source = addSource("/test.dart", "library lib;"); |
777 LibraryElement element = context.getLibraryElement(source); | 777 LibraryElement element = context.getLibraryElement(source); |
778 assertNull(element); | 778 assertNull(element); |
779 context.computeLibraryElement(source); | 779 context.computeLibraryElement(source); |
780 element = context.getLibraryElement(source); | 780 element = context.getLibraryElement(source); |
781 assertNotNull(element); | 781 assertNotNull(element); |
782 } | 782 } |
783 | 783 |
784 public void test_getLibrarySources() { | 784 public void test_getLibrarySources() { |
785 Source[] sources = context.getLibrarySources(); | 785 Source[] sources = context.getLibrarySources(); |
786 assertLength(0, sources); | 786 int originalLength = sources.length; |
787 Source source = addSource("/test.dart", "library lib;"); | 787 Source source = addSource("/test.dart", "library lib;"); |
788 context.computeKindOf(source); | 788 context.computeKindOf(source); |
789 sources = context.getLibrarySources(); | 789 sources = context.getLibrarySources(); |
790 assertLength(1, sources); | 790 assertLength(originalLength + 1, sources); |
791 assertEquals(source, sources[0]); | 791 for (Source returnedSource : sources) { |
| 792 if (returnedSource.equals(source)) { |
| 793 return; |
| 794 } |
| 795 } |
| 796 fail("The added source was not in the list of library sources"); |
792 } | 797 } |
793 | 798 |
794 public void test_getLineInfo() throws Exception { | 799 public void test_getLineInfo() throws Exception { |
795 Source source = addSource("/test.dart", createSource("library lib;", "", "ma
in() {}")); | 800 Source source = addSource("/test.dart", createSource("library lib;", "", "ma
in() {}")); |
796 LineInfo info = context.getLineInfo(source); | 801 LineInfo info = context.getLineInfo(source); |
797 assertNull(info); | 802 assertNull(info); |
798 context.parseCompilationUnit(source); | 803 context.parseCompilationUnit(source); |
799 info = context.getLineInfo(source); | 804 info = context.getLineInfo(source); |
800 assertNotNull(info); | 805 assertNotNull(info); |
801 } | 806 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 assertNotNull(context.getResolvedHtmlUnit(source)); | 896 assertNotNull(context.getResolvedHtmlUnit(source)); |
892 } | 897 } |
893 | 898 |
894 public void test_getSourceFactory() { | 899 public void test_getSourceFactory() { |
895 assertSame(sourceFactory, context.getSourceFactory()); | 900 assertSame(sourceFactory, context.getSourceFactory()); |
896 } | 901 } |
897 | 902 |
898 public void test_getStatistics() { | 903 public void test_getStatistics() { |
899 AnalysisContextStatistics statistics = context.getStatistics(); | 904 AnalysisContextStatistics statistics = context.getStatistics(); |
900 assertNotNull(statistics); | 905 assertNotNull(statistics); |
901 assertLength(0, statistics.getCacheRows()); | 906 // The following lines are fragile. The values depend on the number of libra
ries in the SDK. |
902 assertLength(0, statistics.getExceptions()); | 907 // assertLength(0, statistics.getCacheRows()); |
903 assertLength(0, statistics.getSources()); | 908 // assertLength(0, statistics.getExceptions()); |
| 909 // assertLength(0, statistics.getSources()); |
904 } | 910 } |
905 | 911 |
906 public void test_isClientLibrary_dart() throws Exception { | 912 public void test_isClientLibrary_dart() throws Exception { |
907 context = AnalysisContextFactory.contextWithCore(); | 913 context = AnalysisContextFactory.contextWithCore(); |
908 sourceFactory = context.getSourceFactory(); | 914 sourceFactory = context.getSourceFactory(); |
909 Source source = addSource("/test.dart", createSource("import 'dart:html';",
"", "main() {}")); | 915 Source source = addSource("/test.dart", createSource("import 'dart:html';",
"", "main() {}")); |
910 assertFalse(context.isClientLibrary(source)); | 916 assertFalse(context.isClientLibrary(source)); |
911 assertFalse(context.isServerLibrary(source)); | 917 assertFalse(context.isServerLibrary(source)); |
912 context.computeLibraryElement(source); | 918 context.computeLibraryElement(source); |
913 assertTrue(context.isClientLibrary(source)); | 919 assertTrue(context.isClientLibrary(source)); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 | 1249 |
1244 public void test_resolveCompilationUnit_source() throws Exception { | 1250 public void test_resolveCompilationUnit_source() throws Exception { |
1245 context = AnalysisContextFactory.contextWithCore(); | 1251 context = AnalysisContextFactory.contextWithCore(); |
1246 sourceFactory = context.getSourceFactory(); | 1252 sourceFactory = context.getSourceFactory(); |
1247 Source source = addSource("/lib.dart", "library lib;"); | 1253 Source source = addSource("/lib.dart", "library lib;"); |
1248 CompilationUnit compilationUnit = context.resolveCompilationUnit(source, sou
rce); | 1254 CompilationUnit compilationUnit = context.resolveCompilationUnit(source, sou
rce); |
1249 assertNotNull(compilationUnit); | 1255 assertNotNull(compilationUnit); |
1250 } | 1256 } |
1251 | 1257 |
1252 public void test_resolveCompilationUnit_sourceChangeDuringResolution() throws
Exception { | 1258 public void test_resolveCompilationUnit_sourceChangeDuringResolution() throws
Exception { |
1253 context = new AnalysisContextImpl() { | 1259 context = new AnalysisContextFactory.AnalysisContextForTests() { |
1254 @Override | 1260 @Override |
1255 protected DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibrary
Task task) | 1261 protected DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibrary
Task task) |
1256 throws AnalysisException { | 1262 throws AnalysisException { |
1257 ChangeSet changeSet = new ChangeSet(); | 1263 ChangeSet changeSet = new ChangeSet(); |
1258 changeSet.changedSource(task.getLibrarySource()); | 1264 changeSet.changedSource(task.getLibrarySource()); |
1259 applyChanges(changeSet); | 1265 applyChanges(changeSet); |
1260 return super.recordResolveDartLibraryTaskResults(task); | 1266 return super.recordResolveDartLibraryTaskResults(task); |
1261 } | 1267 } |
1262 }; | 1268 }; |
1263 AnalysisContextFactory.initContextWithCore(context); | 1269 AnalysisContextFactory.initContextWithCore(context); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 } | 1497 } |
1492 ChangeNotice[] notice = context.performAnalysisTask().getChangeNotices(); | 1498 ChangeNotice[] notice = context.performAnalysisTask().getChangeNotices(); |
1493 if (notice != null) { | 1499 if (notice != null) { |
1494 fail("performAnalysisTask failed to terminate after analyzing all sources"
); | 1500 fail("performAnalysisTask failed to terminate after analyzing all sources"
); |
1495 } | 1501 } |
1496 } | 1502 } |
1497 | 1503 |
1498 @Override | 1504 @Override |
1499 protected void tearDown() throws Exception { | 1505 protected void tearDown() throws Exception { |
1500 context = null; | 1506 context = null; |
| 1507 sourceFactory = null; |
1501 super.tearDown(); | 1508 super.tearDown(); |
1502 } | 1509 } |
1503 | 1510 |
1504 private Source addSource(String fileName, String contents) { | 1511 private Source addSource(String fileName, String contents) { |
1505 Source source = new FileBasedSource(createFile(fileName)); | 1512 Source source = new FileBasedSource(createFile(fileName)); |
1506 ChangeSet changeSet = new ChangeSet(); | 1513 ChangeSet changeSet = new ChangeSet(); |
1507 changeSet.addedSource(source); | 1514 changeSet.addedSource(source); |
1508 context.applyChanges(changeSet); | 1515 context.applyChanges(changeSet); |
1509 context.setContents(source, contents); | 1516 context.setContents(source, contents); |
1510 return source; | 1517 return source; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 context.applyChanges(changeSet); | 1595 context.applyChanges(changeSet); |
1589 } | 1596 } |
1590 | 1597 |
1591 private void setIncrementalAnalysisCache(AnalysisContextImpl context2, | 1598 private void setIncrementalAnalysisCache(AnalysisContextImpl context2, |
1592 IncrementalAnalysisCache incrementalCache) throws Exception { | 1599 IncrementalAnalysisCache incrementalCache) throws Exception { |
1593 Field field = AnalysisContextImpl.class.getDeclaredField("incrementalAnalysi
sCache"); | 1600 Field field = AnalysisContextImpl.class.getDeclaredField("incrementalAnalysi
sCache"); |
1594 field.setAccessible(true); | 1601 field.setAccessible(true); |
1595 field.set(context2, incrementalCache); | 1602 field.set(context2, incrementalCache); |
1596 } | 1603 } |
1597 } | 1604 } |
OLD | NEW |