use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processConfigMap.
/**
* Process ConfigMap annotations.
*
* @param attachmentNode Attachment Node
* @return Set of @{@link ConfigMapModel} objects
*/
Set<ConfigMapModel> processConfigMap(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<ConfigMapModel> configMapModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> configAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
ConfigMapModel configMapModel = new ConfigMapModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
configMapModel.setName(getValidName(annotationValue));
break;
case mountPath:
configMapModel.setMountPath(annotationValue);
break;
case isBallerinaConf:
configMapModel.setBallerinaConf(Boolean.parseBoolean(annotationValue));
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
configMapModel.setData(getDataForConfigMap(data));
break;
case readOnly:
configMapModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
configMapModels.add(configMapModel);
}
}
return configMapModels;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processPodAutoscalerAnnotation.
/**
* Process annotations and create service model object.
*
* @param attachmentNode annotation attachment node.
* @return Service model object
*/
PodAutoscalerModel processPodAutoscalerAnnotation(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
PodAutoscalerModel podAutoscalerModel = new PodAutoscalerModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
PodAutoscalerConfiguration podAutoscalerConfiguration = PodAutoscalerConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(podAutoscalerConfiguration) {
case name:
podAutoscalerModel.setName(getValidName(annotationValue));
break;
case labels:
podAutoscalerModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case cpuPercentage:
podAutoscalerModel.setCpuPercentage(Integer.parseInt(annotationValue));
break;
case minReplicas:
podAutoscalerModel.setMinReplicas(Integer.parseInt(annotationValue));
break;
case maxReplicas:
podAutoscalerModel.setMaxReplicas(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
return podAutoscalerModel;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getSignatureInfoModel.
/**
* Get the required signature information filled model.
*
* @param bInvokableSymbol Invokable symbol
* @param signatureContext Signature operation context
* @return {@link SignatureInfoModel} SignatureInfoModel containing signature information
*/
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
Map<String, String> paramDescMap = new HashMap<>();
SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
List<ParameterInfoModel> paramModels = new ArrayList<>();
String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
if (!blangFunction.getDocumentationAttachments().isEmpty()) {
// Get the first documentation attachment
BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
bLangDocumentation.attributes.forEach(attribute -> {
if (attribute.docTag.equals(DocTag.PARAM)) {
paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
}
});
} else {
// TODO: Should be deprecated in due course
// Iterate over the attachments list and extract the attachment Description Map
blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
BLangExpression expr = annotationAttachment.expr;
if (expr instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
BLangExpression key = recordKeyValue.key.expr;
BLangExpression value = recordKeyValue.getValue();
if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
String annotationValue = ((BLangLiteral) value).getValue().toString();
if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
paramDescMap.put(paramName, annotationDesc);
} else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
signatureInfoModel.setSignatureDescription(annotationValue);
}
}
}
}
});
}
bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
parameterInfoModel.setParamType(bVarSymbol.getType().toString());
parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
paramModels.add(parameterInfoModel);
});
signatureInfoModel.setParameterInfoModels(paramModels);
return signatureInfoModel;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandExecutor method getDocumentEditForNode.
/**
* Get the document edit attachment info for a given particular node.
* @param node Node given
* @return Doc Attachment Info
*/
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
int replaceFrom;
switch(node.getKind()) {
case FUNCTION:
if (((BLangFunction) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
}
break;
case STRUCT:
if (((BLangStruct) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
}
break;
case ENUM:
if (((BLangEnum) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
}
break;
case TRANSFORMER:
if (((BLangTransformer) node).docAttachments.isEmpty()) {
replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
}
break;
case RESOURCE:
if (((BLangResource) node).docAttachments.isEmpty()) {
BLangResource bLangResource = (BLangResource) node;
replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
}
break;
case SERVICE:
if (((BLangService) node).docAttachments.isEmpty()) {
BLangService bLangService = (BLangService) node;
replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
}
break;
default:
break;
}
return docAttachmentInfo;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandUtil method getStructDocumentationByPosition.
/**
* Get the Documentation attachment for the struct definition.
* @param bLangPackage BLangPackage built
* @param line Start line of the struct in the source
* @return {@link String} Documentation attachment for the struct
*/
static DocAttachmentInfo getStructDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangStruct) {
BLangStruct structNode = (BLangStruct) topLevelNode;
DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(structNode.getPosition());
int structStart = structPos.getStartLine();
if (structStart == line) {
return getStructNodeDocumentation(structNode, line);
}
}
}
return null;
}
Aggregations