Search in sources :

Example 1 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class CommandExecutor method getDocumentEditForNode.

/**
 * Get the document edit attachment info for a given particular node.
 * @param node      Node given
 * @return          Doc Attachment Info
 */
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
    CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
    int replaceFrom;
    switch(node.getKind()) {
        case FUNCTION:
            if (((BLangFunction) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
            }
            break;
        case STRUCT:
            if (((BLangStruct) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
            }
            break;
        case ENUM:
            if (((BLangEnum) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
            }
            break;
        case TRANSFORMER:
            if (((BLangTransformer) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
            }
            break;
        case RESOURCE:
            if (((BLangResource) node).docAttachments.isEmpty()) {
                BLangResource bLangResource = (BLangResource) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
            }
            break;
        case SERVICE:
            if (((BLangService) node).docAttachments.isEmpty()) {
                BLangService bLangService = (BLangService) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
            }
            break;
        default:
            break;
    }
    return docAttachmentInfo;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum)

Example 2 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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 3 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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 4 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class SymbolEnter method createReceiver.

private BLangVariable createReceiver(BLangStruct struct) {
    BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
    receiver.pos = struct.pos;
    IdentifierNode name = createIdentifier(Names.SELF.getValue());
    receiver.setName(name);
    receiver.docTag = DocTag.RECEIVER;
    BLangUserDefinedType structTypeNode = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    structTypeNode.pkgAlias = new BLangIdentifier();
    structTypeNode.typeName = struct.name;
    receiver.setTypeNode(structTypeNode);
    return receiver;
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 5 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangStruct structNode) {
    BSymbol structSymbol = structNode.symbol;
    SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
    structNode.fields.forEach(field -> analyzeDef(field, structEnv));
    structNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
        annotationAttachment.accept(this);
    });
    analyzeDef(structNode.initFunction, structEnv);
    structNode.docAttachments.forEach(doc -> analyzeDef(doc, structEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Aggregations

BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)11 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)10 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)7 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 List (java.util.List)6 CompileResult (org.ballerinalang.launcher.util.CompileResult)6 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)6 PackageNode (org.ballerinalang.model.tree.PackageNode)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5