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

Unified Diff: compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java

Issue 9148026: Recompile unit with potential conflict/dependency on some top-level symbol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for compiling corelib, so NPE in TreeShaker 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
Index: compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java
diff --git a/compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java b/compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java
index 14de2a45d8b6d7489880ec87f833dcf7489a2585..0d06d73e87d20c5199caa5d2bb4553401d2cafc1 100644
--- a/compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java
+++ b/compiler/java/com/google/dart/compiler/LibraryDepsVisitor.java
@@ -4,10 +4,7 @@
package com.google.dart.compiler;
-import com.google.dart.compiler.ast.DartClass;
-import com.google.dart.compiler.ast.DartField;
import com.google.dart.compiler.ast.DartIdentifier;
-import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartNodeTraverser;
import com.google.dart.compiler.ast.DartParameterizedTypeNode;
@@ -29,23 +26,17 @@ import java.net.URI;
public class LibraryDepsVisitor extends DartNodeTraverser<Void> {
/**
- * Fill in library dependencies from a compilation unit.
- *
- * @param unit the unit whose dependencies are to be filled in
- * @param deps the target library deps
+ * Fill in {@link LibraryDeps} from a {@link DartUnit}.
*/
- static void exec(DartUnit unit, LibraryDeps deps) {
- LibraryDepsVisitor v = new LibraryDepsVisitor();
+ static void exec(DartUnit unit, LibraryDeps.Source source) {
+ LibraryDepsVisitor v = new LibraryDepsVisitor(source);
unit.accept(v);
-
- String relPath = unit.getSource().getRelativePath();
- deps.setSource(relPath, v.source);
}
- private final LibraryDeps.Source source = new LibraryDeps.Source();
- private DartClass currentClass;
+ private final LibraryDeps.Source source;
- private LibraryDepsVisitor() {
+ private LibraryDepsVisitor(LibraryDeps.Source source) {
+ this.source = source;
}
@Override
@@ -61,7 +52,6 @@ public class LibraryDepsVisitor extends DartNodeTraverser<Void> {
case FIELD:
case METHOD: {
EnclosingElement enclosing = target.getEnclosingElement();
- addHoleIfSuper(node, enclosing);
if (enclosing.getKind().equals(ElementKind.LIBRARY)) {
addElementDependency(target);
}
@@ -107,14 +97,6 @@ public class LibraryDepsVisitor extends DartNodeTraverser<Void> {
}
@Override
- public Void visitClass(DartClass node) {
- currentClass = node;
- node.visitChildren(this);
- currentClass = null;
- return null;
- }
-
- @Override
public Void visitParameterizedTypeNode(DartParameterizedTypeNode node) {
if (TypeKind.of(node.getType()).equals(TypeKind.INTERFACE)) {
addElementDependency(((InterfaceType) node.getType()).getElement());
@@ -133,49 +115,16 @@ public class LibraryDepsVisitor extends DartNodeTraverser<Void> {
}
/**
- * Add a 'hole' for the given identifier, if its declaring class is a superclass of the current
- * class. A 'hole' dependency specifies a name that, if filled by something in the library scope,
- * would require this unit to be recompiled.
- *
- * This situation occurs because names in the library scope bind more strongly than unqualified
- * superclass members.
- */
- private void addHoleIfSuper(DartIdentifier node, Element holder) {
- if (ElementKind.of(holder).equals(ElementKind.CLASS)
- && holder != currentClass.getSymbol()) {
- source.putHole(node.getTargetName());
- }
- }
-
- /**
- * Adds a direct dependency on the given class.
+ * Adds a direct dependency on the unit providing given {@link Element}.
*/
private void addElementDependency(Element elem) {
DartNode node = elem.getNode();
if (node != null) {
- Source nodeSource = node.getSource();
- URI libUri = ((DartSource) nodeSource).getLibrary().getUri();
- LibraryDeps.Dependency dep = new LibraryDeps.Dependency(libUri,
- Integer.toString(node.computeHash()));
-
- String name;
- switch (elem.getKind()) {
- case CLASS:
- name = ((DartClass) node).getClassName();
- break;
- case FIELD:
- name = ((DartField) node).getName().getTargetName();
- break;
- case METHOD:
- DartMethodDefinition method = (DartMethodDefinition) node;
- DartIdentifier ident = (DartIdentifier) method.getName();
- name = ident.getTargetName();
- break;
- default:
- throw new AssertionError("Unexpected top-level node type");
- }
-
- source.putDependency(name, dep);
+ DartSource unitSource = (DartSource) node.getSource();
+ URI libUri = unitSource.getLibrary().getUri();
+ LibraryDeps.Dependency dep =
+ new LibraryDeps.Dependency(libUri, unitSource.getName(), unitSource.getLastModified());
+ source.getDeps().add(dep);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698