use of org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createDocumentationAttribute.
public void createDocumentationAttribute(DiagnosticPos pos, Set<Whitespace> ws, String attributeName, String endText, String docPrefix) {
BLangDocumentationAttribute attrib = (BLangDocumentationAttribute) TreeBuilder.createDocumentationAttributeNode();
attrib.documentationField = (BLangIdentifier) createIdentifier(attributeName);
attrib.documentationText = endText;
attrib.docTag = DocTag.fromString(docPrefix);
attrib.pos = pos;
attrib.addWS(ws);
docAttachmentStack.peek().addAttribute(attrib);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute 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.expressions.BLangDocumentationAttribute 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.expressions.BLangDocumentationAttribute 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;
}
Aggregations