How can I check if my variable has some annotation?

I know this can be done for properties using the keyword has.

Is there a similar way to do this for annotations?

有帮助吗?

解决方案

There are two ways you can do this. I've shown both in the code given below.

rascal>data T = c(int x);
ok

rascal>anno bool T@truth;
ok

rascal>v1 = c(1)[@truth=true];
T: c(1)[
  @truth=true
]

rascal>v2 = c(2);
T: c(2)

rascal>(v1@truth)?
bool: true

rascal>(v2@truth)?
bool: false

rascal>import Node;
ok

rascal>"truth" in getAnnotations(v1);
bool: true

rascal>"truth" in getAnnotations(v2);
bool: false
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top