| Index: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/PropertySemanticProcessorTest.java
|
| diff --git a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/PropertySemanticProcessorTest.java b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/PropertySemanticProcessorTest.java
|
| index 1dca4ac3446b050a1ae53a4423337d4b5b6c9cb7..b7615ee859c111c9b804f173ab9eff4b7f4b3b5c 100644
|
| --- a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/PropertySemanticProcessorTest.java
|
| +++ b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/processor/PropertySemanticProcessorTest.java
|
| @@ -17,7 +17,45 @@ package com.google.dart.java2dart.processor;
|
| * Test for {@link PropertySemanticProcessor}.
|
| */
|
| public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| - public void test_makeProperty_getSet() throws Exception {
|
| + public void test_field_BAD_accessedInConstructorInvocation() throws Exception {
|
| + translateSingleFile(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "package test;",
|
| + "public class Test {",
|
| + " public class Super {",
|
| + " public Super(int bar) {",
|
| + " }",
|
| + " }",
|
| + " public class Sub extends Super {",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| + " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| + " }",
|
| + " public Sub(int foo) {",
|
| + " super(foo + 1);",
|
| + " this.foo = foo;",
|
| + " }",
|
| + " }",
|
| + "}");
|
| + runProcessor();
|
| + assertFormattedSource(
|
| + "class Test {",
|
| + "}",
|
| + "class Test_Super {",
|
| + " Test_Super(int bar);",
|
| + "}",
|
| + "class Test_Sub extends Test_Super {",
|
| + " int foo = 0;",
|
| + " Test_Sub(int foo) : super(foo + 1) {",
|
| + " this.foo = foo;",
|
| + " }",
|
| + "}");
|
| + }
|
| +
|
| + public void test_field_BAD_noSetter_butCannotBeFinal() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| @@ -26,14 +64,10 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| " public int getFoo() {",
|
| " return foo;",
|
| " }",
|
| - " public void setFoo(int v) {",
|
| - " this.foo = v + 1;",
|
| + " public Test(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| - " public void main() {",
|
| - " setFoo(1);",
|
| - " print(getFoo());",
|
| - " this.setFoo(2);",
|
| - " print(this.getFoo());",
|
| + " public Test(boolean bar) {",
|
| " }",
|
| "}");
|
| runProcessor();
|
| @@ -41,193 +75,140 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| "class Test {",
|
| " int _foo = 0;",
|
| " int get foo => _foo;",
|
| - " void set foo(int v) {",
|
| - " this._foo = v + 1;",
|
| - " }",
|
| - " void main() {",
|
| - " foo = 1;",
|
| - " print(foo);",
|
| - " this.foo = 2;",
|
| - " print(this.foo);",
|
| + " Test.con1(int foo) {",
|
| + " this._foo = foo;",
|
| " }",
|
| + " Test.con2(bool bar);",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_isSet() throws Exception {
|
| + public void test_field_BAD_notSameGetterSetterFields() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " private boolean foo;",
|
| - " public boolean isFoo() {",
|
| - " return foo && true;",
|
| + " private int fooA;",
|
| + " private int fooB;",
|
| + " public int getFoo() {",
|
| + " return fooA;",
|
| " }",
|
| - " public void setFoo(boolean v) {",
|
| - " this.foo = v && true;",
|
| - " }",
|
| - " public void main() {",
|
| - " setFoo(true);",
|
| - " print(isFoo());",
|
| - " this.setFoo(false);",
|
| - " print(this.isFoo());",
|
| + " public void setFoo(int foo) {",
|
| + " this.fooB = foo;",
|
| " }",
|
| "}");
|
| runProcessor();
|
| assertFormattedSource(
|
| "class Test {",
|
| - " bool _foo = false;",
|
| - " bool get isFoo => _foo && true;",
|
| - " void set foo(bool v) {",
|
| - " this._foo = v && true;",
|
| - " }",
|
| - " void main() {",
|
| - " foo = true;",
|
| - " print(isFoo);",
|
| - " this.foo = false;",
|
| - " print(this.isFoo);",
|
| + " int _fooA = 0;",
|
| + " int _fooB = 0;",
|
| + " int get foo => _fooA;",
|
| + " void set foo(int foo) {",
|
| + " this._fooB = foo;",
|
| " }",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_justField_getSet() throws Exception {
|
| + public void test_field_BAD_onlySetter() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| " private int foo;",
|
| - " public int getFoo() {",
|
| - " return foo;",
|
| - " }",
|
| - " public void setFoo(int v) {",
|
| - " this.foo = v;",
|
| - " }",
|
| - " public void main() {",
|
| - " setFoo(1);",
|
| - " print(getFoo());",
|
| - " this.setFoo(2);",
|
| - " print(this.getFoo());",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| "}");
|
| runProcessor();
|
| assertFormattedSource(
|
| "class Test {",
|
| - " int foo = 0;",
|
| - " void main() {",
|
| - " foo = 1;",
|
| - " print(foo);",
|
| - " this.foo = 2;",
|
| - " print(this.foo);",
|
| + " int _foo = 0;",
|
| + " void set foo(int foo) {",
|
| + " this._foo = foo;",
|
| " }",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_justField_inherited() throws Exception {
|
| + public void test_field_BAD_overriden_getterSetter() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " static class A {",
|
| - " protected int data;",
|
| - " }",
|
| - " static class B extends A {",
|
| + " public class Super {",
|
| + " private int foo;",
|
| " public int getFoo() {",
|
| - " return data;",
|
| + " return foo;",
|
| + " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| " }",
|
| - " public void main() {",
|
| - " B b = new B();",
|
| - " print(b.getFoo());",
|
| + " public class Sub extends Super {",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| + " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| + " }",
|
| " }",
|
| "}");
|
| runProcessor();
|
| assertFormattedSource(
|
| "class Test {",
|
| - " void main() {",
|
| - " Test_B b = new Test_B();",
|
| - " print(b.foo);",
|
| - " }",
|
| "}",
|
| - "class Test_A {",
|
| - " int _data = 0;",
|
| + "class Test_Super {",
|
| + " int _foo = 0;",
|
| + " int get foo => _foo;",
|
| + " void set foo(int foo) {",
|
| + " this._foo = foo;",
|
| + " }",
|
| "}",
|
| - "class Test_B extends Test_A {",
|
| - " int get foo => _data;",
|
| + "class Test_Sub extends Test_Super {",
|
| + " int foo = 0;",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_justField_onlyGetter_noAssignments() throws Exception {
|
| + public void test_field_BAD_overriden_setter() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " private int foo;",
|
| - " public int getFoo() {",
|
| - " return foo;",
|
| + " public class Super {",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| + " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| + " }",
|
| " }",
|
| - " public void main() {",
|
| - " print(getFoo());",
|
| - " print(this.getFoo());",
|
| + " public class Sub extends Super {",
|
| + " private int foo;",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| + " }",
|
| " }",
|
| "}");
|
| runProcessor();
|
| assertFormattedSource(
|
| "class Test {",
|
| - " final int foo = 0;",
|
| - " void main() {",
|
| - " print(foo);",
|
| - " print(this.foo);",
|
| - " }",
|
| - "}");
|
| - }
|
| -
|
| - public void test_makeProperty_justField_override() throws Exception {
|
| - setFileLines(
|
| - "test/A.java",
|
| - toString(
|
| - "// filler filler filler filler filler filler filler filler filler filler",
|
| - "package test;",
|
| - "public class A {",
|
| - " private int foo;",
|
| - " public int getFoo() {",
|
| - " return foo;",
|
| - " }",
|
| - "}"));
|
| - setFileLines(
|
| - "test/B.java",
|
| - toString(
|
| - "// filler filler filler filler filler filler filler filler filler filler",
|
| - "package test;",
|
| - "public class B extends A {",
|
| - " private int bar;",
|
| - " public int getFoo() {",
|
| - " return bar;",
|
| - " }",
|
| - " public void main() {",
|
| - " print(getFoo());",
|
| - " print(this.getFoo());",
|
| - " }",
|
| - "}"));
|
| - context.addSourceFolder(tmpFolder);
|
| - context.addSourceFiles(tmpFolder);
|
| - // do translate
|
| - unit = context.translate();
|
| - runProcessor();
|
| - assertFormattedSource(
|
| - "class A {",
|
| + "}",
|
| + "class Test_Super {",
|
| " int _foo = 0;",
|
| " int get foo => _foo;",
|
| + " void set foo(int foo) {",
|
| + " this._foo = foo;",
|
| + " }",
|
| "}",
|
| - "class B extends A {",
|
| - " int _bar = 0;",
|
| - " int get foo => _bar;",
|
| - " void main() {",
|
| - " print(foo);",
|
| - " print(this.foo);",
|
| + "class Test_Sub extends Test_Super {",
|
| + " int _foo = 0;",
|
| + " void set foo(int foo) {",
|
| + " this._foo = foo;",
|
| " }",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_justField_updateBinding() throws Exception {
|
| + public void test_field_OK_getter() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| @@ -236,141 +217,119 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| " public int getFoo() {",
|
| " return foo;",
|
| " }",
|
| - " public void setFoo(int v) {",
|
| - " this.foo = v;",
|
| - " }",
|
| - " public void foo() {",
|
| - " }",
|
| - " public void main() {",
|
| - " setFoo(1);",
|
| - " print(getFoo());",
|
| - " this.setFoo(2);",
|
| - " print(this.getFoo());",
|
| - " }",
|
| "}");
|
| runProcessor();
|
| - context.ensureUniqueClassMemberNames(unit);
|
| - assertFormattedSource(
|
| + assertFormattedSource(//
|
| "class Test {",
|
| - " int foo3 = 0;",
|
| - " void foo() {",
|
| + " final int foo = 0;",
|
| + "}");
|
| + }
|
| +
|
| + public void test_field_OK_getter_withConstructor() throws Exception {
|
| + translateSingleFile(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "package test;",
|
| + "public class Test {",
|
| + " private int foo;",
|
| + " public Test(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| - " void main() {",
|
| - " foo3 = 1;",
|
| - " print(foo3);",
|
| - " this.foo3 = 2;",
|
| - " print(this.foo3);",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| " }",
|
| "}");
|
| + runProcessor();
|
| + assertFormattedSource(//
|
| + "class Test {",
|
| + " final int foo;",
|
| + " Test(this.foo);",
|
| + "}");
|
| }
|
|
|
| - public void test_makeProperty_override() throws Exception {
|
| + public void test_field_OK_getterSetter() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " public class Super {",
|
| - " public int getFoo() {",
|
| - " return 0;",
|
| - " }",
|
| - " public void setFoo(int v) {",
|
| - " }",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| " }",
|
| - " public class Sub extends Super {",
|
| - " public int getFoo() {",
|
| - " return 2;",
|
| - " }",
|
| - " public void setFoo(int v2) {",
|
| - " }",
|
| - " public void main() {",
|
| - " setFoo(1);",
|
| - " print(getFoo());",
|
| - " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| "}");
|
| runProcessor();
|
| - assertFormattedSource(
|
| + assertFormattedSource(//
|
| "class Test {",
|
| - "}",
|
| - "class Test_Super {",
|
| - " int get foo => 0;",
|
| - " void set foo(int v) {",
|
| + " int foo = 0;",
|
| + "}");
|
| + }
|
| +
|
| + public void test_field_OK_getterSetter_withConstructor() throws Exception {
|
| + translateSingleFile(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "package test;",
|
| + "public class Test {",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo;",
|
| " }",
|
| - "}",
|
| - "class Test_Sub extends Test_Super {",
|
| - " int get foo => 2;",
|
| - " void set foo(int v2) {",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| - " void main() {",
|
| - " foo = 1;",
|
| - " print(foo);",
|
| + " public Test(int foo) {",
|
| + " this.foo = foo;",
|
| " }",
|
| "}");
|
| + runProcessor();
|
| + assertFormattedSource(//
|
| + "class Test {",
|
| + " int foo = 0;",
|
| + " Test(this.foo);",
|
| + "}");
|
| }
|
|
|
| - public void test_makeProperty_shareGetSetNames() throws Exception {
|
| + public void test_methodGetWithoutName() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " public int getFoo() {",
|
| - " return 0;",
|
| - " }",
|
| - " public void setFoo(int v) {",
|
| + " public boolean get() {",
|
| + " return true;",
|
| " }",
|
| " public void main() {",
|
| - " setFoo(1);",
|
| - " print(getFoo());",
|
| + " print(get());",
|
| " }",
|
| "}");
|
| runProcessor();
|
| - context.ensureUniqueClassMemberNames(unit);
|
| assertFormattedSource(
|
| "class Test {",
|
| - " int get foo => 0;",
|
| - " void set foo(int v) {",
|
| - " }",
|
| + " bool get() => true;",
|
| " void main() {",
|
| - " foo = 1;",
|
| - " print(foo);",
|
| + " print(get());",
|
| " }",
|
| "}");
|
| }
|
|
|
| - public void test_makeProperty_veto() throws Exception {
|
| + public void test_methodSetWithoutName() throws Exception {
|
| translateSingleFile(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| "package test;",
|
| "public class Test {",
|
| - " private boolean foo;",
|
| - " public boolean isFoo() {",
|
| - " return foo;",
|
| - " }",
|
| - " public void setFoo(boolean v) {",
|
| - " this.foo = v;",
|
| + " public void set(int v) {",
|
| " }",
|
| " public void main() {",
|
| - " setFoo(true);",
|
| - " print(isFoo());",
|
| - " this.setFoo(false);",
|
| - " print(this.isFoo());",
|
| + " set(0);",
|
| " }",
|
| "}");
|
| - context.addNotProperty("Ltest/Test;.isFoo()");
|
| - context.addNotProperty("Ltest/Test;.setFoo(Z)");
|
| runProcessor();
|
| assertFormattedSource(
|
| "class Test {",
|
| - " bool _foo = false;",
|
| - " bool isFoo() => _foo;",
|
| - " void setFoo(bool v) {",
|
| - " this._foo = v;",
|
| + " void set(int v) {",
|
| " }",
|
| " void main() {",
|
| - " setFoo(true);",
|
| - " print(isFoo());",
|
| - " this.setFoo(false);",
|
| - " print(this.isFoo());",
|
| + " set(0);",
|
| " }",
|
| "}");
|
| }
|
| @@ -402,8 +361,8 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| " public int getFoo() {",
|
| " return foo - 1;",
|
| " }",
|
| - " public int setFoo(int v) {",
|
| - " this.foo = v + 1;",
|
| + " public int setFoo(int foo) {",
|
| + " this.foo = foo + 1;",
|
| " return 42;",
|
| " }",
|
| " public void main() {",
|
| @@ -416,8 +375,8 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| "class Test {",
|
| " int _foo = 0;",
|
| " int get foo => _foo - 1;",
|
| - " int setFoo(int v) {",
|
| - " this._foo = v + 1;",
|
| + " int setFoo(int foo) {",
|
| + " this._foo = foo + 1;",
|
| " return 42;",
|
| " }",
|
| " void main() {",
|
| @@ -427,6 +386,82 @@ public class PropertySemanticProcessorTest extends SemanticProcessorTest {
|
| "}");
|
| }
|
|
|
| + public void test_shareGetSetNames() throws Exception {
|
| + translateSingleFile(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "package test;",
|
| + "public class Test {",
|
| + " private int onlyBasicGettersSetters;",
|
| + " private int foo;",
|
| + " public int getFoo() {",
|
| + " return foo - 1;",
|
| + " }",
|
| + " public void setFoo(int foo) {",
|
| + " this.foo = foo + 1;",
|
| + " }",
|
| + " public void main() {",
|
| + " setFoo(1);",
|
| + " print(getFoo());",
|
| + " this.setFoo(2);",
|
| + " print(this.getFoo());",
|
| + " }",
|
| + "}");
|
| + runProcessor();
|
| + context.ensureUniqueClassMemberNames(unit);
|
| + assertFormattedSource(
|
| + "class Test {",
|
| + " int _foo = 0;",
|
| + " int get foo => _foo - 1;",
|
| + " void set foo(int foo) {",
|
| + " this._foo = foo + 1;",
|
| + " }",
|
| + " void main() {",
|
| + " foo = 1;",
|
| + " print(foo);",
|
| + " this.foo = 2;",
|
| + " print(this.foo);",
|
| + " }",
|
| + "}");
|
| + }
|
| +
|
| + public void test_veto() throws Exception {
|
| + translateSingleFile(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "package test;",
|
| + "public class Test {",
|
| + " private boolean foo;",
|
| + " public boolean isFoo() {",
|
| + " return foo;",
|
| + " }",
|
| + " public void setFoo(boolean v) {",
|
| + " this.foo = v;",
|
| + " }",
|
| + " public void main() {",
|
| + " setFoo(true);",
|
| + " print(isFoo());",
|
| + " this.setFoo(false);",
|
| + " print(this.isFoo());",
|
| + " }",
|
| + "}");
|
| + context.addNotProperty("Ltest/Test;.isFoo()");
|
| + context.addNotProperty("Ltest/Test;.setFoo(Z)");
|
| + runProcessor();
|
| + assertFormattedSource(
|
| + "class Test {",
|
| + " bool _foo = false;",
|
| + " bool isFoo() => _foo;",
|
| + " void setFoo(bool v) {",
|
| + " this._foo = v;",
|
| + " }",
|
| + " void main() {",
|
| + " setFoo(true);",
|
| + " print(isFoo());",
|
| + " this.setFoo(false);",
|
| + " print(this.isFoo());",
|
| + " }",
|
| + "}");
|
| + }
|
| +
|
| private void runProcessor() {
|
| new PropertySemanticProcessor(context).process(unit);
|
| }
|
|
|