Permalink
Browse files

Adds before/after code injection to get methods for subclasses

  • Loading branch information...
ZainabAlShowely committed Jun 25, 2018
1 parent 49cd2c9 commit 8d5e5256fff1e783cac49a482ab40b5f780a26d7
@@ -0,0 +1,15 @@
class UmpleToJava {
attribute_GetDefaultedSubclass <<! /* Code from template attribute_GetDefaultedSubclass */
<</*attribute_GetDefaultedSubclass*/>> public <<=gen.translate("type",av)>> <<=gen.translate("getDefaultMethod",av)>>()
{
<<# if (customGetDefaultPrefixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPrefixCode,gen.translate("getDefaultMethod",av));
append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetDefaultPrefixCode, " ")); } #>>
<<=gen.translate("type",av)>> <<=gen.translate("parameterOne",av)>> = super.<<= gen.translate("getMethod",av) >>();
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null?traceItem.trace(gen, av,"at_g", uClass):"")>>
<<# if (customGetDefaultPostfixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetDefaultPostfixCode,gen.translate("getDefaultMethod",av));
append(realSb, "{0}\n",GeneratorHelper.doIndent(customGetDefaultPostfixCode, " ")); } #>> return <<= gen.translate("parameterValue",av) >>;
}
!>>
}
@@ -0,0 +1,15 @@
class UmpleToJava {
attribute_GetDerivedSubclass <<! /* Code from template attribute_GetDerivedSubclass */<</*attribute_GetDerivedSubclass*/>><<# if (av.numberOfComments() > 0) { append(realSb, "\n {0}\n", Comment.format("Attribute Javadoc", av.getComments())); } #>><<= umpleSourceFile >>
public <<=gen.translate("type",av)>> <<= gen.translate("getMethod",av) >>()
{
<<# if (customGetPrefixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPrefixCode,gen.translate("getMethod",av));
append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
<<= gen.translate("type",av) >> <<= gen.translate("parameterOne",av) >> = super.<<= gen.translate("getMethod",av) >>();
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null?traceItem.trace(gen, av,"at_g", uClass):"")>>
<<# if (customGetPostfixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPostfixCode,gen.translate("getMethod",av));
append(realSb, "{0}\n",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>> return <<= gen.translate("parameterOne",av) >>;<<#addUncaughtExceptionVariables(gen.translate("getMethod",av),av.getPosition().getFilename(),av.getPosition().getLineNumber(),realSb.toString().split("\\n").length-1,1);#>>
}
!>>
}
@@ -0,0 +1,15 @@
class UmpleToJava {
attribute_GetManySubclass <<! /* Code from template attribute_GetManySubclass */
<</*attribute_GetManySubclass*/>> public <<=gen.translate("typeMany",av)>> <<=gen.translate("getMethod",av)>>(int index)
{
<<# if (customGetPrefixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPrefixCode,gen.translate("getMethod",av));
append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
<<= gen.translate("typeMany",av)>> <<=gen.translate("parameterOne",av)>> = super.<<=gen.translate("getMethod",av)>>(index);
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null?traceItem.trace(gen, av,"at_g", uClass):"")>>
<<# if (customGetPostfixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPostfixCode,gen.translate("getMethod",av));
append(realSb, "{0}\n",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>> return <<=gen.translate("parameterOne",av)>>;
}
!>>
}
@@ -0,0 +1,13 @@
class UmpleToJava {
attribute_GetSubclass <<!<</*attribute_GetSubclass*/>><<# if (av.numberOfComments() > 0) { append(realSb, "\n {0}", Comment.format("Attribute Javadoc", av.getComments())); } #>><<= umpleSourceFile >>
public <<=gen.translate("type",av)>> <<= gen.translate("getMethod",av) >>()
{
<<# if (customGetPrefixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPrefixCode,gen.translate("getMethod",av));
append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
<<= gen.translate("type",av) >> <<= gen.translate("parameterOne",av) >> = super.<<= gen.translate("getMethod",av) >>();
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null?traceItem.trace(gen, av,"at_g", uClass):"")>><<#
if (customGetPostfixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetPostfixCode,gen.translate("getMethod",av));
append(realSb, "{0}\n",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>>
return <<= gen.translate("parameterOne",av) >>;
}!>>
}
@@ -0,0 +1,15 @@
class UmpleToJava {
attribute_GetUniqueSubclass <<! /* Code from template attribute_GetUniqueSubclass */
<</*attribute_GetUniqueCodeInjection*/>> public static <<=av.getUmpleClass().getName()>> <<=gen.translate("getUniqueMethod",av)>>(<<=gen.translate("type", av)>> <<=gen.translate("parameterOne", av)>>)
{
<<# if (customGetUniquePrefixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetUniquePrefixCode,gen.translate("getUniqueMethod",av));
append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetUniquePrefixCode, " ")); } #>>
<<=av.getUmpleClass().getName()>> <<=gen.translate("parameterGetUnique",av)>> = super.<<=gen.translate("getUniqueMethod",av)>>(<<=gen.translate("type", av)>> <<=gen.translate("parameterOne", av)>>);
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null?traceItem.trace(gen, av,"at_g", uClass):"")>>
<<# if (customGetUniquePostfixCode != null) { addUncaughtExceptionVariables(realSb.toString().split("\\n").length,customGetUniquePostfixCode,gen.translate("getUniqueMethod",av));
append(realSb, "{0}\n",GeneratorHelper.doIndent(customGetUniquePostfixCode, " ")); } #>> return <<=gen.translate("parameterGetUnique",av)>>;
}
!>>
}
@@ -2,15 +2,19 @@ use attribute_Get.ump;
use attribute_GetCodeInjection.ump;
use attribute_GetDefaulted.ump;
use attribute_GetDefaultedCodeInjection.ump;
use attribute_GetDefaultedSubclass.ump;
use attribute_GetDerived.ump;
use attribute_GetDerivedCodeInjection.ump;
use attribute_GetDerivedSubclass.ump;
use attribute_GetMany.ump;
use attribute_GetManySubclass.ump;
use attribute_GetUnique.ump;
use attribute_GetUniqueCodeInjection.ump;
use attribute_GetUniqueSubclass.ump;
use attribute_GetSubclass.ump;
use attribute_HasUnique.ump;
use attribute_HasUniqueCodeInjection.ump;
class UmpleToJava {
attribute_Get_All <<!<</*attribute_Get_All*/>><<#
// GENERIC FILE - EDIT IN UmpleToTemplate project, then run "ant -f build.codegen.xml to move into the appropriate projects
@@ -127,6 +131,59 @@ class UmpleToJava {
appendln(realSb, "");
}
}
if(uClass.getExtendsClass()!=null)
{
for(Attribute av:uClass.getExtendsClass().getAttributes())
{
if (av.isConstant())
{
continue;
}
List<TraceItem> traceItems = av.getTraced("getMethod", uClass);
gen.setParameterConstraintName(av.getName());
String customGetPrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getMethod",av)));
String customGetPostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getMethod",av)));
String customGetDefaultPrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getDefaultMethod",av)));
String customGetDefaultPostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getDefaultMethod",av)));
String customGetManyPrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getManyMethod",av)));
String customGetManyPostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getManyMethod",av)));
String customGetUniquePrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getUniqueMethod",av)));
String customGetUniquePostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getUniqueMethod",av)));
if (customGetDefaultPrefixCode!=null || customGetDefaultPostfixCode!=null)
{
#>><<@ UmpleToJava.attribute_GetDefaultedSubclass >><<#
}
else if (customGetManyPrefixCode!=null || customGetManyPostfixCode!=null)
{
#>><<@ UmpleToJava.attribute_GetManySubclass >><<#
}
else if (customGetUniquePrefixCode!=null || customGetUniquePostfixCode!=null)
{
#>><<@ UmpleToJava.attribute_GetUniqueSubclass >><<#
}
else if(customGetPrefixCode!=null||customGetPostfixCode!=null)
{
if (av.getIsDerived())
{
#>><<@ UmpleToJava.attribute_GetDerivedSubclass >><<#
}
else
{
#>><<@ UmpleToJava.attribute_GetSubclass >><<#
}
}
}
}
gen.setParameterConstraintName("");
#>>!>>
}
@@ -0,0 +1,11 @@
class UmpleToPhp {
attribute_GetManySubclass <<!<</*attribute_GetManySubclass*/>>
public function <<=gen.translate("getMethod",av)>>($index)
{
<<# if (customGetPrefixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
$<<=gen.translate("parameterOne",av)>> = parent::<<=gen.translate("getMethod",av)>>($index);
<<# if (customGetPostfixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>>
return $<<=gen.translate("parameterOne",av)>>;
}
!>>
}
@@ -0,0 +1,11 @@
class UmpleToPhp {
attribute_GetSubclass <<!<</*attribute_GetSubclass*/>>
public function <<=gen.translate("getMethod",av)>>()
{
<<# if (customGetPrefixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
$<<= gen.translate("parameterOne",av) >> = parent::<<=gen.translate("getMethod",av)>>();
<<# if (customGetPostfixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>>
return $<<= gen.translate("parameterOne",av) >>;
}
!>>
}
@@ -5,10 +5,14 @@ use attribute_GetDefaultedCodeInjection.ump;
use attribute_GetDerived.ump;
use attribute_GetDerivedCodeInjection.ump;
use attribute_GetMany.ump;
use attribute_GetManySubclass.ump;
use attribute_GetUnique.ump;
use attribute_GetUniqueCodeInjection.ump;
use attribute_HasUnique.ump;
use attribute_HasUniqueCodeInjection.ump;
use attribute_GetSubclass.ump;
class UmpleToPhp {
@@ -127,6 +131,37 @@ class UmpleToPhp {
appendln(realSb, "");
}
}
if(uClass.getExtendsClass()!=null)
{
for(Attribute av:uClass.getExtendsClass().getAttributes())
{
if (av.isConstant())
{
continue;
}
List<TraceItem> traceItems = av.getTraced("getMethod", uClass);
gen.setParameterConstraintName(av.getName());
String customGetPrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getMethod",av)));
String customGetPostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getMethod",av)));
String customGetManyPrefixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("before", gen.translate("getManyMethod",av)));
String customGetManyPostfixCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjections("after", gen.translate("getManyMethod",av)));
if (customGetManyPrefixCode!=null || customGetManyPostfixCode!=null)
{
#>><<@ UmpleToPhp.attribute_GetManySubclass >><<#
}
else if(customGetPrefixCode!=null||customGetPostfixCode!=null)
{
#>><<@ UmpleToPhp.attribute_GetSubclass >><<#
}
}
}
gen.setParameterConstraintName("");
#>>!>>
}
@@ -0,0 +1,10 @@
class UmpleToRuby {
attribute_GetManySubclass <<!
def <<=gen.translate("getMethod",av)>>(index)
<<# if (customGetPrefixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
<<=gen.translate("parameterOne",av)>> = super(index)
<<# if (customGetPostfixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>>
<<=gen.translate("parameterOne",av)>>
end
!>>
}
@@ -0,0 +1,10 @@
class UmpleToRuby {
attribute_GetSubclass <<!
def <<= gen.translate("getMethod",av) >>
<<# if (customGetPrefixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPrefixCode, " ")); } #>>
<<= gen.translate("parameterOne",av) >> = super
<<# if (customGetPostfixCode != null) { append(realSb, "\n{0}",GeneratorHelper.doIndent(customGetPostfixCode, " ")); } #>>
<<= gen.translate("parameterOne",av) >>
end
!>>
}
@@ -5,10 +5,12 @@ use attribute_GetDefaultedCodeInjection.ump;
use attribute_GetDerived.ump;
use attribute_GetDerivedCodeInjection.ump;
use attribute_GetMany.ump;
use attribute_GetManySubclass.ump;
use attribute_GetUnique.ump;
use attribute_GetUniqueCodeInjection.ump;
use attribute_HasUnique.ump;
use attribute_HasUniqueCodeInjection.ump;
use attribute_GetSubclass.ump;
class UmpleToRuby {
@@ -127,6 +129,37 @@ class UmpleToRuby {
appendln(realSb, "");
}
}
if(uClass.getExtendsClass()!=null)
{
for(Attribute av:uClass.getExtendsClass().getAttributes())
{
if (av.isConstant())
{
continue;
}
List<TraceItem> traceItems = av.getTraced("getMethod", uClass.getExtendsClass());
gen.setParameterConstraintName(av.getName());
String customGetPrefixCode = GeneratorHelper.toCode(gen.getApplicableCodeInjections(uClass, "before", "getMethod", av));
String customGetPostfixCode = GeneratorHelper.toCode(gen.getApplicableCodeInjections(uClass, "after", "getMethod", av));
String customGetManyPrefixCode = GeneratorHelper.toCode(gen.getApplicableCodeInjections(uClass, "before", "getManyMethod", av));
String customGetManyPostfixCode = GeneratorHelper.toCode(gen.getApplicableCodeInjections(uClass, "after", "getManyMethod", av));
if (customGetManyPrefixCode!=null || customGetManyPostfixCode!=null)
{
#>><<@ UmpleToRuby.attribute_GetManySubclass >><<#
}
else if(customGetPrefixCode!=null||customGetPostfixCode!=null)
{
#>><<@ UmpleToRuby.attribute_GetSubclass >><<#
}
}
}
gen.setParameterConstraintName("");
#>>!>>
}
@@ -5,11 +5,12 @@ class UmpleToRuby {
<<# if (customAddPrefixCode != null) {
append(realSb, "\n{0}",GeneratorHelper.doIndent(customAddPrefixCode, " ")); } #>>
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null&&traceItem.getIsPre()?traceItem.trace(gen, av,"at_a", uClass,gen.translate("parameterOne",av)):"")>>
was_added = super
was_added = super
<<# for( TraceItem traceItem : traceItems ) #>><<= (traceItem!=null&&traceItem.getIsPost()?traceItem.trace(gen, av,"at_a", uClass):"")>>
<<# if (customAddPostfixCode != null) {
append(realSb, "{0}\n",GeneratorHelper.doIndent(customAddPostfixCode, " "));
} #>>
was_added
end!>>
end
!>>
}
@@ -38,4 +38,17 @@ public void StateMachines()
assertUmpleTemplateFor("CodeInjectionStateMachineTest.ump",languagePath + "/CodeInjectionStateMachineTest."+ languagePath +".txt","Example");
}
@Test
public void SubclassInjection()
{
if (languagePath == "ruby")
{
assertUmpleTemplateFor("RubyCodeInjectionTestSubclass.ump",languagePath + "/CodeInjectionTestSubclass."+ languagePath +".txt","Example");
}
else
{
assertUmpleTemplateFor("CodeInjectionTestSubclass.ump",languagePath + "/CodeInjectionTestSubclass."+ languagePath +".txt","Example");
}
}
}
@@ -0,0 +1,21 @@
class Mentor
{
attr;
Integer derivedAttr = {1 + 1}
String[] listAttr;
defaulted defaultedAttr = "value";
}
class Example
{
isA Mentor;
before getAttr {/*before getAttr*/}
before getDerivedAttr {/*before getDerivedAttr*/}
before getListAttr {/*before getListAttr*/}
before getDefaultedAttr {/*before getDefaultedAttr*/}
after getAttr {/*after getAttr*/}
after getDerivedAttr {/*after getDerivedAttr*/}
after getListAttr {/*after getListAttr*/}
after getDefaultedAttr {/*after getDefaultedAttr*/}
}
@@ -0,0 +1,21 @@
class Mentor
{
attr;
Integer derivedAttr = {1 + 1}
String[] listAttr;
defaulted defaultedAttr = "value";
}
class Example
{
isA Mentor;
before getAttr {#before getAttr}
before getDerivedAttr {#before getDerivedAttr}
before getListAttr {#before getListAttr}
before getDefaultedAttr {#before getDefaultedAttr}
after getAttr {#after getAttr}
after getDerivedAttr {#after getDerivedAttr}
after getListAttr {#after getListAttr}
after getDefaultedAttr {#after getDefaultedAttr}
}
Oops, something went wrong.

0 comments on commit 8d5e525

Please sign in to comment.