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;
}
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);
}
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);
}
}
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);
}
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);
}
}
}
Aggregations