use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangConnector connectorNode) {
SymbolEnv conEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorNode.symbol.scope, env);
connectorNode.params = rewrite(connectorNode.params, conEnv);
connectorNode.actions = rewrite(connectorNode.actions, conEnv);
connectorNode.varDefs = rewrite(connectorNode.varDefs, conEnv);
connectorNode.endpoints = rewrite(connectorNode.endpoints, conEnv);
connectorNode.initFunction = rewrite(connectorNode.initFunction, conEnv);
connectorNode.initAction = rewrite(connectorNode.initAction, conEnv);
result = connectorNode;
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endConnectorDef.
public void endConnectorDef(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicCon) {
BLangConnector connectorNode = (BLangConnector) this.connectorNodeStack.pop();
connectorNode.pos = pos;
connectorNode.addWS(ws);
connectorNode.setName(this.createIdentifier(identifier));
if (publicCon) {
connectorNode.flagSet.add(Flag.PUBLIC);
}
endEndpointDeclarationScope();
this.compUnit.addTopLevelNode(connectorNode);
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangConnector connectorNode) {
String connectorName = connectorNode.getName().getValue();
BSymbol connectorSymbol = connectorNode.symbol;
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, symbolEnv);
if (isWithinParameterContext(connectorName, NODE_TYPE_CONNECTOR)) {
this.populateSymbols(this.resolveAllVisibleSymbols(connectorEnv), connectorEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(connectorNode.getPosition(), connectorNode, this, this.documentServiceContext)) {
// Reset the previous node
this.setPreviousNode(null);
// TODO: Handle Annotation attachments
if (!(connectorNode.actions.isEmpty() && connectorNode.varDefs.isEmpty() && connectorNode.endpoints.isEmpty())) {
// Visit the endpoints
connectorNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, connectorEnv));
// Since the connector def does not contains a block statement, we consider the block owner only.
// Here it is Connector Definition
this.blockOwnerStack.push(connectorNode);
connectorNode.varDefs.forEach(varDef -> {
// Cursor position is calculated against the Connector scope resolver
cursorPositionResolver = ConnectorScopeResolver.class;
this.acceptNode(varDef, connectorEnv);
});
connectorNode.actions.forEach(action -> {
// Cursor position is calculated against the Connector scope resolver
cursorPositionResolver = ConnectorScopeResolver.class;
this.acceptNode(action, connectorEnv);
});
if (terminateVisitor) {
this.acceptNode(null, null);
}
this.blockOwnerStack.pop();
} else {
this.isCursorWithinBlock(connectorNode.getPosition(), connectorEnv);
}
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangConnector connectorNode) {
BConnectorSymbol conSymbol = Symbols.createConnectorSymbol(Flags.asMask(connectorNode.flagSet), names.fromIdNode(connectorNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
connectorNode.symbol = conSymbol;
defineSymbol(connectorNode.pos, conSymbol);
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, conSymbol.scope, env);
connectorNode.endpoints.forEach(ep -> defineNode(ep, connectorEnv));
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class SymbolEnter method defineConnectorInitFunction.
private void defineConnectorInitFunction(BLangConnector connector, SymbolEnv conEnv) {
BLangFunction initFunction = createInitFunction(connector.pos, connector.getName().getValue(), Names.INIT_FUNCTION_SUFFIX);
// Add connector as a parameter to the init function
BLangVariable param = (BLangVariable) TreeBuilder.createVariableNode();
param.pos = connector.pos;
param.setName(this.createIdentifier(Names.CONNECTOR.getValue()));
BLangUserDefinedType connectorType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
connectorType.pos = connector.pos;
connectorType.typeName = connector.name;
connectorType.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
param.setTypeNode(connectorType);
initFunction.addParameter(param);
// Add connector level variables to the init function
connector.varDefs.stream().filter(f -> f.var.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v.var)));
addInitReturnStatement(initFunction.body);
connector.initFunction = initFunction;
BLangAction initAction = createNativeInitAction(connector.pos);
connector.initAction = initAction;
defineNode(connector.initFunction, conEnv);
defineNode(connector.initAction, conEnv);
connector.symbol.initFunctionSymbol = connector.initFunction.symbol;
}
Aggregations