|
| 1 | +import { |
| 2 | + isSdsAssignment, |
| 3 | + isSdsBlockLambdaResult, |
| 4 | + isSdsDeclaration, |
| 5 | + isSdsPlaceholder, |
| 6 | + SdsAnnotatedObject, |
| 7 | + SdsAnnotationCall, |
| 8 | + SdsAssignee, |
| 9 | + SdsAssignment, |
| 10 | + SdsBlock, |
| 11 | + SdsBlockLambda, |
| 12 | + SdsBlockLambdaResult, |
| 13 | + SdsClass, |
| 14 | + SdsClassMember, |
| 15 | + SdsEnum, |
| 16 | + SdsEnumVariant, |
| 17 | + SdsLiteral, |
| 18 | + SdsLiteralType, |
| 19 | + SdsParameter, |
| 20 | + SdsParameterList, |
| 21 | + SdsPlaceholder, |
| 22 | + SdsResult, |
| 23 | + SdsResultList, |
| 24 | + SdsStatement, |
| 25 | + SdsTypeArgument, |
| 26 | + SdsTypeArgumentList, |
| 27 | + SdsTypeParameter, |
| 28 | + SdsTypeParameterList, |
| 29 | +} from '../generated/ast.js'; |
| 30 | +import { stream } from 'langium'; |
| 31 | + |
| 32 | +export const annotationCallsOrEmpty = function (node: SdsAnnotatedObject | undefined): SdsAnnotationCall[] { |
| 33 | + if (!node) { |
| 34 | + /* c8 ignore next 2 */ |
| 35 | + return []; |
| 36 | + } |
| 37 | + |
| 38 | + if (isSdsDeclaration(node)) { |
| 39 | + return node?.annotationCallList?.annotationCalls ?? node?.annotationCalls ?? []; |
| 40 | + } else { |
| 41 | + /* c8 ignore next 2 */ |
| 42 | + return node?.annotationCalls ?? []; |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +export const assigneesOrEmpty = function (node: SdsAssignment | undefined): SdsAssignee[] { |
| 47 | + return node?.assigneeList?.assignees ?? []; |
| 48 | +}; |
| 49 | + |
| 50 | +export const blockLambdaResultsOrEmpty = function (node: SdsBlockLambda | undefined): SdsBlockLambdaResult[] { |
| 51 | + return stream(statementsOrEmpty(node?.body)) |
| 52 | + .filter(isSdsAssignment) |
| 53 | + .flatMap(assigneesOrEmpty) |
| 54 | + .filter(isSdsBlockLambdaResult) |
| 55 | + .toArray(); |
| 56 | +}; |
| 57 | + |
| 58 | +export const literalsOrEmpty = function (node: SdsLiteralType | undefined): SdsLiteral[] { |
| 59 | + return node?.literalList?.literals ?? []; |
| 60 | +}; |
| 61 | + |
| 62 | +export const classMembersOrEmpty = function (node: SdsClass | undefined): SdsClassMember[] { |
| 63 | + return node?.body?.members ?? []; |
| 64 | +}; |
| 65 | + |
| 66 | +export const parametersOrEmpty = function (node: SdsParameterList | undefined): SdsParameter[] { |
| 67 | + return node?.parameters ?? []; |
| 68 | +}; |
| 69 | + |
| 70 | +export const placeholdersOrEmpty = function (node: SdsBlock | undefined): SdsPlaceholder[] { |
| 71 | + return stream(statementsOrEmpty(node)) |
| 72 | + .filter(isSdsAssignment) |
| 73 | + .flatMap(assigneesOrEmpty) |
| 74 | + .filter(isSdsPlaceholder) |
| 75 | + .toArray(); |
| 76 | +}; |
| 77 | + |
| 78 | +export const resultsOrEmpty = function (node: SdsResultList | undefined): SdsResult[] { |
| 79 | + return node?.results ?? []; |
| 80 | +}; |
| 81 | + |
| 82 | +export const statementsOrEmpty = function (node: SdsBlock | undefined): SdsStatement[] { |
| 83 | + return node?.statements ?? []; |
| 84 | +}; |
| 85 | + |
| 86 | +export const typeArgumentsOrEmpty = function (node: SdsTypeArgumentList | undefined): SdsTypeArgument[] { |
| 87 | + return node?.typeArguments ?? []; |
| 88 | +}; |
| 89 | + |
| 90 | +export const typeParametersOrEmpty = function (node: SdsTypeParameterList | undefined): SdsTypeParameter[] { |
| 91 | + return node?.typeParameters ?? []; |
| 92 | +}; |
| 93 | + |
| 94 | +export const variantsOrEmpty = function (node: SdsEnum | undefined): SdsEnumVariant[] { |
| 95 | + return node?.body?.variants ?? []; |
| 96 | +}; |
0 commit comments