Search code examples
rascal

Does my variable have an annotation?


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?


Solution

  • 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