forked from eclipse-jdtls/eclipse.jdt.ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.show variable list in debug view (eclipse-jdtls#43)
* 1.add variable list Signed-off-by: andxu <andxu@microsoft.com> * 1.fix a constructor error: missing field assignment. Signed-off-by: andxu <andxu@microsoft.com> * ArrayUtils.toStringArray is not available in a low version, remove the usage. Signed-off-by: andxu <andxu@microsoft.com> * add javadoc back Signed-off-by: andxu <andxu@microsoft.com> * remove local debug code Signed-off-by: andxu <andxu@microsoft.com> * remove local debug code Signed-off-by: andxu <andxu@microsoft.com> * adjust class signature about util class Signed-off-by: andxu <andxu@microsoft.com> * change the options per request. Signed-off-by: andxu <andxu@microsoft.com> * change the options per request. Signed-off-by: andxu <andxu@microsoft.com> * 1. check all thread running to recycle all ids. 2. remove a unused method in variable formatter. Signed-off-by: andxu <andxu@microsoft.com> * 1. check all thread running to recycle all ids. 2. remove a unused method in variable formatter. Signed-off-by: andxu <andxu@microsoft.com>
- Loading branch information
Showing
9 changed files
with
765 additions
and
69 deletions.
There are no files selected for viewing
308 changes: 251 additions & 57 deletions
308
org.eclipse.jdt.ls.debug/src/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java
Large diffs are not rendered by default.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
org.eclipse.jdt.ls.debug/src/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.ls.debug.adapter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* An utility object pool class with the following ability: | ||
* 1. store an object to get an object id. | ||
* 2. remove an object. | ||
* 3. remove objects which has specified owner. | ||
* 4. remove all objects. | ||
* | ||
* <p>It is thread-safe, the duplicate object will not be stored, an object can be referenced by multiple owners, it is | ||
* removed only when user explicitly calls removeObjectById or all the owners has been removed.</p> | ||
* | ||
* @param <O> the owner class type | ||
* @param <V> the object type | ||
*/ | ||
public class RecyclableObjectPool<O, V> { | ||
private final IdCollection<V> objectCollection = new IdCollection<>(); | ||
private final Map<V, Set<O>> referenceMap = new HashMap<>(); | ||
private final Map<V, Integer> objectIdMap = new HashMap<>(); | ||
|
||
/** | ||
* Add an object into this pool, if the object is already added, the original id will be used, it will also create a | ||
* reference link from the object to its owner. | ||
* | ||
* @param owner the owner of this object | ||
* @param object the object | ||
* @return the inner id of this object | ||
*/ | ||
public int addObject(O owner, V object) { | ||
if (owner == null) { | ||
throw new IllegalArgumentException("Owner cannot be null."); | ||
} | ||
if (object == null) { | ||
throw new IllegalArgumentException("Null object cannot be added."); | ||
} | ||
synchronized (this) { | ||
if (!referenceMap.containsKey(object)) { | ||
// the object is new | ||
Set<O> owners = new HashSet<>(1); | ||
owners.add(owner); | ||
referenceMap.put(object, owners); | ||
int id = objectCollection.create(object); | ||
objectIdMap.put(object, id); | ||
return id; | ||
} else { | ||
// the object is already in this pool | ||
referenceMap.get(object).add(owner); | ||
return objectIdMap.get(object); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the object by object id. | ||
* | ||
* @param id the object id. | ||
* @return the object, null if the object cannot be found. | ||
*/ | ||
public V getObjectById(int id) { | ||
synchronized (this) { | ||
return objectCollection.get(id); | ||
} | ||
} | ||
|
||
/** | ||
* Remove the object by object id. | ||
* | ||
* @param id the object id. | ||
* @return true if the object is removed successfully, false if the object cannot be found. | ||
*/ | ||
public boolean removeObjectById(int id) { | ||
synchronized (this) { | ||
V object = this.objectCollection.remove(id); | ||
if (object == null) { | ||
return false; | ||
} | ||
referenceMap.remove(object); | ||
objectIdMap.remove(object); | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Remove a group of objects with the owner, the objects which only refers this owner will be removed. | ||
* | ||
* @param owner the owner. | ||
* @return true if any object is removed. | ||
*/ | ||
public boolean removeObjectsByOwner(O owner) { | ||
if (owner == null) { | ||
throw new IllegalArgumentException("owner cannot be null."); | ||
} | ||
synchronized (this) { | ||
List<V> recycling = new ArrayList<>(); | ||
referenceMap.forEach((key, value) -> { | ||
if (value.remove(owner)) { | ||
if (value.isEmpty()) { | ||
recycling.add(key); | ||
} | ||
} | ||
}); | ||
for (V recycled : recycling) { | ||
this.objectCollection.remove(objectIdMap.remove(recycled)); | ||
referenceMap.remove(recycled); | ||
} | ||
return !recycling.isEmpty(); | ||
} | ||
} | ||
|
||
/** | ||
* Removes all the objects. | ||
*/ | ||
public void removeAllObjects() { | ||
synchronized (this) { | ||
this.objectCollection.reset(); | ||
this.referenceMap.clear(); | ||
this.objectIdMap.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...lipse.jdt.ls.debug/src/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.ls.debug.adapter.variables; | ||
|
||
import com.sun.jdi.Type; | ||
import com.sun.jdi.Value; | ||
import org.eclipse.jdt.ls.debug.adapter.formatter.ITypeFormatter; | ||
import org.eclipse.jdt.ls.debug.adapter.formatter.IValueFormatter; | ||
|
||
import java.util.Map; | ||
|
||
public interface IVariableFormatter { | ||
/** | ||
* Register a type formatter. Be careful about the priority of formatters, the formatter with the largest | ||
* priority which accepts the type will be used. | ||
* | ||
* @param typeFormatter the type formatter | ||
* @param priority the priority for this formatter | ||
*/ | ||
void registerTypeFormatter(ITypeFormatter typeFormatter, int priority); | ||
|
||
/** | ||
* Register a value formatter. Be careful about the priority of formatters, the formatter with the largest | ||
* priority which accepts the type will be used. | ||
* | ||
* @param formatter the value formatter | ||
* @param priority the priority for this formatter | ||
*/ | ||
void registerValueFormatter(IValueFormatter formatter, int priority); | ||
|
||
/** | ||
* Get the default options for all formatters registered. | ||
* @return The default options. | ||
*/ | ||
Map<String, Object> getDefaultOptions(); | ||
|
||
/** | ||
* Get display text of the value. | ||
* | ||
* @param value the value. | ||
* @param options additional information about expected format | ||
* @return the display text of the value | ||
*/ | ||
String valueToString(Value value, Map<String, Object> options); | ||
|
||
/** | ||
* Get display name of type. | ||
* | ||
* @param type the JDI type | ||
* @param options additional information about expected format | ||
* @return display name of type of the value. | ||
*/ | ||
String typeToString(Type type, Map<String, Object> options); | ||
} |
63 changes: 63 additions & 0 deletions
63
org.eclipse.jdt.ls.debug/src/org/eclipse/jdt/ls/debug/adapter/variables/StackFrameScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.ls.debug.adapter.variables; | ||
|
||
import java.util.Objects; | ||
|
||
import com.sun.jdi.StackFrame; | ||
|
||
public class StackFrameScope { | ||
private final StackFrame stackFrame; | ||
private final String scope; | ||
private int hashCode; | ||
|
||
|
||
/** | ||
* Create a stack frame scope with the related stack frame. | ||
* | ||
* @param stackFrame the JDI stack frame | ||
* @param scope the scope | ||
*/ | ||
public StackFrameScope(StackFrame stackFrame, String scope) { | ||
this.stackFrame = stackFrame; | ||
this.scope = scope; | ||
this.hashCode = this.getStackFrame().hashCode() & this.getScope().hashCode(); | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s %s", String.valueOf(getStackFrame()), getScope()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof StackFrameScope)) { | ||
return false; | ||
} | ||
final StackFrameScope other = (StackFrameScope) o; | ||
return (Objects.equals(this.getStackFrame(), other.getStackFrame()) && Objects.equals(this.getScope(), other.getScope())); | ||
} | ||
|
||
public StackFrame getStackFrame() { | ||
return stackFrame; | ||
} | ||
|
||
public String getScope() { | ||
return scope; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...se.jdt.ls.debug/src/org/eclipse/jdt/ls/debug/adapter/variables/ThreadObjectReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.ls.debug.adapter.variables; | ||
|
||
import java.util.Objects; | ||
|
||
import com.sun.jdi.ObjectReference; | ||
import com.sun.jdi.ThreadReference; | ||
|
||
public class ThreadObjectReference { | ||
private final ThreadReference thread; | ||
private final ObjectReference object; | ||
private int hashCode; | ||
|
||
/** | ||
* Create a JDI object with the related thread. | ||
* | ||
* @param thread the JDI thread | ||
* @param object the object | ||
*/ | ||
public ThreadObjectReference(ThreadReference thread, | ||
ObjectReference object) { | ||
if (thread == null) { | ||
throw new IllegalArgumentException("Null argument 'thread' is illegal."); | ||
} | ||
if (object == null) { | ||
throw new IllegalArgumentException("Parameter 'object' is null."); | ||
} | ||
this.thread = thread; | ||
this.object = object; | ||
hashCode = this.object.hashCode() & this.thread.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.object.toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof ThreadObjectReference)) { | ||
return false; | ||
} | ||
final ThreadObjectReference other = (ThreadObjectReference) o; | ||
return (Objects.equals(this.thread, other.thread) && Objects.equals(this.object, other.object)); | ||
} | ||
|
||
public ThreadReference getThread() { | ||
return thread; | ||
} | ||
|
||
public ObjectReference getObject() { | ||
return object; | ||
} | ||
} |
Oops, something went wrong.