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

Unified Diff: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.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
« no previous file with comments | « no previous file | editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java
diff --git a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java
index e46a75aca74ccd5581cccf96fac96e181b78e11e..61f7348baedbaeda4ca264d0667e1f81170e86c9 100644
--- a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java
+++ b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java
@@ -38,6 +38,7 @@ import com.google.dart.engine.ast.ListLiteral;
import com.google.dart.engine.ast.MethodDeclaration;
import com.google.dart.engine.ast.MethodInvocation;
import com.google.dart.engine.ast.NodeList;
+import com.google.dart.engine.ast.PropertyAccess;
import com.google.dart.engine.ast.SimpleIdentifier;
import com.google.dart.engine.ast.SuperConstructorInvocation;
import com.google.dart.engine.ast.ThisExpression;
@@ -276,8 +277,40 @@ public class Context {
@Override
public Void visitSimpleIdentifier(SimpleIdentifier node) {
- hasNameReference |= node.getName().equals(currentVariableName);
- return super.visitSimpleIdentifier(node);
+ if (node.getName().equals(currentVariableName)) {
+ ASTNode parent = node.getParent();
+ // name()
+ if (parent instanceof MethodInvocation) {
+ MethodInvocation invocation = (MethodInvocation) parent;
+ if (invocation.getMethodName() == node) {
+ // name = target.name()
+ if (invocation.getTarget() != null) {
+ return null;
+ }
+ // name = name()
+ hasNameReference = true;
+ return null;
+ }
+ }
+ // name = target.name
+ if (parent instanceof PropertyAccess) {
+ PropertyAccess propertyAccess = (PropertyAccess) parent;
+ if (propertyAccess.getPropertyName() == node && propertyAccess.getTarget() != null) {
+ return null;
+ }
+ }
+ // name = name_whichWasGetMethod_butNowGetter
+ {
+ Object bindingObject = getNodeBinding(node);
+ if (bindingObject instanceof IMethodBinding) {
+ SyntaxTranslator.replaceNode(parent, node, propertyAccess(thisExpression(), node));
+ return null;
+ }
+ }
+ // OK, this is really conflict
+ hasNameReference = true;
+ }
+ return null;
}
@Override
« no previous file with comments | « no previous file | editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698