Permalink
Browse files

Merge pull request #980 from nwam/master

Fix #964
  • Loading branch information...
2 parents 56a6305 + 3caf8ed commit 61a14ab8ee6ca90a09c84bd8d745ca71f986a12e @vahdat-ab vahdat-ab committed on GitHub Feb 3, 2017
@@ -2,6 +2,10 @@ class UmpleToPhp {
class_MethodDeclaration <<!<</*class_MethodDeclaration*/>><<#
if (uClass.hasMethods())
{
+ // method parameters of primitives should not explicitly list the parameter type
+ // ex: function f($a){} and not f(integer $a){}
+ List<String> primitives = Arrays.asList("string", "boolean", "integer", "float", "double",
+ "String", "Boolean", "Integer", "Float", "Double");
for (Method aMethod : uClass.getMethods())
{
if(!aMethod.getExistsInLanguage("Php"))
@@ -10,8 +14,8 @@ class UmpleToPhp {
String methodImplementationModifier = aMethod.getIsAbstract() ? " abstract" : "";
String methodName = aMethod.getName();
String methodType = "function";
- String customBeforeInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("before", aMethod.getName(), aMethod.getMethodParameters()));
- String customAfterInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("after", aMethod.getName(), aMethod.getMethodParameters()));
+ String customBeforeInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("before", aMethod.getName(), aMethod.getMethodParameters()));
+ String customAfterInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("after", aMethod.getName(), aMethod.getMethodParameters()));
String customPreconditionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", aMethod.getName()+"Precondition"));String customPostconditionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", aMethod.getName()+"Postcondition"));
customPostconditionCode = customPostconditionCode==null?"":customPostconditionCode;
@@ -30,14 +34,23 @@ class UmpleToPhp {
String aSingleParameter="";
String finalParams = "";
String isList="";
- String parameters = "";
+ String parameters = "";
if (aMethod.hasMethodParameters())
{
for (MethodParameter aMethodParam : aMethod.getMethodParameters())
{
- paramName = aMethodParam.getName();
- paramType = aMethodParam.getType();
- isList = aMethodParam.getIsList() ? " [] " : " ";
+ paramName = "$" + aMethodParam.getName();
+ if (!aMethodParam.getIsList()){
+ paramType = aMethodParam.getType();
+ if (primitives.contains(paramType)) {
+ paramType = "";
+ }else{
+ paramType+=" ";}
+
+ }else{
+ paramType = "";
+ }
+ //isList = aMethodParam.getIsList() ? " [] " : " ";
aSingleParameter = paramType + isList + paramName;
parameters += aSingleParameter + ", ";
}
@@ -46,21 +46,21 @@ class Client
public function delete()
{}
- public function someMethod(Integer arg)
+ public function someMethod($arg)
{
- $result = someMethodOriginal(Integer arg);
+ $result = someMethodOriginal($arg);
if ($this->arg<=5)
{
throw new RuntimeException("Please provide a valid arg");
}
return $result;
}
- public function someMethodOriginal(Integer arg)
+ public function someMethodOriginal($arg)
{
// rest of stuff that we don't interpret
return 0;
}
}
-?>
+?>
@@ -1,6 +1,6 @@
<?php
/*PLEASE DO NOT EDIT THIS CODE*/
-/*This code was generated using the UMPLE 1.16.0.2388 modeling language!*/
+/*This code was generated using the UMPLE @UMPLE_VERSION@ modeling language!*/
class Client
{
@@ -46,7 +46,7 @@ class Client
public function delete()
{}
- public function someMethod(Integer arg)
+ public function someMethod($arg)
{
if ($this->arg<=5)
@@ -62,4 +62,4 @@ class Client
}
}
-?>
+?>
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo with argument: " + a);
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo with argument: " + a);
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo with argument: " + a);
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo...");
@@ -40,7 +40,7 @@ class Student
return 3;
}
- public function foo(int a, String b)
+ public function foo(int $a, $b)
{
System.out.println("Starting foo...");
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo...");
@@ -41,7 +41,7 @@ class Student
}
- public function foo(int a, String b)
+ public function foo(int $a, $b)
{
System.out.println("Starting foo...");
@@ -28,7 +28,7 @@ class Student
public function delete()
{}
- public function foo(int a)
+ public function foo(int $a)
{
System.out.println("Starting foo with argument: " + a);
@@ -1,42 +1,42 @@
-<?php
-/*PLEASE DO NOT EDIT THIS CODE*/
-/*This code was generated using the UMPLE @UMPLE_VERSION@ modeling language!*/
-
-class Something implements ISomething
-{
-
- //------------------------
- // MEMBER VARIABLES
- //------------------------
-
- //------------------------
- // CONSTRUCTOR
- //------------------------
-
- public function __construct()
- {}
-
- //------------------------
- // INTERFACE
- //------------------------
-
- public function equals($compareTo)
- {
- return $this == $compareTo;
- }
-
- public function delete()
- {}
-
- public function getCode(String [] aParam, Integer anotherParam)
- {
- return "";
- }
-
- public function isValid()
- {
- return "";
- }
-
-}
-?>
+<?php
+/*PLEASE DO NOT EDIT THIS CODE*/
+/*This code was generated using the UMPLE @UMPLE_VERSION@ modeling language!*/
+
+class Something implements ISomething
+{
+
+ //------------------------
+ // MEMBER VARIABLES
+ //------------------------
+
+ //------------------------
+ // CONSTRUCTOR
+ //------------------------
+
+ public function __construct()
+ {}
+
+ //------------------------
+ // INTERFACE
+ //------------------------
+
+ public function equals($compareTo)
+ {
+ return $this == $compareTo;
+ }
+
+ public function delete()
+ {}
+
+ public function getCode($aParam, $anotherParam)
+ {
+ return "";
+ }
+
+ public function isValid()
+ {
+ return "";
+ }
+
+}
+?>
@@ -0,0 +1,72 @@
+<?php
+/*PLEASE DO NOT EDIT THIS CODE*/
+/*This code was generated using the UMPLE @UMPLE_VERSION@ modeling language!*/
+
+class Object
+{
+
+ //------------------------
+ // MEMBER VARIABLES
+ //------------------------
+
+ //------------------------
+ // CONSTRUCTOR
+ //------------------------
+
+ public function __construct()
+ {}
+
+ //------------------------
+ // INTERFACE
+ //------------------------
+
+ public function equals($compareTo)
+ {
+ return $this == $compareTo;
+ }
+
+ public function delete()
+ {}
+
+ public function example_obj(Object $g)
+ {
+ /*implementation*/
+ }
+
+ public function example_bool($b)
+ {
+
+ }
+
+ public function example_int($i)
+ {
+
+ }
+
+ public function example_float($f)
+ {
+
+ }
+
+ public function example_double($d)
+ {
+
+ }
+
+ public function example_string($s)
+ {
+
+ }
+
+ public function example_obj_array($gs)
+ {
+
+ }
+
+ public function example_primitive_array($is)
+ {
+
+ }
+
+}
+?>
@@ -0,0 +1,10 @@
+class Object {
+ void example_obj(Object g){/*implementation*/}
+ void example_bool(Boolean b) {}
+ void example_int(Integer i) {}
+ void example_float(Float f) {}
+ void example_double(Double d) {}
+ void example_string(String s) {}
+ void example_obj_array(Object[] gs){}
+ void example_primitive_array(Integer[] is){}
+}
@@ -57,7 +57,12 @@ public void abstractClass()
language = "Php";
assertUmpleTemplateFor("php/ClassTemplateTest_AbstractClass.ump","php/ClassTemplateTest_AbstractClass.php.txt", "Student");
}
-
+
+ @Test
+ public void MethodParameterTypes(){
+ assertUmpleTemplateFor("php/MethodParameterTypes.ump", "php/MethodParameterTypes.php.txt", "Object");
+ }
+
@Test
public void GeneratePathTest()
{

0 comments on commit 61a14ab

Please sign in to comment.