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

Unified Diff: plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java

Issue 7089017: Change source look-up design (Closed) Base URL: https://chromedevtools.googlecode.com/svn/trunk
Patch Set: fcr Created 9 years, 6 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: plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java
diff --git a/plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java b/plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java
index 95f733ba78eee963980928ed263fd9c0b980e58e..cd1cb89eb1776afd9a2c141a2babf40362604718 100644
--- a/plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java
+++ b/plugins/org.chromium.debug.core/src/org/chromium/debug/core/model/VmResourceId.java
@@ -4,119 +4,77 @@
package org.chromium.debug.core.model;
+import org.chromium.debug.core.util.ChromiumDebugPluginUtil;
import org.chromium.sdk.Breakpoint;
-import org.chromium.sdk.JavascriptVm;
import org.chromium.sdk.Script;
/**
* Id of resources loaded in V8 VM. We only know that they may have name (typically filename or
- * URL) or numerical id instead. This class reflects this.
- * The class also contains several utility methods that probably should be separated in the future.
+ * URL) and/or numerical id.
*/
public class VmResourceId {
-
- public static VmResourceId forName(String scriptName) {
- return new VmResourceId(scriptName);
+ public static VmResourceId forScript(final Script script) {
+ return new VmResourceId(script.getName(), script.getId());
}
- public static VmResourceId forId(long scriptId) {
- return new VmResourceId(Long.valueOf(scriptId));
- }
+ private final String name;
+ private final Long id;
- public static VmResourceId forScript(Script script) {
- if (script.getName() != null) {
- return forName(script.getName());
- } else {
- return forId(script.getId());
- }
+ public VmResourceId(String name, Long id) {
+ this.name = name;
+ this.id = id;
}
- private final Object value;
+ public String getName() {
+ return name;
+ }
- private VmResourceId(Object value) {
- if (value == null) {
- throw new IllegalArgumentException("Null id value"); //$NON-NLS-1$
- }
- this.value = value;
+ public Long getId() {
+ return id;
}
@Override
public int hashCode() {
- return value.hashCode();
+ return ChromiumDebugPluginUtil.hashCode(getName()) +
+ 31 * ChromiumDebugPluginUtil.hashCode(getId());
}
@Override
public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
if (obj instanceof VmResourceId == false) {
return false;
}
VmResourceId other = (VmResourceId) obj;
- return this.value.equals(other.value);
- }
-
- /**
- * @return parameter for {@link JavascriptVm#setBreakpoint} method.
- */
- public Breakpoint.Target getTargetForBreakpoint() {
- if (value instanceof String) {
- return new Breakpoint.Target.ScriptName((String) value);
- } else {
- return new Breakpoint.Target.ScriptId((Long) value);
- }
- }
-
- String createFileNameTemplate(boolean isEval) {
- if (value instanceof String) {
- return value.toString();
- } else {
- if (isEval) {
- return "<eval #" + value + ">"; //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- return "<no name #" + value + ">"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
+ return ChromiumDebugPluginUtil.eq(this.name, other.name) &&
+ ChromiumDebugPluginUtil.eq(this.id, other.id);
}
@Override
public String toString() {
- return getEclipseSourceName();
+ return "<" + name + " : " + id + ">";
}
/**
- * @return source name that is suitable for Eclipse debug source lookup.
+ * @return parameter for {@link JavascriptVm#setBreakpoint} method.
*/
- public String getEclipseSourceName() {
- if (value instanceof String) {
- String stringValue = (String) value;
- if (stringValue.startsWith("#")) {
- // Quote it.
- stringValue = "#" + stringValue;
- }
- return stringValue;
+ public Breakpoint.Target getTargetForBreakpoint() {
+ if (name != null) {
+ return new Breakpoint.Target.ScriptName(name);
} else {
- return "#" + value;
+ return new Breakpoint.Target.ScriptId(id);
}
}
- public static VmResourceId parseString(String name) {
- if (name.startsWith("##")) {
- return VmResourceId.forName(name.substring(1));
- } else if (name.startsWith("#")) {
- return VmResourceId.forId(Long.parseLong(name.substring(1)));
- } else {
- return VmResourceId.forName(name);
- }
- }
- /**
- * @return source name or null
- */
- public String getSourceName() {
- if (value instanceof String) {
- return (String) value;
- } else {
- return null;
+ public String getVisibleName() {
+ String name = getName();
+ if (name != null) {
+ return name;
}
+ return "<unnamed # " + getId() + ">";
}
}

Powered by Google App Engine
This is Rietveld 408576698