use of org.ballerinalang.util.codegen.StructInfo 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;
}
use of org.ballerinalang.util.codegen.StructInfo 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);
}
use of org.ballerinalang.util.codegen.StructInfo 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;
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class MimeUtil method getParserError.
/**
* Get parser error as a ballerina struct.
*
* @param context Represent ballerina context
* @param errMsg Error message in string form
* @return Ballerina struct with parse error
*/
public static BStruct getParserError(Context context, String errMsg) {
PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(BUILTIN_PACKAGE);
StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
BStruct parserError = new BStruct(errorStructInfo.getType());
parserError.setStringField(0, errMsg);
return parserError;
}
use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.
the class MimeUtil method createEntityError.
/**
* Get entity error as a ballerina struct.
*
* @param context Represent ballerina context
* @param msg Error message in string form
* @return Ballerina struct with entity error
*/
public static BStruct createEntityError(Context context, String msg) {
PackageInfo filePkg = context.getProgramFile().getPackageInfo(PROTOCOL_PACKAGE_MIME);
StructInfo entityErrInfo = filePkg.getStructInfo(ENTITY_ERROR);
return BLangVMStructs.createBStruct(entityErrInfo, msg);
}
Aggregations