Skip to content

Commit

Permalink
fix for issue #911
Browse files Browse the repository at this point in the history
  • Loading branch information
vash-evg committed Oct 13, 2018
1 parent be9f3d1 commit 7c74247
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
43 changes: 43 additions & 0 deletions cruise.umple/src/Generator_CodeJson.ump
Expand Up @@ -181,6 +181,49 @@ class JsonGenerator
boolean isInterface = true;
String implementedInterfaces = "";
boolean isAbstract = false;

//Fix for issue #911 - UmpleOnline in Editable diagram mode was not displaying methods for interfaces
for(Method method : aInterface.getMethods())
{
if (method.getSource() == Method.Source.fAutoAPI)
continue;

if(jsonForMethods.length() > 0)
{
jsonForMethods += ", ";
}
String methodModifier = method.getModifier();
String methodReturnType = method.getType();

String visibility="";
if(methodModifier.matches(".*public.*"))
visibility = "public";
else if(methodModifier.matches(".*private.*"))
visibility = "private";
else if(methodModifier.matches(".*protected.*"))
visibility = "protected";

String methodParams = "";
for(MethodParameter param : method.getMethodParameters())
{
if(methodParams.length() > 0)
{
methodParams += ",";
}
methodParams += param.getFullType().trim();
}

jsonForMethods += StringFormatter.format(
"{ {0}type{0} : {0}{1}{0}, {0}name{0} : {0}{2}{0}, " +
"{0}parameters{0} : {0}{3}{0}, {0}visibility{0} : {0}{4}{0}, {0}isAbstract{0} : {0}{5}{0}}",
"\"",
methodReturnType,
method.getName(),
methodParams,
visibility,
method.getIsAbstract());
}
//End of fix

if (!isFirst)
{
Expand Down
43 changes: 43 additions & 0 deletions cruise.umple/src/Generator_CodeJsonMixed.ump
Expand Up @@ -192,6 +192,49 @@ class JsonMixedGenerator
String implementedInterfaces = "";
boolean isAbstract = false;

//Fix for issue #911 - UmpleOnline in Editable diagram mode was not displaying methods for interfaces
for(Method method : aInterface.getMethods())
{
if (method.getSource() == Method.Source.fAutoAPI)
continue;

if(jsonForMethods.length() > 0)
{
jsonForMethods += ", ";
}
String methodModifier = method.getModifier();
String methodReturnType = method.getType();

String visibility="";
if(methodModifier.matches(".*public.*"))
visibility = "public";
else if(methodModifier.matches(".*private.*"))
visibility = "private";
else if(methodModifier.matches(".*protected.*"))
visibility = "protected";

String methodParams = "";
for(MethodParameter param : method.getMethodParameters())
{
if(methodParams.length() > 0)
{
methodParams += ",";
}
methodParams += param.getFullType().trim();
}

jsonForMethods += StringFormatter.format(
"{ {0}type{0} : {0}{1}{0}, {0}name{0} : {0}{2}{0}, " +
"{0}parameters{0} : {0}{3}{0}, {0}visibility{0} : {0}{4}{0}, {0}isAbstract{0} : {0}{5}{0}}",
"\"",
methodReturnType,
method.getName(),
methodParams,
visibility,
method.getIsAbstract());
}
//End of fix

if (!isFirst)
{
jsonForClasses += ", ";
Expand Down
@@ -1 +1 @@
{"umpleClasses":[{"position": {"x": 50, "y": 30, "width": 109, "height": 45}, "attributes": [{ "type" : "String", "name" : "var", "modifier" : "", "traceColor" : "black" }],"methods": [{ "type" : "void", "name" : "test", "parameters" : "", "visibility" : "", "isAbstract" : "true"}], "id": "AAA", "name": "AAA", "isAbstract": "true", "displayColor": "" , "isInterface": "false"}, {"position": {"x": 50, "y": 130, "width": 109, "height": 45}, "attributes": [],"methods": [{ "type" : "void", "name" : "test", "parameters" : "", "visibility" : "", "isAbstract" : "false"}], "id": "BBB", "name": "BBB", "isAbstract": "false", "displayColor": "" , "extendsClass": "AAA", "isInterface": "false"}, {"position": {"x": 50, "y": 230, "width": 109, "height": 45}, "attributes": [],"methods": [], "id": "CCC", "name": "CCC", "isAbstract": "true", "displayColor": "" , "isInterface": "false"}, {"position": {"x": 268, "y": 30, "width": 109, "height": 45}, "attributes": [],"methods": [], "id": "FFF", "name": "FFF", "isAbstract": "false", "displayColor": "" , "isInterface": "true"}], "umpleAssociations":[] }
{"umpleClasses":[{"position": {"x": 50, "y": 30, "width": 109, "height": 45}, "attributes": [{ "type" : "String", "name" : "var", "modifier" : "", "traceColor" : "black" }],"methods": [{ "type" : "void", "name" : "test", "parameters" : "", "visibility" : "", "isAbstract" : "true"}], "id": "AAA", "name": "AAA", "isAbstract": "true", "displayColor": "" , "isInterface": "false"}, {"position": {"x": 50, "y": 130, "width": 109, "height": 45}, "attributes": [],"methods": [{ "type" : "void", "name" : "test", "parameters" : "", "visibility" : "", "isAbstract" : "false"}], "id": "BBB", "name": "BBB", "isAbstract": "false", "displayColor": "" , "extendsClass": "AAA", "isInterface": "false"}, {"position": {"x": 50, "y": 230, "width": 109, "height": 45}, "attributes": [],"methods": [], "id": "CCC", "name": "CCC", "isAbstract": "true", "displayColor": "" , "isInterface": "false"}, {"position": {"x": 268, "y": 30, "width": 109, "height": 45}, "attributes": [],"methods": [{ "type" : "void", "name" : "testTwo", "parameters" : "", "visibility" : "", "isAbstract" : "false"}], "id": "FFF", "name": "FFF", "isAbstract": "false", "displayColor": "" , "isInterface": "true"}], "umpleAssociations":[] }
@@ -0,0 +1 @@
{"umpleClasses":[{"position": {"x": 268, "y": 30, "width": 109, "height": 45}, "attributes": [],"methods": [{ "type" : "void", "name" : "m1", "parameters" : "", "visibility" : "", "isAbstract" : "false"}], "id": "X", "name": "X", "isAbstract": "false", "displayColor": "" , "isInterface": "true"}], "umpleAssociations":[] }
@@ -0,0 +1,3 @@
interface X {
void m1();
}
Expand Up @@ -151,4 +151,10 @@ public void AbstractTest()
assertUmpleTemplateFor("json/AbstractClass.ump", "json/AbstractClass.json.txt");
}

@Test
public void InterfaceWithMethodTest()
{
assertUmpleTemplateFor("json/InterfaceWithMethod.ump", "json/InterfaceWithMethod.json.txt");
}

}

0 comments on commit 7c74247

Please sign in to comment.