Skip to content

Commit 54b3859

Browse files
committed
Add builtin @Feed annotation (#435)
* Refs #22761. Add builtin @Feed annotation. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22761. Add auxiliary STG utilities to Operation class. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22761. Add auxiliary STG utilities to Param class. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 8eaca9a commit 54b3859

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.eprosima.fastdds.idl.grammar;
16+
17+
import com.eprosima.idl.parser.tree.AnnotationDeclaration;
18+
19+
public class Annotation extends com.eprosima.idl.parser.tree.Annotation
20+
{
21+
public static final String rpc_feed_str = "feed";
22+
23+
public Annotation(AnnotationDeclaration declaration)
24+
{
25+
super(declaration);
26+
}
27+
}

src/main/java/com/eprosima/fastdds/idl/grammar/Context.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public Context(
8686
AnnotationDeclaration keyann = this.createAnnotationDeclaration(Annotation.eprosima_key_str, null);
8787
keyann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str));
8888

89+
// Create default @feed annotation.
90+
AnnotationDeclaration feed_ann = this.createAnnotationDeclaration(com.eprosima.fastdds.idl.grammar.Annotation.rpc_feed_str, null);
91+
feed_ann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str));
8992
}
9093

9194
public void setTypelimitation(
@@ -699,6 +702,25 @@ else if (name.equals(Annotation.external_str))
699702
return super.getAnnotationDeclaration(name);
700703
}
701704

705+
@Override
706+
public Operation createOperation(
707+
String name,
708+
Token token)
709+
{
710+
Operation operationObject = new Operation(getScopeFile(), isInScopedFile(), null, name, token);
711+
return operationObject;
712+
}
713+
714+
@Override
715+
public Param createParam(
716+
String name,
717+
TypeCode typecode,
718+
Param.Kind kind)
719+
{
720+
Param paramObject = new Param(name, typecode, kind);
721+
return paramObject;
722+
}
723+
702724
//// Java block ////
703725
// Java package name.
704726
private String m_package = "";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.eprosima.fastdds.idl.grammar;
16+
17+
import com.eprosima.idl.parser.exception.RuntimeGenerationException;
18+
import org.antlr.v4.runtime.Token;
19+
20+
public class Operation extends com.eprosima.idl.parser.tree.Operation
21+
{
22+
public Operation(String scopeFile, boolean isInScope, String scope, String name, Token tk)
23+
{
24+
super(scopeFile, isInScope, scope, name, tk);
25+
}
26+
27+
/**
28+
* Return whether the operation has been annotated as feed
29+
*
30+
* @return true when the operation has been annotated as feed, false otherwise.
31+
*/
32+
public boolean isAnnotationFeed()
33+
{
34+
com.eprosima.idl.parser.tree.Annotation ann = getAnnotations().get(Annotation.rpc_feed_str);
35+
if (ann != null)
36+
{
37+
try
38+
{
39+
return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str);
40+
}
41+
catch (RuntimeGenerationException ex)
42+
{
43+
// Should not be called as @feed annotation has only one parameter
44+
}
45+
}
46+
return false;
47+
}
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.eprosima.fastdds.idl.grammar;
16+
17+
import com.eprosima.idl.parser.exception.RuntimeGenerationException;
18+
import com.eprosima.idl.parser.typecode.TypeCode;
19+
20+
import org.antlr.v4.runtime.Token;
21+
22+
public class Param extends com.eprosima.idl.parser.tree.Param
23+
{
24+
public Param(String name, TypeCode typecode, Kind kind)
25+
26+
{
27+
super(name, typecode, kind);
28+
}
29+
30+
/**
31+
* Return whether the operation has been annotated as feed
32+
*
33+
* @return true when the operation has been annotated as feed, false otherwise.
34+
*/
35+
public boolean isAnnotationFeed()
36+
{
37+
com.eprosima.idl.parser.tree.Annotation ann = getAnnotations().get(Annotation.rpc_feed_str);
38+
if (ann != null)
39+
{
40+
try
41+
{
42+
return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str);
43+
}
44+
catch (RuntimeGenerationException ex)
45+
{
46+
// Should not be called as @feed annotation has only one parameter
47+
}
48+
}
49+
return false;
50+
}
51+
}

0 commit comments

Comments
 (0)