google-code-export / umple

Automatically exported from code.google.com/p/umple
1 stars 0 forks source link

Multi-line code injections are not correctly indented #350

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write some code with multi-line code injection functions (before/after 
statements).
{{{
class A {}

class B
{
  0..1 --  0..1 A buddy;
  after setBuddy
  {
    print("hello");
    print("line two");
  }
}
}}}
2. Umplify the code and look at the Java/PHP/whatever results.

What is the expected output? What do you see instead?
At line 121-122 I see that the second line is not indented correctly. Since it 
is in an if statement, it should have 6 spaces of indentation rather than 4.

The problem is located within many different jet templates, which only indent 
the code correctly on the first line.
For example in association_SetMNToOptionalOne.jet line 36:
{{{    append(stringBuffer, "\n          {0}",customSetManyPostfixCode); }}}
customSetManyPostfixCode is potentially a multi-line string, but this static 
way of doing indentation will only apply to the first line.

The 4 space indentation for the following lines is done in the GeneratorHelper 
getCode function (by memory, will update if incorrect). 4 spaces cannot always 
be assumed since some of the code is contained within if statements or other 
further indented elements.

Suggested fix:
Instead of statically adding the indentation to the first line as is being 
done, scan through the string and add the correct amount of indentation after 
each newline. Perhaps the default 4 space indentation should be removed from 
the getCode function, or the spaces should be added relative to this amount. 
(There seems to be no cases where less than 4 spaces will be required).

Original issue reported on code.google.com by andrew.p...@gmail.com on 5 Nov 2012 at 7:36

Attachments:

GoogleCodeExporter commented 9 years ago
First step in fixing this, now indentation is applied to all lines of code 
injections. This allows // line comments to be added, allowing me to continue 
my work on issue 231.

However, pre-exisiting indentation not on the first line will still cause the 
indentation to be incorrect, which is less than ideal. Will look into fixing 
this.

A test should also be added.

Original comment by andrew.p...@gmail.com on 8 Nov 2012 at 11:51

Attachments:

GoogleCodeExporter commented 9 years ago
Here is a *hopefully* complete patch for this partial fix.

Original comment by andrew.p...@gmail.com on 16 Nov 2012 at 5:04

Attachments:

GoogleCodeExporter commented 9 years ago
Added and fixed by Andrew Paugh

Original comment by TimothyCLethbridge on 11 Dec 2012 at 1:06