Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » [Solved]: Source code formatter: inline comments not being formatted
[Solved]: Source code formatter: inline comments not being formatted [message #1815829] Fri, 11 October 2019 15:20 Go to next message
Chkiron Chronos is currently offline Chkiron ChronosFriend
Messages: 8
Registered: October 2019
Junior Member
Hi!

I am writing a custom application to format Java source files in the same way that Eclipse's formatter does.

The only failing test I have at the moment is checking if my application can format JDK 8's java.util.HashMap source code in the same way that Eclipse does.

I have only 8 differences, all of them caused by this type of comment:

https://i.imgur.com/s4wGRqk.png
(on the left is the hashmap as formatted by Eclipse, on the right is my version)

I have created a CodeFormatter using both ToolFactory.M_FORMAT_EXISTING and ToolFactory.M_FORMAT_NEW, with no difference in the results:


    // Using ToolFactory.M_FORMAT_NEW
    // CodeFormatter codeFormatter =
    //        ToolFactory.createCodeFormatter(GoogleStyleOptions.getGoogleOptions());

    // Using ToolFactory.M_FORMAT_EXISTING
    CodeFormatter codeFormatter =
            ToolFactory.createCodeFormatter(GoogleStyleOptions.getGoogleOptions(), ToolFactory.M_FORMAT_EXISTING);

    TextEdit textEdit = codeFormatter.format(
           CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
           sourceCodeToFormat,
           FROM_THE_BEGINNING,
           sourceCodeToFormat.length(),
           ZERO_INITIAL_INDENTATION,
           LINE_SEPARATOR);
    
    IDocument doc = new Document(sourceCodeToFormat);
    textEdit.apply(doc);
    return doc.get();


I am using the same XML file to configure the formatter both of my Eclipse and my custom application, and have checked that they are identical in runtime.

What my formatter is missing, would you know?

Thanks in advance and kind regards!

[Updated on: Mon, 14 October 2019 05:07]

Report message to a moderator

Re: Source code formatter: inline comments not being formatted [message #1815833 is a reply to message #1815829] Fri, 11 October 2019 17:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
It's probably better to ask on the JDT forum. https://www.eclipse.org/forums/index.php/f/13/

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Source code formatter: inline comments not being formatted [message #1815870 is a reply to message #1815833] Mon, 14 October 2019 05:06 Go to previous message
Chkiron Chronos is currently offline Chkiron ChronosFriend
Messages: 8
Registered: October 2019
Junior Member
Thanks, Ed.

Fortunately I was able to solve this during the weekend.

The problem was that a mistake on my side. I had a hardcoded option, FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, forgotten in the code that was overriding the configuration provided by the files.

Once I fixed this, the formatting worked as expected.

Kind regards,

Rodrigo
Previous Topic:Problem occured while invoking director
Next Topic:Trouble with Arduino Plugin
Goto Forum:
  


Current Time: Sat Apr 20 01:45:53 GMT 2024

Powered by FUDForum. Page generated in 0.09467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top