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

Unified Diff: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java

Issue 18129004: Simplify constructors translation, improve code style. (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/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 b517f84ce1e456667cbda88e9fa524f14a50d847..f56567d3ab75dc32d932050c4d70e9937acff199 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
@@ -40,6 +40,7 @@ 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.RedirectingConstructorInvocation;
import com.google.dart.engine.ast.SimpleIdentifier;
import com.google.dart.engine.ast.SuperConstructorInvocation;
import com.google.dart.engine.ast.ThisExpression;
@@ -50,6 +51,7 @@ import com.google.dart.engine.ast.visitor.RecursiveASTVisitor;
import com.google.dart.engine.scanner.Keyword;
import com.google.dart.engine.scanner.KeywordToken;
import com.google.dart.engine.scanner.TokenType;
+import com.google.dart.java2dart.processor.ConstructorSemanticProcessor;
import com.google.dart.java2dart.util.Bindings;
import com.google.dart.java2dart.util.JavaUtils;
@@ -93,13 +95,13 @@ public class Context {
/**
* Information about constructor and its usages.
*/
- class ConstructorDescription {
+ public static class ConstructorDescription {
final IMethodBinding binding;
- final List<SuperConstructorInvocation> superInvocations = Lists.newArrayList();
- final List<InstanceCreationExpression> instanceCreations = Lists.newArrayList();
- final List<SimpleIdentifier> implInvocations = Lists.newArrayList();
+ public final List<RedirectingConstructorInvocation> redirectingInvocations = Lists.newArrayList();
+ public final List<SuperConstructorInvocation> superInvocations = Lists.newArrayList();
+ public final List<InstanceCreationExpression> instanceCreations = Lists.newArrayList();
+ public boolean isEnum;
String declName;
- String implName;
public ConstructorDescription(IMethodBinding binding) {
this.binding = binding;
@@ -548,6 +550,18 @@ public class Context {
return anonymousDeclarations.get(creation);
}
+ /**
+ * @return the not <code>null</code> {@link ConstructorDescription}, may be just added.
+ */
+ public ConstructorDescription getConstructorDescription(IMethodBinding binding) {
+ ConstructorDescription description = bindingToConstructor.get(binding);
+ if (description == null) {
+ description = new ConstructorDescription(binding);
+ bindingToConstructor.put(binding, description);
+ }
+ return description;
+ }
+
public Map<File, List<CompilationUnitMember>> getFileToMembers() {
return fileToMembers;
}
@@ -611,11 +625,11 @@ public class Context {
// update references
ConstructorDescription constructorDescription = bindingToConstructor.get(binding);
if (constructorDescription != null) {
- // set name in InstanceCreationExpression
+ // set name in RedirectingConstructorInvocation
{
- List<InstanceCreationExpression> creations = constructorDescription.instanceCreations;
- for (InstanceCreationExpression creation : creations) {
- creation.getConstructorName().setName(newIdentifier);
+ List<RedirectingConstructorInvocation> invocations = constructorDescription.redirectingInvocations;
+ for (RedirectingConstructorInvocation invocation : invocations) {
+ invocation.setConstructorName(newIdentifier);
}
}
// set name in SuperConstructorInvocation
@@ -625,11 +639,11 @@ public class Context {
invocation.setConstructorName(newIdentifier);
}
}
- // set name in invocation of implementation
+ // set name in InstanceCreationExpression
{
- List<SimpleIdentifier> invocations = constructorDescription.implInvocations;
- for (SimpleIdentifier identifier : invocations) {
- identifier.setToken(token(TokenType.IDENTIFIER, constructorDescription.implName));
+ List<InstanceCreationExpression> creations = constructorDescription.instanceCreations;
+ for (InstanceCreationExpression creation : creations) {
+ creation.getConstructorName().setName(newIdentifier);
}
}
}
@@ -674,6 +688,7 @@ public class Context {
ensureUniqueClassMemberNames(dartUniverse);
ensureNoVariableNameReferenceFromInitializer(dartUniverse);
ensureMethodParameterDoesNotHide(dartUniverse);
+ new ConstructorSemanticProcessor(this).process(dartUniverse);
renameConstructors(dartUniverse);
}
// done
@@ -702,18 +717,6 @@ public class Context {
}
/**
- * @return the not <code>null</code> {@link ConstructorDescription}, may be just added.
- */
- ConstructorDescription getConstructorDescription(IMethodBinding binding) {
- ConstructorDescription description = bindingToConstructor.get(binding);
- if (description == null) {
- description = new ConstructorDescription(binding);
- bindingToConstructor.put(binding, description);
- }
- return description;
- }
-
- /**
* Remembers artificial {@link ClassDeclaration} created for Java creation of anonymous class
* declaration.
*/
@@ -832,29 +835,17 @@ public class Context {
if (thisInitializers.isEmpty()) {
return;
}
- ConstructorDeclaration singleConstructor = null;
- boolean hasImpl = false;
+ boolean hasConstructor = false;
for (ClassMember classMember : classDeclaration.getMembers()) {
if (classMember instanceof ConstructorDeclaration) {
- singleConstructor = (ConstructorDeclaration) classMember;
+ ConstructorDeclaration constructor = (ConstructorDeclaration) classMember;
+ hasConstructor = true;
+ Block block = ((BlockFunctionBody) constructor.getBody()).getBlock();
+ addAssignmentsToBlock(block, thisInitializers);
}
- if (classMember instanceof MethodDeclaration) {
- MethodDeclaration method = (MethodDeclaration) classMember;
- String methodName = method.getName().getName();
- if (methodName.startsWith("_jtd_constructor_") && methodName.endsWith("_impl")) {
- hasImpl = true;
- Block block = ((BlockFunctionBody) method.getBody()).getBlock();
- addAssignmentsToBlock(block, thisInitializers);
- }
- }
- }
- // no "_impl", add assignments to the single constructor
- if (!hasImpl && singleConstructor != null) {
- Block block = ((BlockFunctionBody) singleConstructor.getBody()).getBlock();
- addAssignmentsToBlock(block, thisInitializers);
}
- // no "_impl", generate default constructor
- if (singleConstructor == null) {
+ // no constructors, generate default constructor
+ if (!hasConstructor) {
Block block = block();
addAssignmentsToBlock(block, thisInitializers);
ConstructorDeclaration constructor = constructorDeclaration(

Powered by Google App Engine
This is Rietveld 408576698