| OLD | NEW | 
|---|
| 1 // Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; | 
| 6 | 6 | 
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; | 
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; | 
| 10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37 @reflectiveTest | 37 @reflectiveTest | 
| 38 class IncrementalResolvedAstGeneratorTest { | 38 class IncrementalResolvedAstGeneratorTest { | 
| 39   static final sdkSummaryUri = Uri.parse('special:sdk_summary'); | 39   static final sdkSummaryUri = Uri.parse('special:sdk_summary'); | 
| 40 | 40 | 
| 41   /// Virtual filesystem for testing. | 41   /// Virtual filesystem for testing. | 
| 42   final fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///')); | 42   final fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///')); | 
| 43 | 43 | 
| 44   /// The object under test. | 44   /// The object under test. | 
| 45   IncrementalResolvedAstGenerator incrementalResolvedAstGenerator; | 45   IncrementalResolvedAstGenerator incrementalResolvedAstGenerator; | 
| 46 | 46 | 
| 47   Future<Map<Uri, ResolvedLibrary>> getInitialProgram(Uri startingUri) async { | 47   Future<Map<Uri, Map<Uri, CompilationUnit>>> getInitialProgram( | 
|  | 48       Uri startingUri) async { | 
| 48     fileSystem.entityForUri(sdkSummaryUri).writeAsBytesSync(_sdkSummary); | 49     fileSystem.entityForUri(sdkSummaryUri).writeAsBytesSync(_sdkSummary); | 
| 49     incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( | 50     incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( | 
| 50         startingUri, | 51         startingUri, | 
| 51         new CompilerOptions() | 52         new CompilerOptions() | 
| 52           ..fileSystem = fileSystem | 53           ..fileSystem = fileSystem | 
| 53           ..chaseDependencies = true | 54           ..chaseDependencies = true | 
| 54           ..sdkSummary = sdkSummaryUri | 55           ..sdkSummary = sdkSummaryUri | 
| 55           ..packagesFileUri = new Uri()); | 56           ..packagesFileUri = new Uri()); | 
| 56     return (await incrementalResolvedAstGenerator.computeDelta()).newState; | 57     return (await incrementalResolvedAstGenerator.computeDelta()).newState; | 
| 57   } | 58   } | 
| 58 | 59 | 
| 59   test_incrementalUpdate_referenceToCore() async { | 60   test_incrementalUpdate_referenceToCore() async { | 
| 60     writeFiles({'/foo.dart': 'main() { print(1); }'}); | 61     writeFiles({'/foo.dart': 'main() { print(1); }'}); | 
| 61     var fooUri = Uri.parse('file:///foo.dart'); | 62     var fooUri = Uri.parse('file:///foo.dart'); | 
| 62     var initialProgram = await getInitialProgram(fooUri); | 63     var initialProgram = await getInitialProgram(fooUri); | 
| 63     expect(initialProgram.keys, unorderedEquals([fooUri])); | 64     expect(initialProgram.keys, unorderedEquals([fooUri])); | 
| 64 | 65 | 
| 65     void _checkMain(CompilationUnit unit, int expectedArgument) { | 66     void _checkMain(CompilationUnit unit, int expectedArgument) { | 
| 66       var mainStatements = _getFunctionStatements(_getFunction(unit, 'main')); | 67       var mainStatements = _getFunctionStatements(_getFunction(unit, 'main')); | 
| 67       expect(mainStatements, hasLength(1)); | 68       expect(mainStatements, hasLength(1)); | 
| 68       _checkPrintLiteralInt(mainStatements[0], expectedArgument); | 69       _checkPrintLiteralInt(mainStatements[0], expectedArgument); | 
| 69     } | 70     } | 
| 70 | 71 | 
| 71     _checkMain(initialProgram[fooUri].definingCompilationUnit, 1); | 72     _checkMain(initialProgram[fooUri][fooUri], 1); | 
| 72     writeFiles({'/foo.dart': 'main() { print(2); }'}); | 73     writeFiles({'/foo.dart': 'main() { print(2); }'}); | 
| 73     // Verify that the file isn't actually reread until invalidate is called. | 74     // Verify that the file isn't actually reread until invalidate is called. | 
| 74     var deltaProgram1 = await incrementalResolvedAstGenerator.computeDelta(); | 75     var deltaProgram1 = await incrementalResolvedAstGenerator.computeDelta(); | 
| 75     // TODO(paulberry): since there is no delta, computeDelta should return an | 76     // TODO(paulberry): since there is no delta, computeDelta should return an | 
| 76     // empty map. | 77     // empty map. | 
| 77     // expect(deltaProgram1.newState, isEmpty); | 78     // expect(deltaProgram1.newState, isEmpty); | 
| 78     expect(deltaProgram1.newState.keys, unorderedEquals([fooUri])); | 79     expect(deltaProgram1.newState.keys, unorderedEquals([fooUri])); | 
| 79     _checkMain(deltaProgram1.newState[fooUri].definingCompilationUnit, 1); | 80     _checkMain(deltaProgram1.newState[fooUri][fooUri], 1); | 
| 80     incrementalResolvedAstGenerator.invalidateAll(); | 81     incrementalResolvedAstGenerator.invalidateAll(); | 
| 81     var deltaProgram2 = await incrementalResolvedAstGenerator.computeDelta(); | 82     var deltaProgram2 = await incrementalResolvedAstGenerator.computeDelta(); | 
| 82     expect(deltaProgram2.newState.keys, unorderedEquals([fooUri])); | 83     expect(deltaProgram2.newState.keys, unorderedEquals([fooUri])); | 
| 83     _checkMain(deltaProgram2.newState[fooUri].definingCompilationUnit, 2); | 84     _checkMain(deltaProgram2.newState[fooUri][fooUri], 2); | 
| 84   } | 85   } | 
| 85 | 86 | 
| 86   test_invalidateAllBeforeInitialProgram() async { | 87   test_invalidateAllBeforeInitialProgram() async { | 
| 87     incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( | 88     incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( | 
| 88         Uri.parse('file:///foo.dart'), | 89         Uri.parse('file:///foo.dart'), | 
| 89         new CompilerOptions() | 90         new CompilerOptions() | 
| 90           ..fileSystem = fileSystem | 91           ..fileSystem = fileSystem | 
| 91           ..chaseDependencies = true | 92           ..chaseDependencies = true | 
| 92           ..packagesFileUri = new Uri()); | 93           ..packagesFileUri = new Uri()); | 
| 93     incrementalResolvedAstGenerator.invalidateAll(); | 94     incrementalResolvedAstGenerator.invalidateAll(); | 
| 94   } | 95   } | 
| 95 | 96 | 
| 96   test_part() async { | 97   test_part() async { | 
| 97     writeFiles({ | 98     writeFiles({ | 
| 98       '/foo.dart': 'library foo; part "bar.dart"; main() { print(1); f(); }', | 99       '/foo.dart': 'library foo; part "bar.dart"; main() { print(1); f(); }', | 
| 99       '/bar.dart': 'part of foo; f() { print(2); }' | 100       '/bar.dart': 'part of foo; f() { print(2); }' | 
| 100     }); | 101     }); | 
| 101     var fooUri = Uri.parse('file:///foo.dart'); | 102     var fooUri = Uri.parse('file:///foo.dart'); | 
| 102     var barUri = Uri.parse('file:///bar.dart'); | 103     var barUri = Uri.parse('file:///bar.dart'); | 
| 103     var initialProgram = await getInitialProgram(fooUri); | 104     var initialProgram = await getInitialProgram(fooUri); | 
| 104     expect(initialProgram.keys, unorderedEquals([fooUri])); | 105     expect(initialProgram.keys, unorderedEquals([fooUri])); | 
| 105     expect(initialProgram[fooUri].partUnits.keys, unorderedEquals([barUri])); | 106     expect(initialProgram[fooUri].keys, unorderedEquals([fooUri, barUri])); | 
| 106     var mainStatements = _getFunctionStatements( | 107     var mainStatements = _getFunctionStatements( | 
| 107         _getFunction(initialProgram[fooUri].definingCompilationUnit, 'main')); | 108         _getFunction(initialProgram[fooUri][fooUri], 'main')); | 
| 108     var fDeclaration = | 109     var fDeclaration = _getFunction(initialProgram[fooUri][barUri], 'f'); | 
| 109         _getFunction(initialProgram[fooUri].partUnits[barUri], 'f'); |  | 
| 110     var fStatements = _getFunctionStatements(fDeclaration); | 110     var fStatements = _getFunctionStatements(fDeclaration); | 
| 111     expect(mainStatements, hasLength(2)); | 111     expect(mainStatements, hasLength(2)); | 
| 112     _checkPrintLiteralInt(mainStatements[0], 1); | 112     _checkPrintLiteralInt(mainStatements[0], 1); | 
| 113     _checkFunctionCall(mainStatements[1], | 113     _checkFunctionCall(mainStatements[1], | 
| 114         resolutionMap.elementDeclaredByFunctionDeclaration(fDeclaration)); | 114         resolutionMap.elementDeclaredByFunctionDeclaration(fDeclaration)); | 
| 115     expect(fStatements, hasLength(1)); | 115     expect(fStatements, hasLength(1)); | 
| 116     _checkPrintLiteralInt(fStatements[0], 2); | 116     _checkPrintLiteralInt(fStatements[0], 2); | 
| 117     // TODO(paulberry): now test incremental updates | 117     // TODO(paulberry): now test incremental updates | 
| 118   } | 118   } | 
| 119 | 119 | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164     } | 164     } | 
| 165     throw fail('No function declaration found with name "$name"'); | 165     throw fail('No function declaration found with name "$name"'); | 
| 166   } | 166   } | 
| 167 | 167 | 
| 168   NodeList<Statement> _getFunctionStatements(FunctionDeclaration function) { | 168   NodeList<Statement> _getFunctionStatements(FunctionDeclaration function) { | 
| 169     var body = function.functionExpression.body; | 169     var body = function.functionExpression.body; | 
| 170     expect(body, new isInstanceOf<BlockFunctionBody>()); | 170     expect(body, new isInstanceOf<BlockFunctionBody>()); | 
| 171     return (body as BlockFunctionBody).block.statements; | 171     return (body as BlockFunctionBody).block.statements; | 
| 172   } | 172   } | 
| 173 } | 173 } | 
| OLD | NEW | 
|---|