Code review comment: For now, this is ok I guess. But this should be set to the position covering the finite type elements. i.e., starting pos should be the first element's starting pos and the ending pos should be the last element's ending pos.

Code before review:
public BLangNode transform(UnionTypeDescriptorNode unionTypeDescriptorNode) {
List<TypeDescriptorNode> nodes = flattenUnionType(unionTypeDescriptorNode);
List<TypeDescriptorNode> finiteTypeElements = new ArrayList<>();
List<List<TypeDescriptorNode>> unionTypeElementsCollection = new ArrayList<>();
for (TypeDescriptorNode type : nodes) {
if (type.kind() == SyntaxKind.SINGLETON_TYPE_DESC) {
finiteTypeElements.add(type);
unionTypeElementsCollection.add(new ArrayList<>());
} else {
List<TypeDescriptorNode> lastOfOthers;
if (unionTypeElementsCollection.isEmpty()) {
lastOfOthers = new ArrayList<>();
unionTypeElementsCollection.add(lastOfOthers);
} else {
lastOfOthers = unionTypeElementsCollection.get(unionTypeElementsCollection.size() - 1);
}
lastOfOthers.add(type);
}
}
List<TypeDescriptorNode> unionElements = new ArrayList<>();
reverseFlatMap(unionTypeElementsCollection, unionElements);
BLangFiniteTypeNode bLangFiniteTypeNode = (BLangFiniteTypeNode) TreeBuilder.createFiniteTypeNode();
for (TypeDescriptorNode finiteTypeEl : finiteTypeElements) {
SingletonTypeDescriptorNode singletonTypeNode = (SingletonTypeDescriptorNode) finiteTypeEl;
BLangLiteral literal = createSimpleLiteral(singletonTypeNode.simpleContExprNode(), true);
bLangFiniteTypeNode.addValue(literal);
}
if (unionElements.isEmpty()) {
return bLangFiniteTypeNode;
}
BLangUnionTypeNode unionTypeNode = (BLangUnionTypeNode) TreeBuilder.createUnionTypeNode();
unionTypeNode.pos = getPosition(unionTypeDescriptorNode);
for (TypeDescriptorNode unionElement : unionElements) {
unionTypeNode.memberTypeNodes.add(createTypeNode(unionElement));
}
bLangFiniteTypeNode.setPosition(unionTypeNode.pos);
if (!finiteTypeElements.isEmpty()) {
unionTypeNode.memberTypeNodes.add(deSugarTypeAsUserDefType(bLangFiniteTypeNode));
}
return unionTypeNode;
}

Line under review: bLangFiniteTypeNode.setPosition(unionTypeNode.pos);

Code after addressing the review:
public BLangNode transform(UnionTypeDescriptorNode unionTypeDescriptorNode) {
List<TypeDescriptorNode> nodes = flattenUnionType(unionTypeDescriptorNode);
List<TypeDescriptorNode> finiteTypeElements = new ArrayList<>();
List<List<TypeDescriptorNode>> unionTypeElementsCollection = new ArrayList<>();
for (TypeDescriptorNode type : nodes) {
if (type.kind() == SyntaxKind.SINGLETON_TYPE_DESC) {
finiteTypeElements.add(type);
unionTypeElementsCollection.add(new ArrayList<>());
} else {
List<TypeDescriptorNode> lastOfOthers;
if (unionTypeElementsCollection.isEmpty()) {
lastOfOthers = new ArrayList<>();
unionTypeElementsCollection.add(lastOfOthers);
} else {
lastOfOthers = unionTypeElementsCollection.get(unionTypeElementsCollection.size() - 1);
}
lastOfOthers.add(type);
}
}
List<TypeDescriptorNode> unionElements = new ArrayList<>();
reverseFlatMap(unionTypeElementsCollection, unionElements);
BLangFiniteTypeNode bLangFiniteTypeNode = (BLangFiniteTypeNode) TreeBuilder.createFiniteTypeNode();
for (TypeDescriptorNode finiteTypeEl : finiteTypeElements) {
SingletonTypeDescriptorNode singletonTypeNode = (SingletonTypeDescriptorNode) finiteTypeEl;
BLangLiteral literal = createSimpleLiteral(singletonTypeNode.simpleContExprNode(), true);
bLangFiniteTypeNode.addValue(literal);
}
if (unionElements.isEmpty()) {
return bLangFiniteTypeNode;
}
BLangUnionTypeNode unionTypeNode = (BLangUnionTypeNode) TreeBuilder.createUnionTypeNode();
unionTypeNode.pos = getPosition(unionTypeDescriptorNode);
for (TypeDescriptorNode unionElement : unionElements) {
unionTypeNode.memberTypeNodes.add(createTypeNode(unionElement));
}
bLangFiniteTypeNode.setPosition(unionTypeNode.pos);
if (!finiteTypeElements.isEmpty()) {
unionTypeNode.memberTypeNodes.add(deSugarTypeAsUserDefType(bLangFiniteTypeNode));
}
return unionTypeNode;
}