use of io.nuls.contract.vm.ObjectRef in project nuls by nuls-io.
the class NativeClass method getSuperclass.
/**
* native
*
* @see Class#getSuperclass()
*/
private static Result getSuperclass(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
ObjectRef objectRef = methodArgs.objectRef;
VariableType variableType;
if (objectRef.getVariableType().isArray()) {
variableType = objectRef.getVariableType();
} else {
variableType = VariableType.valueOf(objectRef.getRef());
}
ClassCode classCode = frame.methodArea.loadClass(variableType.getType());
VariableType superVariableType = VariableType.valueOf(classCode.superName);
ObjectRef classRef = frame.heap.getClassRef(superVariableType.getDesc());
Result result = NativeMethod.result(methodCode, classRef, frame);
return result;
}
use of io.nuls.contract.vm.ObjectRef in project nuls by nuls-io.
the class NativeClass method isArray.
/**
* native
*
* @see Class#isArray()
*/
private static Result isArray(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
ObjectRef objectRef = methodArgs.objectRef;
VariableType variableType;
if (objectRef.getVariableType().isArray()) {
variableType = objectRef.getVariableType();
} else {
variableType = VariableType.valueOf(objectRef.getRef());
}
boolean b = variableType.isArray();
Result result = NativeMethod.result(methodCode, b, frame);
return result;
}
use of io.nuls.contract.vm.ObjectRef in project nuls by nuls-io.
the class NativeClass method getPrimitiveClass.
/**
* native
*
* @see Class#getPrimitiveClass(String)
*/
private static Result getPrimitiveClass(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
ObjectRef objectRef = (ObjectRef) methodArgs.invokeArgs[0];
String name = frame.heap.runToString(objectRef);
VariableType variableType = VariableType.valueOf(name);
ObjectRef classRef = frame.heap.getClassRef(variableType.getDesc());
Result result = NativeMethod.result(methodCode, classRef, frame);
return result;
}
use of io.nuls.contract.vm.ObjectRef in project nuls by nuls-io.
the class NativeClass method isPrimitive.
/**
* native
*
* @see Class#isPrimitive()
*/
private static Result isPrimitive(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
ObjectRef objectRef = methodArgs.objectRef;
VariableType variableType;
if (objectRef.getVariableType().isArray()) {
variableType = objectRef.getVariableType();
} else {
variableType = VariableType.valueOf(objectRef.getRef());
}
boolean b = variableType.isPrimitive();
Result result = NativeMethod.result(methodCode, b, frame);
return result;
}
use of io.nuls.contract.vm.ObjectRef in project nuls by nuls-io.
the class JsonUtils method encode.
public static String encode(Object value, BiMap<String, String> classNames) {
if (value == null) {
return null;
} else if (value.getClass().isArray()) {
Class clazz = value.getClass().getComponentType();
if (clazz == Integer.TYPE) {
return "[I_" + encodeArray(value, clazz, classNames);
} else if (clazz == Long.TYPE) {
return "[J_" + encodeArray(value, clazz, classNames);
} else if (clazz == Float.TYPE) {
return "[F_" + encodeArray(value, clazz, classNames);
} else if (clazz == Double.TYPE) {
return "[D_" + encodeArray(value, clazz, classNames);
} else if (clazz == Boolean.TYPE) {
return "[Z_" + encodeArray(value, clazz, classNames);
} else if (clazz == Byte.TYPE) {
return "[B_" + encodeArray(value, clazz, classNames);
} else if (clazz == Character.TYPE) {
return "[C_" + encodeArray(value, clazz, classNames);
} else if (clazz == Short.TYPE) {
return "[S_" + encodeArray(value, clazz, classNames);
} else {
return "[R_" + encodeArray(value, clazz, classNames);
}
} else if (value instanceof Map) {
Map map = (Map) value;
Map map1 = new LinkedHashMap(hashMapInitialCapacity(map.size()));
map.forEach((k, v) -> {
map1.put(k, encode(v, classNames));
});
return toJson(map1);
} else if (value instanceof Integer) {
return "I_" + value;
} else if (value instanceof Long) {
return "J_" + value;
} else if (value instanceof Float) {
return "F_" + value;
} else if (value instanceof Double) {
return "D_" + value;
} else if (value instanceof Boolean) {
return "Z_" + value;
} else if (value instanceof Byte) {
return "B_" + value;
} else if (value instanceof Character) {
return "C_" + value;
} else if (value instanceof Short) {
return "S_" + value;
} else if (value instanceof String) {
return "s_" + value;
} else if (value instanceof ObjectRef) {
return "R_" + ((ObjectRef) value).getEncoded(classNames);
} else {
throw new IllegalArgumentException("unknown value");
}
}
Aggregations