| 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 engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/incremental_resolver.dart'; | 10 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
| 11 import 'package:analyzer/src/generated/java_engine.dart'; | 11 import 'package:analyzer/src/generated/java_engine.dart'; |
| 12 import 'package:analyzer/src/generated/resolver.dart'; | 12 import 'package:analyzer/src/generated/resolver.dart'; |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 13 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 14 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 15 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 15 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 17 | 17 |
| 18 import '../reflective_tests.dart'; | 18 import '../reflective_tests.dart'; |
| 19 import 'parser_test.dart'; | 19 import 'parser_test.dart'; |
| 20 import 'resolver_test.dart'; | 20 import 'resolver_test.dart'; |
| 21 import 'test_support.dart'; | 21 import 'test_support.dart'; |
| 22 | 22 |
| 23 | 23 |
| 24 main() { | 24 main() { |
| 25 groupSep = ' | '; | 25 groupSep = ' | '; |
| 26 runReflectiveTests(ScopeBuilderTest); | |
| 27 runReflectiveTests(DeclarationMatcherTest); | 26 runReflectiveTests(DeclarationMatcherTest); |
| 28 runReflectiveTests(IncrementalResolverTest); | 27 runReflectiveTests(IncrementalResolverTest); |
| 28 runReflectiveTests(ScopeBuilderTest); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 class DeclarationMatcherTest extends ResolverTestCase { | 32 class DeclarationMatcherTest extends ResolverTestCase { |
| 33 void test_compilationUnitMatches_false_topLevelVariable() { | 33 void fail_test_methodDeclarationMatches_false_localVariable() { |
| 34 _assertCompilationUnitMatches(false, r''' | 34 // TODO(scheglov) as I understand DeclarationMatcher, we care only |
| 35 // about externally visible model changes. So, because we analyze (at least |
| 36 // right now) incremental changes on method level, local variable can be |
| 37 // ignored. |
| 38 _assertMethodMatches(false, r''' |
| 35 class C { | 39 class C { |
| 36 int m(int p) { | 40 int m(int p) { |
| 37 return p + p; | 41 return p + p; |
| 38 } | 42 } |
| 39 }''', r''' | 43 }''', r''' |
| 40 const int ZERO = 0; | |
| 41 class C { | 44 class C { |
| 42 int m(int p) { | 45 int m(int p) { |
| 43 return p + p; | 46 int product = p * p; |
| 47 return product + product; |
| 44 } | 48 } |
| 45 }'''); | 49 }'''); |
| 46 } | 50 } |
| 47 | 51 |
| 48 void test_compilationUnitMatches_true_different() { | 52 void test_compilationUnitMatches_true_different() { |
| 49 _assertCompilationUnitMatches(true, r''' | 53 _assertCompilationUnitMatches(true, r''' |
| 50 class C { | 54 class C { |
| 51 int m(int p) { | 55 int m(int p) { |
| 52 return p + p; | 56 return p + p; |
| 53 } | 57 } |
| 54 }''', r''' | 58 }''', r''' |
| 55 class C { | 59 class C { |
| 56 int m(int p) { | 60 int m(int p) { |
| 57 return (p * p) + (p * p); | 61 return (p * p) + (p * p); |
| 58 } | 62 } |
| 59 }'''); | 63 }'''); |
| 60 } | 64 } |
| 61 | 65 |
| 62 void test_compilationUnitMatches_true_same() { | 66 void test_compilationUnitMatches_true_same() { |
| 63 String content = r''' | 67 String content = r''' |
| 64 class C { | 68 class C { |
| 65 int m(int p) { | 69 int m(int p) { |
| 66 return p + p; | 70 return p + p; |
| 67 } | 71 } |
| 68 }'''; | 72 }'''; |
| 69 _assertCompilationUnitMatches(true, content, content); | 73 _assertCompilationUnitMatches(true, content, content); |
| 70 } | 74 } |
| 71 | 75 |
| 72 void test_methodDeclarationMatches_false_localVariable() { | 76 void test_false_topLevelVariable_list_add() { |
| 73 _assertMethodMatches(false, r''' | 77 _assertCompilationUnitMatches(false, r''' |
| 74 class C { | 78 const int A = 1; |
| 75 int m(int p) { | 79 const int C = 3; |
| 76 return p + p; | 80 ''', r''' |
| 81 const int A = 1; |
| 82 const int B = 2; |
| 83 const int C = 3; |
| 84 '''); |
| 77 } | 85 } |
| 78 }''', r''' | 86 |
| 79 class C { | 87 void test_false_topLevelVariable_list_remove() { |
| 80 int m(int p) { | 88 _assertCompilationUnitMatches(false, r''' |
| 81 int product = p * p; | 89 const int A = 1; |
| 82 return product + product; | 90 const int B = 2; |
| 91 const int C = 3; |
| 92 ''', r''' |
| 93 const int A = 1; |
| 94 const int C = 3; |
| 95 '''); |
| 83 } | 96 } |
| 84 }'''); | 97 |
| 98 void test_false_topLevelVariable_modifier_isConst() { |
| 99 _assertCompilationUnitMatches(false, r''' |
| 100 final int A = 1; |
| 101 ''', r''' |
| 102 const int A = 1; |
| 103 '''); |
| 104 } |
| 105 |
| 106 void test_false_topLevelVariable_modifier_isFinal() { |
| 107 _assertCompilationUnitMatches(false, r''' |
| 108 int A = 1; |
| 109 ''', r''' |
| 110 final int A = 1; |
| 111 '''); |
| 112 } |
| 113 |
| 114 void test_false_topLevelVariable_modifier_wasConst() { |
| 115 _assertCompilationUnitMatches(false, r''' |
| 116 const int A = 1; |
| 117 ''', r''' |
| 118 final int A = 1; |
| 119 '''); |
| 120 } |
| 121 |
| 122 void test_false_topLevelVariable_modifier_wasFinal() { |
| 123 _assertCompilationUnitMatches(false, r''' |
| 124 final int A = 1; |
| 125 ''', r''' |
| 126 int A = 1; |
| 127 '''); |
| 128 } |
| 129 |
| 130 void test_false_topLevelVariable_type_different() { |
| 131 _assertCompilationUnitMatches(false, r''' |
| 132 int A; |
| 133 ''', r''' |
| 134 String A; |
| 135 '''); |
| 136 } |
| 137 |
| 138 void test_false_topLevelVariable_type_differentArgs() { |
| 139 _assertCompilationUnitMatches(false, r''' |
| 140 List<int> A; |
| 141 ''', r''' |
| 142 List<String> A; |
| 143 '''); |
| 85 } | 144 } |
| 86 | 145 |
| 87 void test_methodDeclarationMatches_false_parameter() { | 146 void test_methodDeclarationMatches_false_parameter() { |
| 88 _assertMethodMatches(false, r''' | 147 _assertMethodMatches(false, r''' |
| 89 class C { | 148 class C { |
| 90 int m(int p) { | 149 int m(int p) { |
| 91 return p + p; | 150 return p + p; |
| 92 } | 151 } |
| 93 }''', r''' | 152 }''', r''' |
| 94 class C { | 153 class C { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 115 void test_methodDeclarationMatches_true_same() { | 174 void test_methodDeclarationMatches_true_same() { |
| 116 String content = r''' | 175 String content = r''' |
| 117 class C { | 176 class C { |
| 118 int m(int p) { | 177 int m(int p) { |
| 119 return p + p; | 178 return p + p; |
| 120 } | 179 } |
| 121 }'''; | 180 }'''; |
| 122 _assertMethodMatches(true, content, content); | 181 _assertMethodMatches(true, content, content); |
| 123 } | 182 } |
| 124 | 183 |
| 184 void test_true_topLevelVariable_list_reorder() { |
| 185 _assertCompilationUnitMatches(true, r''' |
| 186 const int A = 1; |
| 187 const int B = 2; |
| 188 const int C = 3; |
| 189 ''', r''' |
| 190 const int C = 3; |
| 191 const int A = 1; |
| 192 const int B = 2; |
| 193 '''); |
| 194 } |
| 195 |
| 196 void test_true_topLevelVariable_list_same() { |
| 197 _assertCompilationUnitMatches(true, r''' |
| 198 const int A = 1; |
| 199 const int B = 2; |
| 200 const int C = 3; |
| 201 ''', r''' |
| 202 const int A = 1; |
| 203 const int B = 2; |
| 204 const int C = 3; |
| 205 '''); |
| 206 } |
| 207 |
| 208 void test_true_topLevelVariable_type_sameArgs() { |
| 209 _assertCompilationUnitMatches(true, r''' |
| 210 Map<int, String> A; |
| 211 ''', r''' |
| 212 Map<int, String> A; |
| 213 '''); |
| 214 } |
| 215 |
| 125 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, | 216 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, |
| 126 String newContent) { | 217 String newContent) { |
| 127 Source source = addSource(oldContent); | 218 Source source = addSource(oldContent); |
| 128 LibraryElement library = resolve(source); | 219 LibraryElement library = resolve(source); |
| 129 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 220 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 130 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); | 221 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); |
| 131 DeclarationMatcher matcher = new DeclarationMatcher(); | 222 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 132 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); | 223 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); |
| 133 } | 224 } |
| 134 | 225 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 AstFactory.formalParameterList()); | 527 AstFactory.formalParameterList()); |
| 437 classNode.members.add(methodNode); | 528 classNode.members.add(methodNode); |
| 438 MethodElement methodElement = | 529 MethodElement methodElement = |
| 439 ElementFactory.methodElement(methodName, null); | 530 ElementFactory.methodElement(methodName, null); |
| 440 methodNode.name.staticElement = methodElement; | 531 methodNode.name.staticElement = methodElement; |
| 441 (classNode.element as ClassElementImpl).methods = | 532 (classNode.element as ClassElementImpl).methods = |
| 442 <MethodElement>[methodElement]; | 533 <MethodElement>[methodElement]; |
| 443 return methodNode; | 534 return methodNode; |
| 444 } | 535 } |
| 445 } | 536 } |
| OLD | NEW |