OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 " return a | b;", | 43 " return a | b;", |
44 " }", | 44 " }", |
45 "}"); | 45 "}"); |
46 runProcessor(); | 46 runProcessor(); |
47 assertFormattedSource( | 47 assertFormattedSource( |
48 "class Test {", | 48 "class Test {", |
49 " bool test(bool a, bool b) => javaBooleanOr(a, b);", | 49 " bool test(bool a, bool b) => javaBooleanOr(a, b);", |
50 "}"); | 50 "}"); |
51 } | 51 } |
52 | 52 |
| 53 public void test_Boolean_orEq() throws Exception { |
| 54 translateSingleFile( |
| 55 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 56 "package test;", |
| 57 "public class Test {", |
| 58 " public void test(boolean a, boolean b) {", |
| 59 " a |= b;", |
| 60 " }", |
| 61 "}"); |
| 62 runProcessor(); |
| 63 assertFormattedSource( |
| 64 "class Test {", |
| 65 " void test(bool a, bool b) {", |
| 66 " a = javaBooleanOr(a, b);", |
| 67 " }", |
| 68 "}"); |
| 69 } |
| 70 |
53 public void test_Boolean_TRUE() throws Exception { | 71 public void test_Boolean_TRUE() throws Exception { |
54 translateSingleFile( | 72 translateSingleFile( |
55 "// filler filler filler filler filler filler filler filler filler fille
r", | 73 "// filler filler filler filler filler filler filler filler filler fille
r", |
56 "package test;", | 74 "package test;", |
57 "public class Test {", | 75 "public class Test {", |
58 " public Object testTrue() {", | 76 " public Object testTrue() {", |
59 " return Boolean.TRUE;", | 77 " return Boolean.TRUE;", |
60 " }", | 78 " }", |
61 " public Object testFalse() {", | 79 " public Object testFalse() {", |
62 " return Boolean.FALSE;", | 80 " return Boolean.FALSE;", |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 runProcessor(); | 412 runProcessor(); |
395 assertFormattedSource(// | 413 assertFormattedSource(// |
396 "class Test {", | 414 "class Test {", |
397 " void main(String p) {", | 415 " void main(String p) {", |
398 " int.parse(p);", | 416 " int.parse(p);", |
399 " int.parse(p, radix: 16);", | 417 " int.parse(p, radix: 16);", |
400 " }", | 418 " }", |
401 "}"); | 419 "}"); |
402 } | 420 } |
403 | 421 |
| 422 public void test_Number_intValue() throws Exception { |
| 423 translateSingleFile( |
| 424 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 425 "package test;", |
| 426 "public class Test {", |
| 427 " public int main(Number p) {", |
| 428 " return p.intValue();", |
| 429 " }", |
| 430 "}"); |
| 431 runProcessor(); |
| 432 assertFormattedSource(// |
| 433 "class Test {", |
| 434 " int main(num p) => p.toInt();", |
| 435 "}"); |
| 436 } |
| 437 |
404 public void test_Object_equals() throws Exception { | 438 public void test_Object_equals() throws Exception { |
405 translateSingleFile( | 439 translateSingleFile( |
406 "// filler filler filler filler filler filler filler filler filler fille
r", | 440 "// filler filler filler filler filler filler filler filler filler fille
r", |
407 "package test;", | 441 "package test;", |
408 "public class Test {", | 442 "public class Test {", |
409 " Object o;", | 443 " Object o;", |
410 " public boolean equals(Object o) {", | 444 " public boolean equals(Object o) {", |
411 " return this.equals(o);", | 445 " return this.equals(o);", |
412 " }", | 446 " }", |
413 "}"); | 447 "}"); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 runProcessor(); | 803 runProcessor(); |
770 assertFormattedSource(// | 804 assertFormattedSource(// |
771 "class Test {", | 805 "class Test {", |
772 " void main(String s) {", | 806 " void main(String s) {", |
773 " s.length;", | 807 " s.length;", |
774 " s.isEmpty;", | 808 " s.isEmpty;", |
775 " }", | 809 " }", |
776 "}"); | 810 "}"); |
777 } | 811 } |
778 | 812 |
| 813 public void test_String_plusEqualsChar() throws Exception { |
| 814 translateSingleFile( |
| 815 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 816 "package test;", |
| 817 "public class Test {", |
| 818 " public void test(String s) {", |
| 819 " s += '=';", |
| 820 " }", |
| 821 "}"); |
| 822 runProcessor(); |
| 823 assertFormattedSource(// |
| 824 "class Test {", |
| 825 " void test(String s) {", |
| 826 " s += '=';", |
| 827 " }", |
| 828 "}"); |
| 829 } |
| 830 |
779 public void test_String_replace() throws Exception { | 831 public void test_String_replace() throws Exception { |
780 translateSingleFile( | 832 translateSingleFile( |
781 "// filler filler filler filler filler filler filler filler filler fille
r", | 833 "// filler filler filler filler filler filler filler filler filler fille
r", |
782 "package test;", | 834 "package test;", |
783 "public class Test {", | 835 "public class Test {", |
784 " public String foo(String s, String p, String r) {", | 836 " public String testA(String s, String p, String r) {", |
785 " return s.replace(p, r);", | 837 " return s.replace(p, r);", |
786 " }", | 838 " }", |
| 839 " public String testB(String s, String r) {", |
| 840 " return s.replace('/', r);", |
| 841 " }", |
787 "}"); | 842 "}"); |
788 runProcessor(); | 843 runProcessor(); |
789 assertFormattedSource(// | 844 assertFormattedSource( |
790 "class Test {", | 845 "class Test {", |
791 " String foo(String s, String p, String r) => s.replaceAll(p, r);", | 846 " String testA(String s, String p, String r) => s.replaceAll(p, r);", |
| 847 " String testB(String s, String r) => s.replaceAll('/', r);", |
792 "}"); | 848 "}"); |
793 } | 849 } |
794 | 850 |
795 public void test_String_startsWith() throws Exception { | 851 public void test_String_startsWith() throws Exception { |
796 translateSingleFile( | 852 translateSingleFile( |
797 "// filler filler filler filler filler filler filler filler filler fille
r", | 853 "// filler filler filler filler filler filler filler filler filler fille
r", |
798 "package test;", | 854 "package test;", |
799 "public class Test {", | 855 "public class Test {", |
800 " public boolean main(String s, String prefix, int index) {", | 856 " public boolean main(String s, String prefix, int index) {", |
801 " return s.startsWith(prefix, index);", | 857 " return s.startsWith(prefix, index);", |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 " sb.append(\"abc\");", | 913 " sb.append(\"abc\");", |
858 " sb.append(42);", | 914 " sb.append(42);", |
859 " sb.appendChar(0x30);", | 915 " sb.appendChar(0x30);", |
860 " sb.length;", | 916 " sb.length;", |
861 " sb.length = 0;", | 917 " sb.length = 0;", |
862 " return sb.toString();", | 918 " return sb.toString();", |
863 " }", | 919 " }", |
864 "}"); | 920 "}"); |
865 } | 921 } |
866 | 922 |
| 923 public void test_Throwable_getMessage() throws Exception { |
| 924 translateSingleFile( |
| 925 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 926 "package test;", |
| 927 "public class Test {", |
| 928 " public main(Throwable e) {", |
| 929 " e.getMessage();", |
| 930 " }", |
| 931 "}"); |
| 932 runProcessor(); |
| 933 assertFormattedSource(// |
| 934 "class Test {", |
| 935 " main(Exception e) {", |
| 936 " e.toString();", |
| 937 " }", |
| 938 "}"); |
| 939 } |
| 940 |
867 public void test_Throwable_printStackTrace() throws Exception { | 941 public void test_Throwable_printStackTrace() throws Exception { |
868 translateSingleFile( | 942 translateSingleFile( |
869 "// filler filler filler filler filler filler filler filler filler fille
r", | 943 "// filler filler filler filler filler filler filler filler filler fille
r", |
870 "package test;", | 944 "package test;", |
871 "public class Test {", | 945 "public class Test {", |
872 " public main(Throwable e) {", | 946 " public main(Throwable e) {", |
873 " e.printStackTrace();", | 947 " e.printStackTrace();", |
874 " }", | 948 " }", |
875 "}"); | 949 "}"); |
876 runProcessor(); | 950 runProcessor(); |
877 assertFormattedSource(// | 951 assertFormattedSource(// |
878 "class Test {", | 952 "class Test {", |
879 " main(Exception e) {", | 953 " main(Exception e) {", |
880 " print(e);", | 954 " print(e);", |
881 " }", | 955 " }", |
882 "}"); | 956 "}"); |
883 } | 957 } |
884 | 958 |
885 private void runProcessor() { | 959 private void runProcessor() { |
886 new ObjectSemanticProcessor(context).process(unit); | 960 new ObjectSemanticProcessor(context).process(unit); |
887 } | 961 } |
888 } | 962 } |
OLD | NEW |