This fixes an issue where nesting a WARN underneath an ERROR will cause the ERROR log message to turn yellow (the WARN color). In the process of fixing this, I decided that Type's API needed a little bit of a face lift. No one is really using the getParent() stuff, so it made sense to me to introduce an abstract concept of priority instead, because it makes the O(n) operations O(1).
Review by: bruce
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@421 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/TreeLogger.java b/dev/core/src/com/google/gwt/core/ext/TreeLogger.java
index 122277b..5485e56 100644
--- a/dev/core/src/com/google/gwt/core/ext/TreeLogger.java
+++ b/dev/core/src/com/google/gwt/core/ext/TreeLogger.java
@@ -28,14 +28,16 @@
*/
class Type {
+ private static final int TYPES_COUNT = 7;
+
/**
* MUST lazy-init (@link #instances}. Some compilers (javac) will cause
* Type's clinit to call TreeLogger's clinit <i>first</i>. This means
* ERROR, WARN, etc run their constructors before instances can
* self-initialize.
*/
- private static Map instances;
- private static final Type[] NO_TYPES = new Type[0];
+ private static Map labelMap;
+ private static Type[] typeList;
static {
// ensure the standard types are actually registered
@@ -48,7 +50,7 @@
* @return an array of severity types
*/
public static Type[] instances() {
- return (Type[]) instances.values().toArray(NO_TYPES);
+ return (Type[]) typeList.clone();
}
/**
@@ -59,27 +61,30 @@
* <code>null</code> if no such type exists
*/
public static Type valueOf(String label) {
- return (Type) instances.get(label.toUpperCase());
+ return (Type) labelMap.get(label.toUpperCase());
}
private final String label;
-
- private final Type parent;
-
private final boolean needsAttention;
+ private final int priority;
/**
* Constructs a log type with an optional parent.
*/
- private Type(boolean needsAttention, String name, Type parent) {
- if (instances == null) {
- instances = new HashMap();
+ private Type(boolean needsAttention, String name, int priority) {
+ if (labelMap == null) {
+ labelMap = new HashMap();
}
- Object existing = instances.put(name.toUpperCase(), this);
+ if (typeList == null) {
+ typeList = new Type[TYPES_COUNT];
+ }
+ Object existing = labelMap.put(name.toUpperCase(), this);
assert (existing == null);
+ assert (typeList[priority] == null);
+ typeList[priority] = this;
this.needsAttention = needsAttention;
this.label = name;
- this.parent = parent;
+ this.priority = priority;
}
/**
@@ -92,13 +97,16 @@
}
/**
- * Gets the parent of this severity type.
+ * Determines whether this log type is of lower priority than some other log
+ * type.
*
- * @return the parent
+ * @param other the other log type
+ * @return <code>true</code> if this log type is lower priority
*/
- public Type getParent() {
- return parent;
+ public boolean isLowerPriorityThan(Type other) {
+ return this.priority > other.priority;
}
+
/**
* Indicates whether this severity type represents a high severity that
* should be highlighted for the user.
@@ -109,6 +117,7 @@
public boolean needsAttention() {
return needsAttention;
}
+
public String toString() {
return label;
}
@@ -117,38 +126,38 @@
/**
* Logs an error.
*/
- Type ERROR = new Type(true, "ERROR", null);
+ Type ERROR = new Type(true, "ERROR", 0);
/**
* Logs a warning.
*/
- Type WARN = new Type(true, "WARN", ERROR);
+ Type WARN = new Type(true, "WARN", 1);
/**
* Logs information.
*/
- Type INFO = new Type(false, "INFO", WARN);
+ Type INFO = new Type(false, "INFO", 2);
/**
* Logs information related to lower-level operation.
*/
- Type TRACE = new Type(false, "TRACE", INFO);
+ Type TRACE = new Type(false, "TRACE", 3);
/**
* Logs detailed information that could be useful during debugging.
*/
- Type DEBUG = new Type(false, "DEBUG", TRACE);
+ Type DEBUG = new Type(false, "DEBUG", 4);
/**
* Logs extremely verbose and detailed information that is typically useful
* only to product implementors.
*/
- Type SPAM = new Type(false, "SPAM", DEBUG);
+ Type SPAM = new Type(false, "SPAM", 5);
/**
* Logs everything -- quite a bit of stuff.
*/
- Type ALL = new Type(false, "ALL", SPAM);
+ Type ALL = new Type(false, "ALL", 6);
/**
* A valid logger that ignores all messages. Occasionally useful when calling
diff --git a/dev/core/src/com/google/gwt/dev/util/log/AbstractTreeLogger.java b/dev/core/src/com/google/gwt/dev/util/log/AbstractTreeLogger.java
index cd12428..5300345 100644
--- a/dev/core/src/com/google/gwt/dev/util/log/AbstractTreeLogger.java
+++ b/dev/core/src/com/google/gwt/dev/util/log/AbstractTreeLogger.java
@@ -95,8 +95,6 @@
public int indexWithinMyParent;
- private UncommittedBranchData uncommitted;
-
private TreeLogger.Type logLevel = TreeLogger.ALL;
private int nextChildIndex;
@@ -105,6 +103,8 @@
private AbstractTreeLogger parent;
+ private UncommittedBranchData uncommitted;
+
/**
* The constructor used when creating a top-level logger.
*/
@@ -167,11 +167,7 @@
}
public final synchronized boolean isLoggable(TreeLogger.Type type) {
- TreeLogger.Type maxLevel = logLevel;
- while (maxLevel != null && maxLevel != type) {
- maxLevel = maxLevel.getParent();
- }
- return maxLevel == type;
+ return !type.isLowerPriorityThan(logLevel);
}
/**
diff --git a/dev/core/src/com/google/gwt/dev/util/log/TreeItemLogger.java b/dev/core/src/com/google/gwt/dev/util/log/TreeItemLogger.java
index 4994ba3..010b832 100644
--- a/dev/core/src/com/google/gwt/dev/util/log/TreeItemLogger.java
+++ b/dev/core/src/com/google/gwt/dev/util/log/TreeItemLogger.java
@@ -212,10 +212,18 @@
// For types needing attention, set all parents to the warning color.
//
if (type.needsAttention()) {
+ boolean propagateColor = true;
TreeItem parent = child.getParentItem();
while (parent != null) {
+ LogEvent parentEvent = (LogEvent) parent.getData();
+ if (propagateColor) {
+ if (parentEvent.type.isLowerPriorityThan(type)) {
+ parent.setForeground(color);
+ } else {
+ propagateColor = false;
+ }
+ }
parent.setExpanded(true);
- parent.setForeground(color);
parent = parent.getParentItem();
}
}