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

Unified Diff: pkg/analyzer2dart/lib/src/tree_shaker.dart

Issue 900403003: Support default constructors in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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: pkg/analyzer2dart/lib/src/tree_shaker.dart
diff --git a/pkg/analyzer2dart/lib/src/tree_shaker.dart b/pkg/analyzer2dart/lib/src/tree_shaker.dart
index 7e765ccf8cdfd7a3a73cd712b6f2f8f4f9cc637a..6b9eaa67a95bd3ca3f7220eed3c28eff85fbe011 100644
--- a/pkg/analyzer2dart/lib/src/tree_shaker.dart
+++ b/pkg/analyzer2dart/lib/src/tree_shaker.dart
@@ -90,7 +90,16 @@ class LocalReachabilityComputer {
// constructor, in which case all we need to do is record the class as
// being instantiated by this method. TODO(paulberry): handle the
// mixin case.
- analysis.instantiates.add(method.enclosingElement);
+ ClassElement instantiatedClass = method.enclosingElement;
+ analysis.instantiates.add(instantiatedClass);
+ if (instantiatedClass.supertype != null) {
+ ClassElement superClass = instantiatedClass.supertype.element;
+ ConstructorElement superConstructor = superClass.unnamedConstructor;
+ if (superConstructor != null) {
+ // TODO(johnniwinther): Register instantiated type and selector.
+ analysis.calls.add(superConstructor);
+ }
+ }
} else {
// This is an executable element with no associated declaration in the
// AST, and it's not a constructor. TODO(paulberry): can this ever
@@ -369,7 +378,18 @@ class TreeShakingVisitor extends SemanticVisitor {
// we don't need to, because the redirected-to constructor will take care
// of that).
if (node.initializers.length != 1 || node.initializers[0] is! RedirectingConstructorInvocation) {
sigurdm 2015/02/10 09:37:56 Long line (was there already)
Johnni Winther 2015/02/10 13:51:57 The analyzer is dog-fooding the formatter so toler
sigurdm 2015/02/10 13:55:31 Acknowledged.
+ ClassElement classElement = node.element.enclosingElement;
analysis.instantiates.add(node.element.enclosingElement);
+ if (!node.initializers.any((i) => i is SuperConstructorInvocation)) {
+ if (classElement.supertype != null) {
+ ClassElement superClass = classElement.supertype.element;
+ ConstructorElement superConstructor = superClass.unnamedConstructor;
+ if (superConstructor != null) {
+ // TODO(johnniwinther): Register instantiated type and selector.
+ analysis.calls.add(superConstructor);
+ }
+ }
+ }
}
} else if (node.redirectedConstructor != null) {
if (node.redirectedConstructor.staticElement == null) {

Powered by Google App Engine
This is Rietveld 408576698