use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandUtil method getTransformerDocumentationByPosition.
/**
* Get the Documentation attachment for the transformer.
* @param bLangPackage BLangPackage built
* @param line Start line of the transformer in the source
* @return {@link String} Documentation attachment for the transformer
*/
static DocAttachmentInfo getTransformerDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangTransformer) {
BLangTransformer transformerNode = (BLangTransformer) topLevelNode;
DiagnosticPos transformerPos = CommonUtil.toZeroBasedPosition(transformerNode.getPosition());
int transformerStart = transformerPos.getStartLine();
if (transformerStart == line) {
return getTransformerNodeDocumentation(transformerNode, line);
}
}
}
return null;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment 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.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandUtil method getFunctionDocumentationByPosition.
/**
* Get the Documentation attachment for the function.
* @param bLangPackage BLangPackage built
* @param line Start line of the function in the source
* @return {@link String} Documentation attachment for the function
*/
static DocAttachmentInfo getFunctionDocumentationByPosition(BLangPackage bLangPackage, int line) {
List<FunctionNode> filteredFunctions = new ArrayList<>();
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangFunction) {
filteredFunctions.add((BLangFunction) topLevelNode);
} else if (topLevelNode instanceof BLangObject) {
filteredFunctions.addAll(((BLangObject) topLevelNode).getFunctions());
}
for (FunctionNode filteredFunction : filteredFunctions) {
DiagnosticPos functionPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) filteredFunction.getPosition());
int functionStart = functionPos.getStartLine();
if (functionStart == line) {
return getFunctionNodeDocumentation(filteredFunction, line);
}
}
}
return null;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandUtil method getEnumDocumentationByPosition.
/**
* Get the Documentation attachment for the enum.
* @param bLangPackage BLangPackage built
* @param line Start line of the enum in the source
* @return {@link String} Documentation attachment for the enum
*/
static DocAttachmentInfo getEnumDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangEnum) {
BLangEnum enumNode = (BLangEnum) topLevelNode;
DiagnosticPos enumPos = CommonUtil.toZeroBasedPosition(enumNode.getPosition());
int enumStart = enumPos.getStartLine();
if (enumStart == line) {
return getEnumNodeDocumentation(enumNode, line);
}
}
}
return null;
}
Aggregations