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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
6 | 6 |
7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
8 import com.google.dart.compiler.DartCompilerListener; | 8 import com.google.dart.compiler.DartCompilerListener; |
9 import com.google.dart.compiler.DartSourceTest; | 9 import com.google.dart.compiler.DartSourceTest; |
10 import com.google.dart.compiler.ast.DartArrayLiteral; | 10 import com.google.dart.compiler.ast.DartArrayLiteral; |
11 import com.google.dart.compiler.ast.DartBinaryExpression; | 11 import com.google.dart.compiler.ast.DartBinaryExpression; |
12 import com.google.dart.compiler.ast.DartClass; | 12 import com.google.dart.compiler.ast.DartClass; |
| 13 import com.google.dart.compiler.ast.DartComment; |
13 import com.google.dart.compiler.ast.DartExprStmt; | 14 import com.google.dart.compiler.ast.DartExprStmt; |
14 import com.google.dart.compiler.ast.DartExpression; | 15 import com.google.dart.compiler.ast.DartExpression; |
15 import com.google.dart.compiler.ast.DartField; | 16 import com.google.dart.compiler.ast.DartField; |
16 import com.google.dart.compiler.ast.DartFieldDefinition; | 17 import com.google.dart.compiler.ast.DartFieldDefinition; |
17 import com.google.dart.compiler.ast.DartIdentifier; | 18 import com.google.dart.compiler.ast.DartIdentifier; |
18 import com.google.dart.compiler.ast.DartIntegerLiteral; | 19 import com.google.dart.compiler.ast.DartIntegerLiteral; |
19 import com.google.dart.compiler.ast.DartMapLiteral; | 20 import com.google.dart.compiler.ast.DartMapLiteral; |
20 import com.google.dart.compiler.ast.DartMethodDefinition; | 21 import com.google.dart.compiler.ast.DartMethodDefinition; |
21 import com.google.dart.compiler.ast.DartNode; | 22 import com.google.dart.compiler.ast.DartNode; |
22 import com.google.dart.compiler.ast.DartPropertyAccess; | 23 import com.google.dart.compiler.ast.DartPropertyAccess; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 parseUnitErrors("StringsErrorsNegativeTest.dart", | 177 parseUnitErrors("StringsErrorsNegativeTest.dart", |
177 "Unexpected token 'ILLEGAL'", 7, 13, | 178 "Unexpected token 'ILLEGAL'", 7, 13, |
178 "Unexpected token 'ILLEGAL'", 9, 9, | 179 "Unexpected token 'ILLEGAL'", 9, 9, |
179 "Unexpected token 'ILLEGAL'", 11, 9); | 180 "Unexpected token 'ILLEGAL'", 11, 9); |
180 } | 181 } |
181 | 182 |
182 public void testNullAssign() { | 183 public void testNullAssign() { |
183 String sourceCode = "= 123;"; | 184 String sourceCode = "= 123;"; |
184 try { | 185 try { |
185 DartSourceTest dartSrc = new DartSourceTest(getName(), sourceCode, null); | 186 DartSourceTest dartSrc = new DartSourceTest(getName(), sourceCode, null); |
186 DartScannerParserContext context = | 187 DartParser parser = makeParser(dartSrc, sourceCode, new DartCompilerListen
er.Empty()); |
187 new DartScannerParserContext(dartSrc, sourceCode, new DartCompilerListen
er.Empty()); | |
188 DartParser parser = new DartParser(context); | |
189 parser.parseExpression(); | 188 parser.parseExpression(); |
190 } | 189 } |
191 catch(Exception e) { | 190 catch(Exception e) { |
192 fail("unexpected exception " + e); | 191 fail("unexpected exception " + e); |
193 } | 192 } |
194 } | 193 } |
195 | 194 |
196 public void testFactoryInitializerError() { | 195 public void testFactoryInitializerError() { |
197 parseUnitErrors("FactoryInitializersNegativeTest.dart", | 196 parseUnitErrors("FactoryInitializersNegativeTest.dart", |
198 "Unexpected token ':' (expected '{')", 10, 22, | 197 "Unexpected token ':' (expected '{')", 10, 22, |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 public void testRedirectingConstructorBody() throws Exception { | 795 public void testRedirectingConstructorBody() throws Exception { |
797 parseUnit("phony_test_redirecting_constructor_body.dart", | 796 parseUnit("phony_test_redirecting_constructor_body.dart", |
798 Joiner.on("\n").join( | 797 Joiner.on("\n").join( |
799 "class A {", | 798 "class A {", |
800 " A.c() {}", // OK | 799 " A.c() {}", // OK |
801 " A.d() : this.c();", // OK | 800 " A.d() : this.c();", // OK |
802 " A(): this.b() {}", // body not allowed | 801 " A(): this.b() {}", // body not allowed |
803 "}"), | 802 "}"), |
804 ParserErrorCode.REDIRECTING_CONSTRUCTOR_CANNOT_HAVE_A_BODY, 4, 18); | 803 ParserErrorCode.REDIRECTING_CONSTRUCTOR_CANNOT_HAVE_A_BODY, 4, 18); |
805 } | 804 } |
| 805 public void test_metadata_deprecated() { |
| 806 String code = makeCode( |
| 807 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 808 "class A {", |
| 809 " m0() {}", |
| 810 " // @deprecated", |
| 811 " m1() {}", |
| 812 "}", |
| 813 ""); |
| 814 DartUnit unit = parseUnit(getName() + ".dart", code); |
| 815 // A |
| 816 { |
| 817 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0); |
| 818 // m0() |
| 819 { |
| 820 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(0); |
| 821 assertEquals("m0", method.getName().toSource()); |
| 822 assertEquals(false, method.getMetadata().isDeprecated()); |
| 823 } |
| 824 // m1() |
| 825 { |
| 826 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(1); |
| 827 assertEquals("m1", method.getName().toSource()); |
| 828 assertEquals(true, method.getMetadata().isDeprecated()); |
| 829 } |
| 830 } |
| 831 } |
| 832 |
| 833 public void test_metadata_override() { |
| 834 String code = makeCode( |
| 835 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 836 "class A {", |
| 837 " m0() {}", |
| 838 " // @override", |
| 839 " m1() {}", |
| 840 " /** Leading DartDoc comment */", |
| 841 " // @override", |
| 842 " m2() {}", |
| 843 " /**", |
| 844 " * DartDoc comment", |
| 845 " * @override", |
| 846 " */", |
| 847 " m3() {}", |
| 848 "}", |
| 849 ""); |
| 850 DartUnit unit = parseUnit(getName() + ".dart", code); |
| 851 // A |
| 852 { |
| 853 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0); |
| 854 // m0() |
| 855 { |
| 856 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(0); |
| 857 assertEquals("m0", method.getName().toSource()); |
| 858 assertEquals(false, method.getMetadata().isOverride()); |
| 859 assertNull(method.getDartDoc()); |
| 860 } |
| 861 // m1() |
| 862 { |
| 863 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(1); |
| 864 assertEquals("m1", method.getName().toSource()); |
| 865 assertEquals(true, method.getMetadata().isOverride()); |
| 866 assertNull(method.getDartDoc()); |
| 867 } |
| 868 // m2() |
| 869 { |
| 870 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(2); |
| 871 assertEquals("m2", method.getName().toSource()); |
| 872 assertEquals(true, method.getMetadata().isOverride()); |
| 873 { |
| 874 DartComment dartDoc = method.getDartDoc(); |
| 875 assertNotNull(dartDoc); |
| 876 assertEquals("/** Leading DartDoc comment */", getNodeSource(code, dar
tDoc)); |
| 877 } |
| 878 } |
| 879 // m3() |
| 880 { |
| 881 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers()
.get(3); |
| 882 assertEquals("m3", method.getName().toSource()); |
| 883 assertEquals(true, method.getMetadata().isOverride()); |
| 884 { |
| 885 DartComment dartDoc = method.getDartDoc(); |
| 886 assertNotNull(dartDoc); |
| 887 String commentCode = getNodeSource(code, dartDoc); |
| 888 assertTrue(commentCode.contains("DartDoc comment")); |
| 889 assertTrue(commentCode.contains("@override")); |
| 890 } |
| 891 } |
| 892 } |
| 893 } |
806 } | 894 } |
OLD | NEW |