1
1
import {
2
2
isSdsAnnotation ,
3
3
isSdsCall ,
4
+ isSdsClass ,
5
+ isSdsEnum ,
4
6
isSdsFunction ,
5
7
isSdsMemberAccess ,
6
8
isSdsPipeline ,
@@ -11,20 +13,23 @@ import {
11
13
import { AstNode , ValidationAcceptor } from 'langium' ;
12
14
13
15
export const CODE_REFERENCE_FUNCTION_POINTER = 'reference/function-pointer' ;
16
+ export const CODE_REFERENCE_STATIC_CLASS_REFERENCE = 'reference/static-class-reference' ;
17
+ export const CODE_REFERENCE_STATIC_ENUM_REFERENCE = 'reference/static-enum-reference' ;
14
18
export const CODE_REFERENCE_TARGET = 'reference/target' ;
15
19
16
20
export const referenceMustNotBeFunctionPointer = ( node : SdsReference , accept : ValidationAcceptor ) : void => {
17
- const target = node . target ? .ref ;
21
+ const target = node . target . ref ;
18
22
if ( ! isSdsFunction ( target ) && ! isSdsSegment ( target ) ) {
19
23
return ;
20
24
}
21
25
22
- let container : AstNode | undefined = node . $container ;
23
- if ( isSdsMemberAccess ( container ) && node . $containerProperty === 'member' ) {
24
- container = container . $container ;
26
+ // Get the containing member access if the node is on its right side
27
+ let nodeOrContainer : AstNode | undefined = node ;
28
+ if ( isSdsMemberAccess ( node . $container ) && node . $containerProperty === 'member' ) {
29
+ nodeOrContainer = nodeOrContainer . $container ;
25
30
}
26
31
27
- if ( ! isSdsCall ( container ) ) {
32
+ if ( ! isSdsCall ( nodeOrContainer ?. $ container) ) {
28
33
accept (
29
34
'error' ,
30
35
'Function pointers are not allowed to provide a cleaner graphical view. Use a lambda instead.' ,
@@ -36,11 +41,47 @@ export const referenceMustNotBeFunctionPointer = (node: SdsReference, accept: Va
36
41
}
37
42
} ;
38
43
44
+ export const referenceMustNotBeStaticClassOrEnumReference = ( node : SdsReference , accept : ValidationAcceptor ) => {
45
+ const target = node . target . ref ;
46
+ if ( ! isSdsClass ( target ) && ! isSdsEnum ( target ) ) {
47
+ return ;
48
+ }
49
+
50
+ // Get the containing member access if the node is on its right side
51
+ let nodeOrContainer : AstNode | undefined = node ;
52
+ if ( isSdsMemberAccess ( node . $container ) && node . $containerProperty === 'member' ) {
53
+ nodeOrContainer = nodeOrContainer . $container ;
54
+ }
55
+
56
+ // Access to a member of the class or enum
57
+ if ( isSdsMemberAccess ( nodeOrContainer ?. $container ) && nodeOrContainer ?. $containerProperty === 'receiver' ) {
58
+ return ;
59
+ }
60
+
61
+ // Call of the class or enum
62
+ if ( isSdsCall ( nodeOrContainer ?. $container ) ) {
63
+ return ;
64
+ }
65
+
66
+ // Static reference to the class or enum
67
+ if ( isSdsClass ( target ) ) {
68
+ accept ( 'error' , 'A class must not be statically referenced.' , {
69
+ node,
70
+ code : CODE_REFERENCE_STATIC_CLASS_REFERENCE ,
71
+ } ) ;
72
+ } else if ( isSdsEnum ( target ) ) {
73
+ accept ( 'error' , 'An enum must not be statically referenced.' , {
74
+ node,
75
+ code : CODE_REFERENCE_STATIC_ENUM_REFERENCE ,
76
+ } ) ;
77
+ }
78
+ } ;
79
+
39
80
export const referenceTargetMustNotBeAnnotationPipelineOrSchema = (
40
81
node : SdsReference ,
41
82
accept : ValidationAcceptor ,
42
83
) : void => {
43
- const target = node . target ? .ref ;
84
+ const target = node . target . ref ;
44
85
45
86
if ( isSdsAnnotation ( target ) ) {
46
87
accept ( 'error' , 'An annotation must not be the target of a reference.' , {
0 commit comments