Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java

Issue 10860012: Add support for metadata annotation syntax (issue 4056) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.DartComment;
14 import com.google.dart.compiler.ast.DartExprStmt; 14 import com.google.dart.compiler.ast.DartExprStmt;
15 import com.google.dart.compiler.ast.DartExpression; 15 import com.google.dart.compiler.ast.DartExpression;
16 import com.google.dart.compiler.ast.DartField; 16 import com.google.dart.compiler.ast.DartField;
17 import com.google.dart.compiler.ast.DartFieldDefinition; 17 import com.google.dart.compiler.ast.DartFieldDefinition;
18 import com.google.dart.compiler.ast.DartFunctionExpression; 18 import com.google.dart.compiler.ast.DartFunctionExpression;
19 import com.google.dart.compiler.ast.DartIdentifier; 19 import com.google.dart.compiler.ast.DartIdentifier;
20 import com.google.dart.compiler.ast.DartIntegerLiteral; 20 import com.google.dart.compiler.ast.DartIntegerLiteral;
21 import com.google.dart.compiler.ast.DartMapLiteral; 21 import com.google.dart.compiler.ast.DartMapLiteral;
22 import com.google.dart.compiler.ast.DartAnnotation;
22 import com.google.dart.compiler.ast.DartMethodDefinition; 23 import com.google.dart.compiler.ast.DartMethodDefinition;
23 import com.google.dart.compiler.ast.DartNode; 24 import com.google.dart.compiler.ast.DartNode;
24 import com.google.dart.compiler.ast.DartPropertyAccess; 25 import com.google.dart.compiler.ast.DartPropertyAccess;
25 import com.google.dart.compiler.ast.DartStatement; 26 import com.google.dart.compiler.ast.DartStatement;
26 import com.google.dart.compiler.ast.DartStringInterpolation; 27 import com.google.dart.compiler.ast.DartStringInterpolation;
27 import com.google.dart.compiler.ast.DartStringLiteral; 28 import com.google.dart.compiler.ast.DartStringLiteral;
28 import com.google.dart.compiler.ast.DartTryStatement; 29 import com.google.dart.compiler.ast.DartTryStatement;
29 import com.google.dart.compiler.ast.DartTypeExpression; 30 import com.google.dart.compiler.ast.DartTypeExpression;
30 import com.google.dart.compiler.ast.DartTypeNode; 31 import com.google.dart.compiler.ast.DartTypeNode;
31 import com.google.dart.compiler.ast.DartUnaryExpression; 32 import com.google.dart.compiler.ast.DartUnaryExpression;
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 "main() {", 922 "main() {",
922 " const v = 1;", 923 " const v = 1;",
923 "}")); 924 "}"));
924 assertNotNull(unit); 925 assertNotNull(unit);
925 DartNode firstNode = unit.getTopLevelNodes().get(0); 926 DartNode firstNode = unit.getTopLevelNodes().get(0);
926 assertTrue(firstNode instanceof DartMethodDefinition); 927 assertTrue(firstNode instanceof DartMethodDefinition);
927 DartStatement statement = ((DartMethodDefinition) firstNode).getFunction().g etBody().getStatements().get(0); 928 DartStatement statement = ((DartMethodDefinition) firstNode).getFunction().g etBody().getStatements().get(0);
928 assertTrue(((DartVariableStatement) statement).getModifiers().isConstant()); 929 assertTrue(((DartVariableStatement) statement).getModifiers().isConstant());
929 } 930 }
930 931
932 public void test_metadata_identifier() {
933 String code = makeCode(
934 "// filler filler filler filler filler filler filler filler filler fille r",
935 "const int annotation = 0;",
936 "class A {",
937 " m0() {}",
938 " @annotation",
939 " m1() {}",
940 "}",
941 "");
942 DartUnit unit = parseUnit(getName() + ".dart", code);
943 DartClass classA = (DartClass) unit.getTopLevelNodes().get(1);
944
945 DartMethodDefinition method0 = (DartMethodDefinition) classA.getMembers().ge t(0);
946 assertEquals("m0", method0.getName().toSource());
947 assertEquals(0, method0.getMetadata().size());
948
949 DartMethodDefinition method1 = (DartMethodDefinition) classA.getMembers().ge t(1);
950 assertEquals("m1", method1.getName().toSource());
951 assertEquals(1, method1.getMetadata().size());
952 DartAnnotation metadata = method1.getMetadata().get(0);
953 assertNotNull(metadata);
954 DartExpression name = metadata.getName();
955 assertTrue(name instanceof DartIdentifier);
956 assertEquals("annotation", name.toSource());
957 assertEquals(0, metadata.getArguments().size());
958 }
959
960 public void test_metadata_constructor() {
961 String code = makeCode(
962 "// filler filler filler filler filler filler filler filler filler fille r",
963 "class A {",
964 " const A();",
965 "}",
966 "",
967 "class B {",
968 " m0() {}",
969 " @A()",
970 " m1() {}",
971 "}",
972 "");
973 DartUnit unit = parseUnit(getName() + ".dart", code);
974 DartClass classB = (DartClass) unit.getTopLevelNodes().get(1);
975
976 DartMethodDefinition method0 = (DartMethodDefinition) classB.getMembers().ge t(0);
977 assertEquals("m0", method0.getName().toSource());
978 assertEquals(0, method0.getMetadata().size());
979
980 DartMethodDefinition method1 = (DartMethodDefinition) classB.getMembers().ge t(1);
981 assertEquals("m1", method1.getName().toSource());
982 assertEquals(1, method1.getMetadata().size());
983 }
984
931 public void test_metadata_deprecated() { 985 public void test_metadata_deprecated() {
932 String code = makeCode( 986 String code = makeCode(
933 "// filler filler filler filler filler filler filler filler filler fille r", 987 "// filler filler filler filler filler filler filler filler filler fille r",
934 "class A {", 988 "class A {",
935 " m0() {}", 989 " m0() {}",
936 " // @deprecated", 990 " // @deprecated",
937 " m1() {}", 991 " m1() {}",
938 "}", 992 "}",
939 ""); 993 "");
940 DartUnit unit = parseUnit(getName() + ".dart", code); 994 DartUnit unit = parseUnit(getName() + ".dart", code);
941 // A 995 // A
942 { 996 {
943 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0); 997 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0);
944 // m0() 998 // m0()
945 { 999 {
946 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(0); 1000 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(0);
947 assertEquals("m0", method.getName().toSource()); 1001 assertEquals("m0", method.getName().toSource());
948 assertEquals(false, method.getMetadata().isDeprecated()); 1002 assertEquals(false, method.getObsoleteMetadata().isDeprecated());
949 } 1003 }
950 // m1() 1004 // m1()
951 { 1005 {
952 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(1); 1006 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(1);
953 assertEquals("m1", method.getName().toSource()); 1007 assertEquals("m1", method.getName().toSource());
954 assertEquals(true, method.getMetadata().isDeprecated()); 1008 assertEquals(true, method.getObsoleteMetadata().isDeprecated());
955 } 1009 }
956 } 1010 }
957 } 1011 }
958 1012
959 public void test_metadata_override() { 1013 public void test_metadata_override() {
960 String code = makeCode( 1014 String code = makeCode(
961 "// filler filler filler filler filler filler filler filler filler fille r", 1015 "// filler filler filler filler filler filler filler filler filler fille r",
962 "class A {", 1016 "class A {",
963 " m0() {}", 1017 " m0() {}",
964 " // @override", 1018 " // @override",
965 " m1() {}", 1019 " m1() {}",
966 " /** Leading DartDoc comment */", 1020 " /** Leading DartDoc comment */",
967 " // @override", 1021 " // @override",
968 " m2() {}", 1022 " m2() {}",
969 " /**", 1023 " /**",
970 " * DartDoc comment", 1024 " * DartDoc comment",
971 " * @override", 1025 " * @override",
972 " */", 1026 " */",
973 " m3() {}", 1027 " m3() {}",
974 "}", 1028 "}",
975 ""); 1029 "");
976 DartUnit unit = parseUnit(getName() + ".dart", code); 1030 DartUnit unit = parseUnit(getName() + ".dart", code);
977 // A 1031 // A
978 { 1032 {
979 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0); 1033 DartClass classA = (DartClass) unit.getTopLevelNodes().get(0);
980 // m0() 1034 // m0()
981 { 1035 {
982 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(0); 1036 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(0);
983 assertEquals("m0", method.getName().toSource()); 1037 assertEquals("m0", method.getName().toSource());
984 assertEquals(false, method.getMetadata().isOverride()); 1038 assertEquals(false, method.getObsoleteMetadata().isOverride());
985 assertNull(method.getDartDoc()); 1039 assertNull(method.getDartDoc());
986 } 1040 }
987 // m1() 1041 // m1()
988 { 1042 {
989 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(1); 1043 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(1);
990 assertEquals("m1", method.getName().toSource()); 1044 assertEquals("m1", method.getName().toSource());
991 assertEquals(true, method.getMetadata().isOverride()); 1045 assertEquals(true, method.getObsoleteMetadata().isOverride());
992 assertNull(method.getDartDoc()); 1046 assertNull(method.getDartDoc());
993 } 1047 }
994 // m2() 1048 // m2()
995 { 1049 {
996 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(2); 1050 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(2);
997 assertEquals("m2", method.getName().toSource()); 1051 assertEquals("m2", method.getName().toSource());
998 assertEquals(true, method.getMetadata().isOverride()); 1052 assertEquals(true, method.getObsoleteMetadata().isOverride());
999 { 1053 {
1000 DartComment dartDoc = method.getDartDoc(); 1054 DartComment dartDoc = method.getDartDoc();
1001 assertNotNull(dartDoc); 1055 assertNotNull(dartDoc);
1002 assertEquals("/** Leading DartDoc comment */", getNodeSource(code, dar tDoc)); 1056 assertEquals("/** Leading DartDoc comment */", getNodeSource(code, dar tDoc));
1003 } 1057 }
1004 } 1058 }
1005 // m3() 1059 // m3()
1006 { 1060 {
1007 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(3); 1061 DartMethodDefinition method = (DartMethodDefinition) classA.getMembers() .get(3);
1008 assertEquals("m3", method.getName().toSource()); 1062 assertEquals("m3", method.getName().toSource());
1009 assertEquals(true, method.getMetadata().isOverride()); 1063 assertEquals(true, method.getObsoleteMetadata().isOverride());
1010 { 1064 {
1011 DartComment dartDoc = method.getDartDoc(); 1065 DartComment dartDoc = method.getDartDoc();
1012 assertNotNull(dartDoc); 1066 assertNotNull(dartDoc);
1013 String commentCode = getNodeSource(code, dartDoc); 1067 String commentCode = getNodeSource(code, dartDoc);
1014 assertTrue(commentCode.contains("DartDoc comment")); 1068 assertTrue(commentCode.contains("DartDoc comment"));
1015 assertTrue(commentCode.contains("@override")); 1069 assertTrue(commentCode.contains("@override"));
1016 } 1070 }
1017 } 1071 }
1018 } 1072 }
1019 } 1073 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 "typedef func(var arg());", 1301 "typedef func(var arg());",
1248 ParserErrorCode.FUNCTION_TYPED_PARAMETER_IS_VAR, 1, 18); 1302 ParserErrorCode.FUNCTION_TYPED_PARAMETER_IS_VAR, 1, 18);
1249 } 1303 }
1250 1304
1251 public void test_finalInFunctionType() throws Exception { 1305 public void test_finalInFunctionType() throws Exception {
1252 parseUnit("phony_var_in_function_type.dart", 1306 parseUnit("phony_var_in_function_type.dart",
1253 "typedef func(final arg());", 1307 "typedef func(final arg());",
1254 ParserErrorCode.FUNCTION_TYPED_PARAMETER_IS_FINAL, 1, 20); 1308 ParserErrorCode.FUNCTION_TYPED_PARAMETER_IS_FINAL, 1, 20);
1255 } 1309 }
1256 } 1310 }
OLDNEW
« no previous file with comments | « compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698