use of org.wso2.ballerinalang.programfile.ResourceInfo in project ballerina by ballerina-lang.
the class CommandExecutor method executeAddAllDocumentation.
/**
* Generate workspace edit for generating doc comments for all top level nodes and resources.
* @param context Workspace Service Context
*/
private static void executeAddAllDocumentation(WorkspaceServiceContext context) {
String documentUri = "";
VersionedTextDocumentIdentifier textDocumentIdentifier = new VersionedTextDocumentIdentifier();
for (Object arg : context.get(ExecuteCommandKeys.COMMAND_ARGUMENTS_KEY)) {
if (((LinkedTreeMap) arg).get(ARG_KEY).equals(CommandConstants.ARG_KEY_DOC_URI)) {
documentUri = (String) ((LinkedTreeMap) arg).get(ARG_VALUE);
textDocumentIdentifier.setUri(documentUri);
context.put(DocumentServiceKeys.FILE_URI_KEY, documentUri);
}
}
BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(context, context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY), false, LSCustomErrorStrategy.class, false).get(0);
String fileContent = context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY).getFileContent(Paths.get(URI.create(documentUri)));
String[] contentComponents = fileContent.split(System.lineSeparator());
List<TextEdit> textEdits = new ArrayList<>();
bLangPackage.topLevelNodes.forEach(topLevelNode -> {
CommandUtil.DocAttachmentInfo docAttachmentInfo = getDocumentEditForNode(topLevelNode);
if (docAttachmentInfo != null) {
textEdits.add(getTextEdit(docAttachmentInfo, contentComponents));
}
if (topLevelNode instanceof BLangService) {
((BLangService) topLevelNode).getResources().forEach(bLangResource -> {
CommandUtil.DocAttachmentInfo resourceInfo = getDocumentEditForNode(bLangResource);
if (resourceInfo != null) {
textEdits.add(getTextEdit(resourceInfo, contentComponents));
}
});
}
});
TextDocumentEdit textDocumentEdit = new TextDocumentEdit(textDocumentIdentifier, textEdits);
applyWorkspaceEdit(Collections.singletonList(textDocumentEdit), context.get(ExecuteCommandKeys.LANGUAGE_SERVER_KEY).getClient());
}
use of org.wso2.ballerinalang.programfile.ResourceInfo in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangResource resourceNode) {
ResourceInfo resourceInfo = currentServiceInfo.resourceInfoMap.get(resourceNode.name.getValue());
currentCallableUnitInfo = resourceInfo;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, this.env);
visitInvokableNode(resourceNode, currentCallableUnitInfo, resourceEnv);
}
use of org.wso2.ballerinalang.programfile.ResourceInfo in project ballerina by ballerina-lang.
the class CodeGenerator method createResourceInfoEntry.
private void createResourceInfoEntry(BLangResource resourceNode, ServiceInfo serviceInfo) {
BInvokableType resourceType = (BInvokableType) resourceNode.symbol.type;
// Add resource name as an UTFCPEntry to the constant pool
int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, resourceNode.name.value);
ResourceInfo resourceInfo = new ResourceInfo(currentPackageRefCPIndex, serviceNameCPIndex);
resourceInfo.paramTypes = resourceType.paramTypes.toArray(new BType[0]);
setParameterNames(resourceNode, resourceInfo);
resourceInfo.retParamTypes = new BType[0];
resourceInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(resourceInfo.paramTypes, resourceInfo.retParamTypes));
// Add worker info
int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, "default");
resourceInfo.defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
resourceNode.workers.forEach(worker -> addWorkerInfoEntry(worker, resourceInfo));
// Add resource info to the service info
serviceInfo.resourceInfoMap.put(resourceNode.name.getValue(), resourceInfo);
}
use of org.wso2.ballerinalang.programfile.ResourceInfo in project ballerina by ballerina-lang.
the class CodeGenerator method setParameterNames.
private void setParameterNames(BLangResource resourceNode, ResourceInfo resourceInfo) {
int paramCount = resourceNode.requiredParams.size();
resourceInfo.paramNameCPIndexes = new int[paramCount];
for (int i = 0; i < paramCount; i++) {
BLangVariable paramVar = resourceNode.requiredParams.get(i);
String paramName = null;
boolean isAnnotated = false;
for (BLangAnnotationAttachment annotationAttachment : paramVar.annAttachments) {
String attachmentName = annotationAttachment.getAnnotationName().getValue();
if ("PathParam".equalsIgnoreCase(attachmentName) || "QueryParam".equalsIgnoreCase(attachmentName)) {
// TODO:
// paramName = annotationAttachment.getAttributeNameValuePairs().get("value")
// .getLiteralValue().stringValue();
isAnnotated = true;
break;
}
}
if (!isAnnotated) {
paramName = paramVar.name.getValue();
}
int paramNameCPIndex = addUTF8CPEntry(currentPkgInfo, paramName);
resourceInfo.paramNameCPIndexes[i] = paramNameCPIndex;
}
}
Aggregations