use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class HoverUtil method getDocumentationContent.
/**
* Get documentation content.
*
* @param docAnnotation list of doc annotation
* @return {@link Hover} hover object.
*/
private static Hover getDocumentationContent(List<BLangDocumentation> docAnnotation) {
Hover hover = new Hover();
StringBuilder content = new StringBuilder();
BLangDocumentation bLangDocumentation = docAnnotation.get(0);
Map<String, List<BLangDocumentationAttribute>> filterAttributes = filterDocumentationAttributes(docAnnotation.get(0));
if (!bLangDocumentation.documentationText.isEmpty()) {
content.append(getFormattedHoverDocContent(ContextConstants.DESCRIPTION, bLangDocumentation.documentationText));
}
if (filterAttributes.get(ContextConstants.DOC_RECEIVER) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RECEIVER, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RECEIVER))));
}
if (filterAttributes.get(ContextConstants.DOC_PARAM) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_PARAM, getDocAttributes(filterAttributes.get(ContextConstants.DOC_PARAM))));
}
if (filterAttributes.get(ContextConstants.DOC_FIELD) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_FIELD, getDocAttributes(filterAttributes.get(ContextConstants.DOC_FIELD))));
}
if (filterAttributes.get(ContextConstants.DOC_RETURN) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RETURN, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RETURN))));
}
if (filterAttributes.get(ContextConstants.DOC_VARIABLE) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_VARIABLE, getDocAttributes(filterAttributes.get(ContextConstants.DOC_VARIABLE))));
}
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(content.toString()));
hover.setContents(contents);
return hover;
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangDocumentation docNode) {
Set<BLangIdentifier> visitedAttributes = new HashSet<>();
for (BLangDocumentationAttribute attribute : docNode.attributes) {
if (!visitedAttributes.add(attribute.documentationField)) {
this.dlog.warning(attribute.pos, DiagnosticCode.DUPLICATE_DOCUMENTED_ATTRIBUTE, attribute.documentationField);
continue;
}
Name attributeName = names.fromIdNode(attribute.documentationField);
BSymbol attributeSymbol = this.env.scope.lookup(attributeName).symbol;
if (attributeSymbol == null) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
int ownerSymTag = env.scope.owner.tag;
if ((ownerSymTag & SymTag.ANNOTATION) == SymTag.ANNOTATION) {
if (attributeSymbol.tag != SymTag.ANNOTATION_ATTRIBUTE || ((BAnnotationAttributeSymbol) attributeSymbol).docTag != attribute.docTag) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
} else {
if (attributeSymbol.tag != SymTag.VARIABLE || ((BVarSymbol) attributeSymbol).docTag != attribute.docTag) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
}
attribute.type = attributeSymbol.type;
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class HoverUtil method filterDocumentationAttributes.
/**
* Filter documentation attributes to each tags.
*
* @param bLangDocumentation documentation node
* @return {@link Map} filtered content map
*/
private static Map<String, List<BLangDocumentationAttribute>> filterDocumentationAttributes(BLangDocumentation bLangDocumentation) {
Map<String, List<BLangDocumentationAttribute>> filteredAttributes = new HashMap<>();
for (BLangDocumentationAttribute bLangDocumentationAttribute : bLangDocumentation.attributes) {
if (filteredAttributes.get(bLangDocumentationAttribute.docTag.name()) == null) {
filteredAttributes.put(bLangDocumentationAttribute.docTag.name(), new ArrayList<>());
filteredAttributes.get(bLangDocumentationAttribute.docTag.name()).add(bLangDocumentationAttribute);
} else {
filteredAttributes.get(bLangDocumentationAttribute.docTag.name()).add(bLangDocumentationAttribute);
}
}
return filteredAttributes;
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class DocumentationTest method testDeprecatedTransformer.
@Test(description = "Test doc deprecated Transformer.")
public void testDeprecatedTransformer() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/deprecated_transformer.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDeprecatedNode> dNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).deprecatedAttachments;
BLangDeprecatedNode dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Transformer is deprecated use\n" + " `transformer <Person p, Employee e> Bar(any defaultAddress) { e.name = p.firstName; }\n" + " ` instead.\n");
List<BLangDocumentation> docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
BLangDocumentation docNode = docNodes.get(0);
Assert.assertNotNull(docNode);
Assert.assertEquals(docNode.documentationText, "\n Transformer Foo Person -> Employee\n ");
Assert.assertEquals(docNode.getAttributes().size(), 3);
Assert.assertEquals(docNode.getAttributes().get(0).documentationField.getValue(), "p");
Assert.assertEquals(docNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
Assert.assertEquals(docNode.getAttributes().get(1).documentationField.getValue(), "e");
Assert.assertEquals(docNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
Assert.assertEquals(docNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
Assert.assertEquals(docNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class DocumentationTest method testDocEnum.
@Test(description = "Test doc annotation enum.")
public void testDocEnum() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/enum.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
}
Aggregations