Search in sources :

Example 1 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class CommandUtil method getStructDocumentationByPosition.

/**
 * Get the Documentation attachment for the struct definition.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the struct in the source
 * @return {@link String}   Documentation attachment for the struct
 */
static DocAttachmentInfo getStructDocumentationByPosition(BLangPackage bLangPackage, int line) {
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangStruct) {
            BLangStruct structNode = (BLangStruct) topLevelNode;
            DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(structNode.getPosition());
            int structStart = structPos.getStartLine();
            if (structStart == line) {
                return getStructNodeDocumentation(structNode, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 2 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class CommandUtil method getEnumNodeDocumentation.

static DocAttachmentInfo getEnumNodeDocumentation(BLangEnum bLangEnum, int replaceFrom) {
    List<String> attributes = new ArrayList<>();
    DiagnosticPos enumPos = CommonUtil.toZeroBasedPosition(bLangEnum.getPosition());
    int offset = enumPos.getStartColumn();
    bLangEnum.getEnumerators().forEach(enumerator -> attributes.add(getDocumentationAttribute(DocTag.FIELD.getValue(), enumerator.getName().getValue(), offset)));
    return new DocAttachmentInfo(getDocumentationAttachment(attributes, enumPos.getStartColumn()), replaceFrom);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) ArrayList(java.util.ArrayList)

Example 3 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class CommandUtil method getServiceDocumentationByPosition.

/**
 * Get the Documentation attachment for the service.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the service in the source
 * @return {@link String}   Documentation attachment for the service
 */
static DocAttachmentInfo getServiceDocumentationByPosition(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;
            DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
            List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
            if (!annotationAttachments.isEmpty()) {
                DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
                if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
                    return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
                }
            } else if (servicePos.getStartLine() == line) {
                return getServiceNodeDocumentation(serviceNode, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 4 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class CommandUtil method getStructNodeDocumentation.

static DocAttachmentInfo getStructNodeDocumentation(BLangStruct bLangStruct, int replaceFrom) {
    List<String> attributes = new ArrayList<>();
    DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(bLangStruct.getPosition());
    int offset = structPos.getStartColumn();
    bLangStruct.getFields().forEach(bLangVariable -> attributes.add(getDocAttributeFromBLangVariable(bLangVariable, offset)));
    return new DocAttachmentInfo(getDocumentationAttachment(attributes, structPos.getStartColumn()), replaceFrom);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) ArrayList(java.util.ArrayList)

Example 5 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class SymbolEnter method createNativeInitAction.

private BLangAction createNativeInitAction(DiagnosticPos pos) {
    BLangAction initAction = (BLangAction) TreeBuilder.createActionNode();
    initAction.setName(createIdentifier(Names.INIT_ACTION_SUFFIX.getValue()));
    initAction.flagSet = EnumSet.of(Flag.NATIVE, Flag.PUBLIC);
    initAction.pos = pos;
    return initAction;
}
Also used : BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Aggregations

DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)56 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)33 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)22 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17 ArrayList (java.util.ArrayList)15 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)14 Whitespace (org.ballerinalang.model.Whitespace)13 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)12 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)11 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)11 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)9 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)9 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)9 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)9 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)9 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)9 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)8 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)8