Commit 272da9e0 authored by Lubomir Bulej's avatar Lubomir Bulej

DiSL-RE: ShadowObject: get/set()->get/setState(),...

DiSL-RE: ShadowObject: get/set()->get/setState(), getSClass()->getShadowClass(), getState() with support for downcast
DiSL-RE: ShadowArrayClass, ShadowClass: minor cleanups
parent 520a4395
......@@ -8,19 +8,24 @@ import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
public class ShadowArrayClass extends ShadowClass {
private Type t;
private ShadowClass superClass;
private ShadowClass arrayComponentClass;
private final Type type;
private final ShadowClass superClass;
private final ShadowClass arrayComponentClass;
ShadowArrayClass(long net_ref, ShadowObject classLoader,
ShadowClass superClass,
ShadowClass arrayComponentClass, Type t) {
super(net_ref, classLoader);
//
ShadowArrayClass (
final long netReference, final ShadowObject classLoader,
final ShadowClass superClass, final ShadowClass arrayComponentClass,
final Type type
) {
super (netReference, classLoader);
this.type = type;
this.superClass = superClass;
this.arrayComponentClass = arrayComponentClass;
}
this.t = t;
this.superClass = superClass;
this.arrayComponentClass = arrayComponentClass;
}
@Override
public boolean isArray() {
......@@ -28,7 +33,7 @@ public class ShadowArrayClass extends ShadowClass {
}
public int getArrayDimensions() {
return t.getDimensions();
return type.getDimensions();
}
@Override
......@@ -40,7 +45,7 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public boolean isInstance(ShadowObject obj) {
return equals(obj.getSClass());
return equals(obj.getShadowClass());
}
@Override
......@@ -77,12 +82,12 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public String getName() {
return t.getDescriptor().replace('/', '.');
return type.getDescriptor().replace('/', '.');
}
@Override
public String getCanonicalName() {
return t.getClassName();
return type.getClassName();
}
@Override
......@@ -107,7 +112,7 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public FieldInfo getField(String fieldName) throws NoSuchFieldException {
throw new NoSuchFieldException(t.getClassName() + "." + fieldName);
throw new NoSuchFieldException(type.getClassName() + "." + fieldName);
}
@Override
......@@ -127,7 +132,7 @@ public class ShadowArrayClass extends ShadowClass {
}
}
throw new NoSuchMethodException(t.getClassName() + "." + methodName
throw new NoSuchMethodException(type.getClassName() + "." + methodName
+ argumentNamesToString(argumentNames));
}
......@@ -144,7 +149,7 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public FieldInfo getDeclaredField(String fieldName)
throws NoSuchFieldException {
throw new NoSuchFieldException(t.getClassName() + "." + fieldName);
throw new NoSuchFieldException(type.getClassName() + "." + fieldName);
}
@Override
......@@ -155,7 +160,7 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public MethodInfo getDeclaredMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException {
throw new NoSuchMethodException(t.getClassName() + "." + methodName
throw new NoSuchMethodException(type.getClassName() + "." + methodName
+ argumentNamesToString(argumentNames));
}
......
......@@ -2,15 +2,21 @@ package ch.usi.dag.dislreserver.shadow;
public abstract class ShadowClass extends ShadowObject {
private int classId;
private ShadowObject classLoader;
private final int classId;
private final ShadowObject classLoader;
protected ShadowClass(long net_ref, ShadowObject classLoader) {
super(net_ref, null);
//
protected ShadowClass (
final long netReference, final ShadowObject classLoader
) {
super (netReference, null);
this.classId = NetReferenceHelper.get_class_id(net_ref);
this.classLoader = classLoader;
}
this.classId = NetReferenceHelper.get_class_id (netReference);
this.classLoader = classLoader;
}
//
public final int getClassId() {
return classId;
......
package ch.usi.dag.dislreserver.shadow;
public class ShadowObject {
import java.util.Formattable;
import java.util.Formatter;
final private long objectId;
final private ShadowClass sClass;
public class ShadowObject implements Formattable {
final private long shadowId;
final private ShadowClass shadowClass;
private Object shadowState;
ShadowObject(long net_ref) {
//
this(net_ref, ShadowClassTable.get(NetReferenceHelper
.get_class_id(net_ref)));
}
ShadowObject (final long netReference) {
this (
netReference, ShadowClassTable.get (
NetReferenceHelper.get_class_id (netReference)
)
);
}
ShadowObject(long net_ref, ShadowClass sClass) {
this.objectId = NetReferenceHelper.get_object_id(net_ref);
this.sClass = sClass;
this.shadowState = null;
}
ShadowObject (final long netReference, final ShadowClass shadowClass) {
this.shadowId = NetReferenceHelper.get_object_id (netReference);
this.shadowClass = shadowClass;
this.shadowState = null;
}
public long getId() {
return objectId;
//
public long getId () {
return shadowId;
}
public ShadowClass getSClass() {
return sClass;
public ShadowClass getShadowClass () {
return shadowClass;
}
public Object get() {
return shadowState;
}
public void set(Object shadowState) {
public Object getState () {
return shadowState;
}
public <T> T getState (final Class <T> type) {
return type.cast (shadowState);
}
public void setState (final Object shadowState) {
this.shadowState = shadowState;
}
//
@Override
public void formatTo (
final Formatter formatter,
final int flags, final int width, final int precision
) {
formatter.format ("%s@%x", shadowClass.getName (), shadowId);
}
}
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