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

Side by Side Diff: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java

Issue 16611004: Improve java2dart code style - relax 'don't reference variable name in its initializer'. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, 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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 "class Test extends B {", 1390 "class Test extends B {",
1391 " static int foo() => 42;", 1391 " static int foo() => 42;",
1392 " static void bar() {", 1392 " static void bar() {",
1393 " int foo3 = foo();", 1393 " int foo3 = foo();",
1394 " baz(foo3);", 1394 " baz(foo3);",
1395 " }", 1395 " }",
1396 "}"), 1396 "}"),
1397 getFormattedSource(unit)); 1397 getFormattedSource(unit));
1398 } 1398 }
1399 1399
1400 public void test_giveUniqueName_variableInitializer_propertyReference() throws Exception {
1401 File file = setFileLines(
1402 "test/Test.java",
1403 toString(
1404 "// filler filler filler filler filler filler filler filler filler f iller",
1405 "package test;",
1406 "public class Test {",
1407 " int getFoo() {return 42;}",
1408 " static void main() {",
1409 " int foo = getFoo();",
1410 " process(foo);",
1411 " }",
1412 " void process(int x) {}",
1413 "}",
1414 ""));
1415 Context context = new Context();
1416 context.addSourceFolder(tmpFolder);
1417 context.addSourceFile(file);
1418 CompilationUnit unit = context.translate();
1419 // convert to properties and run variable checks again
1420 new PropertySemanticProcessor(context).process(unit);
1421 context.ensureNoVariableNameReferenceFromInitializer(unit);
1422 // verify
1423 assertEquals(
1424 toString(
1425 "class Test {",
1426 " int get foo => 42;",
1427 " static void main() {",
1428 " int foo = this.foo;",
1429 " process(foo);",
1430 " }",
1431 " void process(int x) {",
1432 " }",
1433 "}"),
1434 getFormattedSource(unit));
1435 }
1436
1437 public void test_giveUniqueName_variableInitializer_qualifiedReference() throw s Exception {
1438 File file = setFileLines(
1439 "test/Test.java",
1440 toString(
1441 "// filler filler filler filler filler filler filler filler filler f iller",
1442 "package test;",
1443 "public class Test {",
1444 " int foo() {return 42;}",
1445 " int bar;",
1446 " static void mainA() {",
1447 " int foo = this.foo();",
1448 " process(foo);",
1449 " }",
1450 " static void mainB() {",
1451 " int bar = this.bar;",
1452 " process(bar);",
1453 " }",
1454 " void process(int x) {}",
1455 "}",
1456 ""));
1457 Context context = new Context();
1458 context.addSourceFolder(tmpFolder);
1459 context.addSourceFile(file);
1460 CompilationUnit unit = context.translate();
1461 assertEquals(
1462 toString(
1463 "class Test {",
1464 " int foo() => 42;",
1465 " int bar = 0;",
1466 " static void mainA() {",
1467 " int foo = this.foo();",
1468 " process(foo);",
1469 " }",
1470 " static void mainB() {",
1471 " int bar = this.bar;",
1472 " process(bar);",
1473 " }",
1474 " void process(int x) {",
1475 " }",
1476 "}"),
1477 getFormattedSource(unit));
1478 }
1479
1400 public void test_giveUniqueName_withStatic() throws Exception { 1480 public void test_giveUniqueName_withStatic() throws Exception {
1401 setFileLines( 1481 setFileLines(
1402 "test/Super.java", 1482 "test/Super.java",
1403 toString( 1483 toString(
1404 "// filler filler filler filler filler filler filler filler filler f iller", 1484 "// filler filler filler filler filler filler filler filler filler f iller",
1405 "package test;", 1485 "package test;",
1406 "public class Super {", 1486 "public class Super {",
1407 " static int add(int a, int b) {return a + b;}", 1487 " static int add(int a, int b) {return a + b;}",
1408 "}", 1488 "}",
1409 "")); 1489 ""));
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 " Test_A(List<int> args) {", 2177 " Test_A(List<int> args) {",
2098 " }", 2178 " }",
2099 "}", 2179 "}",
2100 "class Test_B extends Test_A {", 2180 "class Test_B extends Test_A {",
2101 " Test_B(List<int> args) : super(args) {", 2181 " Test_B(List<int> args) : super(args) {",
2102 " }", 2182 " }",
2103 "}"), 2183 "}"),
2104 getFormattedSource(unit)); 2184 getFormattedSource(unit));
2105 } 2185 }
2106 } 2186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698