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

Unified Diff: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java

Issue 18010002: Report errors for invalid annotations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
diff --git a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
index ebfd277ffc7884522b3a2742c9d88d375b32c944..33635b792239a415fc0d4f2ab6d27224b94cd685 100644
--- a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
+++ b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
@@ -757,7 +757,21 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
- public void test_constWithNonConstantArgument() throws Exception {
+ public void test_constWithNonConstantArgument_annotation() throws Exception {
+ Source source = addSource(createSource(//
+ "class A {",
+ " const A(int p);",
+ "}",
+ "var v = 42;",
+ "@A(v)",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
+ verify(source);
+ }
+
+ public void test_constWithNonConstantArgument_instanceCreation() throws Exception {
Source source = addSource(createSource(//
"class A {",
" const A(a);",
@@ -1660,6 +1674,95 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_invalidAnnotation_getter() throws Exception {
+ Source source = addSource(createSource(//
+ "get V => 0;",
+ "@V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_importWithPrefix_getter() throws Exception {
+ addSource("/lib.dart", createSource(//
+ "library lib;",
+ "get V => 0;"));
+ Source source = addSource(createSource(//
+ "import 'lib.dart' as p;",
+ "@p.V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_importWithPrefix_notConstantVariable() throws Exception {
+ addSource("/lib.dart", createSource(//
+ "library lib;",
+ "final V = 0;"));
+ Source source = addSource(createSource(//
+ "import 'lib.dart' as p;",
+ "@p.V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocation()
+ throws Exception {
+ addSource("/lib.dart", createSource(//
+ "library lib;",
+ "typedef V();"));
+ Source source = addSource(createSource(//
+ "import 'lib.dart' as p;",
+ "@p.V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_notConstantVariable() throws Exception {
+ Source source = addSource(createSource(//
+ "final V = 0;",
+ "@V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_notVariableOrConstructorInvocation() throws Exception {
+ Source source = addSource(createSource(//
+ "typedef V();",
+ "@V",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
+ public void test_invalidAnnotation_staticMethodReference() throws Exception {
+ Source source = addSource(createSource(//
+ "class A {",
+ " static f() {}",
+ "}",
+ "@A.f",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.INVALID_ANNOTATION);
+ verify(source);
+ }
+
public void test_invalidConstructorName_notEnclosingClassName() throws Exception {
Source source = addSource(createSource(//
"class A {",
@@ -2144,6 +2247,19 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_noAnnotationConstructorArguments() throws Exception {
+ Source source = addSource(createSource(//
+ "class A {",
+ " const A();",
+ "}",
+ "@A",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS);
+ verify(source);
+ }
+
public void test_noDefaultSuperConstructorExplicit() throws Exception {
Source source = addSource(createSource(//
"class A {",
@@ -2178,6 +2294,32 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_nonConstantAnnotationConstructor_named() throws Exception {
+ Source source = addSource(createSource(//
+ "class A {",
+ " A.fromInt() {}",
+ "}",
+ "@A.fromInt()",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR);
+ verify(source);
+ }
+
+ public void test_nonConstantAnnotationConstructor_unnamed() throws Exception {
+ Source source = addSource(createSource(//
+ "class A {",
+ " A() {}",
+ "}",
+ "@A()",
+ "main() {",
+ "}"));
+ resolve(source);
+ assertErrors(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR);
+ verify(source);
+ }
+
public void test_nonConstantDefaultValue_function_named() throws Exception {
Source source = addSource(createSource(//
"int y;",

Powered by Google App Engine
This is Rietveld 408576698