Skip to content

Commit

Permalink
Add builtin @Feed annotation (#435)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
MiguelCompany authored Feb 11, 2025
1 parent 4772983 commit 5492e2f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Annotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.eprosima.fastdds.idl.grammar;

import com.eprosima.idl.parser.tree.AnnotationDeclaration;

public class Annotation extends com.eprosima.idl.parser.tree.Annotation
{
public static final String rpc_feed_str = "feed";

public Annotation(AnnotationDeclaration declaration)
{
super(declaration);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public Context(
AnnotationDeclaration keyann = this.createAnnotationDeclaration(Annotation.eprosima_key_str, null);
keyann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str));

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

public void setTypelimitation(
Expand Down Expand Up @@ -699,6 +702,25 @@ else if (name.equals(Annotation.external_str))
return super.getAnnotationDeclaration(name);
}

@Override
public Operation createOperation(
String name,
Token token)
{
Operation operationObject = new Operation(getScopeFile(), isInScopedFile(), null, name, token);
return operationObject;
}

@Override
public Param createParam(
String name,
TypeCode typecode,
Param.Kind kind)
{
Param paramObject = new Param(name, typecode, kind);
return paramObject;
}

//// Java block ////
// Java package name.
private String m_package = "";
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Operation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.eprosima.fastdds.idl.grammar;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;
import org.antlr.v4.runtime.Token;

public class Operation extends com.eprosima.idl.parser.tree.Operation
{
public Operation(String scopeFile, boolean isInScope, String scope, String name, Token tk)
{
super(scopeFile, isInScope, scope, name, tk);
}

/**
* Return whether the operation has been annotated as feed
*
* @return true when the operation has been annotated as feed, false otherwise.
*/
public boolean isAnnotationFeed()
{
com.eprosima.idl.parser.tree.Annotation ann = getAnnotations().get(Annotation.rpc_feed_str);
if (ann != null)
{
try
{
return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str);
}
catch (RuntimeGenerationException ex)
{
// Should not be called as @feed annotation has only one parameter
}
}
return false;
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Param.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.eprosima.fastdds.idl.grammar;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;
import com.eprosima.idl.parser.typecode.TypeCode;

import org.antlr.v4.runtime.Token;

public class Param extends com.eprosima.idl.parser.tree.Param
{
public Param(String name, TypeCode typecode, Kind kind)

{
super(name, typecode, kind);
}

/**
* Return whether the operation has been annotated as feed
*
* @return true when the operation has been annotated as feed, false otherwise.
*/
public boolean isAnnotationFeed()
{
com.eprosima.idl.parser.tree.Annotation ann = getAnnotations().get(Annotation.rpc_feed_str);
if (ann != null)
{
try
{
return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str);
}
catch (RuntimeGenerationException ex)
{
// Should not be called as @feed annotation has only one parameter
}
}
return false;
}
}

0 comments on commit 5492e2f

Please sign in to comment.