aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-08-01 22:26:51 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-08-01 22:26:51 +0200
commit3be2152a0e8c8c30d23634aa97c38c1c3b4cd2e7 (patch)
treee5edbe0b36f521e816de22000253e111a07cd9da /src/core
parentced7a8d5549af733bd0463daf533d08fe21a65ab (diff)
downloadlombok-3be2152a0e8c8c30d23634aa97c38c1c3b4cd2e7.tar.gz
lombok-3be2152a0e8c8c30d23634aa97c38c1c3b4cd2e7.tar.bz2
lombok-3be2152a0e8c8c30d23634aa97c38c1c3b4cd2e7.zip
Updates to the DebugSnapshot system (stack-free logs, global disable switch, print once only)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/core/debug/DebugSnapshot.java18
-rw-r--r--src/core/lombok/core/debug/DebugSnapshotStore.java30
2 files changed, 42 insertions, 6 deletions
diff --git a/src/core/lombok/core/debug/DebugSnapshot.java b/src/core/lombok/core/debug/DebugSnapshot.java
index 3982539e..42bb62fe 100644
--- a/src/core/lombok/core/debug/DebugSnapshot.java
+++ b/src/core/lombok/core/debug/DebugSnapshot.java
@@ -22,9 +22,13 @@ public class DebugSnapshot implements Comparable<DebugSnapshot> {
public DebugSnapshot(CompilationUnitDeclaration owner, int stackHiding, String message, Object... params) {
this.when = System.currentTimeMillis();
this.bits = owner.bits;
- StackTraceElement[] stackTrace = new Throwable().getStackTrace();
- this.trace = new ArrayList<StackTraceElement>(Math.max(0, stackTrace.length - stackHiding - 1));
- for (int i = 1 + stackHiding; i < stackTrace.length; i++) trace.add(stackTrace[i]);
+ if (stackHiding < 0) {
+ this.trace = null;
+ } else {
+ StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ this.trace = new ArrayList<StackTraceElement>(Math.max(0, stackTrace.length - stackHiding - 1));
+ for (int i = 1 + stackHiding; i < stackTrace.length; i++) trace.add(stackTrace[i]);
+ }
this.threadName = Thread.currentThread().getName();
this.message = message;
this.params = params == null ? new Object[0] : params;
@@ -53,8 +57,12 @@ public class DebugSnapshot implements Comparable<DebugSnapshot> {
@Override public String toString() {
StringBuilder out = new StringBuilder();
out.append(shortToString()).append("\n");
- for (StackTraceElement elem : trace) {
- out.append(" ").append(elem.toString()).append("\n");
+ if (trace == null) {
+ out.append(" Stack Omitted");
+ } else {
+ for (StackTraceElement elem : trace) {
+ out.append(" ").append(elem.toString()).append("\n");
+ }
}
return out.toString();
}
diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java
index 7abfc07c..64c91473 100644
--- a/src/core/lombok/core/debug/DebugSnapshotStore.java
+++ b/src/core/lombok/core/debug/DebugSnapshotStore.java
@@ -13,11 +13,13 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
public class DebugSnapshotStore {
public static final DebugSnapshotStore INSTANCE = new DebugSnapshotStore();
+ public static boolean GLOBAL_DSS_DISABLE_SWITCH = true;
private final Map<CompilationUnitDeclaration, List<DebugSnapshot>> map =
new WeakHashMap<CompilationUnitDeclaration, List<DebugSnapshot>>();
public void snapshot(CompilationUnitDeclaration owner, String message, Object... params) {
+ if (GLOBAL_DSS_DISABLE_SWITCH) return;
DebugSnapshot snapshot = new DebugSnapshot(owner, 1, message, params);
List<DebugSnapshot> list;
@@ -26,18 +28,44 @@ public class DebugSnapshotStore {
if (list == null) {
list = new ArrayList<DebugSnapshot>();
map.put(owner, list);
+ list.add(snapshot);
+ } else if (!list.isEmpty()) {
+ list.add(snapshot);
+ } else {
+ // An empty list is an indicator that we no longer care about that particular CUD.
+ }
+ }
+ }
+
+ public void log(CompilationUnitDeclaration owner, String message, Object... params) {
+ if (GLOBAL_DSS_DISABLE_SWITCH) return;
+ DebugSnapshot snapshot = new DebugSnapshot(owner, -1, message, params);
+ List<DebugSnapshot> list;
+
+ synchronized (map) {
+ list = map.get(owner);
+ if (list == null) {
+ list = new ArrayList<DebugSnapshot>();
+ map.put(owner, list);
+ list.add(snapshot);
+ } else if (!list.isEmpty()) {
+ list.add(snapshot);
+ } else {
+ // An empty list is an indicator that we no longer care about that particular CUD.
}
- list.add(snapshot);
}
}
public String print(CompilationUnitDeclaration owner, String message, Object... params) {
+ if (GLOBAL_DSS_DISABLE_SWITCH) return null;
List<DebugSnapshot> list;
synchronized (map) {
snapshot(owner, message == null ? "Printing" : message, params);
list = new ArrayList<DebugSnapshot>();
list.addAll(map.get(owner));
+ if (list.isEmpty()) return null; // An empty list is an indicator that we no longer care about that particular CUD.
+ map.get(owner).clear();
}
Collections.sort(list);