lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.AttributeUtils Class Reference

A helper class for processing attributes in the AST. More...

Static Public Member Functions

static Attribute findAttributeByName (EObject node, String name)
 Return the attribute with the given name if present, otherwise return null.
static List< Attribute > findAttributesByName (EObject node, String name) throws IllegalArgumentException
 Return a list of attributes with the given name.
static TimeValue getAbsentAfter (EObject node)
 Return the value of the @absent_after attribute of the given node or TimeValue.ZERO if does not have one.
static AttrParm getAttributeParameter (Attribute attribute, String parameterName)
 Return the parameter with the given name for the specified attribute or null if no such parameter is found.
static List< Attribute > getAttributes (EObject node)
 Return a list of attributes declared on the given node.
static String getAttributeValue (EObject node, String attrName)
 Return the first argument specified for the first attribute with the given name.
static boolean getBooleanAttributeParameter (Attribute attribute, String parameterName)
 Return true if there is a parameter of the given attribute with the given name whose value is "true" (case-insensitive) and return false otherwise.
static Attribute getEnclaveAttribute (Instantiation node)
 Return the @enclave attribute annotated on the given node.
static int getEnclaveNumWorkersFromAttribute (Instantiation node)
 Retrieve the number of worker parameter from an enclave attribute.
static String getFirstArgumentValue (Attribute attr)
 Return the first argument specified for the attribute or null if the attribute is not found or if it does not have any arguments.
static String getIconPath (EObject node)
 Return the declared icon of the node, as given by the @icon annotation, or null if there is no such annotation.
static String getLabel (EObject node)
 Return the declared label of the node, as given by the @label annotation.
static Map< String, String > getLayoutOption (EObject node)
 Return the layout annotations for the given element or null if there is no such annotation.
static TimeValue getMaxWait (EObject node)
 Return the value of the @maxwait attribute of the given node or TimeValue.ZERO if does not have one.
static String getPortSide (EObject node)
 Return the @side annotation for the given node (presumably a port) or null if there is no such annotation.
static boolean hasCBody (Reaction reaction)
 Return true if the reaction is marked to have a C code body.
static boolean isEnclave (Instantiation node)
 Return true if the specified instance has an @enclave attribute.
static boolean isEnclaveConnection (Instantiation node)
 Return true if the specified instantiation is of an EnclaveConnection reactor.
static boolean isFederate (Reactor reactor)
 Return true if the reactor is marked to be a federate.
static boolean isSparse (EObject node)
 Return true if the specified node is an Input and has an @sparse attribute.

Detailed Description

A helper class for processing attributes in the AST.

An attribute is an annotation using the @ syntax. For example, @label("My Label") is an attribute. It is associated with whatever node comes immediately after it.

Author
Shaokai Lin
Clément Fournier
Alexander Schulz-Rosengarten

Member Function Documentation

◆ findAttributeByName()

Attribute org.lflang.AttributeUtils.findAttributeByName ( EObject node,
String name )
static

Return the attribute with the given name if present, otherwise return null.

If there are multiple attributes with the same name, this returns the first one.

Parameters
nodeThe node to search for the attribute.
nameThe name of the attribute to search for.
Returns
The attribute with the given name or null if it is not found.

◆ findAttributesByName()

List< Attribute > org.lflang.AttributeUtils.findAttributesByName ( EObject node,
String name ) throws IllegalArgumentException
static

Return a list of attributes with the given name.

An empty list is returned if the node does not have any attributes with the given name.

Parameters
nodeThe node to get the attributes from.
nameThe name of the attributes to get.
Exceptions
IllegalArgumentExceptionIf the node cannot have attributes

◆ getAbsentAfter()

TimeValue org.lflang.AttributeUtils.getAbsentAfter ( EObject node)
static

Return the value of the @absent_after attribute of the given node or TimeValue.ZERO if does not have one.

Parameters
nodeThe AST node (a Connection).

◆ getAttributeParameter()

AttrParm org.lflang.AttributeUtils.getAttributeParameter ( Attribute attribute,
String parameterName )
static

Return the parameter with the given name for the specified attribute or null if no such parameter is found.

Parameters
attributeThe attribute to get the parameter from.
parameterNameThe name of the parameter to get.

◆ getAttributes()

List< Attribute > org.lflang.AttributeUtils.getAttributes ( EObject node)
static

Return a list of attributes declared on the given node.

An empty list is returned if the node does not have any attributes.

Parameters
nodeThe node to get the attributes from.
Exceptions
IllegalArgumentExceptionIf the node cannot have attributes.

◆ getAttributeValue()

String org.lflang.AttributeUtils.getAttributeValue ( EObject node,
String attrName )
static

Return the first argument specified for the first attribute with the given name.

