2

I'm using the OpenJML plugin for my project, but Eclipse auto formatting messes with my JML code. JML is written after a //@ symbol.

//@ requires password != null;
//@ ensures !isActive() && getPassword().testWord(password) ? isActive() && \result : isActive() == \old(isActive()) && !\result;

Eclipse auto formatting, however, adds a space in between of the // and the @ symbols, rendering my JML code useless.

// @ requires password != null;
// @ ensures !isActive() && getPassword().testWord(password) ? isActive() && \result : isActive() == \old(isActive()) && !\result;

Is there a way in which I can disable adding a space between // and @ symbols, or otherwise a way in which I can disable spacing after comments altogether?

I've tried changing the formatter profile, but I couldn't find the setting there.

I've also tried auto-removing trailing whitespace as explained here: How to auto-remove trailing whitespace in Eclipse? But that didn't work either. I assume because I'm specifically trying to change the comment auto formatting.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
HYBR1D
  • 464
  • 2
  • 6
  • 19
  • 2
    Possible duplicate of [How to auto-remove trailing whitespace in Eclipse?](https://stackoverflow.com/questions/1043433/how-to-auto-remove-trailing-whitespace-in-eclipse) – AxelH Dec 01 '17 at 09:27
  • 1
    @AxelH I don't think a question about auto-removing trailing whitespace is a duplicate of a question about Eclipse **inserting** a space after the single-line comment start (so `//@` becomes `// @`) – Mark Rotteveel Dec 01 '17 at 17:08
  • @MarkRotteveel the linked question has answer that point how to enable/disable the auto formatting that is messing with `//@`. And I keep looking on those configuration to see if the "template" can be updated. – AxelH Dec 01 '17 at 18:08
  • @AxelH I have scanned the answers to that question several times, but I don't see it addressed (or at least not explicitly), and even then, the question is not a duplicate, so it should not be closed as one. – Mark Rotteveel Dec 01 '17 at 18:17
  • 1
    @MarkRotteveel, in that case, see my answer, this will be more explicit ;-) – AxelH Dec 01 '17 at 18:46

1 Answers1

2

My solution would be simple, disable the line comment formatting.

Window > Preferences > Java > Code Style > Formatter

Edit the current profile (you need to rename it if this is the default profile).

In the Comment tab, uncheck Enable line comment formatting.

Reason

Even if this is possible to remove that space so that the formatting give you a correct

//@

This would impact every comment, not a big deal you can say. But what about a commented annotation ?

// @SuppressWarning("...") 

This would be formatted into

//@SuppressWarning("...") 

That will become a problem for the OpenJML, it will be a conflict. You can see more about that in the User guide - 4.2 Syntactic conflicts with @

Another solution, for both annotation or JML is to disable the formatter, but this will not be usable to be honest :

// @formatter:off 
...
// @formatter:on

Everything between those tags while not be formatted (if the formatter:on is omitted, everything after that in the file won't be formatted

Community
  • 1
  • 1
AxelH
  • 14,325
  • 2
  • 25
  • 55