Search in sources :

Example 1 with BLangDocumentationAttribute

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);
}
Also used : BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute)

Example 2 with BLangDocumentationAttribute

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;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) ArrayList(java.util.ArrayList) List(java.util.List) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 3 with BLangDocumentationAttribute

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;
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) HashSet(java.util.HashSet) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 4 with BLangDocumentationAttribute

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;
}
Also used : HashMap(java.util.HashMap) BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute) ArrayList(java.util.ArrayList) List(java.util.List) MarkedString(org.eclipse.lsp4j.MarkedString)

Aggregations

BLangDocumentationAttribute (org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MarkedString (org.eclipse.lsp4j.MarkedString)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Hover (org.eclipse.lsp4j.Hover)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1 BAnnotationAttributeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)1 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 Name (org.wso2.ballerinalang.compiler.util.Name)1