1
1
import { ValidationAcceptor } from 'langium' ;
2
- import { SdsDeclaration } from '../../generated/ast.js' ;
2
+ import { SdsDeclaration , SdsFunction } from '../../generated/ast.js' ;
3
3
import { SafeDsServices } from '../../safe-ds-module.js' ;
4
- import { findFirstAnnotationCallOf } from '../../helpers/nodeProperties.js' ;
4
+ import { findFirstAnnotationCallOf , hasAnnotationCallOf } from '../../helpers/nodeProperties.js' ;
5
5
6
+ export const CODE_PYTHON_NAME_MUTUALLY_EXCLUSIVE_WITH_PYTHON_CALL = 'python-name/mutually-exclusive-with-python-call' ;
6
7
export const CODE_PYTHON_NAME_SAME_AS_SAFE_DS_NAME = 'python-name/same-as-safe-ds-name' ;
7
8
9
+ export const pythonNameMustNotBeSetIfPythonCallIsSet = ( services : SafeDsServices ) => {
10
+ const builtinAnnotations = services . builtins . Annotations ;
11
+
12
+ return ( node : SdsFunction , accept : ValidationAcceptor ) => {
13
+ if ( ! hasAnnotationCallOf ( node , builtinAnnotations . PythonCall ) ) {
14
+ return ;
15
+ }
16
+
17
+ const firstPythonName = findFirstAnnotationCallOf ( node , builtinAnnotations . PythonName ) ;
18
+ if ( ! firstPythonName ) {
19
+ return ;
20
+ }
21
+
22
+ accept ( 'error' , 'A Python name must not be set if a Python call is set.' , {
23
+ node : firstPythonName ,
24
+ property : 'annotation' ,
25
+ code : CODE_PYTHON_NAME_MUTUALLY_EXCLUSIVE_WITH_PYTHON_CALL ,
26
+ } ) ;
27
+ } ;
28
+ } ;
29
+
8
30
export const pythonNameShouldDifferFromSafeDsName = ( services : SafeDsServices ) => {
9
31
const builtinAnnotations = services . builtins . Annotations ;
10
32
@@ -17,6 +39,7 @@ export const pythonNameShouldDifferFromSafeDsName = (services: SafeDsServices) =
17
39
const annotationCall = findFirstAnnotationCallOf ( node , builtinAnnotations . PythonName ) ! ;
18
40
accept ( 'info' , 'The Python name is identical to the Safe-DS name, so the annotation call can be removed.' , {
19
41
node : annotationCall ,
42
+ property : 'annotation' ,
20
43
code : CODE_PYTHON_NAME_SAME_AS_SAFE_DS_NAME ,
21
44
} ) ;
22
45
} ;
0 commit comments