Chromium Code Reviews| Index: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/EngineAnnotationProcessorTest.java |
| diff --git a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/EngineAnnotationProcessorTest.java b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/EngineAnnotationProcessorTest.java |
| index ac80676e6d49b8dd4282f699ef5a8f251456660b..2586057ffde569eadd7539c213b5d7ac297203d9 100644 |
| --- a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/EngineAnnotationProcessorTest.java |
| +++ b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/EngineAnnotationProcessorTest.java |
| @@ -32,7 +32,6 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| translateSingleFile( |
| "// filler filler filler filler filler filler filler filler filler filler", |
| "package test;", |
| - "import com.google.dart.engine.utilities.collection.IntList;", |
| "public class Test {", |
| " @DartBlockBody({'if (true) {', ' return 42;', '}', 'return 5;'})", |
| " public int foo() {", |
| @@ -73,7 +72,6 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| translateSingleFile( |
| "// filler filler filler filler filler filler filler filler filler filler", |
| "package test;", |
| - "import com.google.dart.engine.utilities.collection.IntList;", |
| "public class Test {", |
| " @DartExpressionBody('42')", |
| " public int foo() {", |
| @@ -91,18 +89,117 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| "}"); |
| } |
| + public void test_DartName_class() throws Exception { |
| + declareDartName(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "@DartName('NewName')", |
| + "public class Test {", |
| + " public Test(int p) {", |
| + " }", |
| + " public Test create() {", |
| + " return new Test(42);", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class NewName {", |
| + " NewName(int p);", |
| + " NewName create() => new NewName(42);", |
| + "}"); |
| + } |
| + |
| + public void test_DartName_constructor() throws Exception { |
| + declareDartName(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "public class Test {", |
| + " @DartName('forInt')", |
| + " public Test(int p) {", |
| + " }", |
| + " @DartName('forDouble')", |
| + " public Test(double p) {", |
| + " }", |
| + " @DartName()", |
|
Brian Wilkerson
2014/03/09 23:43:15
Do we need to include an annotation to get an unna
scheglov
2014/03/10 01:13:42
No, we don't.
It was a test artefact.
In MainEngin
|
| + " public Test(String p) {", |
| + " }", |
| + " public Test createInt() {", |
| + " return new Test(42);", |
| + " }", |
| + " public Test createDouble() {", |
| + " return new Test(4.2);", |
| + " }", |
| + " public Test createString() {", |
| + " return new Test('abc');", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " Test.forInt(int p);", |
| + " Test.forDouble(double p);", |
| + " Test(String p);", |
| + " Test createInt() => new Test.forInt(42);", |
| + " Test createDouble() => new Test.forDouble(4.2);", |
| + " Test createString() => new Test('abc');", |
| + "}"); |
| + } |
| + |
| + public void test_DartName_field() throws Exception { |
| + declareDartName(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "public class Test {", |
| + " @DartName('_newName')", |
| + " private int foo;", |
| + " public void bar() {", |
| + " foo = 42;", |
| + " print(foo);", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " int _newName = 0;", |
| + " void bar() {", |
| + " _newName = 42;", |
| + " print(_newName);", |
| + " }", |
| + "}"); |
| + } |
| + |
| + public void test_DartName_method() throws Exception { |
| + declareDartName(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "public class Test {", |
| + " @DartName('newName')", |
| + " public void foo() {", |
| + " }", |
| + " public void bar() {", |
| + " foo();", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " void newName() {", |
| + " }", |
| + " void bar() {", |
| + " newName();", |
| + " }", |
| + "}"); |
| + } |
| + |
| public void test_DartOmit_class() throws Exception { |
| - setFileLines( |
| - "test/DartOmit.java", |
| - toString( |
| - "// filler filler filler filler filler filler filler filler filler filler", |
| - "package test;", |
| - "public class DartOmit {", |
| - "}")); |
| + declareDartOmit(); |
| translateSingleFile( |
| "// filler filler filler filler filler filler filler filler filler filler", |
| "package test;", |
| - "import com.google.dart.engine.utilities.collection.IntList;", |
| "public class Test {", |
| " @DartOmit", |
| " class A {", |
| @@ -119,13 +216,7 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| } |
| public void test_DartOmit_field() throws Exception { |
| - setFileLines( |
| - "test/DartOmit.java", |
| - toString( |
| - "// filler filler filler filler filler filler filler filler filler filler", |
| - "package test;", |
| - "public class DartOmit {", |
| - "}")); |
| + declareDartOmit(); |
| translateSingleFile( |
| "// filler filler filler filler filler filler filler filler filler filler", |
| "package test;", |
| @@ -145,13 +236,7 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| } |
| public void test_DartOmit_method() throws Exception { |
| - setFileLines( |
| - "test/DartOmit.java", |
| - toString( |
| - "// filler filler filler filler filler filler filler filler filler filler", |
| - "package test;", |
| - "public class DartOmit {", |
| - "}")); |
| + declareDartOmit(); |
| translateSingleFile( |
| "// filler filler filler filler filler filler filler filler filler filler", |
| "package test;", |
| @@ -171,12 +256,153 @@ public class EngineAnnotationProcessorTest extends SemanticProcessorTest { |
| "}"); |
| } |
| + public void test_DartOptional_method_named() throws Exception { |
| + declareDartOmit(); |
| + declareDartOptional(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import com.google.dart.engine.utilities.collection.IntList;", |
| + "public class Test {", |
| + " @DartOmit", |
| + " public void foo(int a) {", |
| + " foo(a, 42);", |
| + " }", |
| + " public void foo(int a, @DartOptional(defaultValue = '42', kind = ParameterKind.NAMED) int b) {", |
| + " }", |
| + " public void bar() {", |
| + " foo(1);", |
| + " foo(1, 2);", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " void foo(int a, {int b: 42}) {", |
| + " }", |
| + " void bar() {", |
| + " foo(1);", |
| + " foo(1, b: 2);", |
| + " }", |
| + "}"); |
| + } |
| + |
| + public void test_DartOptional_method_positional() throws Exception { |
| + declareDartOmit(); |
| + declareDartOptional(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import com.google.dart.engine.utilities.collection.IntList;", |
| + "public class Test {", |
| + " @DartOmit", |
| + " public void foo(int a) {", |
| + " foo(a, 42);", |
| + " }", |
| + " public void foo(int a, @DartOptional(defaultValue = '42', kind = ParameterKind.POSITIONAL) int b) {", |
| + " }", |
| + " public void bar() {", |
| + " foo(1);", |
| + " foo(1, 2);", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " void foo(int a, [int b = 42]) {", |
| + " }", |
| + " void bar() {", |
| + " foo(1);", |
| + " foo(1, 2);", |
| + " }", |
| + "}"); |
| + } |
| + |
| + public void test_DartOptional_method_positional_byDefault() throws Exception { |
| + declareDartOmit(); |
| + declareDartOptional(); |
| + translateSingleFile( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import com.google.dart.engine.utilities.collection.IntList;", |
| + "public class Test {", |
| + " @DartOmit", |
| + " public void foo(int a) {", |
| + " foo(a, 42);", |
| + " }", |
| + " public void foo(int a, @DartOptional(defaultValue = '42') int b) {", |
| + " }", |
| + " public void bar() {", |
| + " foo(1);", |
| + " foo(1, 2);", |
| + " }", |
| + "}"); |
| + runProcessor(); |
| + assertFormattedSource(// |
| + "class Test {", |
| + " void foo(int a, [int b = 42]) {", |
| + " }", |
| + " void bar() {", |
| + " foo(1);", |
| + " foo(1, 2);", |
| + " }", |
| + "}"); |
| + } |
| + |
| @Override |
| protected void setUp() throws Exception { |
| super.setUp(); |
| replaceSingleQuotes = true; |
| } |
| + private void declareDartName() throws Exception { |
| + setFileLines( |
| + "test/DartName.java", |
| + toString( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import java.lang.annotation.*;", |
| + "@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})", |
| + "public @interface DartOmit {", |
| + " String value();", |
| + "}")); |
| + } |
| + |
| + private void declareDartOmit() throws Exception { |
| + setFileLines( |
| + "test/DartOmit.java", |
| + toString( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import java.lang.annotation.*;", |
| + "@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})", |
| + "public @interface DartOmit {", |
| + "}")); |
| + } |
| + |
| + private void declareDartOptional() throws Exception { |
| + setFileLines( |
| + "test/ParameterKind.java", |
| + toString( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import java.lang.annotation.*;", |
| + "public enum ParameterKind {", |
| + " REQUIRED, POSITIONAL, NAMED;", |
| + "}")); |
| + setFileLines( |
| + "test/DartOptional.java", |
| + toString( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "package test;", |
| + "import java.lang.annotation.*;", |
| + "@Target(ElementType.PARAMETER)", |
| + "public @interface DartOptional {", |
| + " String defaultValue() default '';", |
| + " ParameterKind kind() default ParameterKind.POSITIONAL;", |
| + "}")); |
| + } |
| + |
| private void runProcessor() { |
| new EngineAnnotationProcessor(context).process(unit); |
| } |