Skip to content

Commit

Permalink
Fixed #142 Empty line of the sample contents in the new wizard should…
Browse files Browse the repository at this point in the history
… not be indented.
  • Loading branch information
ylussaud committed Mar 6, 2024
1 parent 2767831 commit e0cb972
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.UUID;

import org.eclipse.acceleo.AcceleoPackage;
import org.eclipse.acceleo.Block;
Expand Down Expand Up @@ -241,8 +242,7 @@ private Block createTemplateBody(ModuleConfiguration configuration) {
fileBlock.setInlined(false);
final TextStatement fileText = AcceleoPackage.eINSTANCE.getAcceleoFactory()
.createTextStatement();
fileText.setValue(initialContent.replaceAll("\\r\\n|\\n", NEW_LINE + " ") + NEW_LINE
+ " ");
fileText.setValue(getTextStatementValue(initialContent));
fileBlock.getStatements().add(fileText);
fileStatement.setBody(fileBlock);
res.getStatements().add(fileStatement);
Expand All @@ -252,6 +252,26 @@ private Block createTemplateBody(ModuleConfiguration configuration) {
return res;
}

/**
* Gets the {@link TextStatement} value for the given initial content.
*
* @param initialContent
* the initial content
* @return the {@link TextStatement} value for the given initial content
*/
private String getTextStatementValue(final String initialContent) {
String res;

final String emptyLineReplacement = UUID.randomUUID().toString() + UUID.randomUUID().toString()
+ UUID.randomUUID().toString();

res = initialContent.replaceAll("(\\r\\n|\\n)(\\r\\n|\\n)", emptyLineReplacement);
res = res.replaceAll("(\\r\\n|\\n)", NEW_LINE + " ");
res = res.replace(emptyLineReplacement, NEW_LINE + NEW_LINE + " ");

return res + NEW_LINE + " ";
}

/**
* Creates the {@link ModuleElement}'s {@link Documentation}.
*
Expand Down

0 comments on commit e0cb972

Please sign in to comment.