Commit 48201afa authored by Lubomir Bulej's avatar Lubomir Bulej

ShadowClass: add equalsType() to allow checking if a shadow class represents a particular type.

ShadowClass: add extendsType() to allow checking if a shadow class represents a type that extends a particular type.
ShadowObjectTable: replace usage of isAssignableFromThread() with equalsType() and extendsType() in __createShadowObject().
ShadowObjectTable: eliminate isAssignableFromThread().
parent c466c77c
......@@ -191,6 +191,32 @@ public abstract class ShadowClass extends ShadowObject {
*/
public abstract boolean isAssignableFrom (ShadowClass other);
//
/**
* Returns {@code true} if this class matches the given {@link Type type}.
*/
final boolean equalsType (final Type type) {
return __type.equals (type);
}
/**
* Returns {@code true} if this class is derived from the given {@link Type
* type}. This method checks for presence of {@link Type type} in the
* inheritance hierarchy of this class.
*/
final boolean extendsType (final Type type) {
if (equalsType (type)) {
return true;
} else {
final ShadowClass superClass = getSuperclass ();
return (superClass != null) ? superClass.extendsType (type) : false;
}
}
//
public abstract int getModifiers ();
......
......@@ -4,6 +4,8 @@ import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.objectweb.asm.Type;
import ch.usi.dag.dislreserver.DiSLREServerFatalException;
import ch.usi.dag.dislreserver.util.Logging;
import ch.usi.dag.util.logging.Logger;
......@@ -42,19 +44,6 @@ public final class ShadowObjectTable {
}
private static boolean isAssignableFromThread (ShadowClass klass) {
while (!"java.lang.Object".equals (klass.getName ())) {
if ("java.lang.Thread".equals (klass.getName ())) {
return true;
}
klass = klass.getSuperclass ();
}
return false;
}
public static ShadowObject get (final long netReference) {
final long objectId = NetReferenceHelper.getObjectId (netReference);
if (objectId == 0) {
......@@ -88,7 +77,8 @@ public final class ShadowObjectTable {
}
private static final String __STRING_CLASS_NAME__ = String.class.getName ();
private static final Type __THREAD_CLASS_TYPE__ = Type.getType (Thread.class);
private static final Type __STRING_CLASS_TYPE__ = Type.getType (String.class);
private static ShadowObject __createShadowObject (
final long netReference
......@@ -97,10 +87,10 @@ public final class ShadowObjectTable {
NetReferenceHelper.getClassId (netReference)
);
if (__STRING_CLASS_NAME__.equals (shadowClass.getName ())) {
if (shadowClass.equalsType (__STRING_CLASS_TYPE__)) {
return new ShadowString (netReference, shadowClass);
} else if (isAssignableFromThread (shadowClass)) {
} else if (shadowClass.extendsType (__THREAD_CLASS_TYPE__)) {
return new ShadowThread (netReference, shadowClass);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment