use of org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType in project ballerina by ballerina-lang.
the class ParserUtils method createNewParameter.
/**
* Create new parameter.
*
* @param name parameter name
* @param type parameter type
* @return {Parameter} parameter
*/
private static Parameter createNewParameter(String name, String type, BLangType typeNode) {
Parameter parameter = new Parameter();
parameter.setType(type);
parameter.setName(name);
BType bType = typeNode.type;
if (bType instanceof BConnectorType) {
parameter.setPkgAlias(((BLangUserDefinedType) typeNode).pkgAlias.toString());
parameter.setConnector(true);
}
return parameter;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType in project ballerina by ballerina-lang.
the class SymbolEnter method defineConnectorSymbolParams.
private void defineConnectorSymbolParams(BLangConnector connectorNode, BConnectorSymbol symbol, SymbolEnv connectorEnv) {
List<BVarSymbol> paramSymbols = connectorNode.params.stream().peek(varNode -> defineNode(varNode, connectorEnv)).map(varNode -> varNode.symbol).collect(Collectors.toList());
symbol.params = paramSymbols;
// Create connector type
List<BType> paramTypes = paramSymbols.stream().map(paramSym -> paramSym.type).collect(Collectors.toList());
symbol.type = new BConnectorType(paramTypes, symbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType in project ballerina by ballerina-lang.
the class Types method checkConnectorEquivalency.
public boolean checkConnectorEquivalency(BType actualType, BType expType) {
if (actualType.tag != TypeTags.CONNECTOR || expType.tag != TypeTags.CONNECTOR) {
return false;
}
if (isSameType(actualType, expType)) {
return true;
}
BConnectorType expConnectorType = (BConnectorType) expType;
BConnectorType actualConnectorType = (BConnectorType) actualType;
// take actions in connectors
List<BInvokableSymbol> expActions = symResolver.getConnectorActionSymbols(expConnectorType.tsymbol.scope);
List<BInvokableSymbol> actActions = symResolver.getConnectorActionSymbols(actualConnectorType.tsymbol.scope);
if (expActions.isEmpty() && actActions.isEmpty()) {
return true;
}
if (expActions.size() != actActions.size()) {
return false;
}
// check every action signatures are matching or not
for (BInvokableSymbol expAction : expActions) {
if (actActions.stream().filter(v -> checkActionTypeEquality(expAction, v)).collect(Collectors.toList()).size() != 1) {
return false;
}
}
return true;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType in project ballerina by ballerina-lang.
the class CodeGenerator method createConnectorInfoEntry.
private void createConnectorInfoEntry(BLangConnector connectorNode) {
BConnectorType connectorType = (BConnectorType) connectorNode.symbol.type;
// Add connector name as an UTFCPEntry to the constant pool
int connectorNameCPIndex = addUTF8CPEntry(currentPkgInfo, connectorNode.name.value);
// Create connector info
ConnectorInfo connectorInfo = new ConnectorInfo(currentPackageRefCPIndex, connectorNameCPIndex, connectorNode.symbol.flags);
connectorInfo.paramTypes = connectorType.paramTypes.toArray(new BType[0]);
connectorInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateConnectorSig(connectorInfo));
// Add connector level variables
int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
connectorNode.params.forEach(var -> visitVarSymbol(var.symbol, fieldIndexes, localVarAttributeInfo));
connectorNode.varDefs.forEach(var -> visitVarSymbol(var.var.symbol, fieldIndexes, localVarAttributeInfo));
connectorInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
// Create variable count attribute info
prepareIndexes(fieldIndexes);
int[] fieldCount = new int[] { fieldIndexes.tInt, fieldIndexes.tFloat, fieldIndexes.tString, fieldIndexes.tBoolean, fieldIndexes.tBlob, fieldIndexes.tRef };
addVariableCountAttributeInfo(currentPkgInfo, connectorInfo, fieldCount);
// Create the init function info
BLangFunction connectorInitFunction = (BLangFunction) connectorNode.getInitFunction();
createFunctionInfoEntry(connectorInitFunction);
this.currentPkgInfo.connectorInfoMap.put(connectorNode.name.value, connectorInfo);
// Create action info entries for all actions
connectorNode.actions.forEach(res -> createActionInfoEntry(res, connectorInfo));
createActionInfoEntry(connectorNode.initAction, connectorInfo);
fieldIndexes = new VariableIndex(FIELD);
}
Aggregations