Skip to content
Permalink
Browse files

fix indent.

  • Loading branch information...
gublan24 committed Jul 4, 2019
1 parent 9bcf714 commit 3d3e23396f83f68834932f8c220b3ab45afafe15
@@ -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.
private void applyCodeInjectionToLabeledMethod(UmpleClass uClass, Method aMethod, String aspectType) {
List<CodeInjection> uClassCodeInectionList = uClass.getApplicableCodeInjectionsCustomMethod(aspectType, aMethod.getName(), aMethod.getMethodParameters());
if(uClassCodeInectionList.size() == 0 )
{
// no code to inject
// return;
}
CodeBlock methodCodeBlock = aMethod.getMethodBody().getCodeblock();
String codesKey_lang = ""; // the type of a language that the method belongs to
ArrayList<String> methodCodeWithLabels = methodCodeBlock.getCodeWithLabels(codesKey_lang);
ArrayList<Integer> indexToRemoveList = new ArrayList<Integer>();
for (CodeInjection codeInjectionItem: uClassCodeInectionList)
{
if(! codeInjectionItem.hasCodeLabel()) // we are concerning with only codeInjection item which has code labels.
continue;
//else
String methodLabelToLookat = codeInjectionItem.getInjectionlabel();
String codeToAdd = codeInjectionItem.getCode(codesKey_lang);
List<CodeInjection> uClassCodeInectionList = uClass.getApplicableCodeInjectionsCustomMethod(aspectType, aMethod.getName(), aMethod.getMethodParameters());
if(uClassCodeInectionList.size() == 0 )
{
// no code to inject
// return;
}
CodeBlock methodCodeBlock = aMethod.getMethodBody().getCodeblock();
String codesKey_lang = ""; // the type of a language that the method belongs to
ArrayList<String> methodCodeWithLabels = methodCodeBlock.getCodeWithLabels(codesKey_lang);
ArrayList<Integer> indexToRemoveList = new ArrayList<Integer>();
for (CodeInjection codeInjectionItem: uClassCodeInectionList)
{
if(! codeInjectionItem.hasCodeLabel()) // we are concerning with only codeInjection item which has code labels.
continue;
//else
String methodLabelToLookat = codeInjectionItem.getInjectionlabel();
String codeToAdd = codeInjectionItem.getCode(codesKey_lang);

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

public ArrayList<String> getCodeWithLabels(String codesKey) {
ArrayList <String> codeLabels = new ArrayList<String>();
String codeToLockAt = getCode(codesKey);
String codeToLockAt = getCode(codesKey);
ArrayList<String> codeWithLabels = new ArrayList<String>();
Pattern labelPatternToMatch = Pattern.compile("(\\S+):");
Matcher matcher = labelPatternToMatch.matcher(codeToLockAt);
@@ -366,7 +366,7 @@ class CodeBlock{
codeLabels.add(matcher.group().replaceFirst(":","")); // remove colon and add it the list of labels
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);
codeWithLabels.add(codeAfterLastLabel);
return codeWithLabels;
@@ -540,7 +540,7 @@ public void parseInlineMixsetInsideUmpleEntity()
=======
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);
umodel.run();
umodel.generate();
@@ -2,36 +2,34 @@ class InjectToLabel
{
firstName;
lastName;
public static void staticMethod( )
{
FirstLabel: System.out.println("this is line 1.");
System.out.println("this is line 2.");
SecondLabel: System.out.println("this is line 3");
}
before custom SecondLabel:staticMethod
{
//Start before SecondLabel.
public static void staticMethod( )
{
FirstLabel: System.out.println("this is line 1.");
System.out.println("this is line 2.");
SecondLabel: System.out.println("this is line 3");
}

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

}

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

}

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

}
}


0 comments on commit 3d3e233

Please sign in to comment.
You can’t perform that action at this time.