Skip to content

Commit

Permalink
Fixed the injection of multiple methods at once.
Browse files Browse the repository at this point in the history
The issue was that the StringBuilder token wasn't properly used by Umple's Internal Parser. It had the target methods in separate tokens, which a StringBuilder was intended to fix. Passing the StringBuilder's result into makeCodeInjection() fixed the issue.

Fixes umple#680

Signed-off-by: Victoria Lacroix <victoria.a.lacroix@gmail.com>
  • Loading branch information
vtrlx committed Jan 26, 2016
1 parent 942b549 commit 66d9b5e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cruise.umple/src/UmpleInternalParser_CodeClass.ump
Expand Up @@ -2556,10 +2556,10 @@ class UmpleInternalParser
return value;
}

//TODO I changed the parameter's type. please remove this comment;
//TODO I changed the parameter's type. please remove this comment;
private void analyzeInjectionCode(Token injectToken, UmpleClassifier uClassifier)
{
String type = injectToken.is("beforeCode") ? "before" : "after";
String type = injectToken.is("beforeCode") ? "before" : "after";
CodeBlock cb = new CodeBlock();
StringBuilder operationName = new StringBuilder();
String comma = "";
Expand All @@ -2571,15 +2571,15 @@ class UmpleInternalParser
comma = ",";
}
}
CodeInjection injection = new CodeInjection(type,injectToken.getValue("operationName"),"",uClassifier);
CodeInjection injection = new CodeInjection(type,operationName.toString(),"",uClassifier);
makeCodeInject(injectToken,injection,cb,uClassifier);
injection.setSnippet(cb);
if (uClassifier instanceof UmpleClass) {
checkCodeInjectionValidity(injectToken, operationName.toString(), uClassifier);
((UmpleClass)uClassifier).addCodeInjection(injection);
((UmpleClass)uClassifier).addCodeInjection(injection);
} else if (uClassifier instanceof UmpleTrait){
((UmpleTrait)uClassifier).addCodeInjection(injection);
}
((UmpleTrait)uClassifier).addCodeInjection(injection);
}
}

private boolean checkCodeInjectionValidity(Token injectToken, String operationName, UmpleClassifier uClassifier) {
Expand Down
@@ -0,0 +1,15 @@
class A{
Integer x;
Integer y;
after setX,setY {
//this code will be injected
}
}

class B{
Integer x;
Integer y;
before setX,setY {
//this code will be injected
}
}
22 changes: 22 additions & 0 deletions cruise.umple/test/cruise/umple/compiler/UmpleParserTest.java
Expand Up @@ -2066,6 +2066,28 @@ public void afterKeyword()
Assert.assertEquals("notReallyPossible();",inject.getCode());
}

@Test
public void multiInject()
{
assertSimpleParse("680_injectMultipleMethods.ump");

UmpleClass a = model.getUmpleClass("A");
Assert.assertEquals(1,a.numberOfCodeInjections());

CodeInjection aInject = a.getCodeInjection(0);
Assert.assertEquals("after",aInject.getType());
Assert.assertEquals("setX,setY", aInject.getOperation());
Assert.assertEquals("//this code will be injected",aInject.getCode());

UmpleClass b = model.getUmpleClass("B");
Assert.assertEquals(1,b.numberOfCodeInjections());

CodeInjection bInject = b.getCodeInjection(0);
Assert.assertEquals("before",bInject.getType());
Assert.assertEquals("setX,setY",bInject.getOperation());
Assert.assertEquals("//this code will be injected",bInject.getCode());
}

@Test
public void upperCaseAssociationKey()
{
Expand Down

0 comments on commit 66d9b5e

Please sign in to comment.