diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java index 0705a29e..ea852eb0 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java @@ -14,8 +14,6 @@ package com.eprosima.idl.generator.manager; -import com.eprosima.idl.generator.manager.TemplateGroup; - import java.util.Iterator; import java.util.Map; import java.util.HashMap; @@ -88,8 +86,13 @@ public void set_current_template_stgroup(TemplateSTGroup template_stgroup) current_template_stgroup_ = template_stgroup; } - public TemplateSTGroup get_current_template_stgroup() + public boolean is_enabled_custom_property_in_current_group(String custom_property) { - return current_template_stgroup_; + if (null != current_template_stgroup_) + { + return current_template_stgroup_.is_enabled_custom_property(custom_property); + } + + return false; } } diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java index 61a23218..61168b88 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java @@ -15,6 +15,7 @@ package com.eprosima.idl.generator.manager; import org.stringtemplate.v4.*; +import java.util.ArrayList; public class TemplateSTGroup { @@ -34,24 +35,23 @@ public STGroup get_stgroup() } /*! - * @brief Returns if the current `Context` scope will be remove from the scoped name of types (returned by - * `getScopedname()`). + * @brief Checks a custom property was added in this template group. */ - public boolean is_enabled_using_explicitly_modules() + public boolean is_enabled_custom_property(String custom_property) { - return using_explicitly_modules_; + return custom_properties.contains(custom_property); } /*! - * @brief Enable removing the current `Context` scope from the scoped name of types (returned by `getScopedname()`). + * @brief Enables a custom property. */ - public void enable_using_explicitly_modules() + public void enable_custom_property(String custom_property) { - using_explicitly_modules_ = true; + custom_properties.add(custom_property); } private STGroup st_group_ = null; - //! If set, the scoped name of types (returned by `getScopedname()`) will remove the current `Context` scope. - private boolean using_explicitly_modules_ = false; + //! List of custom properties added by the user. + ArrayList custom_properties = new ArrayList(); }; diff --git a/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java b/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java index dc007f2c..ab71f37f 100644 --- a/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java +++ b/src/main/java/com/eprosima/idl/generator/manager/TemplateUtil.java @@ -167,7 +167,7 @@ else if(dist_type.getKind() == Kind.KIND_ENUM) if(enum_members.size() > 0) { - union_type.setDefaultvalue(enume.getScope() + "::" + enum_members.get(0).getName()); + union_type.setDefaultvalue(enume.getScopedname() + "::" + enum_members.get(0).getName()); union_type.setJavaDefaultvalue(enume.javapackage + enume.getJavaScopedname() + "." + enum_members.get(0).getName()); } else diff --git a/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java index 8de0abd2..7c4f5ccb 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java @@ -130,11 +130,16 @@ public String getName() return m_name; } + /*! + * @brief Returns the full scoped name of the type, unless the developer uses + * `TemplateSTGroup.enable_custom_proeprty("using_explicitly_modules")`, by removing from the full scoped name the + * current `Context` scope. + */ public String getScopedname() { String scoped_name = getFullScopedname(); - if (!ctx.get_template_manager().get_current_template_stgroup().is_enabled_using_explicitly_modules()) + if (!ctx.get_template_manager().is_enabled_custom_property_in_current_group("using_explicitly_modules")) { return scoped_name; } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java index f74c79e6..a51e052d 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java @@ -99,7 +99,7 @@ public String getInitialValue() { if (getMembers().size() > 0) { - return (getScope() != null ? getScope() + "::" : "") + getMembers().get(0).getName(); + return getScopedname() + "::" + getMembers().get(0).getName(); } return ""; diff --git a/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java index 6855daf5..97aebd82 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java @@ -38,14 +38,14 @@ public String getName() /*! * @brief Returns the full scoped name of the type, unless the developer uses - * `TemplateSTGroup.enable_using_explicitly_modules()`, by removing from the full scoped name the current - * `Context` scope. + * `TemplateSTGroup.enable_custom_proeprty("using_explicitly_modules")`, by removing from the full scoped name the + * current `Context` scope. */ public String getScopedname() { String scoped_name = getFullScopedname(); - if (!ctx.get_template_manager().get_current_template_stgroup().is_enabled_using_explicitly_modules()) + if (!ctx.get_template_manager().is_enabled_custom_property_in_current_group("using_explicitly_modules")) { return scoped_name; } diff --git a/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java b/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java index aa757a7b..0bbe09b1 100644 --- a/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java +++ b/src/main/java/com/eprosima/idl/parser/typecode/UnionTypeCode.java @@ -102,7 +102,7 @@ public int addMember( for (int count = 0; count < internal_labels.size(); ++count) { - labels.add(enum_type.getScope() + "::" + internal_labels.get(count)); + labels.add(enum_type.getScopedname() + "::" + internal_labels.get(count)); javalabels.add(javapackage + enum_type.getJavaScopedname() + "." + internal_labels.get(count)); } }