diff --git a/src/cli/generator.ts b/src/cli/generator.ts index e53a6b454..59fe7b7ba 100644 --- a/src/cli/generator.ts +++ b/src/cli/generator.ts @@ -57,14 +57,14 @@ import chalk from 'chalk'; import { createSafeDsServices, SafeDsServices } from '../language/safe-ds-module.js'; import { NodeFileSystem } from 'langium/node'; import { - abstractResultsOrEmpty, - assigneesOrEmpty, - blockLambdaResultsOrEmpty, - importedDeclarationsOrEmpty, - importsOrEmpty, + getAbstractResults, + getAssignees, + streamBlockLambdaResults, + getImportedDeclarations, + getImports, isRequiredParameter, - moduleMembersOrEmpty, - statementsOrEmpty, + getModuleMembers, + getStatements, } from '../language/helpers/nodeProperties.js'; import { IdManager } from '../language/helpers/idManager.js'; import { isInStubFile } from '../language/helpers/fileExtensions.js'; @@ -150,10 +150,10 @@ const formatGeneratedFileName = function (baseName: string): string { const generateModule = function (services: SafeDsServices, module: SdsModule): string { const importSet = new Map(); - const segments = moduleMembersOrEmpty(module) + const segments = getModuleMembers(module) .filter(isSdsSegment) .map((segment) => generateSegment(services, segment, importSet)); - const pipelines = moduleMembersOrEmpty(module) + const pipelines = getModuleMembers(module) .filter(isSdsPipeline) .map((pipeline) => generatePipeline(services, pipeline, importSet)); const imports = generateImports(Array.from(importSet.values())); @@ -167,7 +167,7 @@ const generateModule = function (services: SafeDsServices, module: SdsModule): s } if (segments.length > 0) { output.push( - expandToStringWithNL`# Steps ------------------------------------------------------------------------\n\n${segments.join( + expandToStringWithNL`# Segments ---------------------------------------------------------------------\n\n${segments.join( '\n\n', )}`, ); @@ -266,7 +266,7 @@ const generateQualifiedImport = function (importStmt: ImportData): string { const generateBlock = function (block: SdsBlock, frame: GenerationInfoFrame): string { // TODO filter withEffect - let statements = statementsOrEmpty(block); + let statements = getStatements(block); if (statements.length === 0) { return 'pass'; } @@ -291,12 +291,10 @@ const generateStatement = function (statement: SdsStatement, frame: GenerationIn const generateAssignment = function (assignment: SdsAssignment, frame: GenerationInfoFrame): string { const requiredAssignees = isSdsCall(assignment.expression) - ? abstractResultsOrEmpty( - frame.getServices().helpers.NodeMapper.callToCallableOrUndefined(assignment.expression), - ).length + ? getAbstractResults(frame.getServices().helpers.NodeMapper.callToCallable(assignment.expression)).length : /* c8 ignore next */ 1; - const assignees = assigneesOrEmpty(assignment); + const assignees = getAssignees(assignment); if (assignees.some((value) => !isSdsWildcard(value))) { const actualAssignees = assignees.map(generateAssignee); if (requiredAssignees === actualAssignees.length) { @@ -327,12 +325,10 @@ const generateAssignee = function (assignee: SdsAssignee): string { }; const generateBlockLambda = function (blockLambda: SdsBlockLambda, frame: GenerationInfoFrame): string { - const lambdaResult = blockLambdaResultsOrEmpty(blockLambda); + const results = streamBlockLambdaResults(blockLambda); let lambdaBlock = generateBlock(blockLambda.body, frame); - if (lambdaResult.length !== 0 && lambdaBlock !== 'pass') { - lambdaBlock += `\nreturn ${lambdaResult - .map((result) => `${BLOCK_LAMBDA_RESULT_PREFIX}${result.name}`) - .join(', ')}`; + if (!results.isEmpty()) { + lambdaBlock += `\nreturn ${results.map((result) => `${BLOCK_LAMBDA_RESULT_PREFIX}${result.name}`).join(', ')}`; } return expandToString`def ${frame.getUniqueLambdaBlockName(blockLambda)}(${generateParameters( blockLambda.parameterList, @@ -431,7 +427,7 @@ const generateExpression = function (expression: SdsExpression, frame: Generatio const suffix = isSdsCall(expression.$container) ? '' : '()'; return `${receiver}.${enumMember}${suffix}`; } else if (isSdsAbstractResult(member)) { - const resultList = abstractResultsOrEmpty(getContainerOfType(member, isSdsCallable)); + const resultList = getAbstractResults(getContainerOfType(member, isSdsCallable)); if (resultList.length === 1) { return receiver; } @@ -474,7 +470,7 @@ const generateExpression = function (expression: SdsExpression, frame: Generatio const sortArguments = function (services: SafeDsServices, argumentList: SdsArgument[]): SdsArgument[] { // $containerIndex contains the index of the parameter in the receivers parameter list const parameters = argumentList.map((argument) => { - return { par: services.helpers.NodeMapper.argumentToParameterOrUndefined(argument), arg: argument }; + return { par: services.helpers.NodeMapper.argumentToParameter(argument), arg: argument }; }); return parameters .slice() @@ -486,7 +482,7 @@ const sortArguments = function (services: SafeDsServices, argumentList: SdsArgum }; const generateArgument = function (argument: SdsArgument, frame: GenerationInfoFrame) { - const parameter = frame.getServices().helpers.NodeMapper.argumentToParameterOrUndefined(argument); + const parameter = frame.getServices().helpers.NodeMapper.argumentToParameter(argument); return expandToString`${ parameter !== undefined && !isRequiredParameter(parameter) ? generateParameter(parameter, frame, false) + '=' @@ -502,13 +498,13 @@ const getExternalReferenceNeededImport = function ( // Root Node is always a module. const currentModule = findRootNode(expression); const targetModule = findRootNode(declaration); - for (const value of importsOrEmpty(currentModule)) { + for (const value of getImports(currentModule)) { // Verify same package if (value.package !== targetModule.name) { continue; } if (isSdsQualifiedImport(value)) { - const importedDeclarations = importedDeclarationsOrEmpty(value); + const importedDeclarations = getImportedDeclarations(value); for (const importedDeclaration of importedDeclarations) { if (declaration === importedDeclaration.declaration.ref) { if (importedDeclaration.alias !== undefined) { diff --git a/src/language/builtins/safe-ds-annotations.ts b/src/language/builtins/safe-ds-annotations.ts index b38ce1e14..678098066 100644 --- a/src/language/builtins/safe-ds-annotations.ts +++ b/src/language/builtins/safe-ds-annotations.ts @@ -1,5 +1,5 @@ import { isSdsAnnotation, SdsAnnotatedObject, SdsAnnotation, SdsModule, SdsParameter } from '../generated/ast.js'; -import { argumentsOrEmpty, findFirstAnnotationCallOf, hasAnnotationCallOf } from '../helpers/nodeProperties.js'; +import { getArguments, findFirstAnnotationCallOf, hasAnnotationCallOf } from '../helpers/nodeProperties.js'; import { SafeDsModuleMembers } from './safe-ds-module-members.js'; import { resourceNameToUri } from '../../helpers/resources.js'; import { URI } from 'langium'; @@ -96,8 +96,8 @@ export class SafeDsAnnotations extends SafeDsModuleMembers { parameterName: string, ): EvaluatedNode { const annotationCall = findFirstAnnotationCallOf(node, annotation); - const argumentValue = argumentsOrEmpty(annotationCall).find( - (it) => this.nodeMapper.argumentToParameterOrUndefined(it)?.name === parameterName, + const argumentValue = getArguments(annotationCall).find( + (it) => this.nodeMapper.argumentToParameter(it)?.name === parameterName, )?.value; return this.partialEvaluator.evaluate(argumentValue); } diff --git a/src/language/builtins/safe-ds-module-members.ts b/src/language/builtins/safe-ds-module-members.ts index 743d6e5d0..9a93bfa52 100644 --- a/src/language/builtins/safe-ds-module-members.ts +++ b/src/language/builtins/safe-ds-module-members.ts @@ -1,7 +1,7 @@ import { SafeDsServices } from '../safe-ds-module.js'; import { isSdsModule, SdsModuleMember } from '../generated/ast.js'; import { LangiumDocuments, URI, WorkspaceCache } from 'langium'; -import { moduleMembersOrEmpty } from '../helpers/nodeProperties.js'; +import { getModuleMembers } from '../helpers/nodeProperties.js'; export abstract class SafeDsModuleMembers { private readonly langiumDocuments: LangiumDocuments; @@ -31,7 +31,7 @@ export abstract class SafeDsModuleMembers { return undefined; } - const firstMatchingModuleMember = moduleMembersOrEmpty(root).find((m) => m.name === name); + const firstMatchingModuleMember = getModuleMembers(root).find((m) => m.name === name); if (!predicate(firstMatchingModuleMember)) { /* c8 ignore next 2 */ return undefined; diff --git a/src/language/helpers/nodeProperties.ts b/src/language/helpers/nodeProperties.ts index 7e2dde176..a698142ad 100644 --- a/src/language/helpers/nodeProperties.ts +++ b/src/language/helpers/nodeProperties.ts @@ -57,7 +57,7 @@ import { SdsTypeParameter, SdsTypeParameterList, } from '../generated/ast.js'; -import { AstNode, getContainerOfType, stream } from 'langium'; +import { AstNode, getContainerOfType, Stream, stream } from 'langium'; // ------------------------------------------------------------------------------------------------- // Checks @@ -67,7 +67,7 @@ export const hasAnnotationCallOf = ( node: SdsAnnotatedObject | undefined, expected: SdsAnnotation | undefined, ): boolean => { - return annotationCallsOrEmpty(node).some((it) => { + return getAnnotationCalls(node).some((it) => { const actual = it.annotation?.ref; return actual === expected; }); @@ -121,25 +121,25 @@ export const isStatic = (node: SdsClassMember): boolean => { // Accessors for list elements // ------------------------------------------------------------------------------------------------- -export const abstractResultsOrEmpty = (node: SdsCallable | undefined): SdsAbstractResult[] => { +export const getAbstractResults = (node: SdsCallable | undefined): SdsAbstractResult[] => { if (!node) { return []; } if (isSdsBlockLambda(node)) { - return blockLambdaResultsOrEmpty(node); + return streamBlockLambdaResults(node).toArray(); } else if (isSdsCallableType(node)) { - return resultsOrEmpty(node.resultList); + return getResults(node.resultList); } else if (isSdsFunction(node)) { - return resultsOrEmpty(node.resultList); + return getResults(node.resultList); } else if (isSdsSegment(node)) { - return resultsOrEmpty(node.resultList); + return getResults(node.resultList); } /* c8 ignore start */ else { return []; } /* c8 ignore stop */ }; -export const annotationCallsOrEmpty = (node: SdsAnnotatedObject | undefined): SdsAnnotationCall[] => { +export const getAnnotationCalls = (node: SdsAnnotatedObject | undefined): SdsAnnotationCall[] => { if (!node) { /* c8 ignore next 2 */ return []; @@ -157,13 +157,13 @@ export const findFirstAnnotationCallOf = ( node: SdsAnnotatedObject | undefined, expected: SdsAnnotation | undefined, ): SdsAnnotationCall | undefined => { - return annotationCallsOrEmpty(node).find((it) => { + return getAnnotationCalls(node).find((it) => { const actual = it.annotation?.ref; return actual === expected; }); }; -export const argumentsOrEmpty = (node: SdsArgumentList | SdsAbstractCall | undefined): SdsArgument[] => { +export const getArguments = (node: SdsArgumentList | SdsAbstractCall | undefined): SdsArgument[] => { if (isSdsArgumentList(node)) { return node.arguments; } else { @@ -171,82 +171,77 @@ export const argumentsOrEmpty = (node: SdsArgumentList | SdsAbstractCall | undef } }; -export const assigneesOrEmpty = (node: SdsAssignment | undefined): SdsAssignee[] => { +export const getAssignees = (node: SdsAssignment | undefined): SdsAssignee[] => { return node?.assigneeList?.assignees ?? []; }; -export const blockLambdaResultsOrEmpty = (node: SdsBlockLambda | undefined): SdsBlockLambdaResult[] => { - return stream(statementsOrEmpty(node?.body)) +export const streamBlockLambdaResults = (node: SdsBlockLambda | undefined): Stream => { + return stream(getStatements(node?.body)) .filter(isSdsAssignment) - .flatMap(assigneesOrEmpty) - .filter(isSdsBlockLambdaResult) - .toArray(); + .flatMap(getAssignees) + .filter(isSdsBlockLambdaResult); }; -export const classMembersOrEmpty = ( +export const getMatchingClassMembers = ( node: SdsClass | undefined, filterFunction: (member: SdsClassMember) => boolean = () => true, ): SdsClassMember[] => { return node?.body?.members?.filter(filterFunction) ?? []; }; -export const columnsOrEmpty = (node: SdsSchema | undefined): SdsColumn[] => { +export const getColumns = (node: SdsSchema | undefined): SdsColumn[] => { return node?.columnList?.columns ?? []; }; -export const enumVariantsOrEmpty = (node: SdsEnum | undefined): SdsEnumVariant[] => { +export const getEnumVariants = (node: SdsEnum | undefined): SdsEnumVariant[] => { return node?.body?.variants ?? []; }; -export const importsOrEmpty = (node: SdsModule | undefined): SdsImport[] => { +export const getImports = (node: SdsModule | undefined): SdsImport[] => { return node?.imports ?? []; }; -export const importedDeclarationsOrEmpty = (node: SdsQualifiedImport | undefined): SdsImportedDeclaration[] => { +export const getImportedDeclarations = (node: SdsQualifiedImport | undefined): SdsImportedDeclaration[] => { return node?.importedDeclarationList?.importedDeclarations ?? []; }; -export const literalsOrEmpty = (node: SdsLiteralType | undefined): SdsLiteral[] => { +export const getLiterals = (node: SdsLiteralType | undefined): SdsLiteral[] => { return node?.literalList?.literals ?? []; }; -export const moduleMembersOrEmpty = (node: SdsModule | undefined): SdsModuleMember[] => { +export const getModuleMembers = (node: SdsModule | undefined): SdsModuleMember[] => { return node?.members?.filter(isSdsModuleMember) ?? []; }; -export const packageNameOrUndefined = (node: AstNode | undefined): string | undefined => { +export const getPackageName = (node: AstNode | undefined): string | undefined => { return getContainerOfType(node, isSdsModule)?.name; }; -export const parametersOrEmpty = (node: SdsCallable | undefined): SdsParameter[] => { +export const getParameters = (node: SdsCallable | undefined): SdsParameter[] => { return node?.parameterList?.parameters ?? []; }; -export const parentTypesOrEmpty = (node: SdsClass | undefined): SdsType[] => { +export const getParentTypes = (node: SdsClass | undefined): SdsType[] => { return node?.parentTypeList?.parentTypes ?? []; }; -export const placeholdersOrEmpty = (node: SdsBlock | undefined): SdsPlaceholder[] => { - return stream(statementsOrEmpty(node)) - .filter(isSdsAssignment) - .flatMap(assigneesOrEmpty) - .filter(isSdsPlaceholder) - .toArray(); +export const streamPlaceholders = (node: SdsBlock | undefined): Stream => { + return stream(getStatements(node)).filter(isSdsAssignment).flatMap(getAssignees).filter(isSdsPlaceholder); }; -export const resultsOrEmpty = (node: SdsResultList | undefined): SdsResult[] => { +export const getResults = (node: SdsResultList | undefined): SdsResult[] => { return node?.results ?? []; }; -export const statementsOrEmpty = (node: SdsBlock | undefined): SdsStatement[] => { +export const getStatements = (node: SdsBlock | undefined): SdsStatement[] => { return node?.statements ?? []; }; -export const typeArgumentsOrEmpty = (node: SdsTypeArgumentList | undefined): SdsTypeArgument[] => { +export const getTypeArguments = (node: SdsTypeArgumentList | undefined): SdsTypeArgument[] => { return node?.typeArguments ?? []; }; -export const typeParametersOrEmpty = ( +export const getTypeParameters = ( node: SdsTypeParameterList | SdsNamedTypeDeclaration | undefined, ): SdsTypeParameter[] => { if (!node) { @@ -256,9 +251,9 @@ export const typeParametersOrEmpty = ( if (isSdsTypeParameterList(node)) { return node.typeParameters; } else if (isSdsClass(node)) { - return typeParametersOrEmpty(node.typeParameterList); + return getTypeParameters(node.typeParameterList); } else if (isSdsEnumVariant(node)) { - return typeParametersOrEmpty(node.typeParameterList); + return getTypeParameters(node.typeParameterList); } /* c8 ignore start */ else { return []; } /* c8 ignore stop */ diff --git a/src/language/helpers/safe-ds-node-mapper.ts b/src/language/helpers/safe-ds-node-mapper.ts index ea083c99d..2ef2a0151 100644 --- a/src/language/helpers/safe-ds-node-mapper.ts +++ b/src/language/helpers/safe-ds-node-mapper.ts @@ -31,13 +31,13 @@ import { import { CallableType, StaticType } from '../typing/model.js'; import { findLocalReferences, getContainerOfType, Stream, stream } from 'langium'; import { - abstractResultsOrEmpty, - argumentsOrEmpty, + getAbstractResults, + getArguments, isNamedArgument, isNamedTypeArgument, - parametersOrEmpty, - typeArgumentsOrEmpty, - typeParametersOrEmpty, + getParameters, + getTypeArguments, + getTypeParameters, } from './nodeProperties.js'; export class SafeDsNodeMapper { @@ -50,7 +50,7 @@ export class SafeDsNodeMapper { /** * Returns the parameter that the argument is assigned to. If there is no matching parameter, returns undefined. */ - argumentToParameterOrUndefined(node: SdsArgument | undefined): SdsParameter | undefined { + argumentToParameter(node: SdsArgument | undefined): SdsParameter | undefined { if (!node) { return undefined; } @@ -62,7 +62,7 @@ export class SafeDsNodeMapper { // Positional argument const containingAbstractCall = getContainerOfType(node, isSdsAbstractCall)!; - const args = argumentsOrEmpty(containingAbstractCall); + const args = getArguments(containingAbstractCall); const argumentPosition = node.$containerIndex ?? -1; // A prior argument is named @@ -73,8 +73,8 @@ export class SafeDsNodeMapper { } // Find parameter at the same position - const callable = this.callToCallableOrUndefined(containingAbstractCall); - const parameters = parametersOrEmpty(callable); + const callable = this.callToCallable(containingAbstractCall); + const parameters = getParameters(callable); if (argumentPosition < parameters.length) { return parameters[argumentPosition]; } @@ -86,7 +86,7 @@ export class SafeDsNodeMapper { * Returns the result, block lambda result, or expression that is assigned to the given assignee. If nothing is * assigned, `undefined` is returned. */ - assigneeToAssignedObjectOrUndefined(node: SdsAssignee | undefined): SdsAbstractResult | SdsExpression | undefined { + assigneeToAssignedObject(node: SdsAssignee | undefined): SdsAbstractResult | SdsExpression | undefined { if (!node) { return undefined; } @@ -111,7 +111,7 @@ export class SafeDsNodeMapper { } // If the RHS instantiates a class or enum variant, the first assignee gets the entire RHS - const callable = this.callToCallableOrUndefined(expression); + const callable = this.callToCallable(expression); if (isSdsClass(callable) || isSdsEnumVariant(callable)) { if (assigneePosition === 0) { return expression; @@ -121,14 +121,14 @@ export class SafeDsNodeMapper { } // Otherwise, the assignee gets the result at the same position - const abstractResults = abstractResultsOrEmpty(callable); + const abstractResults = getAbstractResults(callable); return abstractResults[assigneePosition]; } /** * Returns the callable that is called by the given call. If no callable can be found, returns undefined. */ - callToCallableOrUndefined(node: SdsAbstractCall | undefined): SdsCallable | undefined { + callToCallable(node: SdsAbstractCall | undefined): SdsCallable | undefined { if (!node) { return undefined; } @@ -212,7 +212,7 @@ export class SafeDsNodeMapper { * Returns the type parameter that the type argument is assigned to. If there is no matching type parameter, returns * undefined. */ - typeArgumentToTypeParameterOrUndefined(node: SdsTypeArgument | undefined): SdsTypeParameter | undefined { + typeArgumentToTypeParameter(node: SdsTypeArgument | undefined): SdsTypeParameter | undefined { if (!node) { return undefined; } @@ -228,7 +228,7 @@ export class SafeDsNodeMapper { return undefined; } - const typeArguments = typeArgumentsOrEmpty(containingType.typeArgumentList); + const typeArguments = getTypeArguments(containingType.typeArgumentList); const typeArgumentPosition = node.$containerIndex ?? -1; // A prior type argument is named @@ -240,7 +240,7 @@ export class SafeDsNodeMapper { // Find type parameter at the same position const namedTypeDeclaration = containingType.declaration.ref; - const typeParameters = typeParametersOrEmpty(namedTypeDeclaration); + const typeParameters = getTypeParameters(namedTypeDeclaration); return typeParameters[typeArgumentPosition]; } } diff --git a/src/language/lsp/safe-ds-formatter.ts b/src/language/lsp/safe-ds-formatter.ts index 505ce953d..f2aea5a34 100644 --- a/src/language/lsp/safe-ds-formatter.ts +++ b/src/language/lsp/safe-ds-formatter.ts @@ -9,7 +9,7 @@ import { isAstNode, } from 'langium'; import * as ast from '../generated/ast.js'; -import { annotationCallsOrEmpty, literalsOrEmpty, typeArgumentsOrEmpty } from '../helpers/nodeProperties.js'; +import { getAnnotationCalls, getLiterals, getTypeArguments } from '../helpers/nodeProperties.js'; import noSpace = Formatting.noSpace; import newLine = Formatting.newLine; import newLines = Formatting.newLines; @@ -203,7 +203,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsModule(node: ast.SdsModule): void { const formatter = this.getNodeFormatter(node); - const annotations = annotationCallsOrEmpty(node); + const annotations = getAnnotationCalls(node); const name = node.name; const imports = node.imports; const members = node.members; @@ -264,7 +264,7 @@ export class SafeDsFormatter extends AbstractFormatter { formatter.node(value).prepend(noSpace()); } } else { - const valueAnnotations = annotationCallsOrEmpty(value); + const valueAnnotations = getAnnotationCalls(value); if (valueAnnotations.length > 0) { formatter.node(valueAnnotations[0]).prepend(newLines(2)); } else { @@ -272,7 +272,7 @@ export class SafeDsFormatter extends AbstractFormatter { } } } else { - const valueAnnotations = annotationCallsOrEmpty(value); + const valueAnnotations = getAnnotationCalls(value); if (valueAnnotations.length > 0) { formatter.node(valueAnnotations[0]).prepend(newLines(2)); } else { @@ -315,7 +315,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsAnnotation(node: ast.SdsAnnotation): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.keyword('annotation').prepend(newLine()); } @@ -327,7 +327,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsAttribute(node: ast.SdsAttribute): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { if (node.isStatic) { formatter.keyword('static').prepend(newLine()); } else { @@ -343,7 +343,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsClass(node: ast.SdsClass): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.keyword('class').prepend(newLine()); } @@ -389,7 +389,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsEnum(node: ast.SdsEnum): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.keyword('enum').prepend(newLine()); } @@ -419,11 +419,11 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsEnumVariant(node: ast.SdsEnumVariant): void { const formatter = this.getNodeFormatter(node); - const annotationCalls = annotationCallsOrEmpty(node); + const annotationCalls = getAnnotationCalls(node); formatter.nodes(...annotationCalls.slice(1)).prepend(newLine()); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.property('name').prepend(newLine()); } @@ -435,7 +435,7 @@ export class SafeDsFormatter extends AbstractFormatter { formatSdsFunction(node: ast.SdsFunction): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { if (node.isStatic) { formatter.keyword('static').prepend(newLine()); } else { @@ -456,7 +456,7 @@ export class SafeDsFormatter extends AbstractFormatter { formatter.property('annotationCallList').prepend(noSpace()); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.keyword('pipeline').prepend(newLine()); } @@ -467,7 +467,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsSegment(node: ast.SdsSegment): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length === 0) { + if (getAnnotationCalls(node).length === 0) { if (node.visibility) { formatter.keyword('segment').prepend(oneSpace()); } @@ -548,7 +548,7 @@ export class SafeDsFormatter extends AbstractFormatter { if ( parameters.length >= 3 || - parameters.some((it) => annotationCallsOrEmpty(it).length > 0 || this.isComplexType(it.type)) + parameters.some((it) => getAnnotationCalls(it).length > 0 || this.isComplexType(it.type)) ) { formatter.nodes(...parameters).prepend(indent()); formatter.keywords(',').prepend(noSpace()); @@ -564,7 +564,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsParameter(node: ast.SdsParameter): void { const formatter = this.getNodeFormatter(node); - const lastAnnotationCall = last(annotationCallsOrEmpty(node)); + const lastAnnotationCall = last(getAnnotationCalls(node)); if (lastAnnotationCall) { formatter.node(lastAnnotationCall).append(newLine()); } @@ -587,7 +587,7 @@ export class SafeDsFormatter extends AbstractFormatter { if ( results.length >= 3 || - results.some((it) => annotationCallsOrEmpty(it).length > 0 || this.isComplexType(it.type)) + results.some((it) => getAnnotationCalls(it).length > 0 || this.isComplexType(it.type)) ) { formatter.nodes(...results).prepend(indent()); formatter.keywords(',').prepend(noSpace()); @@ -603,7 +603,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsResult(node: ast.SdsResult): void { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.property('name').prepend(newLine()); } @@ -880,7 +880,7 @@ export class SafeDsFormatter extends AbstractFormatter { const typeParameters = node.typeParameters ?? []; - if (typeParameters.length >= 3 || typeParameters.some((it) => annotationCallsOrEmpty(it).length > 0)) { + if (typeParameters.length >= 3 || typeParameters.some((it) => getAnnotationCalls(it).length > 0)) { formatter.nodes(...typeParameters).prepend(indent()); formatter.keywords(',').prepend(noSpace()); closingBracket.prepend(newLine()); @@ -897,7 +897,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsTypeParameter(node: ast.SdsTypeParameter) { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { if (node.variance) { formatter.property('variance').prepend(newLine()); } else { @@ -941,11 +941,11 @@ export class SafeDsFormatter extends AbstractFormatter { if (ast.isSdsCallableType(node) || ast.isSdsMemberType(node)) { return true; } else if (ast.isSdsLiteralType(node)) { - return literalsOrEmpty(node).length > 0; + return getLiterals(node).length > 0; } else if (ast.isSdsNamedType(node)) { - return typeArgumentsOrEmpty(node.typeArgumentList).length > 0; + return getTypeArguments(node.typeArgumentList).length > 0; } else if (ast.isSdsUnionType(node)) { - return typeArgumentsOrEmpty(node.typeArgumentList).length > 0; + return getTypeArguments(node.typeArgumentList).length > 0; } else { /* c8 ignore next 2 */ return false; @@ -959,7 +959,7 @@ export class SafeDsFormatter extends AbstractFormatter { private formatSdsSchema(node: ast.SdsSchema) { const formatter = this.getNodeFormatter(node); - if (annotationCallsOrEmpty(node).length > 0) { + if (getAnnotationCalls(node).length > 0) { formatter.keyword('schema').prepend(newLine()); } diff --git a/src/language/partialEvaluation/model.ts b/src/language/partialEvaluation/model.ts index 75514988a..603106608 100644 --- a/src/language/partialEvaluation/model.ts +++ b/src/language/partialEvaluation/model.ts @@ -9,7 +9,7 @@ import { SdsResult, } from '../generated/ast.js'; import { stream } from 'langium'; -import { parametersOrEmpty } from '../helpers/nodeProperties.js'; +import { getParameters } from '../helpers/nodeProperties.js'; import { isEmpty } from '../../helpers/collectionUtils.js'; export type ParameterSubstitutions = Map; @@ -219,7 +219,7 @@ export class EvaluatedEnumVariant extends EvaluatedNode { readonly hasBeenInstantiated = this.args !== undefined; override readonly isFullyEvaluated: boolean = - isEmpty(parametersOrEmpty(this.variant)) || + isEmpty(getParameters(this.variant)) || (this.args !== undefined && stream(this.args.values()).every(isFullyEvaluated)); override equals(other: EvaluatedNode): boolean { diff --git a/src/language/partialEvaluation/safe-ds-partial-evaluator.ts b/src/language/partialEvaluation/safe-ds-partial-evaluator.ts index 734afc3d5..67ba7cda6 100644 --- a/src/language/partialEvaluation/safe-ds-partial-evaluator.ts +++ b/src/language/partialEvaluation/safe-ds-partial-evaluator.ts @@ -53,7 +53,7 @@ import { SdsReference, SdsTemplateString, } from '../generated/ast.js'; -import { argumentsOrEmpty, parametersOrEmpty } from '../helpers/nodeProperties.js'; +import { getArguments, getParameters } from '../helpers/nodeProperties.js'; import { SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js'; import { isEmpty } from '../../helpers/collectionUtils.js'; @@ -369,14 +369,14 @@ export class SafeDsPartialEvaluator { // Store default values for all parameters const args = new Map( - parametersOrEmpty(receiver.variant).map((it) => { + getParameters(receiver.variant).map((it) => { return [it, this.cachedDoEvaluate(it.defaultValue, NO_SUBSTITUTIONS)]; }), ); // Override default values with the actual arguments - argumentsOrEmpty(node).forEach((it) => { - const parameter = this.nodeMapper.argumentToParameterOrUndefined(it); + getArguments(node).forEach((it) => { + const parameter = this.nodeMapper.argumentToParameter(it); if (parameter && args.has(parameter)) { args.set(parameter, this.cachedDoEvaluate(it.value, substitutions)); } diff --git a/src/language/scoping/safe-ds-scope-provider.ts b/src/language/scoping/safe-ds-scope-provider.ts index 8a52f92a3..c4a698944 100644 --- a/src/language/scoping/safe-ds-scope-provider.ts +++ b/src/language/scoping/safe-ds-scope-provider.ts @@ -50,18 +50,18 @@ import { } from '../generated/ast.js'; import { isContainedIn } from '../helpers/astUtils.js'; import { - abstractResultsOrEmpty, - assigneesOrEmpty, - classMembersOrEmpty, - enumVariantsOrEmpty, - importedDeclarationsOrEmpty, - importsOrEmpty, + getAbstractResults, + getAssignees, + getMatchingClassMembers, + getEnumVariants, + getImportedDeclarations, + getImports, isStatic, - packageNameOrUndefined, - parametersOrEmpty, - resultsOrEmpty, - statementsOrEmpty, - typeParametersOrEmpty, + getPackageName, + getParameters, + getResults, + getStatements, + getTypeParameters, } from '../helpers/nodeProperties.js'; import { SafeDsServices } from '../safe-ds-module.js'; import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js'; @@ -114,17 +114,17 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { private getScopeForArgumentParameter(node: SdsArgument): Scope { const containingAbstractCall = getContainerOfType(node, isSdsAbstractCall); - const callable = this.nodeMapper.callToCallableOrUndefined(containingAbstractCall); + const callable = this.nodeMapper.callToCallable(containingAbstractCall); if (!callable) { return EMPTY_SCOPE; } - const parameters = parametersOrEmpty(callable); + const parameters = getParameters(callable); return this.createScopeForNodes(parameters); } private getScopeForImportedDeclarationDeclaration(node: SdsImportedDeclaration): Scope { - const ownPackageName = packageNameOrUndefined(node); + const ownPackageName = getPackageName(node); const containingQualifiedImport = getContainerOfType(node, isSdsQualifiedImport); if (!containingQualifiedImport) { @@ -177,7 +177,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { // Static access const declaration = this.getUniqueReferencedDeclarationForExpression(node.receiver); if (isSdsClass(declaration)) { - const ownStaticMembers = classMembersOrEmpty(declaration, isStatic); + const ownStaticMembers = getMatchingClassMembers(declaration, isStatic); // val superTypeMembers = receiverDeclaration.superClassMembers() // .filter { it.isStatic() } // .toList() @@ -185,14 +185,14 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { // return Scopes.scopeFor(ownStaticMembers, Scopes.scopeFor(superTypeMembers)) return this.createScopeForNodes(ownStaticMembers); } else if (isSdsEnum(declaration)) { - return this.createScopeForNodes(enumVariantsOrEmpty(declaration)); + return this.createScopeForNodes(getEnumVariants(declaration)); } // Call results let resultScope = EMPTY_SCOPE; if (isSdsCall(node.receiver)) { - const callable = this.nodeMapper.callToCallableOrUndefined(node.receiver); - const results = abstractResultsOrEmpty(callable); + const callable = this.nodeMapper.callToCallable(node.receiver); + const results = getAbstractResults(callable); if (results.length > 1) { return this.createScopeForNodes(results); @@ -207,7 +207,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { let receiverType = this.typeComputer.computeType(node.receiver); if (receiverType instanceof ClassType) { - const ownInstanceMembers = classMembersOrEmpty(receiverType.declaration, (it) => !isStatic(it)); + const ownInstanceMembers = getMatchingClassMembers(receiverType.declaration, (it) => !isStatic(it)); // val superTypeMembers = type.sdsClass.superClassMembers() // .filter { !it.isStatic() } // .toList() @@ -215,7 +215,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { // Scopes.scopeFor(members, Scopes.scopeFor(superTypeMembers, resultScope)) return this.createScopeForNodes(ownInstanceMembers, resultScope); } else if (receiverType instanceof EnumVariantType) { - const parameters = parametersOrEmpty(receiverType.declaration); + const parameters = getParameters(receiverType.declaration); return this.createScopeForNodes(parameters, resultScope); } @@ -285,7 +285,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { private localDeclarations(node: AstNode, outerScope: Scope): Scope { // Parameters const containingCallable = getContainerOfType(node.$container, isSdsCallable); - const parameters = parametersOrEmpty(containingCallable); + const parameters = getParameters(containingCallable); // Placeholders up to the containing statement const containingStatement = getContainerOfType(node.$container, isSdsStatement); @@ -317,13 +317,13 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { } const containingBlock = getContainerOfType(statement, isSdsBlock); - for (const current of statementsOrEmpty(containingBlock)) { + for (const current of getStatements(containingBlock)) { if (current === statement) { return; } if (isSdsAssignment(current)) { - yield* assigneesOrEmpty(current).filter(isSdsPlaceholder); + yield* getAssignees(current).filter(isSdsPlaceholder); } } } @@ -337,10 +337,10 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { const namedTypeDeclaration = containingNamedType.declaration.ref; if (isSdsClass(namedTypeDeclaration)) { - const typeParameters = typeParametersOrEmpty(namedTypeDeclaration.typeParameterList); + const typeParameters = getTypeParameters(namedTypeDeclaration.typeParameterList); return this.createScopeForNodes(typeParameters); } else if (isSdsEnumVariant(namedTypeDeclaration)) { - const typeParameters = typeParametersOrEmpty(namedTypeDeclaration.typeParameterList); + const typeParameters = getTypeParameters(namedTypeDeclaration.typeParameterList); return this.createScopeForNodes(typeParameters); } else { return EMPTY_SCOPE; @@ -353,7 +353,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { return EMPTY_SCOPE; } - return this.createScopeForNodes(resultsOrEmpty(containingSegment.resultList)); + return this.createScopeForNodes(getResults(containingSegment.resultList)); } protected override getGlobalScope(referenceType: string, context: ReferenceInfo): Scope { @@ -363,7 +363,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { } private getGlobalScopeForNode(referenceType: string, node: AstNode): Scope { - const ownPackageName = packageNameOrUndefined(node); + const ownPackageName = getPackageName(node); // Builtin declarations const builtinDeclarations = this.builtinDeclarations(referenceType); @@ -397,12 +397,12 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { private explicitlyImportedDeclarations(referenceType: string, node: AstNode): AstNodeDescription[] { const containingModule = getContainerOfType(node, isSdsModule); - const imports = importsOrEmpty(containingModule); + const imports = getImports(containingModule); const result: AstNodeDescription[] = []; for (const imp of imports) { if (isSdsQualifiedImport(imp)) { - for (const importedDeclaration of importedDeclarationsOrEmpty(imp)) { + for (const importedDeclaration of getImportedDeclarations(imp)) { const description = importedDeclaration.declaration.$nodeDescription; if (!description || !this.astReflection.isSubtype(description.type, referenceType)) { continue; diff --git a/src/language/typing/safe-ds-class-hierarchy.ts b/src/language/typing/safe-ds-class-hierarchy.ts index 4b57fcb93..479af0752 100644 --- a/src/language/typing/safe-ds-class-hierarchy.ts +++ b/src/language/typing/safe-ds-class-hierarchy.ts @@ -2,7 +2,7 @@ import { SafeDsServices } from '../safe-ds-module.js'; import { SafeDsClasses } from '../builtins/safe-ds-classes.js'; import { SdsClass } from '../generated/ast.js'; import { stream, Stream } from 'langium'; -import { parentTypesOrEmpty } from '../helpers/nodeProperties.js'; +import { getParentTypes } from '../helpers/nodeProperties.js'; import { SafeDsTypeComputer } from './safe-ds-type-computer.js'; import { ClassType } from './model.js'; @@ -65,7 +65,7 @@ export class SafeDsClassHierarchy { * type is considered, i.e. multiple inheritance is not supported. */ private parentClassOrUndefined(node: SdsClass | undefined): SdsClass | undefined { - const [firstParentType] = parentTypesOrEmpty(node); + const [firstParentType] = getParentTypes(node); const computedType = this.typeComputer.computeType(firstParentType); if (computedType instanceof ClassType) { return computedType.declaration; diff --git a/src/language/typing/safe-ds-type-computer.ts b/src/language/typing/safe-ds-type-computer.ts index 836df5162..840c04ef2 100644 --- a/src/language/typing/safe-ds-type-computer.ts +++ b/src/language/typing/safe-ds-type-computer.ts @@ -74,12 +74,12 @@ import { } from '../generated/ast.js'; import { SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js'; import { - assigneesOrEmpty, - blockLambdaResultsOrEmpty, - literalsOrEmpty, - parametersOrEmpty, - resultsOrEmpty, - typeArgumentsOrEmpty, + getAssignees, + streamBlockLambdaResults, + getLiterals, + getParameters, + getResults, + getTypeArguments, } from '../helpers/nodeProperties.js'; import { SafeDsPartialEvaluator } from '../partialEvaluation/safe-ds-partial-evaluator.js'; import { Constant, isConstant } from '../partialEvaluation/model.js'; @@ -170,7 +170,7 @@ export class SafeDsTypeComputer { private computeTypeOfDeclaration(node: SdsDeclaration): Type { if (isSdsAnnotation(node)) { - const parameterEntries = parametersOrEmpty(node).map( + const parameterEntries = getParameters(node).map( (it) => new NamedTupleEntry(it, it.name, this.computeType(it.type)), ); @@ -199,10 +199,10 @@ export class SafeDsTypeComputer { } private computeTypeOfCallableWithManifestTypes(node: SdsFunction | SdsSegment | SdsCallableType): Type { - const parameterEntries = parametersOrEmpty(node).map( + const parameterEntries = getParameters(node).map( (it) => new NamedTupleEntry(it, it.name, this.computeType(it.type)), ); - const resultEntries = resultsOrEmpty(node.resultList).map( + const resultEntries = getResults(node.resultList).map( (it) => new NamedTupleEntry(it, it.name, this.computeType(it.type)), ); @@ -225,7 +225,7 @@ export class SafeDsTypeComputer { // Lambda passed as argument if (isSdsArgument(containerOfLambda)) { - const parameter = this.nodeMapper.argumentToParameterOrUndefined(containerOfLambda); + const parameter = this.nodeMapper.argumentToParameter(containerOfLambda); if (!parameter) { return UnknownType; } @@ -241,7 +241,7 @@ export class SafeDsTypeComputer { // Yielded lambda else if (isSdsAssignment(containerOfLambda)) { - const firstAssignee = assigneesOrEmpty(containerOfLambda)[0]; + const firstAssignee = getAssignees(containerOfLambda)[0]; if (!isSdsYield(firstAssignee)) { return UnknownType; } @@ -280,16 +280,16 @@ export class SafeDsTypeComputer { } else if (isSdsCall(node)) { return this.computeTypeOfCall(node); } else if (isSdsBlockLambda(node)) { - const parameterEntries = parametersOrEmpty(node).map( - (it) => new NamedTupleEntry(it, it.name, this.computeType(it)), - ); - const resultEntries = blockLambdaResultsOrEmpty(node).map( + const parameterEntries = getParameters(node).map( (it) => new NamedTupleEntry(it, it.name, this.computeType(it)), ); + const resultEntries = streamBlockLambdaResults(node) + .map((it) => new NamedTupleEntry(it, it.name, this.computeType(it))) + .toArray(); return new CallableType(node, new NamedTupleType(parameterEntries), new NamedTupleType(resultEntries)); } else if (isSdsExpressionLambda(node)) { - const parameterEntries = parametersOrEmpty(node).map( + const parameterEntries = getParameters(node).map( (it) => new NamedTupleEntry(it, it.name, this.computeType(it)), ); const resultEntries = [ @@ -415,7 +415,7 @@ export class SafeDsTypeComputer { if (memberType instanceof StaticType && !isSdsCall(node.$container)) { const instanceType = memberType.instanceType; - if (instanceType instanceof EnumVariantType && isEmpty(parametersOrEmpty(instanceType.declaration))) { + if (instanceType instanceof EnumVariantType && isEmpty(getParameters(instanceType.declaration))) { return instanceType; } } @@ -455,7 +455,7 @@ export class SafeDsTypeComputer { } else if (isSdsNamedType(node)) { return this.computeType(node.declaration.ref).copyWithNullability(node.isNullable); } else if (isSdsUnionType(node)) { - const typeArguments = typeArgumentsOrEmpty(node.typeArgumentList); + const typeArguments = getTypeArguments(node.typeArgumentList); return new UnionType(typeArguments.map((typeArgument) => this.computeType(typeArgument.value))); } /* c8 ignore start */ else { return UnknownType; @@ -463,7 +463,7 @@ export class SafeDsTypeComputer { } private computeTypeOfLiteralType(node: SdsLiteralType): Type { - const constants = literalsOrEmpty(node).map((it) => this.partialEvaluator.evaluate(it)); + const constants = getLiterals(node).map((it) => this.partialEvaluator.evaluate(it)); if (constants.every(isConstant)) { return new LiteralType(constants); } /* c8 ignore start */ else { diff --git a/src/language/validation/builtins/deprecated.ts b/src/language/validation/builtins/deprecated.ts index 2945c10a5..7527a49ad 100644 --- a/src/language/validation/builtins/deprecated.ts +++ b/src/language/validation/builtins/deprecated.ts @@ -27,7 +27,7 @@ export const assigneeAssignedResultShouldNotBeDeprecated = return; } - const assignedObject = services.helpers.NodeMapper.assigneeToAssignedObjectOrUndefined(node); + const assignedObject = services.helpers.NodeMapper.assigneeToAssignedObject(node); if (!isSdsResult(assignedObject)) { return; } @@ -60,7 +60,7 @@ export const annotationCallAnnotationShouldNotBeDeprecated = export const argumentCorrespondingParameterShouldNotBeDeprecated = (services: SafeDsServices) => (node: SdsArgument, accept: ValidationAcceptor) => { - const parameter = services.helpers.NodeMapper.argumentToParameterOrUndefined(node); + const parameter = services.helpers.NodeMapper.argumentToParameter(node); if (!parameter) { return; } diff --git a/src/language/validation/builtins/experimental.ts b/src/language/validation/builtins/experimental.ts index 6e973effb..39633c20b 100644 --- a/src/language/validation/builtins/experimental.ts +++ b/src/language/validation/builtins/experimental.ts @@ -22,7 +22,7 @@ export const assigneeAssignedResultShouldNotBeExperimental = return; } - const assignedObject = services.helpers.NodeMapper.assigneeToAssignedObjectOrUndefined(node); + const assignedObject = services.helpers.NodeMapper.assigneeToAssignedObject(node); if (!isSdsResult(assignedObject)) { return; } @@ -53,7 +53,7 @@ export const annotationCallAnnotationShouldNotBeExperimental = export const argumentCorrespondingParameterShouldNotBeExperimental = (services: SafeDsServices) => (node: SdsArgument, accept: ValidationAcceptor) => { - const parameter = services.helpers.NodeMapper.argumentToParameterOrUndefined(node); + const parameter = services.helpers.NodeMapper.argumentToParameter(node); if (!parameter) { return; } diff --git a/src/language/validation/builtins/repeatable.ts b/src/language/validation/builtins/repeatable.ts index 92d938a6f..3a8d68d41 100644 --- a/src/language/validation/builtins/repeatable.ts +++ b/src/language/validation/builtins/repeatable.ts @@ -1,14 +1,14 @@ import { ValidationAcceptor } from 'langium'; import { SdsDeclaration } from '../../generated/ast.js'; import { SafeDsServices } from '../../safe-ds-module.js'; -import { annotationCallsOrEmpty } from '../../helpers/nodeProperties.js'; +import { getAnnotationCalls } from '../../helpers/nodeProperties.js'; import { duplicatesBy } from '../../../helpers/collectionUtils.js'; export const CODE_ANNOTATION_NOT_REPEATABLE = 'annotation/not-repeatable'; export const singleUseAnnotationsMustNotBeRepeated = (services: SafeDsServices) => (node: SdsDeclaration, accept: ValidationAcceptor) => { - const callsOfSingleUseAnnotations = annotationCallsOrEmpty(node).filter((it) => { + const callsOfSingleUseAnnotations = getAnnotationCalls(node).filter((it) => { const annotation = it.annotation?.ref; return annotation && !services.builtins.Annotations.isRepeatable(annotation); }); diff --git a/src/language/validation/inheritance.ts b/src/language/validation/inheritance.ts index 7fd374e5a..060612232 100644 --- a/src/language/validation/inheritance.ts +++ b/src/language/validation/inheritance.ts @@ -1,6 +1,6 @@ import { ValidationAcceptor } from 'langium'; import { SdsClass } from '../generated/ast.js'; -import { parentTypesOrEmpty } from '../helpers/nodeProperties.js'; +import { getParentTypes } from '../helpers/nodeProperties.js'; import { SafeDsServices } from '../safe-ds-module.js'; import { ClassType, UnknownType } from '../typing/model.js'; import { isEmpty } from '../../helpers/collectionUtils.js'; @@ -14,7 +14,7 @@ export const classMustOnlyInheritASingleClass = (services: SafeDsServices) => { const computeType = typeComputer.computeType.bind(typeComputer); return (node: SdsClass, accept: ValidationAcceptor): void => { - const parentTypes = parentTypesOrEmpty(node); + const parentTypes = getParentTypes(node); if (isEmpty(parentTypes)) { return; } @@ -47,7 +47,7 @@ export const classMustNotInheritItself = (services: SafeDsServices) => { const superClasses = classHierarchy.streamSuperclasses(node); if (superClasses.includes(node)) { accept('error', 'A class must not directly or indirectly be a subtype of itself.', { - node: parentTypesOrEmpty(node)[0], + node: getParentTypes(node)[0], code: CODE_INHERITANCE_CYCLE, }); } diff --git a/src/language/validation/names.ts b/src/language/validation/names.ts index 55f437a5b..6eb9a48be 100644 --- a/src/language/validation/names.ts +++ b/src/language/validation/names.ts @@ -17,19 +17,19 @@ import { } from '../generated/ast.js'; import { getDocument, ValidationAcceptor } from 'langium'; import { - blockLambdaResultsOrEmpty, - classMembersOrEmpty, - columnsOrEmpty, - enumVariantsOrEmpty, - importedDeclarationsOrEmpty, - importsOrEmpty, + streamBlockLambdaResults, + getMatchingClassMembers, + getColumns, + getEnumVariants, + getImportedDeclarations, + getImports, isStatic, - moduleMembersOrEmpty, - packageNameOrUndefined, - parametersOrEmpty, - placeholdersOrEmpty, - resultsOrEmpty, - typeParametersOrEmpty, + getModuleMembers, + getPackageName, + getParameters, + streamPlaceholders, + getResults, + getTypeParameters, } from '../helpers/nodeProperties.js'; import { duplicatesBy } from '../../helpers/collectionUtils.js'; import { isInPipelineFile, isInStubFile, isInTestFile } from '../helpers/fileExtensions.js'; @@ -150,54 +150,46 @@ const acceptCasingWarning = ( // ----------------------------------------------------------------------------- export const annotationMustContainUniqueNames = (node: SdsAnnotation, accept: ValidationAcceptor): void => { - namesMustBeUnique(parametersOrEmpty(node), (name) => `A parameter with name '${name}' exists already.`, accept); + namesMustBeUnique(getParameters(node), (name) => `A parameter with name '${name}' exists already.`, accept); }; export const blockLambdaMustContainUniqueNames = (node: SdsBlockLambda, accept: ValidationAcceptor): void => { - const parametersAndPlaceholders = [...parametersOrEmpty(node), ...placeholdersOrEmpty(node.body)]; + const parametersAndPlaceholders = [...getParameters(node), ...streamPlaceholders(node.body)]; namesMustBeUnique( parametersAndPlaceholders, (name) => `A parameter or placeholder with name '${name}' exists already.`, accept, ); - namesMustBeUnique( - blockLambdaResultsOrEmpty(node), - (name) => `A result with name '${name}' exists already.`, - accept, - ); + namesMustBeUnique(streamBlockLambdaResults(node), (name) => `A result with name '${name}' exists already.`, accept); }; export const callableTypeMustContainUniqueNames = (node: SdsCallableType, accept: ValidationAcceptor): void => { - namesMustBeUnique(parametersOrEmpty(node), (name) => `A parameter with name '${name}' exists already.`, accept); - namesMustBeUnique( - resultsOrEmpty(node.resultList), - (name) => `A result with name '${name}' exists already.`, - accept, - ); + namesMustBeUnique(getParameters(node), (name) => `A parameter with name '${name}' exists already.`, accept); + namesMustBeUnique(getResults(node.resultList), (name) => `A result with name '${name}' exists already.`, accept); }; export const classMustContainUniqueNames = (node: SdsClass, accept: ValidationAcceptor): void => { - const typeParametersAndParameters = [...typeParametersOrEmpty(node.typeParameterList), ...parametersOrEmpty(node)]; + const typeParametersAndParameters = [...getTypeParameters(node.typeParameterList), ...getParameters(node)]; namesMustBeUnique( typeParametersAndParameters, (name) => `A type parameter or parameter with name '${name}' exists already.`, accept, ); - const instanceMembers = classMembersOrEmpty(node, (it) => !isStatic(it)); + const instanceMembers = getMatchingClassMembers(node, (it) => !isStatic(it)); namesMustBeUnique(instanceMembers, (name) => `An instance member with name '${name}' exists already.`, accept); - const staticMembers = classMembersOrEmpty(node, isStatic); + const staticMembers = getMatchingClassMembers(node, isStatic); namesMustBeUnique(staticMembers, (name) => `A static member with name '${name}' exists already.`, accept); }; export const enumMustContainUniqueNames = (node: SdsEnum, accept: ValidationAcceptor): void => { - namesMustBeUnique(enumVariantsOrEmpty(node), (name) => `A variant with name '${name}' exists already.`, accept); + namesMustBeUnique(getEnumVariants(node), (name) => `A variant with name '${name}' exists already.`, accept); }; export const enumVariantMustContainUniqueNames = (node: SdsEnumVariant, accept: ValidationAcceptor): void => { - const typeParametersAndParameters = [...typeParametersOrEmpty(node.typeParameterList), ...parametersOrEmpty(node)]; + const typeParametersAndParameters = [...getTypeParameters(node.typeParameterList), ...getParameters(node)]; namesMustBeUnique( typeParametersAndParameters, (name) => `A type parameter or parameter with name '${name}' exists already.`, @@ -206,22 +198,18 @@ export const enumVariantMustContainUniqueNames = (node: SdsEnumVariant, accept: }; export const expressionLambdaMustContainUniqueNames = (node: SdsExpressionLambda, accept: ValidationAcceptor): void => { - namesMustBeUnique(parametersOrEmpty(node), (name) => `A parameter with name '${name}' exists already.`, accept); + namesMustBeUnique(getParameters(node), (name) => `A parameter with name '${name}' exists already.`, accept); }; export const functionMustContainUniqueNames = (node: SdsFunction, accept: ValidationAcceptor): void => { - const typeParametersAndParameters = [...typeParametersOrEmpty(node.typeParameterList), ...parametersOrEmpty(node)]; + const typeParametersAndParameters = [...getTypeParameters(node.typeParameterList), ...getParameters(node)]; namesMustBeUnique( typeParametersAndParameters, (name) => `A type parameter or parameter with name '${name}' exists already.`, accept, ); - namesMustBeUnique( - resultsOrEmpty(node.resultList), - (name) => `A result with name '${name}' exists already.`, - accept, - ); + namesMustBeUnique(getResults(node.resultList), (name) => `A result with name '${name}' exists already.`, accept); }; export const moduleMemberMustHaveNameThatIsUniqueInPackage = (services: SafeDsServices) => { @@ -229,8 +217,8 @@ export const moduleMemberMustHaveNameThatIsUniqueInPackage = (services: SafeDsSe const builtinUris = new Set(listBuiltinFiles().map((it) => it.toString())); return (node: SdsModule, accept: ValidationAcceptor): void => { - for (const member of moduleMembersOrEmpty(node)) { - const packageName = packageNameOrUndefined(member) ?? ''; + for (const member of getModuleMembers(node)) { + const packageName = getPackageName(member) ?? ''; const declarationsInPackage = packageManager.getDeclarationsInPackage(packageName); const memberUri = getDocument(member).uri?.toString(); @@ -254,7 +242,7 @@ export const moduleMemberMustHaveNameThatIsUniqueInPackage = (services: SafeDsSe export const moduleMustContainUniqueNames = (node: SdsModule, accept: ValidationAcceptor): void => { // Names of imported declarations must be unique - const importedDeclarations = importsOrEmpty(node).filter(isSdsQualifiedImport).flatMap(importedDeclarationsOrEmpty); + const importedDeclarations = getImports(node).filter(isSdsQualifiedImport).flatMap(getImportedDeclarations); for (const duplicate of duplicatesBy(importedDeclarations, importedDeclarationName)) { if (duplicate.alias) { accept('error', `A declaration with name '${importedDeclarationName(duplicate)}' was imported already.`, { @@ -274,21 +262,21 @@ export const moduleMustContainUniqueNames = (node: SdsModule, accept: Validation // Names of module members must be unique if (isInPipelineFile(node)) { namesMustBeUnique( - moduleMembersOrEmpty(node), + getModuleMembers(node), (name) => `A declaration with name '${name}' exists already in this file.`, accept, declarationIsAllowedInPipelineFile, ); } else if (isInStubFile(node)) { namesMustBeUnique( - moduleMembersOrEmpty(node), + getModuleMembers(node), (name) => `A declaration with name '${name}' exists already in this file.`, accept, declarationIsAllowedInStubFile, ); } else if (isInTestFile(node)) { namesMustBeUnique( - moduleMembersOrEmpty(node), + getModuleMembers(node), (name) => `A declaration with name '${name}' exists already in this file.`, accept, ); @@ -301,14 +289,14 @@ const importedDeclarationName = (node: SdsImportedDeclaration | undefined): stri export const pipelineMustContainUniqueNames = (node: SdsPipeline, accept: ValidationAcceptor): void => { namesMustBeUnique( - placeholdersOrEmpty(node.body), + streamPlaceholders(node.body), (name) => `A placeholder with name '${name}' exists already.`, accept, ); }; export const schemaMustContainUniqueNames = (node: SdsSchema, accept: ValidationAcceptor): void => { - const duplicates = duplicatesBy(columnsOrEmpty(node), (it) => it.columnName.value); + const duplicates = duplicatesBy(getColumns(node), (it) => it.columnName.value); for (const duplicate of duplicates) { accept('error', `A column with name '${duplicate.columnName.value}' exists already.`, { node: duplicate, @@ -319,18 +307,14 @@ export const schemaMustContainUniqueNames = (node: SdsSchema, accept: Validation }; export const segmentMustContainUniqueNames = (node: SdsSegment, accept: ValidationAcceptor): void => { - const parametersAndPlaceholder = [...parametersOrEmpty(node), ...placeholdersOrEmpty(node.body)]; + const parametersAndPlaceholder = [...getParameters(node), ...streamPlaceholders(node.body)]; namesMustBeUnique( parametersAndPlaceholder, (name) => `A parameter or placeholder with name '${name}' exists already.`, accept, ); - namesMustBeUnique( - resultsOrEmpty(node.resultList), - (name) => `A result with name '${name}' exists already.`, - accept, - ); + namesMustBeUnique(getResults(node.resultList), (name) => `A result with name '${name}' exists already.`, accept); }; const namesMustBeUnique = ( diff --git a/src/language/validation/other/argumentLists.ts b/src/language/validation/other/argumentLists.ts index 916184f50..f30a28ad1 100644 --- a/src/language/validation/other/argumentLists.ts +++ b/src/language/validation/other/argumentLists.ts @@ -1,7 +1,7 @@ import { isSdsAnnotation, isSdsCall, SdsAbstractCall, SdsArgumentList } from '../../generated/ast.js'; import { getContainerOfType, ValidationAcceptor } from 'langium'; import { SafeDsServices } from '../../safe-ds-module.js'; -import { argumentsOrEmpty, isRequiredParameter, parametersOrEmpty } from '../../helpers/nodeProperties.js'; +import { getArguments, isRequiredParameter, getParameters } from '../../helpers/nodeProperties.js'; import { duplicatesBy, isEmpty } from '../../../helpers/collectionUtils.js'; import { pluralize } from '../../../helpers/stringUtils.js'; @@ -31,7 +31,7 @@ export const argumentListMustNotHaveTooManyArguments = (services: SafeDsServices const nodeMapper = services.helpers.NodeMapper; return (node: SdsAbstractCall, accept: ValidationAcceptor): void => { - const actualArgumentCount = argumentsOrEmpty(node).length; + const actualArgumentCount = getArguments(node).length; // We can never have too many arguments in this case if (actualArgumentCount === 0) { @@ -39,12 +39,12 @@ export const argumentListMustNotHaveTooManyArguments = (services: SafeDsServices } // We already report other errors in those cases - const callable = nodeMapper.callToCallableOrUndefined(node); + const callable = nodeMapper.callToCallable(node); if (!callable || (isSdsCall(node) && isSdsAnnotation(callable))) { return; } - const parameters = parametersOrEmpty(callable); + const parameters = getParameters(callable); const maxArgumentCount = parameters.length; // All is good @@ -76,17 +76,17 @@ export const argumentListMustNotHaveTooManyArguments = (services: SafeDsServices export const argumentListMustNotSetParameterMultipleTimes = (services: SafeDsServices) => { const nodeMapper = services.helpers.NodeMapper; - const argumentToParameterOrUndefined = nodeMapper.argumentToParameterOrUndefined.bind(nodeMapper); + const argumentToParameterOrUndefined = nodeMapper.argumentToParameter.bind(nodeMapper); return (node: SdsArgumentList, accept: ValidationAcceptor): void => { // We already report other errors in this case const containingCall = getContainerOfType(node, isSdsCall); - const callable = nodeMapper.callToCallableOrUndefined(containingCall); + const callable = nodeMapper.callToCallable(containingCall); if (isSdsAnnotation(callable)) { return; } - const args = argumentsOrEmpty(node); + const args = getArguments(node); const duplicates = duplicatesBy(args, argumentToParameterOrUndefined); for (const duplicate of duplicates) { @@ -109,17 +109,17 @@ export const argumentListMustSetAllRequiredParameters = (services: SafeDsService } // We already report other errors in those cases - const callable = nodeMapper.callToCallableOrUndefined(node); + const callable = nodeMapper.callToCallable(node); if (!callable || (isSdsCall(node) && isSdsAnnotation(callable))) { return; } - const expectedParameters = parametersOrEmpty(callable).filter((it) => isRequiredParameter(it)); + const expectedParameters = getParameters(callable).filter((it) => isRequiredParameter(it)); if (isEmpty(expectedParameters)) { return; } - const actualParameters = argumentsOrEmpty(node).map((it) => nodeMapper.argumentToParameterOrUndefined(it)); + const actualParameters = getArguments(node).map((it) => nodeMapper.argumentToParameter(it)); const missingTypeParameters = expectedParameters.filter((it) => !actualParameters.includes(it)); if (!isEmpty(missingTypeParameters)) { diff --git a/src/language/validation/other/declarations/annotationCalls.ts b/src/language/validation/other/declarations/annotationCalls.ts index 5fa382485..b33e3845c 100644 --- a/src/language/validation/other/declarations/annotationCalls.ts +++ b/src/language/validation/other/declarations/annotationCalls.ts @@ -9,11 +9,11 @@ import { } from '../../../generated/ast.js'; import { getContainerOfType, ValidationAcceptor } from 'langium'; import { - annotationCallsOrEmpty, - argumentsOrEmpty, + getAnnotationCalls, + getArguments, isRequiredParameter, - parametersOrEmpty, - resultsOrEmpty, + getParameters, + getResults, } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; import { isEmpty } from '../../../../helpers/collectionUtils.js'; @@ -27,7 +27,7 @@ export const annotationCallArgumentsMustBeConstant = (services: SafeDsServices) const partialEvaluator = services.evaluation.PartialEvaluator; return (node: SdsAnnotationCall, accept: ValidationAcceptor) => { - for (const argument of argumentsOrEmpty(node)) { + for (const argument of getArguments(node)) { const evaluatedArgumentValue = partialEvaluator.evaluate(argument.value); if (!evaluatedArgumentValue.isFullyEvaluated) { @@ -46,7 +46,7 @@ export const annotationCallMustNotLackArgumentList = (node: SdsAnnotationCall, a return; } - const requiredParameters = parametersOrEmpty(node.annotation?.ref).filter(isRequiredParameter); + const requiredParameters = getParameters(node.annotation?.ref).filter(isRequiredParameter); if (!isEmpty(requiredParameters)) { accept( 'error', @@ -60,8 +60,8 @@ export const annotationCallMustNotLackArgumentList = (node: SdsAnnotationCall, a }; export const callableTypeParametersMustNotBeAnnotated = (node: SdsCallableType, accept: ValidationAcceptor) => { - for (const parameter of parametersOrEmpty(node)) { - for (const annotationCall of annotationCallsOrEmpty(parameter)) { + for (const parameter of getParameters(node)) { + for (const annotationCall of getAnnotationCalls(parameter)) { accept('error', 'Parameters of callable types must not be annotated.', { node: annotationCall, code: CODE_ANNOTATION_CALL_TARGET_PARAMETER, @@ -71,8 +71,8 @@ export const callableTypeParametersMustNotBeAnnotated = (node: SdsCallableType, }; export const callableTypeResultsMustNotBeAnnotated = (node: SdsCallableType, accept: ValidationAcceptor) => { - for (const result of resultsOrEmpty(node.resultList)) { - for (const annotationCall of annotationCallsOrEmpty(result)) { + for (const result of getResults(node.resultList)) { + for (const annotationCall of getAnnotationCalls(result)) { accept('error', 'Results of callable types must not be annotated.', { node: annotationCall, code: CODE_ANNOTATION_CALL_TARGET_RESULT, @@ -82,8 +82,8 @@ export const callableTypeResultsMustNotBeAnnotated = (node: SdsCallableType, acc }; export const lambdaParametersMustNotBeAnnotated = (node: SdsLambda, accept: ValidationAcceptor) => { - for (const parameter of parametersOrEmpty(node)) { - for (const annotationCall of annotationCallsOrEmpty(parameter)) { + for (const parameter of getParameters(node)) { + for (const annotationCall of getAnnotationCalls(parameter)) { accept('error', 'Lambda parameters must not be annotated.', { node: annotationCall, code: CODE_ANNOTATION_CALL_TARGET_PARAMETER, diff --git a/src/language/validation/other/declarations/placeholders.ts b/src/language/validation/other/declarations/placeholders.ts index af3c185ba..e88f58239 100644 --- a/src/language/validation/other/declarations/placeholders.ts +++ b/src/language/validation/other/declarations/placeholders.ts @@ -9,7 +9,7 @@ import { } from '../../../generated/ast.js'; import { getContainerOfType, ValidationAcceptor } from 'langium'; import { SafeDsServices } from '../../../safe-ds-module.js'; -import { statementsOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getStatements } from '../../../helpers/nodeProperties.js'; import { DiagnosticTag } from 'vscode-languageserver'; import { last } from '../../../../helpers/collectionUtils.js'; @@ -47,7 +47,7 @@ export const placeholderShouldBeUsed = // Don't show a warning if the placeholder is declared in the last statement in the block const containingStatement = getContainerOfType(node, isSdsStatement); const containingBlock = getContainerOfType(containingStatement, isSdsBlock); - const allStatementsInBlock = statementsOrEmpty(containingBlock); + const allStatementsInBlock = getStatements(containingBlock); if (last(allStatementsInBlock) === containingStatement) { return; } diff --git a/src/language/validation/other/declarations/segments.ts b/src/language/validation/other/declarations/segments.ts index 9cd40d06b..177a59dbf 100644 --- a/src/language/validation/other/declarations/segments.ts +++ b/src/language/validation/other/declarations/segments.ts @@ -1,6 +1,6 @@ import { SdsSegment } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { parametersOrEmpty, resultsOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getParameters, getResults } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; import { DiagnosticTag } from 'vscode-languageserver'; @@ -10,7 +10,7 @@ export const CODE_SEGMENT_UNUSED_PARAMETER = 'segment/unused-parameter'; export const segmentResultMustBeAssignedExactlyOnce = (services: SafeDsServices) => (node: SdsSegment, accept: ValidationAcceptor) => { - const results = resultsOrEmpty(node.resultList); + const results = getResults(node.resultList); for (const result of results) { const yields = services.helpers.NodeMapper.resultToYields(result); if (yields.isEmpty()) { @@ -35,7 +35,7 @@ export const segmentResultMustBeAssignedExactlyOnce = export const segmentParameterShouldBeUsed = (services: SafeDsServices) => (node: SdsSegment, accept: ValidationAcceptor) => { - for (const parameter of parametersOrEmpty(node)) { + for (const parameter of getParameters(node)) { const usages = services.helpers.NodeMapper.parameterToReferences(parameter); if (usages.isEmpty()) { diff --git a/src/language/validation/other/expressions/calls.ts b/src/language/validation/other/expressions/calls.ts index 0a3e248bf..e0f02a66b 100644 --- a/src/language/validation/other/expressions/calls.ts +++ b/src/language/validation/other/expressions/calls.ts @@ -1,6 +1,6 @@ import { SdsCall } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { argumentsOrEmpty, isConstantParameter } from '../../../helpers/nodeProperties.js'; +import { getArguments, isConstantParameter } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; export const CODE_CALL_CONSTANT_ARGUMENT = 'call/constant-argument'; @@ -10,8 +10,8 @@ export const callArgumentsMustBeConstantIfParameterIsConstant = (services: SafeD const partialEvaluator = services.evaluation.PartialEvaluator; return (node: SdsCall, accept: ValidationAcceptor) => { - for (const argument of argumentsOrEmpty(node)) { - const parameter = nodeMapper.argumentToParameterOrUndefined(argument); + for (const argument of getArguments(node)) { + const parameter = nodeMapper.argumentToParameter(argument); if (!isConstantParameter(parameter)) continue; const evaluatedArgumentValue = partialEvaluator.evaluate(argument.value); diff --git a/src/language/validation/other/expressions/lambdas.ts b/src/language/validation/other/expressions/lambdas.ts index 150fc40e0..90d453b2b 100644 --- a/src/language/validation/other/expressions/lambdas.ts +++ b/src/language/validation/other/expressions/lambdas.ts @@ -1,6 +1,6 @@ import { isSdsArgument, isSdsParameter, isSdsParenthesizedExpression, SdsLambda } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { parametersOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getParameters } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; export const CODE_LAMBDA_CONTEXT = 'lambda/context'; @@ -19,7 +19,7 @@ export const lambdaMustBeAssignedToTypedParameter = (services: SafeDsServices) = if (isSdsParameter(context)) { contextIsValid = context.type !== undefined; } else if (isSdsArgument(context)) { - const parameter = nodeMapper.argumentToParameterOrUndefined(context); + const parameter = nodeMapper.argumentToParameter(context); // If the resolution of the parameter failed, we already show another error nearby contextIsValid = parameter === undefined || parameter.type !== undefined; } @@ -34,7 +34,7 @@ export const lambdaMustBeAssignedToTypedParameter = (services: SafeDsServices) = }; export const lambdaParameterMustNotHaveConstModifier = (node: SdsLambda, accept: ValidationAcceptor): void => { - for (const parameter of parametersOrEmpty(node)) { + for (const parameter of getParameters(node)) { if (parameter.isConstant) { accept('error', 'The const modifier is not applicable to parameters of lambdas.', { node: parameter, diff --git a/src/language/validation/other/expressions/memberAccesses.ts b/src/language/validation/other/expressions/memberAccesses.ts index 9731f79f6..00ea44009 100644 --- a/src/language/validation/other/expressions/memberAccesses.ts +++ b/src/language/validation/other/expressions/memberAccesses.ts @@ -2,7 +2,7 @@ import { SafeDsServices } from '../../../safe-ds-module.js'; import { isSdsCall, isSdsEnumVariant, SdsMemberAccess } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; import { UnknownType } from '../../../typing/model.js'; -import { parametersOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getParameters } from '../../../helpers/nodeProperties.js'; import { isEmpty } from '../../../../helpers/collectionUtils.js'; export const CODE_MEMBER_ACCESS_MISSING_ENUM_VARIANT_INSTANTIATION = 'member-access/missing-enum-variant-instantiation'; @@ -17,7 +17,7 @@ export const memberAccessOfEnumVariantMustNotLackInstantiation = ( return; } - if (!isSdsCall(node.$container) && !isEmpty(parametersOrEmpty(declaration))) { + if (!isSdsCall(node.$container) && !isEmpty(getParameters(declaration))) { accept('error', `The enum variant '${declaration.name}' has parameters, so an argument list must be added.`, { node, property: 'member', diff --git a/src/language/validation/other/statements/assignments.ts b/src/language/validation/other/statements/assignments.ts index 944e17551..3b1b734c5 100644 --- a/src/language/validation/other/statements/assignments.ts +++ b/src/language/validation/other/statements/assignments.ts @@ -1,7 +1,7 @@ import { isSdsCall, isSdsPipeline, SdsAssignment, SdsYield } from '../../../generated/ast.js'; import { getContainerOfType, ValidationAcceptor } from 'langium'; import { SafeDsServices } from '../../../safe-ds-module.js'; -import { abstractResultsOrEmpty, assigneesOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getAbstractResults, getAssignees } from '../../../helpers/nodeProperties.js'; import { pluralize } from '../../../../helpers/stringUtils.js'; export const CODE_ASSIGNMENT_IMPLICITLY_IGNORED_RESULT = 'assignment/implicitly-ignored-result'; @@ -11,8 +11,8 @@ export const CODE_ASSIGMENT_YIELD_FORBIDDEN_IN_PIPELINE = 'assignment/yield-forb export const assignmentAssigneeMustGetValue = (services: SafeDsServices) => (node: SdsAssignment, accept: ValidationAcceptor): void => { - for (const assignee of assigneesOrEmpty(node)) { - if (!services.helpers.NodeMapper.assigneeToAssignedObjectOrUndefined(assignee)) { + for (const assignee of getAssignees(node)) { + if (!services.helpers.NodeMapper.assigneeToAssignedObject(assignee)) { accept('error', 'No value is assigned to this assignee.', { node: assignee, code: CODE_ASSIGMENT_NOTHING_ASSIGNED, @@ -30,9 +30,9 @@ export const assignmentShouldNotImplicitlyIgnoreResult = (services: SafeDsServic return; } - const assignees = assigneesOrEmpty(node); - const callable = nodeMapper.callToCallableOrUndefined(expression); - const results = abstractResultsOrEmpty(callable); + const assignees = getAssignees(node); + const callable = nodeMapper.callToCallable(expression); + const results = getAbstractResults(callable); if (results.length > assignees.length) { const kind = pluralize(results.length - assignees.length, 'result'); diff --git a/src/language/validation/other/types/callableTypes.ts b/src/language/validation/other/types/callableTypes.ts index 104b88031..141a58310 100644 --- a/src/language/validation/other/types/callableTypes.ts +++ b/src/language/validation/other/types/callableTypes.ts @@ -1,7 +1,7 @@ import { SdsCallableType } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { parametersOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getParameters } from '../../../helpers/nodeProperties.js'; export const CODE_CALLABLE_TYPE_CONST_MODIFIER = 'callable-type/const-modifier'; export const CODE_CALLABLE_TYPE_NO_OPTIONAL_PARAMETERS = 'callable-type/no-optional-parameters'; @@ -10,7 +10,7 @@ export const callableTypeParameterMustNotHaveConstModifier = ( node: SdsCallableType, accept: ValidationAcceptor, ): void => { - for (const parameter of parametersOrEmpty(node)) { + for (const parameter of getParameters(node)) { if (parameter.isConstant) { accept('error', 'The const modifier is not applicable to parameters of callable types.', { node: parameter, @@ -22,7 +22,7 @@ export const callableTypeParameterMustNotHaveConstModifier = ( }; export const callableTypeMustNotHaveOptionalParameters = (node: SdsCallableType, accept: ValidationAcceptor): void => { - for (const parameter of parametersOrEmpty(node)) { + for (const parameter of getParameters(node)) { if (parameter.defaultValue) { accept('error', 'A callable type must not have optional parameters.', { node: parameter, diff --git a/src/language/validation/other/types/literalTypes.ts b/src/language/validation/other/types/literalTypes.ts index 363953f6a..49ae962de 100644 --- a/src/language/validation/other/types/literalTypes.ts +++ b/src/language/validation/other/types/literalTypes.ts @@ -1,6 +1,6 @@ import { isSdsList, isSdsMap, SdsLiteralType } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { literalsOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getLiterals } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; import { EvaluatedNode } from '../../../partialEvaluation/model.js'; import { isEmpty } from '../../../../helpers/collectionUtils.js'; @@ -11,7 +11,7 @@ export const CODE_LITERAL_TYPE_MAP_LITERAL = 'literal-type/map-literal'; export const CODE_LITERAL_TYPE_MISSING_LITERALS = 'literal-type/missing-literals'; export const literalTypeMustHaveLiterals = (node: SdsLiteralType, accept: ValidationAcceptor): void => { - if (isEmpty(literalsOrEmpty(node))) { + if (isEmpty(getLiterals(node))) { accept('error', 'A literal type must have at least one literal.', { node, property: 'literalList', @@ -21,7 +21,7 @@ export const literalTypeMustHaveLiterals = (node: SdsLiteralType, accept: Valida }; export const literalTypeMustNotContainListLiteral = (node: SdsLiteralType, accept: ValidationAcceptor): void => { - for (const literal of literalsOrEmpty(node)) { + for (const literal of getLiterals(node)) { if (isSdsList(literal)) { accept('error', 'Literal types must not contain list literals.', { node: literal, @@ -32,7 +32,7 @@ export const literalTypeMustNotContainListLiteral = (node: SdsLiteralType, accep }; export const literalTypeMustNotContainMapLiteral = (node: SdsLiteralType, accept: ValidationAcceptor): void => { - for (const literal of literalsOrEmpty(node)) { + for (const literal of getLiterals(node)) { if (isSdsMap(literal)) { accept('error', 'Literal types must not contain map literals.', { node: literal, @@ -46,7 +46,7 @@ export const literalTypeShouldNotHaveDuplicateLiteral = (services: SafeDsService const partialEvaluator = services.evaluation.PartialEvaluator; return (node: SdsLiteralType, accept: ValidationAcceptor): void => { - const literals = literalsOrEmpty(node); + const literals = getLiterals(node); const constants: EvaluatedNode[] = []; for (const literal of literals) { diff --git a/src/language/validation/other/types/namedTypes.ts b/src/language/validation/other/types/namedTypes.ts index b22446bf0..47da7589c 100644 --- a/src/language/validation/other/types/namedTypes.ts +++ b/src/language/validation/other/types/namedTypes.ts @@ -1,7 +1,7 @@ import { SdsNamedType } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; import { SafeDsServices } from '../../../safe-ds-module.js'; -import { typeArgumentsOrEmpty, typeParametersOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getTypeArguments, getTypeParameters } from '../../../helpers/nodeProperties.js'; import { duplicatesBy } from '../../../../helpers/collectionUtils.js'; import { pluralize } from '../../../../helpers/stringUtils.js'; @@ -11,10 +11,10 @@ export const CODE_NAMED_TYPE_TOO_MANY_TYPE_ARGUMENTS = 'named-type/too-many-type export const namedTypeMustNotSetTypeParameterMultipleTimes = (services: SafeDsServices) => { const nodeMapper = services.helpers.NodeMapper; - const typeArgumentToTypeParameterOrUndefined = nodeMapper.typeArgumentToTypeParameterOrUndefined.bind(nodeMapper); + const typeArgumentToTypeParameterOrUndefined = nodeMapper.typeArgumentToTypeParameter.bind(nodeMapper); return (node: SdsNamedType, accept: ValidationAcceptor): void => { - const typeArguments = typeArgumentsOrEmpty(node.typeArgumentList); + const typeArguments = getTypeArguments(node.typeArgumentList); const duplicates = duplicatesBy(typeArguments, typeArgumentToTypeParameterOrUndefined); for (const duplicate of duplicates) { @@ -55,8 +55,8 @@ export const namedTypeMustNotHaveTooManyTypeArguments = (node: SdsNamedType, acc return; } - const typeParameters = typeParametersOrEmpty(node.declaration.ref); - const typeArguments = typeArgumentsOrEmpty(node.typeArgumentList); + const typeParameters = getTypeParameters(node.declaration.ref); + const typeArguments = getTypeArguments(node.typeArgumentList); if (typeArguments.length > typeParameters.length) { const kind = pluralize(typeParameters.length, 'type argument'); diff --git a/src/language/validation/other/types/unionTypes.ts b/src/language/validation/other/types/unionTypes.ts index 5fe42face..3a8ca39ed 100644 --- a/src/language/validation/other/types/unionTypes.ts +++ b/src/language/validation/other/types/unionTypes.ts @@ -1,6 +1,6 @@ import { SdsUnionType } from '../../../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { typeArgumentsOrEmpty } from '../../../helpers/nodeProperties.js'; +import { getTypeArguments } from '../../../helpers/nodeProperties.js'; import { SafeDsServices } from '../../../safe-ds-module.js'; import { Type } from '../../../typing/model.js'; import { isEmpty } from '../../../../helpers/collectionUtils.js'; @@ -9,7 +9,7 @@ export const CODE_UNION_TYPE_DUPLICATE_TYPE = 'union-type/duplicate-type'; export const CODE_UNION_TYPE_MISSING_TYPES = 'union-type/missing-types'; export const unionTypeMustHaveTypes = (node: SdsUnionType, accept: ValidationAcceptor): void => { - if (isEmpty(typeArgumentsOrEmpty(node.typeArgumentList))) { + if (isEmpty(getTypeArguments(node.typeArgumentList))) { accept('error', 'A union type must have at least one type.', { node, property: 'typeArgumentList', @@ -22,7 +22,7 @@ export const unionTypeShouldNotHaveDuplicateTypes = (services: SafeDsServices) = const typeComputer = services.types.TypeComputer; return (node: SdsUnionType, accept: ValidationAcceptor): void => { - const typeArguments = typeArgumentsOrEmpty(node.typeArgumentList); + const typeArguments = getTypeArguments(node.typeArgumentList); const knownTypes: Type[] = []; for (const typeArgument of typeArguments) { diff --git a/src/language/validation/style.ts b/src/language/validation/style.ts index 8eeb0567c..58d674206 100644 --- a/src/language/validation/style.ts +++ b/src/language/validation/style.ts @@ -19,7 +19,7 @@ import { SdsUnionType, } from '../generated/ast.js'; import { ValidationAcceptor } from 'langium'; -import { isRequiredParameter, parametersOrEmpty, typeParametersOrEmpty } from '../helpers/nodeProperties.js'; +import { isRequiredParameter, getParameters, getTypeParameters } from '../helpers/nodeProperties.js'; import { SafeDsServices } from '../safe-ds-module.js'; import { UnknownType } from '../typing/model.js'; import { NullConstant } from '../partialEvaluation/model.js'; @@ -55,7 +55,7 @@ export const annotationCallArgumentListShouldBeNeeded = (node: SdsAnnotationCall return; } - const hasRequiredParameters = parametersOrEmpty(annotation).some(isRequiredParameter); + const hasRequiredParameters = getParameters(annotation).some(isRequiredParameter); if (!hasRequiredParameters) { accept('info', 'This argument list can be removed.', { node: argumentList, @@ -73,12 +73,12 @@ export const callArgumentListShouldBeNeeded = return; } - const callable = services.helpers.NodeMapper.callToCallableOrUndefined(node); + const callable = services.helpers.NodeMapper.callToCallable(node); if (!isSdsEnumVariant(callable)) { return; } - if (isEmpty(parametersOrEmpty(callable))) { + if (isEmpty(getParameters(callable))) { accept('info', 'This argument list can be removed.', { node: argumentList, code: CODE_STYLE_UNNECESSARY_ARGUMENT_LIST, @@ -130,7 +130,7 @@ export const enumBodyShouldNotBeEmpty = (node: SdsEnumBody, accept: ValidationAc // ----------------------------------------------------------------------------- export const annotationParameterShouldNotHaveConstModifier = (node: SdsAnnotation, accept: ValidationAcceptor) => { - for (const parameter of parametersOrEmpty(node)) { + for (const parameter of getParameters(node)) { if (parameter.isConstant) { accept('info', 'Annotation parameters are always const, so this modifier can be removed.', { node: parameter, @@ -315,7 +315,7 @@ export const namedTypeTypeArgumentListShouldBeNeeded = (node: SdsNamedType, acce return; } - if (isEmpty(typeParametersOrEmpty(namedTypeDeclaration))) { + if (isEmpty(getTypeParameters(namedTypeDeclaration))) { accept('info', 'This type argument list can be removed.', { node: typeArgumentList, code: CODE_STYLE_UNNECESSARY_TYPE_ARGUMENT_LIST, diff --git a/src/language/validation/types.ts b/src/language/validation/types.ts index 9297e08da..a6e1df531 100644 --- a/src/language/validation/types.ts +++ b/src/language/validation/types.ts @@ -14,7 +14,7 @@ import { SdsParameter, SdsResult, } from '../generated/ast.js'; -import { typeArgumentsOrEmpty, typeParametersOrEmpty } from '../helpers/nodeProperties.js'; +import { getTypeArguments, getTypeParameters } from '../helpers/nodeProperties.js'; import { SafeDsServices } from '../safe-ds-module.js'; import { pluralize } from '../../helpers/stringUtils.js'; import { isEmpty } from '../../helpers/collectionUtils.js'; @@ -45,7 +45,7 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => { } } - const callable = nodeMapper.callToCallableOrUndefined(node); + const callable = nodeMapper.callToCallable(node); if (!callable || isSdsAnnotation(callable)) { accept('error', 'This expression is not callable.', { node: node.receiver, @@ -67,14 +67,14 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => { export const namedTypeMustSetAllTypeParameters = (services: SafeDsServices) => (node: SdsNamedType, accept: ValidationAcceptor): void => { - const expectedTypeParameters = typeParametersOrEmpty(node.declaration.ref); + const expectedTypeParameters = getTypeParameters(node.declaration.ref); if (isEmpty(expectedTypeParameters)) { return; } if (node.typeArgumentList) { - const actualTypeParameters = typeArgumentsOrEmpty(node.typeArgumentList).map((it) => - services.helpers.NodeMapper.typeArgumentToTypeParameterOrUndefined(it), + const actualTypeParameters = getTypeArguments(node.typeArgumentList).map((it) => + services.helpers.NodeMapper.typeArgumentToTypeParameter(it), ); const missingTypeParameters = expectedTypeParameters.filter((it) => !actualTypeParameters.includes(it)); diff --git a/src/language/workspace/safe-ds-package-manager.ts b/src/language/workspace/safe-ds-package-manager.ts index 7f42c5ca3..f46dcf4fe 100644 --- a/src/language/workspace/safe-ds-package-manager.ts +++ b/src/language/workspace/safe-ds-package-manager.ts @@ -9,7 +9,7 @@ import { LangiumDocuments, } from 'langium'; import { isSdsSegment } from '../generated/ast.js'; -import { isInternal, packageNameOrUndefined } from '../helpers/nodeProperties.js'; +import { isInternal, getPackageName } from '../helpers/nodeProperties.js'; export class SafeDsPackageManager { private readonly astNodeLocator: AstNodeLocator; @@ -129,7 +129,7 @@ export class SafeDsPackageManager { continue; } - const packageName = packageNameOrUndefined(node); + const packageName = getPackageName(node); if (!packageName || !this.isValidPackageName(packageName)) { /* c8 ignore next 2 */ continue; diff --git a/tests/language/helpers/safe-ds-node-mapper/argumentToParameterOrUndefined.test.ts b/tests/language/helpers/safe-ds-node-mapper/argumentToParameter.test.ts similarity index 81% rename from tests/language/helpers/safe-ds-node-mapper/argumentToParameterOrUndefined.test.ts rename to tests/language/helpers/safe-ds-node-mapper/argumentToParameter.test.ts index 216cc68b4..1eaeafc0a 100644 --- a/tests/language/helpers/safe-ds-node-mapper/argumentToParameterOrUndefined.test.ts +++ b/tests/language/helpers/safe-ds-node-mapper/argumentToParameter.test.ts @@ -4,7 +4,7 @@ import { clearDocuments } from 'langium/test'; import { EmptyFileSystem } from 'langium'; import { getNodeOfType } from '../../../helpers/nodeFinder.js'; import { isSdsAbstractCall, SdsArgument } from '../../../../src/language/generated/ast.js'; -import { argumentsOrEmpty } from '../../../../src/language/helpers/nodeProperties.js'; +import { getArguments } from '../../../../src/language/helpers/nodeProperties.js'; const services = createSafeDsServices(EmptyFileSystem).SafeDs; const nodeMapper = services.helpers.NodeMapper; @@ -14,9 +14,9 @@ describe('SafeDsNodeMapper', () => { await clearDocuments(services); }); - describe('argumentToParameterOrUndefined', () => { + describe('argumentToParameter', () => { it('should return undefined if passed undefined', () => { - expect(nodeMapper.argumentToParameterOrUndefined(undefined)?.$type).toBeUndefined(); + expect(nodeMapper.argumentToParameter(undefined)?.$type).toBeUndefined(); }); describe('named argument', () => { @@ -30,7 +30,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - const parameterNames = argumentsOrEmpty(call).map(parameterNameOrNull); + const parameterNames = getArguments(call).map(parameterNameOrNull); expect(parameterNames).toStrictEqual([undefined]); }); @@ -44,7 +44,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - const parameterNames = argumentsOrEmpty(call).map(parameterNameOrNull); + const parameterNames = getArguments(call).map(parameterNameOrNull); expect(parameterNames).toStrictEqual(['p2', 'p3', 'p1']); }); }); @@ -60,7 +60,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - const parameterNames = argumentsOrEmpty(call).map(parameterNameOrNull); + const parameterNames = getArguments(call).map(parameterNameOrNull); expect(parameterNames).toStrictEqual(['p1', 'p2', 'p3']); }); @@ -74,7 +74,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - const parameterNames = argumentsOrEmpty(call).map(parameterNameOrNull); + const parameterNames = getArguments(call).map(parameterNameOrNull); expect(parameterNames).toStrictEqual(['p2', undefined, undefined]); }); @@ -88,13 +88,13 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - const parameterNames = argumentsOrEmpty(call).map(parameterNameOrNull); + const parameterNames = getArguments(call).map(parameterNameOrNull); expect(parameterNames).toStrictEqual(['p1', 'p2', undefined]); }); }); const parameterNameOrNull = (node: SdsArgument): string | undefined => { - const parameter = nodeMapper.argumentToParameterOrUndefined(node); + const parameter = nodeMapper.argumentToParameter(node); return parameter?.name ?? undefined; }; }); diff --git a/tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObjectOrUndefined.test.ts b/tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObject.test.ts similarity index 86% rename from tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObjectOrUndefined.test.ts rename to tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObject.test.ts index 44fb12958..ead91073c 100644 --- a/tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObjectOrUndefined.test.ts +++ b/tests/language/helpers/safe-ds-node-mapper/assigneeToAssignedObject.test.ts @@ -8,7 +8,7 @@ import { isSdsPlaceholder, SdsAssignee, } from '../../../../src/language/generated/ast.js'; -import { assigneesOrEmpty } from '../../../../src/language/helpers/nodeProperties.js'; +import { getAssignees } from '../../../../src/language/helpers/nodeProperties.js'; import { NodeFileSystem } from 'langium/node'; const services = createSafeDsServices(NodeFileSystem).SafeDs; @@ -24,9 +24,9 @@ describe('SafeDsNodeMapper', () => { await clearDocuments(services); }); - describe('assigneeToAssignedObjectOrUndefined', () => { + describe('assigneeToAssignedObject', () => { it('should return undefined if passed undefined', async () => { - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(undefined)?.$type).toBeUndefined(); + expect(nodeMapper.assigneeToAssignedObject(undefined)?.$type).toBeUndefined(); }); it.each([ @@ -59,7 +59,7 @@ describe('SafeDsNodeMapper', () => { }, ])('should return undefined if nothing is assigned ($name)', async ({ code }) => { const placeholder = await getNodeOfType(services, code, isSdsPlaceholder); - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(placeholder)?.$type).toBeUndefined(); + expect(nodeMapper.assigneeToAssignedObject(placeholder)?.$type).toBeUndefined(); }); it('should return the entire RHS of an assignment if it is not a call (constant)', async () => { @@ -70,7 +70,7 @@ describe('SafeDsNodeMapper', () => { `; const placeholder = await getNodeOfType(services, code, isSdsPlaceholder); - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(placeholder)?.$type).toBe('SdsInt'); + expect(nodeMapper.assigneeToAssignedObject(placeholder)?.$type).toBe('SdsInt'); }); it('should return the entire RHS of an assignment if it is a call of a class', async () => { @@ -82,7 +82,7 @@ describe('SafeDsNodeMapper', () => { `; const placeholder = await getNodeOfType(services, code, isSdsPlaceholder); - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(placeholder)?.$type).toBe('SdsCall'); + expect(nodeMapper.assigneeToAssignedObject(placeholder)?.$type).toBe('SdsCall'); }); it('should return the entire RHS of an assignment if it is a call of an enum variant', async () => { @@ -96,7 +96,7 @@ describe('SafeDsNodeMapper', () => { `; const placeholder = await getNodeOfType(services, code, isSdsPlaceholder); - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(placeholder)?.$type).toBe('SdsCall'); + expect(nodeMapper.assigneeToAssignedObject(placeholder)?.$type).toBe('SdsCall'); }); it('should return the entire RHS of an assignment if it is not a call (unresolved reference)', async () => { @@ -107,7 +107,7 @@ describe('SafeDsNodeMapper', () => { `; const placeholder = await getNodeOfType(services, code, isSdsPlaceholder); - expect(nodeMapper.assigneeToAssignedObjectOrUndefined(placeholder)?.$type).toBe('SdsReference'); + expect(nodeMapper.assigneeToAssignedObject(placeholder)?.$type).toBe('SdsReference'); }); it.each([ @@ -172,13 +172,13 @@ describe('SafeDsNodeMapper', () => { 'should return the corresponding result if the RHS is a call of a $name', async ({ code, expected, index = 0 }) => { const assignment = await getNodeOfType(services, code, isSdsAssignment, index); - const abstractResultNames = assigneesOrEmpty(assignment).map(abstractResultNameOrNull); + const abstractResultNames = getAssignees(assignment).map(abstractResultNameOrNull); expect(abstractResultNames).toStrictEqual(expected); }, ); const abstractResultNameOrNull = (node: SdsAssignee): string | undefined => { - const assignedObject = nodeMapper.assigneeToAssignedObjectOrUndefined(node); + const assignedObject = nodeMapper.assigneeToAssignedObject(node); if (isSdsAbstractResult(assignedObject)) { return assignedObject.name; } else { diff --git a/tests/language/helpers/safe-ds-node-mapper/callToCallableOrUndefined.test.ts b/tests/language/helpers/safe-ds-node-mapper/callToCallable.test.ts similarity index 81% rename from tests/language/helpers/safe-ds-node-mapper/callToCallableOrUndefined.test.ts rename to tests/language/helpers/safe-ds-node-mapper/callToCallable.test.ts index 01ec5e8c7..2e6076078 100644 --- a/tests/language/helpers/safe-ds-node-mapper/callToCallableOrUndefined.test.ts +++ b/tests/language/helpers/safe-ds-node-mapper/callToCallable.test.ts @@ -13,9 +13,9 @@ describe('SafeDsNodeMapper', () => { await clearDocuments(services); }); - describe('callToCallableOrUndefined', () => { + describe('callToCallable', () => { it('should return undefined if passed undefined', () => { - expect(nodeMapper.callToCallableOrUndefined(undefined)).toBeUndefined(); + expect(nodeMapper.callToCallable(undefined)).toBeUndefined(); }); // ----------------------------------------------------------------------------------------- @@ -30,7 +30,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBeUndefined(); + expect(nodeMapper.callToCallable(call)?.$type).toBeUndefined(); }); it('should return the called annotation', async () => { @@ -42,7 +42,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsAnnotation'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsAnnotation'); }); }); @@ -59,7 +59,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBeUndefined(); + expect(nodeMapper.callToCallable(call)?.$type).toBeUndefined(); }); it('should return undefined if receiver is not callable', async () => { @@ -72,7 +72,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBeUndefined(); + expect(nodeMapper.callToCallable(call)?.$type).toBeUndefined(); }); it('should return the called annotation', async () => { @@ -85,7 +85,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsAnnotation'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsAnnotation'); }); it('should return the called annotation (aliased)', async () => { @@ -99,7 +99,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsAnnotation'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsAnnotation'); }); it('should return the called block lambda (aliased)', async () => { @@ -111,7 +111,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsBlockLambda'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsBlockLambda'); }); it('should return the called callable type', async () => { @@ -122,7 +122,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsCallableType'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsCallableType'); }); it('should return the called callable type (aliased)', async () => { @@ -134,7 +134,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsCallableType'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsCallableType'); }); it('should return the called class', async () => { @@ -147,7 +147,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsClass'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsClass'); }); it('should return the called class (aliased)', async () => { @@ -161,7 +161,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsClass'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsClass'); }); it('should return the called enum variant', async () => { @@ -176,7 +176,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsEnumVariant'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsEnumVariant'); }); it('should return undefined (aliased enum variant without parameter)', async () => { @@ -192,7 +192,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)).toBeUndefined(); + expect(nodeMapper.callToCallable(call)).toBeUndefined(); }); it('should return the called enum variant (aliased with parameter)', async () => { @@ -208,7 +208,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsEnumVariant'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsEnumVariant'); }); it('should return the called expression lambda (aliased)', async () => { @@ -220,7 +220,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsExpressionLambda'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsExpressionLambda'); }); it('should return the called function', async () => { @@ -233,7 +233,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsFunction'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsFunction'); }); it('should return the called function (aliased)', async () => { @@ -247,7 +247,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsFunction'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsFunction'); }); it('should return the called segment', async () => { @@ -260,7 +260,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsSegment'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsSegment'); }); it('should return the called segment (aliased)', async () => { @@ -274,7 +274,7 @@ describe('SafeDsNodeMapper', () => { `; const call = await getNodeOfType(services, code, isSdsAbstractCall); - expect(nodeMapper.callToCallableOrUndefined(call)?.$type).toBe('SdsSegment'); + expect(nodeMapper.callToCallable(call)?.$type).toBe('SdsSegment'); }); }); }); diff --git a/tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameterOrUndefined.test.ts b/tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameter.test.ts similarity index 78% rename from tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameterOrUndefined.test.ts rename to tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameter.test.ts index a5032f248..e0eb4d736 100644 --- a/tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameterOrUndefined.test.ts +++ b/tests/language/helpers/safe-ds-node-mapper/typeArgumentToTypeParameter.test.ts @@ -4,7 +4,7 @@ import { clearDocuments } from 'langium/test'; import { EmptyFileSystem } from 'langium'; import { getNodeOfType } from '../../../helpers/nodeFinder.js'; import { isSdsNamedType, isSdsUnionType, SdsTypeArgument } from '../../../../src/language/generated/ast.js'; -import { typeArgumentsOrEmpty } from '../../../../src/language/helpers/nodeProperties.js'; +import { getTypeArguments } from '../../../../src/language/helpers/nodeProperties.js'; const services = createSafeDsServices(EmptyFileSystem).SafeDs; const nodeMapper = services.helpers.NodeMapper; @@ -14,9 +14,9 @@ describe('SafeDsNodeMapper', () => { await clearDocuments(services); }); - describe('typeArgumentToTypeParameterOrUndefined', () => { + describe('typeArgumentToTypeParameter', () => { it('should return undefined if passed undefined', () => { - expect(nodeMapper.typeArgumentToTypeParameterOrUndefined(undefined)?.$type).toBeUndefined(); + expect(nodeMapper.typeArgumentToTypeParameter(undefined)?.$type).toBeUndefined(); }); describe('named type argument', () => { @@ -28,7 +28,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual([undefined]); }); @@ -40,7 +40,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual([undefined]); }); @@ -52,7 +52,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual(['T2', 'T3', 'T1']); }); }); @@ -66,7 +66,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual([undefined]); }); @@ -80,7 +80,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType, 1); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual(['T1', 'T2', 'T3']); }); @@ -92,7 +92,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual(['T2', undefined, undefined]); }); @@ -104,7 +104,7 @@ describe('SafeDsNodeMapper', () => { `; const namedType = await getNodeOfType(services, code, isSdsNamedType); - const parameterNames = typeArgumentsOrEmpty(namedType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(namedType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual(['T1', 'T2', undefined]); }); @@ -116,7 +116,7 @@ describe('SafeDsNodeMapper', () => { `; const unionType = await getNodeOfType(services, code, isSdsUnionType); - const parameterNames = typeArgumentsOrEmpty(unionType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(unionType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual([undefined, undefined]); }); @@ -128,13 +128,13 @@ describe('SafeDsNodeMapper', () => { `; const unionType = await getNodeOfType(services, code, isSdsUnionType); - const parameterNames = typeArgumentsOrEmpty(unionType.typeArgumentList).map(typeParameterNameOrNull); + const parameterNames = getTypeArguments(unionType.typeArgumentList).map(typeParameterNameOrNull); expect(parameterNames).toStrictEqual([undefined, undefined]); }); }); const typeParameterNameOrNull = (node: SdsTypeArgument): string | undefined => { - const typeParameter = nodeMapper.typeArgumentToTypeParameterOrUndefined(node); + const typeParameter = nodeMapper.typeArgumentToTypeParameter(node); return typeParameter?.name ?? undefined; }; }); diff --git a/tests/resources/generation/declarations/empty segment/input.sdstest b/tests/resources/generation/declarations/empty segment/input.sdstest new file mode 100644 index 000000000..266c388a6 --- /dev/null +++ b/tests/resources/generation/declarations/empty segment/input.sdstest @@ -0,0 +1,3 @@ +package tests.generator.emptySegment + +segment test() {} diff --git a/tests/resources/generation/declarations/empty segment/output/tests/generator/emptySegment/gen_input.py b/tests/resources/generation/declarations/empty segment/output/tests/generator/emptySegment/gen_input.py new file mode 100644 index 000000000..7b01f8ace --- /dev/null +++ b/tests/resources/generation/declarations/empty segment/output/tests/generator/emptySegment/gen_input.py @@ -0,0 +1,4 @@ +# Segments --------------------------------------------------------------------- + +def test(): + pass diff --git a/tests/resources/generation/declarations/empty step/input.sdstest b/tests/resources/generation/declarations/empty step/input.sdstest deleted file mode 100644 index 663eb41d6..000000000 --- a/tests/resources/generation/declarations/empty step/input.sdstest +++ /dev/null @@ -1,3 +0,0 @@ -package tests.generator.emptyStep - -segment test() {} diff --git a/tests/resources/generation/declarations/empty step/output/tests/generator/emptyStep/gen_input.py b/tests/resources/generation/declarations/empty step/output/tests/generator/emptyStep/gen_input.py deleted file mode 100644 index 7a62d7d3c..000000000 --- a/tests/resources/generation/declarations/empty step/output/tests/generator/emptyStep/gen_input.py +++ /dev/null @@ -1,4 +0,0 @@ -# Steps ------------------------------------------------------------------------ - -def test(): - pass diff --git a/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py b/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py index 4d9c8f8d5..ae228dbf2 100644 --- a/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py +++ b/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py @@ -1,4 +1,4 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- def test(param1, param_2, param_3=0): f1(lambda param1, param2, param3=0: 1) diff --git a/tests/resources/generation/declarations/segment with python name/input.sdstest b/tests/resources/generation/declarations/segment with python name/input.sdstest new file mode 100644 index 000000000..7bb308431 --- /dev/null +++ b/tests/resources/generation/declarations/segment with python name/input.sdstest @@ -0,0 +1,8 @@ +package tests.generator.segmentWithPythonName + +fun f() + +@PythonName("test_segment") +segment testSegment() { + f(); +} diff --git a/tests/resources/generation/declarations/segment with python name/output/tests/generator/segmentWithPythonName/gen_input.py b/tests/resources/generation/declarations/segment with python name/output/tests/generator/segmentWithPythonName/gen_input.py new file mode 100644 index 000000000..bd35ce794 --- /dev/null +++ b/tests/resources/generation/declarations/segment with python name/output/tests/generator/segmentWithPythonName/gen_input.py @@ -0,0 +1,4 @@ +# Segments --------------------------------------------------------------------- + +def test_segment(): + f() diff --git a/tests/resources/generation/declarations/step with python name/input.sdstest b/tests/resources/generation/declarations/step with python name/input.sdstest deleted file mode 100644 index a58e4b5b0..000000000 --- a/tests/resources/generation/declarations/step with python name/input.sdstest +++ /dev/null @@ -1,8 +0,0 @@ -package tests.generator.stepWithPythonName - -fun f() - -@PythonName("test_step") -segment testStep() { - f(); -} diff --git a/tests/resources/generation/declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py b/tests/resources/generation/declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py deleted file mode 100644 index 26cbaeb4d..000000000 --- a/tests/resources/generation/declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py +++ /dev/null @@ -1,4 +0,0 @@ -# Steps ------------------------------------------------------------------------ - -def test_step(): - f() diff --git a/tests/resources/generation/declarations/two steps/input.sdstest b/tests/resources/generation/declarations/two segments/input.sdstest similarity index 73% rename from tests/resources/generation/declarations/two steps/input.sdstest rename to tests/resources/generation/declarations/two segments/input.sdstest index d265f8262..de170b27d 100644 --- a/tests/resources/generation/declarations/two steps/input.sdstest +++ b/tests/resources/generation/declarations/two segments/input.sdstest @@ -1,4 +1,4 @@ -package tests.generator.twoSteps +package tests.generator.twoSegments fun f() diff --git a/tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py b/tests/resources/generation/declarations/two segments/output/tests/generator/twoSegments/gen_input.py similarity index 52% rename from tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py rename to tests/resources/generation/declarations/two segments/output/tests/generator/twoSegments/gen_input.py index 15d4deb31..fa5aeb3fd 100644 --- a/tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py +++ b/tests/resources/generation/declarations/two segments/output/tests/generator/twoSegments/gen_input.py @@ -1,4 +1,4 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- def test1(a, b=0): f() diff --git a/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py b/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py index 3dfd67ece..ebd90a46b 100644 --- a/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py +++ b/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py @@ -1,4 +1,4 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- def f1(l): h(l(1, 2)) diff --git a/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py b/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py index 56096ed17..2484ff61d 100644 --- a/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py +++ b/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py @@ -1,4 +1,4 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- def test(params): f(params[0]) diff --git a/tests/resources/generation/imports/general/context same package.sdstest b/tests/resources/generation/imports/general/context same package.sdstest index 6cde20255..14bba5b4e 100644 --- a/tests/resources/generation/imports/general/context same package.sdstest +++ b/tests/resources/generation/imports/general/context same package.sdstest @@ -2,10 +2,10 @@ package tests.generator.imports fun impureFunction() -> result: Int -segment step1InSamePackage() -> result: Int { +segment segment1InSamePackage() -> result: Int { yield result = impureFunction(); } -segment step2InSamePackage() -> result: Int { +segment segment2InSamePackage() -> result: Int { yield result = impureFunction(); } diff --git a/tests/resources/generation/imports/general/input.sdstest b/tests/resources/generation/imports/general/input.sdstest index bd19aeb47..771775aff 100644 --- a/tests/resources/generation/imports/general/input.sdstest +++ b/tests/resources/generation/imports/general/input.sdstest @@ -8,10 +8,10 @@ from tests.generator.withPythonModule import function2InCompilationUnitWithPytho fun f(param: Any?) pipeline test { - f(step1InSamePackage()); - f(step1InSamePackage()); - f(step2InSamePackage()); - f(step2InSamePackage()); + f(segment1InSamePackage()); + f(segment1InSamePackage()); + f(segment2InSamePackage()); + f(segment2InSamePackage()); f(function1InDifferentPackage()); f(function1InDifferentPackage()); diff --git a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py index 2575a1ac1..3d5209468 100644 --- a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py +++ b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py @@ -1,9 +1,9 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- -def step1InSamePackage(): +def segment1InSamePackage(): __gen_yield_result = impureFunction() return __gen_yield_result -def step2InSamePackage(): +def segment2InSamePackage(): __gen_yield_result = impureFunction() return __gen_yield_result diff --git a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py index 895f4da5d..8fd2d0cc9 100644 --- a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py +++ b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py @@ -2,15 +2,15 @@ from special_location import function1InCompilationUnitWithPythonModule, function2InCompilationUnitWithPythonModule as h from tests.generator.differentPackage import function1InDifferentPackage, function2InDifferentPackage as g -from tests.generator.imports.gen_context_same_package import step1InSamePackage, step2InSamePackage +from tests.generator.imports.gen_context_same_package import segment1InSamePackage, segment2InSamePackage # Pipelines -------------------------------------------------------------------- def test(): - f(step1InSamePackage()) - f(step1InSamePackage()) - f(step2InSamePackage()) - f(step2InSamePackage()) + f(segment1InSamePackage()) + f(segment1InSamePackage()) + f(segment2InSamePackage()) + f(segment2InSamePackage()) f(function1InDifferentPackage()) f(function1InDifferentPackage()) f(g()) diff --git a/tests/resources/generation/python module/output/special_module/gen_input.py b/tests/resources/generation/python module/output/special_module/gen_input.py index 5c10c6069..eab6391b7 100644 --- a/tests/resources/generation/python module/output/special_module/gen_input.py +++ b/tests/resources/generation/python module/output/special_module/gen_input.py @@ -1,4 +1,4 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- def test(): f() diff --git a/tests/resources/generation/statements/assignment/input.sdstest b/tests/resources/generation/statements/assignment/input.sdstest index 3f7bc5afe..9302a3d87 100644 --- a/tests/resources/generation/statements/assignment/input.sdstest +++ b/tests/resources/generation/statements/assignment/input.sdstest @@ -21,7 +21,7 @@ pipeline testPipeline { }); } -segment testStep() -> c: Int { +segment testSegment() -> c: Int { _, _ ,_ = g(); val a, _, yield c = g(); val x = g(); diff --git a/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py b/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py index d98f68403..a131129c4 100644 --- a/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py +++ b/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py @@ -1,6 +1,6 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- -def testStep(): +def testSegment(): g() a, _, __gen_yield_c = g() x, _, _ = g() diff --git a/tests/resources/generation/statements/expression statement/input.sdstest b/tests/resources/generation/statements/expression statement/input.sdstest index 27b87e6ff..4fcc07ee3 100644 --- a/tests/resources/generation/statements/expression statement/input.sdstest +++ b/tests/resources/generation/statements/expression statement/input.sdstest @@ -12,6 +12,6 @@ pipeline testPipeline { }); } -segment testStep() { +segment testSegment() { g(); } diff --git a/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py b/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py index 117709000..6c765f1b8 100644 --- a/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py +++ b/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py @@ -1,6 +1,6 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- -def testStep(): +def testSegment(): g() # Pipelines -------------------------------------------------------------------- diff --git a/tests/resources/generation/statements/skip-statement without effect/input.sdstest b/tests/resources/generation/statements/skip-statement without effect/input.sdstest index cf9d06e4c..a862d78fb 100644 --- a/tests/resources/generation/statements/skip-statement without effect/input.sdstest +++ b/tests/resources/generation/statements/skip-statement without effect/input.sdstest @@ -12,7 +12,7 @@ pipeline testPipeline { }); } -segment testStep() { +segment testSegment() { 1; _ = 1; } diff --git a/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py b/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py index 2cde3391a..2f7a730f9 100644 --- a/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py +++ b/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py @@ -1,6 +1,6 @@ -# Steps ------------------------------------------------------------------------ +# Segments --------------------------------------------------------------------- -def testStep(): +def testSegment(): pass # Pipelines --------------------------------------------------------------------