Search in sources :

Example 41 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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 42 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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)

Example 43 with PackageInfo

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

the class ConnectorUtils method createAndGetStruct.

/**
 * This method is used to create a struct given the context and required struct details.
 *
 * @param context to get program file.
 * @param packagePath of the struct.
 * @param structName of the struct.
 * @return created struct.
 * @throws BallerinaConnectorException if an error occurs
 */
public static BStruct createAndGetStruct(Context context, String packagePath, String structName) throws BallerinaConnectorException {
    PackageInfo packageInfo = context.getProgramFile().getPackageInfo(packagePath);
    if (packageInfo == null) {
        throw new BallerinaConnectorException("package - " + packagePath + " does not exist");
    }
    StructInfo structInfo = packageInfo.getStructInfo(structName);
    if (structInfo == null) {
        throw new BallerinaConnectorException("struct - " + structName + " does not exist");
    }
    BStructType structType = structInfo.getType();
    BStruct bStruct = new BStruct(structType);
    return bStruct;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 44 with PackageInfo

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

the class FileUtils method createAccessDeniedError.

public static BStruct createAccessDeniedError(Context context, String msg) {
    PackageInfo filePkg = context.getProgramFile().getPackageInfo(FILE_PACKAGE);
    StructInfo accessErrInfo = filePkg.getStructInfo(ACCESS_DENIED_ERROR);
    return BLangVMStructs.createBStruct(accessErrInfo, msg);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 45 with PackageInfo

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

the class AbstractAnnotationReader method createAnnotationStructArray.

private BRefValueArray createAnnotationStructArray(Context context, BValue map) {
    if (map == null || map.getType().getTag() != BTypes.typeMap.getTag()) {
        return null;
    }
    final PackageInfo packageInfo = context.getProgramFile().getPackageInfo(PKG_INTERNAL);
    final StructInfo structInfo = packageInfo.getStructInfo(STRUCT_ANNOTATION);
    BRefValueArray annotationArray = new BRefValueArray(structInfo.getType());
    BMap<String, BValue> annotationMap = (BMap<String, BValue>) map;
    long index = 0;
    for (String key : annotationMap.keySet()) {
        final String annotaionQName = key.split("\\$")[0];
        final String[] qNameParts = annotaionQName.split(":");
        final BStruct annotation = BLangVMStructs.createBStruct(structInfo, qNameParts[1], qNameParts[0], annotationMap.get(key));
        annotationArray.add(index++, annotation);
    }
    return annotationArray;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) BMap(org.ballerinalang.model.values.BMap) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Aggregations

PackageInfo (org.ballerinalang.util.codegen.PackageInfo)48 StructInfo (org.ballerinalang.util.codegen.StructInfo)35 BStruct (org.ballerinalang.model.values.BStruct)17 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)10 BValue (org.ballerinalang.model.values.BValue)6 BStructType (org.ballerinalang.model.types.BStructType)5 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)5 Debugger (org.ballerinalang.util.debugger.Debugger)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 BString (org.ballerinalang.model.values.BString)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 TesterinaFunction (org.ballerinalang.testerina.core.entity.TesterinaFunction)2 Instruction (org.ballerinalang.util.codegen.Instruction)2 PackageVarInfo (org.ballerinalang.util.codegen.PackageVarInfo)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 Test (org.testng.annotations.Test)2 PrintStream (java.io.PrintStream)1