From 3c0f5991fac7bf0844003b848be6fb55980916b2 Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Tue, 19 Mar 2024 17:51:10 +0100 Subject: [PATCH] [WIP] Fix parameter validator --- .../generator/GeneratorHelpers.xtend | 15 ++-- .../validation/RosSystemValidator.xtend | 83 ++++++++++--------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend index 7cf7b243..59be3386 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend @@ -123,13 +123,14 @@ class GeneratorHelpers { var elem_count = (value as ParameterSequenceImpl).eContents.length; for (elem : ((value as ParameterSequenceImpl).eContents)) { - var member = ((elem as ParameterStructImpl).eContents.get(0) as ParameterStructMemberImpl); - val param_val = get_param_value(member.getValue(), name + "/" + member.getName()); - if (param_val.startsWith("{")) { - param_str += param_val; - } else { - param_str += "{ \"" + name + "/" + member.getName() + "\" : " + param_val; - } + if ((elem as ParameterStructImpl).eContents.length > 0){ + var member = ((elem as ParameterStructImpl).eContents.get(0) as ParameterStructMemberImpl); + val param_val = get_param_value(member.getValue(), name + "/" + member.getName()); + if (param_val.startsWith("{")) { + param_str += param_val; + } else { + param_str += "{ \"" + name + "/" + member.getName() + "\" : " + param_val; + }} elem_count--; if (elem_count > 0){ param_str +=" },\n" diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/validation/RosSystemValidator.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/validation/RosSystemValidator.xtend index 35a65c03..69547de2 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/validation/RosSystemValidator.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/validation/RosSystemValidator.xtend @@ -213,7 +213,11 @@ class RosSystemValidator extends AbstractRosSystemValidator { def void CheckParameterValue (EObject expected_parameter, EObject given_parameter){ if (expected_parameter.eClass.name=="Parameter"){ expected_type = (expected_parameter as Parameter).type.eClass.name; - expected_sub_types = expected_parameter.eContents.get(0).eContents.toList + for (content: expected_parameter.eContents){ + if(content.eClass.name.contains("ParameterStructTypeImpl")){ + expected_sub_types = content.eContents.toList + } + } sub_element = false; } else { @@ -254,15 +258,17 @@ class RosSystemValidator extends AbstractRosSystemValidator { //expected_sub_types = expected_parameter.eContents.get(0).eContents.toList if (given_parameter.class.toString.contains("ParameterSequence")){ value_sub_type = given_parameter.eContents.toList - expected_type=expected_sub_types.get(0).eClass.name - if(expected_type.contains("ParameterArrayType")){ - CheckParameterValue((expected_sub_types.get(0).eContents.get(0)),(value_sub_type.get(0).eContents.get(0))) - } else { - for (i=0;i 0){ + expected_type=expected_sub_types.get(0).eClass.name + if(expected_type.contains("ParameterArrayType")){ + CheckParameterValue((expected_sub_types.get(0).eContents.get(0)),(value_sub_type.get(0).eContents.get(0))) + } else { + for (i=0;i(); for (i=0; i 0){ - if (!check_matched_type(expected_sub_types.get(j).eContents.get(0).eClass.name,sub_element_type)){ - error( "Element "+getName(expected_sub_types.get(j).toString)+" , expected type: "+expected_sub_types.get(j).eContents.get(0).eClass.name+ - " given type "+sub_element_type, null, INVALID_TYPE) - info("Struct format: value { {FIRST {value VALUE_FIRST}}, {SECOND {value VALUE_SECOND}}}",null, INVALID_NAME)} - } - } catch (IndexOutOfBoundsException error) { - // Output expected IndexOutOfBoundsExceptions. - } - }}}}}} + if (value_sub_type.get(i).eContents.length>0){ + sub_element_type = value_sub_type.get(i).eContents.get(0).eClass.name + if (!(expected_sub_names.contains(name_given_element))){ + error("Element expected names: "+expected_sub_names+ " instead of: "+name_given_element,null, INVALID_NAME) + info("Struct format: value { {first_element {value value_fisrt element}}, {second_element {value value_second element}}}",null, INVALID_NAME) + } else { + for (j=0;j 0){ + if (!check_matched_type(expected_sub_types.get(j).eContents.get(0).eClass.name,sub_element_type)){ + error( "Element "+getName(expected_sub_types.get(j).toString)+" , expected type: "+expected_sub_types.get(j).eContents.get(0).eClass.name+ + " given type "+sub_element_type, null, INVALID_TYPE) + info("Struct format: value { {FIRST {value VALUE_FIRST}}, {SECOND {value VALUE_SECOND}}}",null, INVALID_NAME)} + } + } catch (IndexOutOfBoundsException error) { + info("Catch error",null, null) + // Output expected IndexOutOfBoundsExceptions. + } + }}}}} + } + } // INT, BOOL, DOUBLE, BASE64, STRING else { @@ -331,7 +340,7 @@ class RosSystemValidator extends AbstractRosSystemValidator { } def String getName(String Element){ - if (Element.length()>0){ + if (Element.length()>0 && Element.contains("name:") && Element.contains(")")){ return Element.substring(Element.indexOf("name:")+5,Element.indexOf(")")) } }