use of org.wso2.ballerinalang.compiler.tree.BLangEndpoint in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointInitFunctionCall.
private BLangBlockStmt generateEndpointInitFunctionCall(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
BLangBlockStmt temp = new BLangBlockStmt();
if (endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
return temp;
}
final String epName = endpoint.name.value;
final DiagnosticPos pos = endpoint.pos;
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
// EPConfigType ep_nameConf = { ep-config-expr };
final BLangVariableDef epConfigNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
epConfigNewStmt.var = ASTBuilderUtil.createVariable(pos, epName + "Conf", endpoint.configurationExpr.type);
epConfigNewStmt.var.expr = endpoint.configurationExpr;
ASTBuilderUtil.defineVariable(epConfigNewStmt.var, varEncSymbol, names);
List<BLangVariable> args = Lists.of(epConfigNewStmt.var);
if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() == 2) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
// epName.init(ep_nameConf);
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.symbol.initFunction, args, symResolver);
if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() != 2) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
use of org.wso2.ballerinalang.compiler.tree.BLangEndpoint in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addEndpointDefinition.
public void addEndpointDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean initExprExist) {
final BLangEndpoint endpointNode = (BLangEndpoint) TreeBuilder.createEndpointNode();
attachAnnotations(endpointNode);
endpointNode.pos = pos;
endpointNode.name = (BLangIdentifier) this.createIdentifier(identifier);
endpointNode.endpointTypeNode = (BLangUserDefinedType) typeNodeStack.pop();
if (initExprExist) {
endpointNode.configurationExpr = (BLangExpression) this.exprNodeStack.pop();
}
endpointNode.addWS(ws);
if (endpointListStack.empty()) {
// Top level node.
lastBuiltEndpoint = endpointNode;
this.compUnit.addTopLevelNode(endpointNode);
} else {
endpointListStack.peek().add(endpointNode);
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangEndpoint 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.BLangEndpoint in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangEndpoint endpointNode) {
if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(endpointNode.getPosition(), endpointNode, this, this.documentServiceContext)) {
SymbolEnv endpointEnv = SymbolEnv.createPkgLevelSymbolEnv(endpointNode, endpointNode.symbol.scope, symbolEnv);
this.isWithinEndpointContext(endpointNode.getPosition(), endpointEnv, endpointNode.getName().getValue());
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangEndpoint in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangAction actionNode) {
String actionName = actionNode.getName().getValue();
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
if (this.isWithinParameterContext(actionName, NODE_TYPE_ACTION)) {
this.populateSymbols(this.resolveAllVisibleSymbols(actionEnv), actionEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(actionNode.getPosition(), actionNode, this, this.documentServiceContext)) {
// TODO: Handle Annotation attachments
// Visit the endpoints
actionNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, actionEnv));
// Cursor position is calculated against the resource parameter scope resolver since both are similar
cursorPositionResolver = ResourceParamScopeResolver.class;
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
}
Aggregations