Skip to content

Commit

Permalink
[WIP] Fix parameter validator
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed Mar 19, 2024
1 parent 075f7a8 commit 3c0f599
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<value_sub_type.length;i++){
if (!check_matched_type(expected_type,value_sub_type.get(i).eClass.name)){
error( "Element "+i+" , expected type: "+expected_type+" given type "+value_sub_type.get(i).eClass.name, null, INVALID_TYPE)
}
}
if (expected_sub_types.length > 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<value_sub_type.length;i++){
if (!check_matched_type(expected_type,value_sub_type.get(i).eClass.name)){
error( "Element "+i+" , expected type: "+expected_type+" given type "+value_sub_type.get(i).eClass.name, null, INVALID_TYPE)
}
}
}
}
}
else {
Expand All @@ -275,7 +281,7 @@ class RosSystemValidator extends AbstractRosSystemValidator {
expected_sub_names = new ArrayList<String>();

for (i=0; i<expected_sub_types.length;i++){
expected_sub_names.add(i,getName(expected_sub_types.get(i).toString));
expected_sub_names.add(i,getName(expected_sub_types.get(i).toString));
}

for (i=0; i<value_sub_type.length;i++){
Expand All @@ -284,31 +290,34 @@ class RosSystemValidator extends AbstractRosSystemValidator {
}else {
name_given_element = getName(value_sub_type.get(i).toString)
}
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<expected_sub_types.length;j++){
if (expected_sub_types.get(j).toString.contains("name")){
if ( ((getName(expected_sub_types.get(j).toString))==name_given_element) ){
if (expected_sub_types.get(j).eContents.get(0).eClass.name.matches("ParameterStructType|ParameterListType|ParameterSequence")){
CheckParameterValue((expected_sub_types.get(j).eContents.get(0)),(value_sub_type.get(i).eContents.get(0)));
//CheckParameterValue((expected_sub_types.get(j).eContents.get(0)),(value_sub_type.get(i).eContents.get(0).eContents.get(0)));
}
try{
expected_sub_type = expected_sub_types.get(j);
if (expected_sub_type.eContents.size > 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<expected_sub_types.length;j++){
if (expected_sub_types.get(j).toString.contains("name")){
if ( ((getName(expected_sub_types.get(j).toString))==name_given_element) ){
if (expected_sub_types.get(j).eContents.get(0).eClass.name.matches("ParameterStructType|ParameterListType|ParameterSequence")){
CheckParameterValue((expected_sub_types.get(j).eContents.get(0)),(value_sub_type.get(i).eContents.get(0)));
//CheckParameterValue((expected_sub_types.get(j).eContents.get(0)),(value_sub_type.get(i).eContents.get(0).eContents.get(0)));
}
try{
expected_sub_type = expected_sub_types.get(j);
if (expected_sub_type.eContents.size > 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 {
Expand All @@ -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(")"))
}
}
Expand Down

0 comments on commit 3c0f599

Please sign in to comment.