Menu

#555 long method and variable declarations not correctly indented

Future
closed
nobody
None
5
2016-09-23
2013-06-10
skarekar
No

hi Ben,

The fix for 536 solves the problem for the class declarations.

Long method and variable declarations though are still not being indented correctly. They work normally, but in case of templatized parameters they break. Adding an additional check should handle this problem.
Around line 1430 in indent.cpp we have this condition check. We need to add this additional check. See comment alongside the new condition.


else if ((vardefcol > 0) &&
(pc->level == pc->brace_level) &&
((pc->type == CT_WORD) || (pc->type == CT_FUNC_CTOR_VAR)) &&
(prev != NULL) &&
((prev->type == CT_COMMA) ||
(prev->type == CT_TYPE) ||
(cpd.lang_flags & LANG_JAVA && prev->parent_type == CT_TEMPLATE) || // New condition added
(prev->type == CT_WORD)) &&
((pc->flags & PCF_VAR_DEF) != 0))
{
LOG_FMT(LINDENT, "%s: %d] Vardefcol => %d\n",
func, pc->orig_line, vardefcol);
reindent_line(pc, vardefcol);
}

For the long method problem though, I am afraid I don't have a solution.

Related

Bugs: #555

Discussion

  • Ben Gardner

    Ben Gardner - 2013-07-13

    I don't have time to work on uncrusitfy very often, and when I do, if I don't have all the needed info in one spot for a bug, I'm not likely to spend the time to dig it up. I'm out of time for today...

    Would you please attach or post inline the configuration file, the input code and the expected output code? That will enable me to actually look at the issue the next time the stars (naps) align and I have some spare.

     
  • Ben Gardner

    Ben Gardner - 2013-07-13
    • status: open --> need-info
     
    • skarekar

      skarekar - 2013-08-17

      I am attaching the initial code, the formatted code and the configuration file. The class declaration is working fine, but the method and variable declaration is not being indented at all.

       

      Last edit: skarekar 2013-08-17
  • skarekar

    skarekar - 2013-07-15

    I have replied to the post with the details. Could you please have a look?

     

    Last edit: skarekar 2013-08-17
  • Ben Gardner

    Ben Gardner - 2013-10-13

    I'm assuming that you want the following:

    public class ParticipantDataFileItemWriter implements ItemStreamWriter<
        ParticipantDataFileDetails> {
    
        private JdbcCursorItemReader<ParticipantDataFileDetails>
            ParticipantDataFileJdbcCursorItemReader = null;
    
        public JdbcCursorItemReader<IParticipantDataFileService> write() throws
            Exception {}
    
    }
    
     
  • skarekar

    skarekar - 2013-10-13

    Thanks for the prompt reply.

    Thats just about it. Perfect would be if the < on the opening line were
    moved to the beginning of the second line so that the template parameter is
    clear.

    public class ParticipantDataFileItemWriter implements ItemStreamWriter
    <ParticipantDataFileDetails> {

    private JdbcCursorItemReader<ParticipantDataFileDetails>
        ParticipantDataFileJdbcCursorItemReader = null;
    
    public JdbcCursorItemReader<IParticipantDataFileService> write() throws
        Exception {}
    

    }

    Hope you get a chance to look at it.

    Cheers.

    On 13 October 2013 07:30, Ben Gardner bengardner@users.sf.net wrote:

    I'm assuming that you want the following:

    public class ParticipantDataFileItemWriter implements ItemStreamWriter<
    ParticipantDataFileDetails> {

    private JdbcCursorItemReader<ParticipantDataFileDetails>
        ParticipantDataFileJdbcCursorItemReader = null;
    
    public JdbcCursorItemReader<IParticipantDataFileService> write() throws
        Exception {}
    

    }


    Status: need-info
    Created: Mon Jun 10, 2013 11:07 AM UTC by skarekar
    Last Updated: Mon Jul 15, 2013 12:11 PM UTC
    Owner: nobody

    hi Ben,

    The fix for 536 solves the problem for the class declarations.

    Long method and variable declarations though are still not being indented
    correctly. They work normally, but in case of templatized parameters they
    break. Adding an additional check should handle this problem.
    Around line 1430 in indent.cpp we have this condition check. We need to
    add this additional check. See comment alongside the new condition.

    else if ((vardefcol > 0) &&
    (pc->level == pc->brace_level) &&
    ((pc->type == CT_WORD) || (pc->type == CT_FUNC_CTOR_VAR)) &&
    (prev != NULL) &&
    ((prev->type == CT_COMMA) ||
    (prev->type == CT_TYPE) ||
    (cpd.lang_flags & LANG_JAVA && prev->parent_type == CT_TEMPLATE) || // New
    condition added
    (prev->type == CT_WORD)) &&
    ((pc->flags & PCF_VAR_DEF) != 0))
    {
    LOG_FMT(LINDENT, "%s: %d] Vardefcol => %d\n",
    func, pc->orig_line, vardefcol);
    reindent_line(pc, vardefcol);
    }

    For the long method problem though, I am afraid I don't have a solution.

    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/uncrustify/bugs/555/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #555

  • skarekar

    skarekar - 2013-11-27

    Hi Ben,

    Any updates on this one? Looking forward to the fix. Let me know if I can be of any assistance.

     
  • skarekar

    skarekar - 2013-12-20

    Hi Ben,

    Any updates on this one? Looking forward to the fix. Let me know if I can be of any assistance.

     
  • skarekar

    skarekar - 2013-12-29

    I did some analysis and found that the reason why variables with template types are not being indented correctly is that in this case the prev->type = ANGLE_CLOSE. So in indent.cpp we need to check for this type (which I do not think is clean at all) or we need to check the parent type of the prev token, i.e. prev->parent_type == CT_TEMPLATE as suggested a couple of posts earlier. They should be added to around line 1435 in indent.cpp in this condition


    else if ((vardefcol > 0) &&
    (pc->level == pc->brace_level) &&
    ((pc->type == CT_WORD) || (pc->type == CT_FUNC_CTOR_VAR)) &&
    (prev != NULL) &&
    ((prev->type == CT_COMMA) ||
    (prev->type == CT_TYPE) ||
    (prev->parent_type == CT_TEMPLATE) || // Condition to check for template type
    (prev->type == CT_WORD)) &&
    ((pc->flags & PCF_VAR_DEF) != 0))

     
  • skarekar

    skarekar - 2013-12-30

    Also I do not think we have the code to indent function continuation at all.

     
  • skarekar

    skarekar - 2014-01-02

    I think the following should solve both the problems, for long variable declaration and long function definitions. I have only extended the long class definition fix to indent long function definitions. Please have a look and let me know if this does not cause a regression and if we can use this?

     
  • skarekar

    skarekar - 2014-04-25

    hi ben, could you check my earlier post and see if it helps. i am really waiting for a solution for this one.

     
  • skarekar

    skarekar - 2014-11-18

    hi ben, did you get a chance to look into this?

     
  • Guy Maurel

    Guy Maurel - 2016-04-07

    Could you push the actual source and config file?

     
  • Guy Maurel

    Guy Maurel - 2016-07-11

    Hello again.
    Could you push a new version of your indent.cpp or a diff again the aktual git version?

     
  • skarekar

    skarekar - 2016-07-13

    Hi Guy,

    The config file is the same as above but i am attaching it again. I have pulled the latest indent.cpp and added the code to it. Look around line 1848

     

    Last edit: skarekar 2016-07-13
  • Guy Maurel

    Guy Maurel - 2016-07-20

    I might missing something: The change around line 1848 doesn't help.
    I get now:

    Parsing: ParticipantDataFileItemWriter.java as language JAVA
    public class ParticipantDataFileItemWriter implements ItemStreamWriter<
            ParticipantDataFileDetails> {
    
        private JdbcCursorItemReader<ParticipantDataFileDetails>
                ParticipantDataFileJdbcCursorItemReader = null;
    
        public JdbcCursorItemReader<IParticipantDataFileService> write() throws
        Exception {}
    
    }
    

    It is probably not what you are looking for!
    Next step?

     
  • skarekar

    skarekar - 2016-07-20

    It is pretty close to what I require. The only thing left is to move the < on the next line with the template type

    public class ParticipantDataFileItemWriter implements ItemStreamWriter
            <ParticipantDataFileDetails> {
    

    I am not a C/C++ person, so I may not be able to provide the exact solution. But I will try.

     
  • Guy Maurel

    Guy Maurel - 2016-09-23
     
  • Guy Maurel

    Guy Maurel - 2016-09-23
    • status: need-info --> closed