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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
diff --git a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
index 18793bf51d4cf66db86c3a338a2ca2f6083b2a33..f4b9ae885943d2a576f95147d72b36046badb335 100644
--- a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
+++ b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
@@ -1397,6 +1397,86 @@ public class SemanticTest extends AbstractSemanticTest {
getFormattedSource(unit));
}
+ public void test_giveUniqueName_variableInitializer_propertyReference() throws Exception {
+ File file = setFileLines(
+ "test/Test.java",
+ toString(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "package test;",
+ "public class Test {",
+ " int getFoo() {return 42;}",
+ " static void main() {",
+ " int foo = getFoo();",
+ " process(foo);",
+ " }",
+ " void process(int x) {}",
+ "}",
+ ""));
+ Context context = new Context();
+ context.addSourceFolder(tmpFolder);
+ context.addSourceFile(file);
+ CompilationUnit unit = context.translate();
+ // convert to properties and run variable checks again
+ new PropertySemanticProcessor(context).process(unit);
+ context.ensureNoVariableNameReferenceFromInitializer(unit);
+ // verify
+ assertEquals(
+ toString(
+ "class Test {",
+ " int get foo => 42;",
+ " static void main() {",
+ " int foo = this.foo;",
+ " process(foo);",
+ " }",
+ " void process(int x) {",
+ " }",
+ "}"),
+ getFormattedSource(unit));
+ }
+
+ public void test_giveUniqueName_variableInitializer_qualifiedReference() throws Exception {
+ File file = setFileLines(
+ "test/Test.java",
+ toString(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "package test;",
+ "public class Test {",
+ " int foo() {return 42;}",
+ " int bar;",
+ " static void mainA() {",
+ " int foo = this.foo();",
+ " process(foo);",
+ " }",
+ " static void mainB() {",
+ " int bar = this.bar;",
+ " process(bar);",
+ " }",
+ " void process(int x) {}",
+ "}",
+ ""));
+ Context context = new Context();
+ context.addSourceFolder(tmpFolder);
+ context.addSourceFile(file);
+ CompilationUnit unit = context.translate();
+ assertEquals(
+ toString(
+ "class Test {",
+ " int foo() => 42;",
+ " int bar = 0;",
+ " static void mainA() {",
+ " int foo = this.foo();",
+ " process(foo);",
+ " }",
+ " static void mainB() {",
+ " int bar = this.bar;",
+ " process(bar);",
+ " }",
+ " void process(int x) {",
+ " }",
+ "}"),
+ getFormattedSource(unit));
+ }
+
public void test_giveUniqueName_withStatic() throws Exception {
setFileLines(
"test/Super.java",

Powered by Google App Engine
This is Rietveld 408576698