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

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/Normalizer.java

Issue 9232050: Issue 801. Use actual super constructor with all named or synthetic. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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 | compiler/javatests/com/google/dart/compiler/backend/js/JsConstructorOptTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/backend/js/Normalizer.java
diff --git a/compiler/java/com/google/dart/compiler/backend/js/Normalizer.java b/compiler/java/com/google/dart/compiler/backend/js/Normalizer.java
index 18947a9d5b8cc733ac2e3a07f31225e403fa512f..aca2528973da8e023849206dc7c7fb3058e2b6f3 100644
--- a/compiler/java/com/google/dart/compiler/backend/js/Normalizer.java
+++ b/compiler/java/com/google/dart/compiler/backend/js/Normalizer.java
@@ -737,8 +737,24 @@ public class Normalizer {
if (superLocator.needsSuperInvocation) {
DartSuperConstructorInvocation superInvocation = new DartSuperConstructorInvocation(
new DartIdentifier(""), Collections.<DartExpression>emptyList());
- superInvocation.setSymbol(new SyntheticDefaultConstructorElement(null,
- classElement.getSupertype().getElement(), null));
+ // Set constructor element - actual constructor with all named parameters or synthetic.
+ ConstructorElement superConstructorElement = null;
+ {
+ ClassElement superTypeElement = classElement.getSupertype().getElement();
+ List<ConstructorElement> constructors = superTypeElement.getConstructors();
+ for (ConstructorElement constructor : constructors) {
+ if (hasOnlyNamedParameters(constructor)) {
+ superConstructorElement = constructor;
+ break;
+ }
+ }
+ if (superConstructorElement == null) {
+ superConstructorElement =
+ new SyntheticDefaultConstructorElement(null, superTypeElement, null);
+ }
+ superInvocation.setSymbol(superConstructorElement);
+ }
+ // Add implicit "super" invocation.
nInit.add(new DartInitializer(null, superInvocation));
}
}
@@ -757,6 +773,18 @@ public class Normalizer {
}
}
+ /**
+ * @return <code>true</code> if given constructor has only named (i.e. optional) parameters.
+ */
+ private static boolean hasOnlyNamedParameters(ConstructorElement constructor) {
+ for (VariableElement parameter : constructor.getParameters()) {
+ if (!parameter.isNamed()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private DartExpression normalizeCompoundAssignment(Token operator,
boolean isPostfix,
DartExpression operand1,
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/backend/js/JsConstructorOptTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698