hallvard / plantuml

Embed UML diagrams in files and view them in Eclipse
http://plantuml.sourceforge.net/
209 stars 57 forks source link

Syntax error on empty lines preceeded with a line comment #152

Closed thom-sch closed 2 years ago

thom-sch commented 2 years ago

A syntax error occurs on creating diagrams using line comments:

// @startuml test // component test1 // // @enduml

Screenshot grafik

Note that there is no additional space character behind the line comment '//' : adding a space char the error disappears!

Playing around with the plantuml plugin I've found the reason in class TextDiagramIntentHelper.java / line 99

After removing prefix and line ending in this case pos1 == pos2 and in line 99

result.append(line, pos1,pos2);`

causes an error thrown by line.append()

Checking this situation

if ( pos1 < pos2 ) result.append(line, pos1,pos2);`

the exception is not thrown and al is fine. As a workaround I've replaced TextDiagramIntentHelper.class by the (corrected) TextDiagramIntentHelper.java; this will resolve this issue - but now Eclipse reports some errors...

I'm not very familar with JAVA and especially don't know how to compile java files into class files; so it would be nice if this issue would be solved by someone else.. :)

Regards from Meerbusch Thomas

hallvard commented 2 years ago

What do you see in the PlantUML source view? In the dev. versjon I see

@startuml test
component test1
//
@enduml

This is due to the "empty" line doesn't start with the common line prefix, since it lacks the final space, and is removed in the output. Instead the whole line is included, which results in a line that isn't syntactically correct.

This also means I don't see any exception, did you actually see it in the Error log or was it your "guess" (don't mean to be rude).

I can imagine this can be a problem for others, so I can test specially for the case where a line the linePrefix sans trailing blanks. and can be totally removed. What do you think?

thom-sch commented 2 years ago

Indeed I also see this syntactically wrong PlantUML-code in the source window.

thom-sch commented 2 years ago

As mentioned in my first post, it seems that the error was thrown by module TextDiagramIntentHelper.java in line 99: which is result.append(line, pos1, pos2);

In case of a line consisting only of line-comment chars, calulating pos2 in line 98 results in pos1 == pos2; I'm not very familar with Java and so I havn't tested tis code snippet but only analysed it (can I found the errorlog somewhre to verify my guess?).

As mentioned in my post, too, I've changed line 99 to if ( pos1 < pos2 ) result.append(line, pos1, pos2); and the error disappears. Since I'm not able to build the whole plugin, I've simply replaced TextDiagramIntentHelper.class with TextDiagramIntentHelper.java; this naiv work-around does the job.

(Though Eclipse itself reports some errors on loading, but seems to have no effect for the plugin itself.)

Regards from Meerbusch Thomas

thom-sch commented 2 years ago

Hello hallvard,

beg your pardon - my naiv solution is completly wrong! On testing it indeed I saw the correct image - but obviously it was the (correct) version from a previous attempt. Since my solution hasn't worked, the previous (correct) image was taken from the cache - and erroneously I assumed that all is fine... :(

So I agree with your solution to check for the line prefix without trailing space; however I'd prefer not to delete the line completly but replace it with an empty line to preserve the programmers's intended code structure.

Little contrite about my error... best regards from Meerbusch Thomas

hallvard commented 2 years ago

With the solution I have now, there will be an empty line.