use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class CommandUtil method getResourceDocumentationByPosition.
/**
* Get the Documentation attachment for the resource.
* @param bLangPackage BLangPackage built
* @param line Start line of the resource in the source
* @return {@link String} Documentation attachment for the resource
*/
static DocAttachmentInfo getResourceDocumentationByPosition(BLangPackage bLangPackage, int line) {
// TODO: Currently resource position is invalid and we use the annotation attachment positions.
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangService) {
BLangService serviceNode = (BLangService) topLevelNode;
for (BLangResource bLangResource : serviceNode.getResources()) {
List<BLangAnnotationAttachment> annotationAttachments = bLangResource.getAnnotationAttachments();
DiagnosticPos resourcePos = CommonUtil.toZeroBasedPosition(bLangResource.getPosition());
if (!annotationAttachments.isEmpty()) {
DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
if (lastAttachmentPos.getEndLine() < line && line < resourcePos.getEndLine()) {
return getResourceNodeDocumentation(bLangResource, lastAttachmentPos.getEndLine() + 1);
}
} else if (resourcePos.getStartLine() == line) {
return getResourceNodeDocumentation(bLangResource, line);
}
}
}
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class CommandUtil method getResourceNodeDocumentation.
static DocAttachmentInfo getResourceNodeDocumentation(BLangResource bLangResource, int replaceFrom) {
List<String> attributes = new ArrayList<>();
DiagnosticPos resourcePos = CommonUtil.toZeroBasedPosition(bLangResource.getPosition());
bLangResource.getParameters().forEach(bLangVariable -> {
if (!(bLangVariable.symbol instanceof BEndpointVarSymbol)) {
attributes.add(getDocAttributeFromBLangVariable(bLangVariable, resourcePos.getStartColumn()));
}
});
return new DocAttachmentInfo(getDocumentationAttachment(attributes, resourcePos.getStartColumn()), replaceFrom);
}
Aggregations