Reviewers: zundel,
Message:
small review
Description:
Report errors cleanly and don't blow up.
Please review this at http://gwt-code-reviews.appspot.com/1451814/
Affected files:
M dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
Index: dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
b/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
index
b29358a91a76a720fde053f122ad21a0e5300be1..641964673fbf83ffbcf642ffb7e8a4c4e9bc2c37
100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
@@ -17,6 +17,7 @@ package com.google.gwt.dev.jjs.impl;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.javac.CompilationProblemReporter;
import com.google.gwt.dev.javac.CompilationUnit;
import com.google.gwt.dev.javac.CompiledClass;
import com.google.gwt.dev.jdt.RebindPermutationOracle;
@@ -189,7 +190,7 @@ public class UnifyAst {
@Override
public void endVisit(JExpression x, Context ctx) {
- assert !x.getType().isExternal();
+ assert !x.getType().isExternal() || errorsFound;
}
@Override
@@ -226,7 +227,10 @@ public class UnifyAst {
public void endVisit(JMethodCall x, Context ctx) {
// Already resolved during visit().
JMethod target = x.getTarget();
- assert !target.isExternal();
+ if (target.isExternal()) {
+ assert errorsFound;
+ return;
+ }
if (magicMethodCalls.contains(target)) {
JExpression result = handleMagicMethodCall(x);
if (result == null) {
@@ -463,6 +467,7 @@ public class UnifyAst {
private final Map<String, CompiledClass> classFileMap;
private boolean errorsFound = false;
+ private final Set<CompilationUnit> failedUnits = new
IdentityHashSet<CompilationUnit>();
private final Map<String, JField> fieldMap = new HashMap<String,
JField>();
/**
@@ -518,7 +523,7 @@ public class UnifyAst {
}
assimilateUnit(cc.getUnit());
type = program.getFromTypeMap(sourceTypeName);
- assert type != null;
+ assert type != null || errorsFound;
}
}
}
@@ -650,8 +655,16 @@ public class UnifyAst {
}
private void assimilateUnit(CompilationUnit unit) {
- // TODO: error checking.
+ if (unit.isError()) {
+ if (failedUnits.add(unit)) {
+ CompilationProblemReporter.reportErrors(logger, unit, false);
+ errorsFound = true;
+ }
+ return;
+ }
+ // TODO(zundel): ask for a recompile if deserialization fails?
List<JDeclaredType> types = unit.getTypes();
+ assert containsAllTypes(unit, types);
for (JDeclaredType t : types) {
program.addType(t);
}
@@ -712,6 +725,19 @@ public class UnifyAst {
}
}
+ private boolean containsAllTypes(CompilationUnit unit,
List<JDeclaredType> types) {
+ Set<String> binaryTypeNames = new HashSet<String>();
+ for (JDeclaredType type : types) {
+ binaryTypeNames.add(type.getName());
+ }
+ for (CompiledClass cc : unit.getCompiledClasses()) {
+ if
(!binaryTypeNames.contains(InternalName.toBinaryName(cc.getInternalName())))
{
+ return false;
+ }
+ }
+ return true;
+ }
+
private void error(JNode x, String errorMessage) {
errorsFound = true;
TreeLogger branch =
@@ -730,7 +756,11 @@ public class UnifyAst {
}
private void flowInto(JField field) {
- if (field == JField.NULL_FIELD || field.isExternal()) {
+ if (field.isExternal()) {
+ assert errorsFound;
+ return;
+ }
+ if (field == JField.NULL_FIELD) {
return;
}
if (!liveFieldsAndMethods.contains(field)) {
@@ -743,7 +773,11 @@ public class UnifyAst {
}
private void flowInto(JMethod method) {
- if (method == JMethod.NULL_METHOD || method.isExternal()) {
+ if (method.isExternal()) {
+ assert errorsFound;
+ return;
+ }
+ if (method == JMethod.NULL_METHOD) {
return;
}
if (!liveFieldsAndMethods.contains(method)) {
@@ -794,7 +828,10 @@ public class UnifyAst {
}
private void instantiate(JDeclaredType type) {
- assert !type.isExternal();
+ if (type.isExternal()) {
+ assert errorsFound;
+ return;
+ }
if (!instantiatedTypes.contains(type)) {
instantiatedTypes.add(type);
if (type.getSuperClass() != null) {
@@ -909,13 +946,16 @@ public class UnifyAst {
}
assimilateUnit(cc.getUnit());
type = program.getFromTypeMap(binaryTypeName);
+ assert type != null || errorsFound;
}
return type;
}
private void staticInitialize(JDeclaredType type) {
- // Make sure the type is already resolved.
- assert !type.isExternal();
+ if (type.isExternal()) {
+ assert errorsFound;
+ return;
+ }
JMethod clinit = type.getMethods().get(0);
if (!liveFieldsAndMethods.contains(clinit)) {
flowInto(clinit);
@@ -953,13 +993,13 @@ public class UnifyAst {
String typeName = type.getName();
JDeclaredType newType = searchForType(typeName);
- if (newType != null) {
- assert !newType.isExternal();
- return newType;
+ if (newType == null) {
+ assert errorsFound;
+ return type;
}
- // Error condition, should be logged.
- errorsFound = true;
- return type;
+
+ assert !newType.isExternal();
+ return newType;
}
private JField translate(JField field) {
@@ -976,7 +1016,7 @@ public class UnifyAst {
enclosingType = translate(enclosingType);
if (enclosingType.isExternal()) {
- // Error condition, should be logged.
+ assert errorsFound;
return field;
}
mapApi(enclosingType);
@@ -1006,7 +1046,7 @@ public class UnifyAst {
enclosingType = translate(enclosingType);
if (enclosingType.isExternal()) {
- // Error condition, should be logged.
+ assert errorsFound;
return method;
}
mapApi(enclosingType);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors