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

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: clean 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 cb536fb30528f25b42c0687eeefea5239afbf02f..1d5f5bdf0083d05e5acb599a27eff3605ea83f91 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,61 +4,64 @@
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 ChromiumDebugPluginUtil.eq(this.name, other.name) &&
+ ChromiumDebugPluginUtil.eq(this.id, other.id);
}
+ @Override
+ public String toString() {
+ return "<" + name + " : " + id + ">";
+ }
/**
* @return parameter for {@link JavascriptVm#setBreakpoint} method.
*/
public Breakpoint.Type getTypeForBreakpoint() {
- if (value instanceof String) {
+ if (name != null) {
return Breakpoint.Type.SCRIPT_NAME;
} else {
return Breakpoint.Type.SCRIPT_ID;
@@ -69,61 +72,19 @@ public class VmResourceId {
* @return parameter for {@link JavascriptVm#setBreakpoint} method.
*/
public String getTargetForBreakpoint() {
- return value.toString();
- }
-
- 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$
- }
- }
-
- }
-
- @Override
- public String toString() {
- return getEclipseSourceName();
- }
-
- /**
- * @return source name that is suitable for Eclipse debug source lookup.
- */
- public String getEclipseSourceName() {
- if (value instanceof String) {
- String stringValue = (String) value;
- if (stringValue.startsWith("#")) {
- // Quote it.
- stringValue = "#" + stringValue;
- }
- return stringValue;
+ if (name != null) {
+ return name;
} else {
- return "#" + value;
+ return id.toString();
}
}
- 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