use of org.wso2.carbon.identity.core.model.ExpressionNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createInvocationNode.
public void createInvocationNode(DiagnosticPos pos, Set<Whitespace> ws, String invocation, boolean argsAvailable) {
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
invocationNode.pos = pos;
invocationNode.addWS(ws);
invocationNode.addWS(invocationWsStack.pop());
if (argsAvailable) {
List<ExpressionNode> exprNodes = exprNodeListStack.pop();
exprNodes.forEach(exprNode -> invocationNode.argExprs.add((BLangExpression) exprNode));
invocationNode.addWS(commaWsStack.pop());
}
invocationNode.expr = (BLangVariableReference) exprNodeStack.pop();
invocationNode.name = (BLangIdentifier) createIdentifier(invocation);
invocationNode.pkgAlias = (BLangIdentifier) createIdentifier(null);
addExpressionNode(invocationNode);
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addAssignmentStatement.
public void addAssignmentStatement(DiagnosticPos pos, Set<Whitespace> ws, boolean isVarDeclaration, boolean safeAssignment) {
ExpressionNode rExprNode = exprNodeStack.pop();
ExpressionNode lExprNode = exprNodeStack.pop();
BLangAssignment assignmentNode = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignmentNode.setExpression(rExprNode);
assignmentNode.setDeclaredWithVar(isVarDeclaration);
assignmentNode.pos = pos;
assignmentNode.addWS(ws);
assignmentNode.safeAssignment = safeAssignment;
assignmentNode.addVariable((BLangVariableReference) lExprNode);
addStmtToCurrentBlock(assignmentNode);
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addTypeInitExpression.
public void addTypeInitExpression(DiagnosticPos pos, Set<Whitespace> ws, String initName, boolean typeAvailable, boolean exprAvailable) {
BLangTypeInit objectInitNode = (BLangTypeInit) TreeBuilder.createObjectInitNode();
objectInitNode.pos = pos;
objectInitNode.addWS(ws);
if (typeAvailable) {
objectInitNode.userDefinedType = (BLangUserDefinedType) typeNodeStack.pop();
}
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
invocationNode.pos = pos;
invocationNode.addWS(ws);
if (exprAvailable) {
List<ExpressionNode> exprNodes = exprNodeListStack.pop();
Set<Whitespace> cws = commaWsStack.pop();
exprNodes.forEach(exprNode -> {
invocationNode.argExprs.add((BLangExpression) exprNode);
objectInitNode.argsExpr.add((BLangExpression) exprNode);
});
invocationNode.addWS(cws);
objectInitNode.addWS(cws);
}
// TODO check whether pkgName can be be empty
IdentifierNode pkgNameNode = TreeBuilder.createIdentifierNode();
IdentifierNode nameNode = createIdentifier(initName);
BLangNameReference nameReference = new BLangNameReference(pos, ws, pkgNameNode, nameNode);
invocationNode.name = (BLangIdentifier) nameReference.name;
invocationNode.addWS(nameReference.ws);
invocationNode.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
objectInitNode.objectInitInvocation = invocationNode;
this.addExpressionNode(objectInitNode);
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project kubernetes by ballerinax.
the class KubernetesPlugin method process.
@Override
public void process(PackageNode packageNode) {
BLangPackage bPackage = (BLangPackage) packageNode;
KubernetesContext.getInstance().addDataHolder(bPackage.packageID, sourceDirectory.getPath());
// Get dependency jar paths
JarResolver jarResolver = KubernetesContext.getInstance().getCompilerContext().get(JAR_RESOLVER_KEY);
if (jarResolver != null) {
Set<Path> dependencyJarPaths = new HashSet<>(jarResolver.allDependencies(bPackage));
KubernetesContext.getInstance().getDataHolder(bPackage.packageID).getDockerModel().addDependencyJarPaths(dependencyJarPaths);
}
// Get the imports with alias _
List<BLangImportPackage> kubernetesImports = bPackage.getImports().stream().filter(i -> i.symbol.toString().startsWith("ballerina/kubernetes") && i.getAlias().toString().equals("_")).collect(Collectors.toList());
if (kubernetesImports.size() > 0) {
for (BLangImportPackage kubernetesImport : kubernetesImports) {
// Get the units of the file which has kubernetes import as _
List<TopLevelNode> topLevelNodes = bPackage.getCompilationUnits().stream().filter(cu -> cu.getName().equals(kubernetesImport.compUnit.getValue())).flatMap(cu -> cu.getTopLevelNodes().stream()).collect(Collectors.toList());
// Filter out the services
List<ServiceNode> serviceNodes = topLevelNodes.stream().filter(tln -> tln instanceof ServiceNode).map(tln -> (ServiceNode) tln).collect(Collectors.toList());
// Generate artifacts for services for all services
serviceNodes.forEach(sn -> process(sn, Collections.singletonList(createAnnotation("Deployment"))));
// Create Service annotation with NodePort service type
AnnotationAttachmentNode serviceAnnotation = createAnnotation("Service");
BLangRecordLiteral svcRecordLiteral = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode();
serviceAnnotation.setExpression(svcRecordLiteral);
BLangLiteral serviceTypeKey = (BLangLiteral) TreeBuilder.createLiteralExpression();
serviceTypeKey.value = ServiceAnnotationProcessor.ServiceConfiguration.serviceType.name();
serviceTypeKey.type = new BType(TypeTags.STRING, null);
BLangLiteral serviceTypeValue = new BLangLiteral();
serviceTypeValue.value = KubernetesConstants.ServiceType.NodePort.name();
serviceTypeValue.type = new BType(TypeTags.STRING, null);
BLangRecordLiteral.BLangRecordKeyValueField serviceTypeRecordField = new BLangRecordLiteral.BLangRecordKeyValueField();
serviceTypeRecordField.key = new BLangRecordLiteral.BLangRecordKey(serviceTypeKey);
serviceTypeRecordField.valueExpr = serviceTypeValue;
svcRecordLiteral.fields.add(serviceTypeRecordField);
// Filter services with 'new Listener()' and generate services
for (ServiceNode serviceNode : serviceNodes) {
Optional<? extends ExpressionNode> initListener = serviceNode.getAttachedExprs().stream().filter(aex -> aex instanceof BLangTypeInit).findAny();
if (initListener.isPresent()) {
serviceNodes.forEach(sn -> process(sn, Collections.singletonList(serviceAnnotation)));
}
}
// Get the variable names of the listeners attached to services
List<String> listenerNamesToExpose = serviceNodes.stream().map(ServiceNode::getAttachedExprs).flatMap(Collection::stream).filter(aex -> aex instanceof BLangSimpleVarRef).map(aex -> (BLangSimpleVarRef) aex).map(BLangSimpleVarRef::toString).collect(Collectors.toList());
// Generate artifacts for listeners attached to services
topLevelNodes.stream().filter(tln -> tln instanceof SimpleVariableNode).map(tln -> (SimpleVariableNode) tln).filter(listener -> listenerNamesToExpose.contains(listener.getName().getValue())).forEach(listener -> process(listener, Collections.singletonList(serviceAnnotation)));
// Generate artifacts for main functions
topLevelNodes.stream().filter(tln -> tln instanceof FunctionNode).map(tln -> (FunctionNode) tln).filter(fn -> "main".equals(fn.getName().getValue())).forEach(fn -> process(fn, Collections.singletonList(createAnnotation("Job"))));
}
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processHttpAnnotation.
/**
* Process http annotation array of the virtual service annotation to a model.
*
* @param httpArray The list of http fields.
* @return Converted list of Istio http routes.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<IstioHttpRoute> processHttpAnnotation(BLangListConstructorExpr httpArray) throws KubernetesPluginException {
List<IstioHttpRoute> httpRoutes = new LinkedList<>();
for (ExpressionNode expression : httpArray.getExpressions()) {
BLangRecordLiteral httpFields = (BLangRecordLiteral) expression;
IstioHttpRoute httpRoute = new IstioHttpRoute();
for (BLangRecordLiteral.BLangRecordKeyValueField httpField : convertRecordFields(httpFields.getFields())) {
switch(HttpRouteConfig.valueOf(httpField.getKey().toString())) {
case route:
BLangListConstructorExpr routeFields = (BLangListConstructorExpr) httpField.getValue();
httpRoute.setRoute(processRoutesAnnotation(routeFields));
break;
case timeout:
httpRoute.setTimeout(getLongValue(httpField.getValue()));
break;
case appendHeaders:
httpRoute.setAppendHeaders(getMap(httpField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + httpField.getKey().toString());
}
}
httpRoutes.add(httpRoute);
}
return httpRoutes;
}
Aggregations