Search in sources :

Example 31 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class ClientSocketTest method testOpenWithProperties.

@Test(dependsOnMethods = "testClosure", description = "Test connection open with properties")
public void testOpenWithProperties() {
    int port = ThreadLocalRandom.current().nextInt(33000, 46000);
    PackageInfo ioPackageInfo = socketClient.getProgFile().getPackageInfo("ballerina.io");
    StructInfo socketProperties = ioPackageInfo.getStructInfo("SocketProperties");
    BStruct propertyStruct = BLangVMStructs.createBStruct(socketProperties, port);
    BValue[] args = { new BString("localhost"), new BInteger(MockSocketServer.SERVER_PORT), propertyStruct };
    final BValue[] returns = BRunUtil.invoke(socketClient, "openSocketConnectionWithProps", args);
    final BStruct socket = (BStruct) returns[0];
    Assert.assertEquals(socket.getIntField(1), port, "Client port didn't bind to assign port.");
    args = new BValue[] { socket };
    BRunUtil.invoke(socketClient, "close", args);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 32 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class CPU method createNewStruct.

private static void createNewStruct(WorkerExecutionContext ctx, int[] operands, WorkerData sf) {
    int cpIndex = operands[0];
    int i = operands[1];
    StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) ctx.constPool[cpIndex];
    StructInfo structInfo = (StructInfo) structureRefCPEntry.getStructureTypeInfo();
    sf.refRegs[i] = new BStruct(structInfo.getType());
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)

Example 33 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class BLangVMErrors method createNullRefException.

/* Type Specific Errors */
public static BStruct createNullRefException(Context context) {
    PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(PACKAGE_RUNTIME);
    StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_NULL_REF_EXCEPTION);
    return generateError(context.getCallableUnitInfo(), true, errorStructInfo, "");
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 34 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class BLangVMErrors method createCallCancelledException.

public static BStruct createCallCancelledException(CallableUnitInfo callableUnitInfo) {
    PackageInfo errorPackageInfo = callableUnitInfo.getPackageInfo().getProgramFile().getPackageInfo(PACKAGE_RUNTIME);
    StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_CALL_FAILED_EXCEPTION);
    return generateError(callableUnitInfo, true, errorStructInfo, MSG_CALL_CANCELLED);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 35 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class BLangVMErrors method generateError.

private static BStruct generateError(WorkerExecutionContext context, boolean attachCallStack, Object... values) {
    PackageInfo errorPackageInfo = context.programFile.getPackageInfo(PACKAGE_BUILTIN);
    StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
    return generateError(context, attachCallStack, errorStructInfo, values);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Aggregations

StructInfo (org.ballerinalang.util.codegen.StructInfo)40 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)35 BStruct (org.ballerinalang.model.values.BStruct)21 BStructType (org.ballerinalang.model.types.BStructType)6 BString (org.ballerinalang.model.values.BString)4 BValue (org.ballerinalang.model.values.BValue)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)3 BType (org.ballerinalang.model.types.BType)2 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 StructFieldInfo (org.ballerinalang.util.codegen.StructFieldInfo)2 Test (org.testng.annotations.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 URL (java.net.URL)1 ByteChannel (java.nio.channels.ByteChannel)1 SocketChannel (java.nio.channels.SocketChannel)1