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.
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.
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
I have replied to the post with the details. Could you please have a look?
Last edit: skarekar 2013-08-17
I'm assuming that you want the following:
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> {
}
Hope you get a chance to look at it.
Cheers.
On 13 October 2013 07:30, Ben Gardner bengardner@users.sf.net wrote:
Related
Bugs:
#555Hi Ben,
Any updates on this one? Looking forward to the fix. Let me know if I can be of any assistance.
Hi Ben,
Any updates on this one? Looking forward to the fix. Let me know if I can be of any assistance.
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))
Also I do not think we have the code to indent function continuation at all.
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?
hi ben, could you check my earlier post and see if it helps. i am really waiting for a solution for this one.
hi ben, did you get a chance to look into this?
Could you push the actual source and config file?
Hello again.
Could you push a new version of your indent.cpp or a diff again the aktual git version?
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
I might missing something: The change around line 1848 doesn't help.
I get now:
It is probably not what you are looking for!
Next step?
It is pretty close to what I require. The only thing left is to move the < on the next line with the template type
I am not a C/C++ person, so I may not be able to provide the exact solution. But I will try.
We have migrated the bug to:
https://github.com/uncrustify/uncrustify/issues/672