From 2efc4987b44df38313f57cd8795e0af34ea1349d Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Sat, 7 Apr 2018 23:33:12 +0300 Subject: [PATCH] #3259 replace variable with the most recent --- .../org/jkiss/dbeaver/debug/DBGVariable.java | 2 ++ .../debug/core/model/DatabaseStackFrame.java | 26 +++++++++++++++++++ .../internal/impl/PostgreDebugSession.java | 2 +- .../internal/impl/PostgreDebugVariable.java | 14 +++++----- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGVariable.java b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGVariable.java index 7f69007cc7..46ea527ee8 100644 --- a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGVariable.java +++ b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGVariable.java @@ -27,4 +27,6 @@ public interface DBGVariable { DBGVariableType getType(); + int getLineNumber(); + } diff --git a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseStackFrame.java b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseStackFrame.java index bdd8ed48b3..a05e77ab9c 100644 --- a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseStackFrame.java +++ b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseStackFrame.java @@ -19,7 +19,9 @@ package org.jkiss.dbeaver.debug.core.model; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.debug.core.DebugException; @@ -28,6 +30,7 @@ import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; import org.eclipse.osgi.util.NLS; +import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.debug.DBGException; import org.jkiss.dbeaver.debug.DBGStackFrame; import org.jkiss.dbeaver.debug.DBGVariable; @@ -38,6 +41,8 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr private static final IRegisterGroup[] NO_REGISTER_GROUPS = new IRegisterGroup[0]; private static final IVariable[] NO_VARIABLES = new IVariable[0]; + private static Log log = Log.getLog(DatabaseStackFrame.class); + private final List variables = new ArrayList(); private final DatabaseThread thread; @@ -154,8 +159,29 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr protected void rebuildVariables(List> dbgVariables) { try { + int frameLN = dbgStackFrame.getLineNumber(); variables.clear(); + Map> filtered = new LinkedHashMap>(); for (DBGVariable dbgVariable : dbgVariables) { + String name = dbgVariable.getName(); + DBGVariable existing = filtered.get(name); + if (existing == null) { + filtered.put(name, dbgVariable); + } else { + int existingLN = existing.getLineNumber(); + int currentLN = dbgVariable.getLineNumber(); + int delta = currentLN - existingLN; + if (delta >= 0) { + filtered.put(name, dbgVariable); + } else { + String pattern = "Already have {0} and ignored {1} for frame at {2}"; + String message = NLS.bind(pattern, new Object[]{existing, dbgVariable, frameLN}); + log.error(message);; + } + } + } + + for (DBGVariable dbgVariable : filtered.values()) { DatabaseVariable variable = new DatabaseVariable(getDatabaseDebugTarget(), dbgVariable); variables.add(variable); } diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java index e113d7b0dc..0b9c92edc0 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java @@ -534,7 +534,7 @@ public class PostgreDebugSession extends DBGBaseSession { stmt.setInt(1, sessionId); stmt.setString(2, var.getName()); - stmt.setInt(3, var.getLinenumber()); + stmt.setInt(3, var.getLineNumber()); stmt.setString(4, (String) value); stmt.execute(); diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugVariable.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugVariable.java index 4c7153718e..80ce4df3b0 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugVariable.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugVariable.java @@ -28,7 +28,7 @@ public class PostgreDebugVariable implements DBGVariable { private final String varclass; - private final int linenumber; + private final int lineNumber; private final boolean unique; @@ -63,7 +63,7 @@ public class PostgreDebugVariable implements DBGVariable { super(); this.name = name; this.varclass = varclass; - this.linenumber = linenumber; + this.lineNumber = linenumber; this.unique = unique; this.constant = constant; this.notnull = notnull; @@ -75,8 +75,9 @@ public class PostgreDebugVariable implements DBGVariable { return varclass; } - public int getLinenumber() { - return linenumber; + @Override + public int getLineNumber() { + return lineNumber; } public boolean isUnique() { @@ -95,10 +96,11 @@ public class PostgreDebugVariable implements DBGVariable { return oid; } + @SuppressWarnings("nls") @Override public String toString() { - return "PostgreDebugVariable [name=" + name + ", val=" + val + ", varclass=" + varclass + ", linenumber=" - + linenumber + ", unique=" + unique + ", constant=" + constant + ", notnull=" + notnull + ", oid=" + oid + return "PostgreDebugVariable [name=" + name + ", val=" + val + ", varclass=" + varclass + ", lineNumber=" + + lineNumber + ", unique=" + unique + ", constant=" + constant + ", notnull=" + notnull + ", oid=" + oid + "]"; } -- GitLab