If there is no attribute with the given name, return null. If the attribute has no arguments, or if the arguments are not of a suitable form, return null. This ignores any argument name, if one is given, and only returns arguments of the form of strings ("foo"), numbers (123), boolean values (true, false), or the time values forever or never. Time values with units are not returned (the return value will be null).

This is a convenience method for common use cases where an attribute is specified with a single argument of a suitable form. The validator should check that the arguments are of a suitable form.

Parameters
nodeThe node to get the attribute value from.
attrNameThe name of the attribute to get the value from.

◆ getBooleanAttributeParameter()

boolean org.lflang.AttributeUtils.getBooleanAttributeParameter ( Attribute attribute,
String parameterName )
static

Return true if there is a parameter of the given attribute with the given name whose value is "true" (case-insensitive) and return false otherwise.

Parameters
attributeThe attribute to get the parameter from.
parameterNameThe name of the parameter to get.

◆ getEnclaveAttribute()

Attribute org.lflang.AttributeUtils.getEnclaveAttribute ( Instantiation node)
static

Return the @enclave attribute annotated on the given node.

Return null if there is no such attribute.

Parameters
nodeThe node to get the enclave attribute from.
Returns
The enclave attribute of the node or null if there is no such attribute.

◆ getEnclaveNumWorkersFromAttribute()

int org.lflang.AttributeUtils.getEnclaveNumWorkersFromAttribute ( Instantiation node)
static

Retrieve the number of worker parameter from an enclave attribute.

Return 1 if not specified or has illegal value

Parameters
nodeThe node to get the number of workers from.
Returns
The number of workers or 1 if not specified or has illegal value.

◆ getFirstArgumentValue()

String org.lflang.AttributeUtils.getFirstArgumentValue ( Attribute attr)
static

Return the first argument specified for the attribute or null if the attribute is not found or if it does not have any arguments.

This should be used only if the attribute is expected to have a single argument.

Parameters
attrThe attribute to get the first argument from.
Returns
The first argument of the attribute or null if the attribute is not found or if it does not have any arguments.

◆ getIconPath()

String org.lflang.AttributeUtils.getIconPath ( EObject node)
static

Return the declared icon of the node, as given by the @icon annotation, or null if there is no such annotation.

Parameters
nodeThe node to get the icon path from.
Returns
The icon path of the node or null if there is no such annotation.

◆ getLabel()

String org.lflang.AttributeUtils.getLabel ( EObject node)
static

Return the declared label of the node, as given by the @label annotation.

Parameters
nodeThe node to get the label from.
Returns
The label of the node or null if there is no such annotation.

◆ getLayoutOption()

Map< String, String > org.lflang.AttributeUtils.getLayoutOption ( EObject node)
static

Return the layout annotations for the given element or null if there is no such annotation.

Layout annotations have the form:


@layout(option="string", value="any")

For example:


@layout(option="port.side", value="WEST")

This will return all such annotations for the specified node in the form of a map from the option name to the value.

◆ getMaxWait()

TimeValue org.lflang.AttributeUtils.getMaxWait ( EObject node)
static

Return the value of the @maxwait attribute of the given node or TimeValue.ZERO if does not have one.

Parameters
nodeThe AST node (Instantiation or Connection).

◆ getPortSide()

String org.lflang.AttributeUtils.getPortSide ( EObject node)
static

Return the @side annotation for the given node (presumably a port) or null if there is no such annotation.

Parameters
nodeThe node to get the port side from.
Returns
The port side of the node or null if there is no such annotation.

◆ hasCBody()

boolean org.lflang.AttributeUtils.hasCBody ( Reaction reaction)
static

Return true if the reaction is marked to have a C code body.

Currently, this is only used for synthesized reactions in the context of federated execution in Python.

Parameters
reactionThe reaction to check.
Returns
True if the reaction is marked to have a C code body.

◆ isEnclave()

boolean org.lflang.AttributeUtils.isEnclave ( Instantiation node)
static

Return true if the specified instance has an @enclave attribute.

Parameters
nodeThe node to check.
Returns
True if the specified instance has an @enclave attribute.

◆ isEnclaveConnection()

boolean org.lflang.AttributeUtils.isEnclaveConnection ( Instantiation node)
static

Return true if the specified instantiation is of an EnclaveConnection reactor.

Parameters
nodeThe node to check.
Returns
True if the specified instantiation is of an EnclaveConnection reactor.

◆ isFederate()

boolean org.lflang.AttributeUtils.isFederate ( Reactor reactor)
static

Return true if the reactor is marked to be a federate.

Parameters
reactorThe reactor to check.
Returns
True if the reactor is marked to be a federate.

◆ isSparse()

boolean org.lflang.AttributeUtils.isSparse ( EObject node)
static

Return true if the specified node is an Input and has an @sparse attribute.

Parameters
nodeAn AST node.
Returns
True if the specified node is an Input and has an @sparse attribute.

The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/AttributeUtils.java