Skip to content

Commit

Permalink
Support annotations on operation parameters (#168)
Browse files Browse the repository at this point in the history
* Refs #22761. Support annotations on class Param

Signed-off-by: Miguel Company <[email protected]>

* Refs #22761. Parse annotations on operation parameters.

Signed-off-by: Miguel Company <[email protected]>

* Refs #22764. Apply suggestion.

Signed-off-by: Miguel Company <[email protected]>

---------

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored Feb 10, 2025
1 parent 8b6d622 commit 5572222
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,20 @@ param_decl_list [Operation operation, TemplateGroup tpl]
;

param_decl returns [Pair<Param, TemplateGroup> returnPair = null]
@init{
ArrayList<Annotation> annotations = new ArrayList<Annotation>();
}
: (annotation_appl { annotations.add($annotation_appl.annotation); })* param_def
{
$returnPair=$param_def.returnPair;
for (Annotation ann : annotations)
{
$returnPair.first().addAnnotation(ctx, ann);
}
}
;

param_def returns [Pair<Param, TemplateGroup> returnPair = null]
@init{
TemplateGroup paramTemplate = null;
TemplateGroup template = null;
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/eprosima/idl/parser/tree/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
package com.eprosima.idl.parser.tree;

import com.eprosima.idl.parser.typecode.TypeCode;
import com.eprosima.idl.context.Context;

public class Param
import java.util.Map;
import java.util.HashMap;

public class Param implements Notebook
{
public enum Kind
{
Expand Down Expand Up @@ -106,9 +110,26 @@ public Object getParent()
return m_parent;
}

@Override
public void addAnnotation(Context ctx, Annotation annotation)
{
if(annotation != null)
{
m_annotations.put(annotation.getName(), annotation);
}
}

@Override
public Map<String, Annotation> getAnnotations()
{
return m_annotations;
}

private Kind m_kind = Kind.IN_PARAM;
private String m_name = null;
private TypeCode m_typecode = null;
private Definition m_definition = null;
private Object m_parent = null;
//! Map that stores the annotations of the parameter.
private HashMap<String, Annotation> m_annotations = new HashMap<String, Annotation>();
}

0 comments on commit 5572222

Please sign in to comment.