@Override public Map<String, BLangMarkdownParameterDocumentation> getParameterDocumentations() { Map<String, BLangMarkdownParameterDocumentation> parameterDocumentations = new HashMap<>(); parameters.forEach(p -> parameterDocumentations.put(p.getParameterName().getValue(), p)); return parameterDocumentations; }
@Override public void visit(BLangInvocation invocationExpr) { StringBuilder sqlStringBuilder = new StringBuilder(); if (invocationExpr.pkgAlias != null) { String pkgAlias = invocationExpr.pkgAlias.value; if (pkgAlias != null && !pkgAlias.isEmpty()) { sqlStringBuilder.append(pkgAlias).append(":"); } } sqlStringBuilder.append(invocationExpr.getName().getValue()).append("("); List<String> argList = new ArrayList<>(); for (BLangExpression arg : invocationExpr.argExprs) { arg.accept(this); argList.add(exprStack.pop()); } sqlStringBuilder.append(String.join(", ", argList)).append(")"); exprStack.push(sqlStringBuilder.toString()); }
/** * Retrieve a specific annotation by name from a list of annotations. * * @param name name of the required annotation * @param pkg package of the required annotation * @param annotations list of annotations containing the required annotation * @return returns annotation with the name <code>name</code> if found or * null if annotation not found in the list */ public static AnnotationAttachmentNode getAnnotationFromList(String name, String pkg, List<? extends AnnotationAttachmentNode> annotations) { AnnotationAttachmentNode annotation = null; if (name == null || pkg == null) { return null; } for (AnnotationAttachmentNode ann : annotations) { if (pkg.equals(ann.getPackageAlias().getValue()) && name.equals(ann.getAnnotationName().getValue())) { annotation = ann; } } return annotation; }
private String getParamNames(List<BLangVariable> paramTypes) { return paramTypes.stream().map(paramType -> { if (paramType.getKind() == NodeKind.USER_DEFINED_TYPE) { return ((UserDefinedTypeNode) paramType).getTypeName().getValue(); } else { return paramType.toString(); } }).collect(Collectors.joining(", ")); } }
@Override public void visit(BLangStreamAction streamAction) { streamActionClause = new StringBuilder("insert into "); String streamName = "stream" + streamAction.getInvokableBody().getFunctionNode().getName().getValue(); streamName = streamName.replaceAll("\\$", "_"); streamActionClause.append(streamName); }
/** * Get the current file's imports. * * @param pkg BLangPackage to extract content from * @param ctx LS Operation Context * @return {@link List} List of imports in the current file */ public static List<BLangImportPackage> getCurrentFileImports(BLangPackage pkg, LSContext ctx) { String currentFile = ctx.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY); return getCurrentFileTopLevelNodes(pkg, ctx).stream() .filter(topLevelNode -> topLevelNode instanceof BLangImportPackage) .map(topLevelNode -> (BLangImportPackage) topLevelNode) .filter(bLangImportPackage -> bLangImportPackage.pos.getSource().cUnitName.replace("/", FILE_SEPARATOR).equals(currentFile) && !(bLangImportPackage.getOrgName().getValue().equals("ballerina") && getPackageNameComponentsCombined(bLangImportPackage).equals("transaction"))) .collect(Collectors.toList()); }
private String getOutputFilePath(ServiceNode serviceNode) { String cUnit = serviceNode.getPosition().getSource().getCompilationUnitName(); String dir = cUnit.substring(0, cUnit.lastIndexOf(File.separator) + 1); String file = serviceNode.getName().getValue().toLowerCase(Locale.ENGLISH) + "_client.bal"; return dir + file; }
@Override public void process(ServiceNode serviceData, List<AnnotationAttachmentNode> annotations) { List<BLangFunction> resources = (List<BLangFunction>) serviceData.getResources(); resources.forEach(res -> validate(serviceData.getName().getValue(), res, this.dlog)); }
private static boolean isServerStreaming(FunctionNode resourceNode) { boolean serverStreaming = false; for (AnnotationAttachmentNode annotationNode : resourceNode.getAnnotationAttachments()) { if (!ANN_RESOURCE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) { continue; } if (annotationNode.getExpression() instanceof BLangRecordLiteral) { List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode .getExpression()).getKeyValuePairs(); for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) { String attributeName = attributeNode.getKey().toString(); String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null; if (ANN_ATTR_RESOURCE_SERVER_STREAM.equals(attributeName)) { serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue); } } } } return serverStreaming; }
@SuppressWarnings("unchecked") @Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { if (annotations.size() > 1) { int count = 0; for (AnnotationAttachmentNode annotation : annotations) { if (annotation.getAnnotationName().getValue().equals(WEBSOCKET_ANNOTATION_CONFIGURATION)) { count++; } } if (count > 1) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "There cannot be more than one " + WEBSOCKET_SERVICE + " annotations"); } } List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); resources.forEach( res -> WebSocketResourceValidator.validate(res, dlog, isResourceReturnsErrorOrNil(res), false)); } }
public void visit(BLangAnnotationAttachment annAttachmentNode) { BSymbol symbol = this.symResolver.resolveAnnotation(annAttachmentNode.pos, env, names.fromString(annAttachmentNode.pkgAlias.getValue()), names.fromString(annAttachmentNode.getAnnotationName().getValue())); if (symbol == this.symTable.notFoundSymbol) { this.dlog.error(annAttachmentNode.pos, DiagnosticCode.UNDEFINED_ANNOTATION, annAttachmentNode.getAnnotationName().getValue()); return; } // Validate Attachment Point against the Annotation Definition. BAnnotationSymbol annotationSymbol = (BAnnotationSymbol) symbol; annAttachmentNode.annotationSymbol = annotationSymbol; if (annotationSymbol.attachPoints > 0 && !Symbols.isAttachPointPresent(annotationSymbol.attachPoints, AttachPoints.asMask(annAttachmentNode.attachPoints))) { String msg = annAttachmentNode.attachPoints.stream() .map(AttachPoint::getValue) .collect(Collectors .joining(",")); this.dlog.error(annAttachmentNode.pos, DiagnosticCode.ANNOTATION_NOT_ALLOWED, annotationSymbol, msg); } // Validate Annotation Attachment data struct against Annotation Definition struct. validateAnnotationAttachmentExpr(annAttachmentNode, annotationSymbol); }
@Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { for (AnnotationAttachmentNode attachmentNode : annotations) { String annotationKey = attachmentNode.getAnnotationName().getValue(); try { AnnotationProcessorFactory.getAnnotationProcessorInstance(annotationKey).processAnnotation (serviceNode, attachmentNode); } catch (KubernetesPluginException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage()); } } }
@Override public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues); if (isBlank(vsModel.getName())) { vsModel.setName(getValidName(serviceNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX); } setDefaultValues(vsModel); KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(serviceNode.getName().getValue(), vsModel); }
@Override public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioGatewayModel gwModel = this.processIstioGatewayAnnotation(keyValues); if (isBlank(gwModel.getName())) { gwModel.setName(getValidName(serviceNode.getName().getValue()) + ISTIO_GATEWAY_POSTFIX); } setDefaultValues(gwModel); KubernetesContext.getInstance().getDataHolder().addIstioGatewayModel(serviceNode.getName().getValue(), gwModel); }
@Override public void process(FunctionNode functionNode, List<AnnotationAttachmentNode> annotations) { for (AnnotationAttachmentNode attachmentNode : annotations) { String annotationKey = attachmentNode.getAnnotationName().getValue(); try { AnnotationProcessorFactory.getAnnotationProcessorInstance(annotationKey).processAnnotation (functionNode, attachmentNode); } catch (KubernetesPluginException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, functionNode.getPosition(), e.getMessage()); } } }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues); if (isBlank(vsModel.getName())) { vsModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX); } setDefaultValues(vsModel); KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(variableNode.getName().getValue(), vsModel); }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioGatewayModel gwModel = this.processIstioGatewayAnnotation(keyValues); if (isBlank(gwModel.getName())) { gwModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_GATEWAY_POSTFIX); } setDefaultValues(gwModel); KubernetesContext.getInstance().getDataHolder().addIstioGatewayModel(variableNode.getName().getValue(), gwModel); }
@Override public void process(SimpleVariableNode variableNode, List<AnnotationAttachmentNode> annotations) { if (!variableNode.getFlags().contains(Flag.LISTENER)) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, variableNode.getPosition(), "@kubernetes annotations are only " + "supported with listeners."); return; } for (AnnotationAttachmentNode attachmentNode : annotations) { String annotationKey = attachmentNode.getAnnotationName().getValue(); try { AnnotationProcessorFactory.getAnnotationProcessorInstance(annotationKey).processAnnotation (variableNode, attachmentNode); } catch (KubernetesPluginException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, variableNode.getPosition(), e.getMessage()); } } }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { ServiceModel serviceModel = getServiceModelFromAnnotation(attachmentNode); if (isBlank(serviceModel.getName())) { serviceModel.setName(getValidName(variableNode.getName().getValue()) + SVC_POSTFIX); } // If service annotation port is not empty, then listener port is used for the k8s svc target port while // service annotation port is used for k8s port. // If service annotation port is empty, then listener port is used for both port and target port of the k8s // svc. BLangTypeInit bListener = (BLangTypeInit) ((BLangSimpleVariable) variableNode).expr; if (serviceModel.getPort() == -1) { serviceModel.setPort(extractPort(bListener)); } serviceModel.setTargetPort(extractPort(bListener)); KubernetesContext.getInstance().getDataHolder().addBListenerToK8sServiceMap(variableNode.getName().getValue() , serviceModel); }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { IngressModel ingressModel = getIngressModelFromAnnotation(attachmentNode); String listenerName = variableNode.getName().getValue(); if (isBlank(ingressModel.getName())) { ingressModel.setName(getValidName(listenerName) + INGRESS_POSTFIX); } if (isBlank(ingressModel.getHostname())) { ingressModel.setHostname(getValidName(listenerName) + INGRESS_HOSTNAME_POSTFIX); } ingressModel.setListenerName(listenerName); BLangTypeInit bListener = (BLangTypeInit) ((BLangSimpleVariable) variableNode).expr; if (bListener.argsExpr.size() == 2) { if (bListener.argsExpr.get(1) instanceof BLangNamedArgsExpression) { BLangNamedArgsExpression configArg = (BLangNamedArgsExpression) bListener.argsExpr.get(1); BLangRecordLiteral bConfigRecordLiteral = (BLangRecordLiteral) configArg.expr; List<BLangRecordLiteral.BLangRecordKeyValue> listenerConfig = bConfigRecordLiteral.getKeyValuePairs(); processListener(listenerName, listenerConfig); } } KubernetesContext.getInstance().getDataHolder().addIngressModel(ingressModel); }