OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:uri'; | 5 import 'dart:uri'; |
6 | 6 |
7 import "../../../lib/compiler/implementation/dart2jslib.dart" | 7 import "../../../lib/compiler/implementation/dart2jslib.dart" |
8 hide TreeElementMapping, TreeElements; | 8 hide TreeElementMapping, TreeElements; |
9 import "../../../lib/compiler/implementation/resolution/resolution.dart"; | 9 import "../../../lib/compiler/implementation/resolution/resolution.dart"; |
10 import "../../../lib/compiler/implementation/elements/elements.dart"; | 10 import "../../../lib/compiler/implementation/elements/elements.dart"; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 testTypeVariables() { | 82 testTypeVariables() { |
83 matchResolvedTypes(visitor, text, name, expectedElements) { | 83 matchResolvedTypes(visitor, text, name, expectedElements) { |
84 VariableDefinitions definition = parseStatement(text); | 84 VariableDefinitions definition = parseStatement(text); |
85 visitor.visit(definition.type); | 85 visitor.visit(definition.type); |
86 InterfaceType type = visitor.mapping.getType(definition.type); | 86 InterfaceType type = visitor.mapping.getType(definition.type); |
87 Expect.equals(definition.type.typeArguments.length(), | 87 Expect.equals(definition.type.typeArguments.length(), |
88 length(type.arguments)); | 88 length(type.arguments)); |
89 int index = 0; | 89 int index = 0; |
90 Link<DartType> arguments = type.arguments; | 90 Link<DartType> arguments = type.arguments; |
91 while (!arguments.isEmpty()) { | 91 while (!arguments.isEmpty) { |
92 Expect.equals(true, index < expectedElements.length); | 92 Expect.equals(true, index < expectedElements.length); |
93 Expect.equals(expectedElements[index], arguments.head.element); | 93 Expect.equals(expectedElements[index], arguments.head.element); |
94 index++; | 94 index++; |
95 arguments = arguments.tail; | 95 arguments = arguments.tail; |
96 } | 96 } |
97 Expect.equals(index, expectedElements.length); | 97 Expect.equals(index, expectedElements.length); |
98 } | 98 } |
99 | 99 |
100 MockCompiler compiler = new MockCompiler(); | 100 MockCompiler compiler = new MockCompiler(); |
101 ResolverVisitor visitor = compiler.resolverVisitor(); | 101 ResolverVisitor visitor = compiler.resolverVisitor(); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 compiler = new MockCompiler(); | 429 compiler = new MockCompiler(); |
430 compiler.parseScript("class Foo extends Bar {}"); | 430 compiler.parseScript("class Foo extends Bar {}"); |
431 compiler.parseScript("class Bar {}"); | 431 compiler.parseScript("class Bar {}"); |
432 Map mapping = compiler.resolveStatement("Foo bar;").map; | 432 Map mapping = compiler.resolveStatement("Foo bar;").map; |
433 Expect.equals(2, mapping.length); | 433 Expect.equals(2, mapping.length); |
434 | 434 |
435 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo')); | 435 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo')); |
436 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar')); | 436 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar')); |
437 Expect.equals(barElement.computeType(compiler), | 437 Expect.equals(barElement.computeType(compiler), |
438 fooElement.supertype); | 438 fooElement.supertype); |
439 Expect.isTrue(fooElement.interfaces.isEmpty()); | 439 Expect.isTrue(fooElement.interfaces.isEmpty); |
440 Expect.isTrue(barElement.interfaces.isEmpty()); | 440 Expect.isTrue(barElement.interfaces.isEmpty); |
441 } | 441 } |
442 | 442 |
443 testVarSuperclass() { | 443 testVarSuperclass() { |
444 MockCompiler compiler = new MockCompiler(); | 444 MockCompiler compiler = new MockCompiler(); |
445 compiler.parseScript("class Foo extends var {}"); | 445 compiler.parseScript("class Foo extends var {}"); |
446 compiler.resolveStatement("Foo bar;"); | 446 compiler.resolveStatement("Foo bar;"); |
447 Expect.equals(1, compiler.errors.length); | 447 Expect.equals(1, compiler.errors.length); |
448 Expect.equals( | 448 Expect.equals( |
449 new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['var']), | 449 new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['var']), |
450 compiler.errors[0].message); | 450 compiler.errors[0].message); |
(...skipping 13 matching lines...) Expand all Loading... |
464 // Add the interface to the world and make sure everything is setup correctly. | 464 // Add the interface to the world and make sure everything is setup correctly. |
465 compiler.parseScript("interface Bar {}"); | 465 compiler.parseScript("interface Bar {}"); |
466 | 466 |
467 ResolverVisitor visitor = new ResolverVisitor(compiler, null); | 467 ResolverVisitor visitor = new ResolverVisitor(compiler, null); |
468 compiler.resolveStatement("Foo bar;"); | 468 compiler.resolveStatement("Foo bar;"); |
469 | 469 |
470 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo')); | 470 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo')); |
471 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar')); | 471 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar')); |
472 | 472 |
473 Expect.equals(null, barElement.supertype); | 473 Expect.equals(null, barElement.supertype); |
474 Expect.isTrue(barElement.interfaces.isEmpty()); | 474 Expect.isTrue(barElement.interfaces.isEmpty); |
475 | 475 |
476 Expect.equals(barElement.computeType(compiler), | 476 Expect.equals(barElement.computeType(compiler), |
477 fooElement.interfaces.head); | 477 fooElement.interfaces.head); |
478 Expect.equals(1, length(fooElement.interfaces)); | 478 Expect.equals(1, length(fooElement.interfaces)); |
479 } | 479 } |
480 | 480 |
481 testTwoInterfaces() { | 481 testTwoInterfaces() { |
482 MockCompiler compiler = new MockCompiler(); | 482 MockCompiler compiler = new MockCompiler(); |
483 compiler.parseScript( | 483 compiler.parseScript( |
484 "interface I1 {} interface I2 {} class C implements I1, I2 {}"); | 484 "interface I1 {} interface I2 {} class C implements I1, I2 {}"); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 | 726 |
727 map(ResolverVisitor visitor) { | 727 map(ResolverVisitor visitor) { |
728 TreeElementMapping elements = visitor.mapping; | 728 TreeElementMapping elements = visitor.mapping; |
729 return elements.map; | 729 return elements.map; |
730 } | 730 } |
731 | 731 |
732 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); | 732 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |
733 | 733 |
734 List<String> asSortedStrings(Link link) { | 734 List<String> asSortedStrings(Link link) { |
735 List<String> result = <String>[]; | 735 List<String> result = <String>[]; |
736 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); | 736 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); |
737 result.sort((s1, s2) => s1.compareTo(s2)); | 737 result.sort((s1, s2) => s1.compareTo(s2)); |
738 return result; | 738 return result; |
739 } | 739 } |
740 | 740 |
741 compileScript(String source) { | 741 compileScript(String source) { |
742 Uri uri = new Uri.fromComponents(scheme: 'source'); | 742 Uri uri = new Uri.fromComponents(scheme: 'source'); |
743 MockCompiler compiler = compilerFor(source, uri); | 743 MockCompiler compiler = compilerFor(source, uri); |
744 compiler.runCompiler(uri); | 744 compiler.runCompiler(uri); |
745 return compiler; | 745 return compiler; |
746 } | 746 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 var d = new D(); | 793 var d = new D(); |
794 --d; | 794 --d; |
795 }"""; | 795 }"""; |
796 final compiler = compileScript(script); | 796 final compiler = compileScript(script); |
797 | 797 |
798 checkMemberResolved(compiler, 'A', operatorName('+', false)); | 798 checkMemberResolved(compiler, 'A', operatorName('+', false)); |
799 checkMemberResolved(compiler, 'B', operatorName('+', false)); | 799 checkMemberResolved(compiler, 'B', operatorName('+', false)); |
800 checkMemberResolved(compiler, 'C', operatorName('-', false)); | 800 checkMemberResolved(compiler, 'C', operatorName('-', false)); |
801 checkMemberResolved(compiler, 'D', operatorName('-', false)); | 801 checkMemberResolved(compiler, 'D', operatorName('-', false)); |
802 } | 802 } |
OLD | NEW |