Search in sources :

Example 1 with BLangEnum

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

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

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

the class CodeGenerator method createEnumInfoEntry.

private void createEnumInfoEntry(BLangEnum enumNode) {
    BTypeSymbol enumSymbol = (BTypeSymbol) enumNode.symbol;
    // Add Enum name as an UTFCPEntry to the constant pool
    int enumNameCPIndex = addUTF8CPEntry(currentPkgInfo, enumSymbol.name.value);
    EnumInfo enumInfo = new EnumInfo(currentPackageRefCPIndex, enumNameCPIndex, enumSymbol.flags);
    currentPkgInfo.addEnumInfo(enumSymbol.name.value, enumInfo);
    enumInfo.enumType = (BEnumType) enumSymbol.type;
    for (int i = 0; i < enumNode.enumerators.size(); i++) {
        BLangEnumerator enumeratorNode = enumNode.enumerators.get(i);
        enumeratorNode.symbol.varIndex = new RegIndex(i, enumSymbol.type.tag);
        enumeratorNode.symbol.varIndex.isVarIndex = true;
        int enumeratorNameCPIndex = addUTF8CPEntry(currentPkgInfo, enumeratorNode.symbol.name.toString());
        EnumeratorInfo enumeratorInfo = new EnumeratorInfo(enumeratorNameCPIndex, i, enumInfo.enumType);
        enumInfo.enumeratorInfoList.add(enumeratorInfo);
    }
}
Also used : EnumInfo(org.wso2.ballerinalang.programfile.EnumInfo) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) EnumeratorInfo(org.wso2.ballerinalang.programfile.EnumeratorInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 4 with BLangEnum

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

the class BLangPackageBuilder method startEnumDef.

public void startEnumDef(DiagnosticPos pos) {
    BLangEnum bLangEnum = (BLangEnum) TreeBuilder.createEnumNode();
    bLangEnum.pos = pos;
    attachAnnotations(bLangEnum);
    attachDocumentations(bLangEnum);
    attachDeprecatedNode(bLangEnum);
    this.enumStack.add(bLangEnum);
}
Also used : BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum)

Example 5 with BLangEnum

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

the class SymbolEnter method visit.

@Override
public void visit(BLangEnum enumNode) {
    BTypeSymbol enumSymbol = Symbols.createEnumSymbol(Flags.asMask(enumNode.flagSet), names.fromIdNode(enumNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    enumNode.symbol = enumSymbol;
    defineSymbol(enumNode.pos, enumSymbol);
    BEnumType enumType = new BEnumType(enumSymbol, null);
    enumSymbol.type = enumType;
    SymbolEnv enumEnv = SymbolEnv.createPkgLevelSymbolEnv(enumNode, enumSymbol.scope, this.env);
    for (int i = 0; i < enumNode.enumerators.size(); i++) {
        BLangEnumerator enumerator = enumNode.enumerators.get(i);
        BVarSymbol enumeratorSymbol = new BVarSymbol(Flags.PUBLIC, names.fromIdNode(enumerator.name), enumSymbol.pkgID, enumType, enumSymbol);
        enumeratorSymbol.docTag = DocTag.FIELD;
        enumerator.symbol = enumeratorSymbol;
        if (symResolver.checkForUniqueSymbol(enumerator.pos, enumEnv, enumeratorSymbol, enumeratorSymbol.tag)) {
            enumEnv.scope.define(enumeratorSymbol.name, enumeratorSymbol);
        }
    }
}
Also used : BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType)

Aggregations

BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)7 Test (org.testng.annotations.Test)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)3 PackageNode (org.ballerinalang.model.tree.PackageNode)3 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)3 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)3 ArrayList (java.util.ArrayList)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)2 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1