Skip to content

Commit

Permalink
fix indent.
Browse files Browse the repository at this point in the history
  • Loading branch information
gublan24 committed Jul 4, 2019
1 parent 9bcf714 commit 3d3e233
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 78 deletions.
100 changes: 48 additions & 52 deletions UmpleToJava/UmpleTLTemplates/JavaClassGenerator.ump
Expand Up @@ -219,59 +219,55 @@ for (StateMachine smq : uClass.getStateMachines())


// This method allows the injection of some code before/after a code label inside a method of an umple class. // This method allows the injection of some code before/after a code label inside a method of an umple class.
private void applyCodeInjectionToLabeledMethod(UmpleClass uClass, Method aMethod, String aspectType) { private void applyCodeInjectionToLabeledMethod(UmpleClass uClass, Method aMethod, String aspectType) {
List<CodeInjection> uClassCodeInectionList = uClass.getApplicableCodeInjectionsCustomMethod(aspectType, aMethod.getName(), aMethod.getMethodParameters()); List<CodeInjection> uClassCodeInectionList = uClass.getApplicableCodeInjectionsCustomMethod(aspectType, aMethod.getName(), aMethod.getMethodParameters());
if(uClassCodeInectionList.size() == 0 ) if(uClassCodeInectionList.size() == 0 )
{ {
// no code to inject // no code to inject
// return; // return;
} }
CodeBlock methodCodeBlock = aMethod.getMethodBody().getCodeblock(); CodeBlock methodCodeBlock = aMethod.getMethodBody().getCodeblock();
String codesKey_lang = ""; // the type of a language that the method belongs to String codesKey_lang = ""; // the type of a language that the method belongs to
ArrayList<String> methodCodeWithLabels = methodCodeBlock.getCodeWithLabels(codesKey_lang); ArrayList<String> methodCodeWithLabels = methodCodeBlock.getCodeWithLabels(codesKey_lang);
ArrayList<Integer> indexToRemoveList = new ArrayList<Integer>(); ArrayList<Integer> indexToRemoveList = new ArrayList<Integer>();
for (CodeInjection codeInjectionItem: uClassCodeInectionList) for (CodeInjection codeInjectionItem: uClassCodeInectionList)
{ {
if(! codeInjectionItem.hasCodeLabel()) // we are concerning with only codeInjection item which has code labels. if(! codeInjectionItem.hasCodeLabel()) // we are concerning with only codeInjection item which has code labels.
continue; continue;
//else //else
String methodLabelToLookat = codeInjectionItem.getInjectionlabel(); String methodLabelToLookat = codeInjectionItem.getInjectionlabel();
String codeToAdd = codeInjectionItem.getCode(codesKey_lang); String codeToAdd = codeInjectionItem.getCode(codesKey_lang);


int indexOfLabel = methodCodeWithLabels.indexOf(methodLabelToLookat); int indexOfLabel = methodCodeWithLabels.indexOf(methodLabelToLookat);
if (indexOfLabel == -1) // the method does not contain the required label if (indexOfLabel == -1) // the method does not contain the required label
{ {
// raise error // raise error
// raise warning // raise warning
} }
else if (codeInjectionItem.getType().equals("before")) else if (codeInjectionItem.getType().equals("before"))
{ {
methodCodeWithLabels.add(indexOfLabel, "\n"+codeToAdd + "\n"); methodCodeWithLabels.add(indexOfLabel, "\n"+codeToAdd + "\n");
} }
else if (codeInjectionItem.getType().equals("after")) else if (codeInjectionItem.getType().equals("after"))
{ {
if(indexOfLabel < methodCodeWithLabels.size()) if(indexOfLabel < methodCodeWithLabels.size())
methodCodeWithLabels.add(indexOfLabel+1, "\n"+codeToAdd + "\n"); methodCodeWithLabels.add(indexOfLabel+1, "\n"+codeToAdd + "\n");
else else
methodCodeWithLabels.add("\n"+codeToAdd + "\n"); methodCodeWithLabels.add("\n"+codeToAdd + "\n");
} }
// at the end, remove the codeInjection belongs to labeled aspect // at the end, remove the codeInjection belongs to labeled aspect
// otherwise it will be added to the code when handling aspects // otherwise it will be added to the code when handling aspects
//uClassCodeInectionList.remove(codeInjectionItem); // causes error:ConcurrentModificationException //uClassCodeInectionList.remove(codeInjectionItem); // causes error:ConcurrentModificationException
indexToRemoveList.add(uClassCodeInectionList.indexOf(codeInjectionItem)); //indexToRemoveList.add(uClassCodeInectionList.indexOf(codeInjectionItem));
// update the method code with addition // update the method code with addition
String resultCode=""; String resultCode="";
for (String stringItem : methodCodeWithLabels) for (String stringItem : methodCodeWithLabels)
{ {
resultCode += stringItem ; resultCode += stringItem ;
} }
aMethod.getMethodBody().getCodeblock().setCode(codesKey_lang, resultCode); aMethod.getMethodBody().getCodeblock().setCode(codesKey_lang, resultCode);
} }
for(int codeInjectionItemIndex:indexToRemoveList) }
{
uClassCodeInectionList.remove(codeInjectionItemIndex);
}
}
/* /*
* Issue 1008 - A helper function to determine if a class uses an enum defined in the model * Issue 1008 - A helper function to determine if a class uses an enum defined in the model
*/ */
Expand Down
2 changes: 1 addition & 1 deletion UmpleToJava/UmpleTLTemplates/class_MethodDeclaration.ump
Expand Up @@ -85,7 +85,7 @@ class UmpleToJava {
if(!aMethod.getLabelsProcessed()) if(!aMethod.getLabelsProcessed())
{ {
applyCodeInjectionToLabeledMethod(uClass, aMethod, "before"); applyCodeInjectionToLabeledMethod(uClass, aMethod, "before");
applyCodeInjectionToLabeledMethod(uClass, aMethod, "after"); applyCodeInjectionToLabeledMethod(uClass, aMethod, "after");
aMethod.setLabelsProcessed(true); aMethod.setLabelsProcessed(true);
} }
String customBeforeInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("before", aMethod.getName(), aMethod.getMethodParameters())); String customBeforeInjectionCode = GeneratorHelper.toCode(uClass.getApplicableCodeInjectionsCustomMethod("before", aMethod.getName(), aMethod.getMethodParameters()));
Expand Down
4 changes: 2 additions & 2 deletions cruise.umple/src/UmpleInternalParser_CodeMixset.ump
Expand Up @@ -353,7 +353,7 @@ class CodeBlock{


public ArrayList<String> getCodeWithLabels(String codesKey) { public ArrayList<String> getCodeWithLabels(String codesKey) {
ArrayList <String> codeLabels = new ArrayList<String>(); ArrayList <String> codeLabels = new ArrayList<String>();
String codeToLockAt = getCode(codesKey); String codeToLockAt = getCode(codesKey);
ArrayList<String> codeWithLabels = new ArrayList<String>(); ArrayList<String> codeWithLabels = new ArrayList<String>();
Pattern labelPatternToMatch = Pattern.compile("(\\S+):"); Pattern labelPatternToMatch = Pattern.compile("(\\S+):");
Matcher matcher = labelPatternToMatch.matcher(codeToLockAt); Matcher matcher = labelPatternToMatch.matcher(codeToLockAt);
Expand All @@ -366,7 +366,7 @@ class CodeBlock{
codeLabels.add(matcher.group().replaceFirst(":","")); // remove colon and add it the list of labels codeLabels.add(matcher.group().replaceFirst(":","")); // remove colon and add it the list of labels
lastMatchedIndex = matcher.end(); lastMatchedIndex = matcher.end();
} }
// This for last label, to add the code after last matched label // This for last label, to add the code after last matched label
String codeAfterLastLabel =codeToLockAt.substring(lastMatchedIndex); String codeAfterLastLabel =codeToLockAt.substring(lastMatchedIndex);
codeWithLabels.add(codeAfterLastLabel); codeWithLabels.add(codeAfterLastLabel);
return codeWithLabels; return codeWithLabels;
Expand Down
Expand Up @@ -540,7 +540,7 @@ public void parseInlineMixsetInsideUmpleEntity()
======= =======
public void parseLabelsInsideMethod() public void parseLabelsInsideMethod()
{ {
UmpleFile umpleFile =new UmpleFile(umpleParserTest.pathToInput,"parseLabelsInsideMethod_basic"); UmpleFile umpleFile =new UmpleFile(umpleParserTest.pathToInput,"parseLabelsInsideMethod_basic.ump");
UmpleModel umodel = new UmpleModel(umpleFile); UmpleModel umodel = new UmpleModel(umpleFile);
umodel.run(); umodel.run();
umodel.generate(); umodel.generate();
Expand Down
Expand Up @@ -2,36 +2,34 @@ class InjectToLabel
{ {
firstName; firstName;
lastName; lastName;
public static void staticMethod( ) public static void staticMethod( )
{ {
FirstLabel: System.out.println("this is line 1."); FirstLabel: System.out.println("this is line 1.");
System.out.println("this is line 2."); System.out.println("this is line 2.");
SecondLabel: System.out.println("this is line 3"); SecondLabel: System.out.println("this is line 3");
} }

before custom SecondLabel:staticMethod before custom SecondLabel:staticMethod
{ {
//Start before SecondLabel. //Start before SecondLabel.
System.out.println("code added before the SecondLabel in staticMethod()."); System.out.println("code added before the SecondLabel in staticMethod().");
//End before SecondLabel. //End before SecondLabel.

} }


void main(String[] arg) void main(String[] arg)
{ {

} }


public void objectMethod() public void objectMethod()
{ {
} }
after custom SecondLabel:staticMethod after custom SecondLabel:staticMethod
{ {
//Start after SecondLabel. //Start after SecondLabel.
System.out.println("code added after the SecondLabel in staticMethod()."); System.out.println("code added after the SecondLabel in staticMethod().");
//End after SecondLabel. //End after SecondLabel.
} }

} }




0 comments on commit 3d3e233

Please sign in to comment.