In what order does Class Completion put its results?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:51:41

问题


Example: I create a new unit, declare a class with several methods like constructor, destructor, method1, method2, method3 in that order and then hit Ctrl-Shift-C. The IDE creates all the method bodies automatically, but the order is mixed up and not as it was declared in the interface section.

Now, this is not a problem, but is there a reason for it. It seems to be more difficult to mix that up than to just do it in the order of the declaration.

Or is there some rule to it that makes sense which I cannot see?


回答1:


This is a bit complicated to answer since it is dependent on how your methods are already arranged.

If they're already implemented in alphabetical order, it will try and maintain that. If the IDE cannot infer any kind of order, it resorts to dropping them at the end of the file.

There is another wrinkle where, by convention, if you include a comment in the form: { <ClassName> } before the first block of implemented method and then use that comment to delineate all subsequent class implementations, it will attempt to keep the methods grouped together.

The alphabetical ordering follows the same rules above, except it may inject the new methods into that logical block delineated by the indicated comment.

If you use class-completion with a brand new class, you'll notice that the IDE will automatically generate that delineating comment.

If you let class completion auto-arrange the methods and only use the Ctrl+Shift+UpAr key to navigate between a method's implementation and the declaration, the ordering should be less important.

Typically, I'll jump to the class decl using the above key-sequence, then use the arrow keys to go to the method in the decl I want, and then use that key-sequence again to quickly get to it.

Another nice key-sequence is the Ctrl+Alt+UpAr or Ctrl+Alt+DnAr which will quickly jump from method impl to method impl in file-order.




回答2:


By default, I'm pretty sure it tries to create them in alphabetical order by method name, and then tries to keep to this when more methods are added afterwards using the same method. The end result can be a bit of a random mix on ordering.




回答3:


From my experience I find that some times the IDE creates the methods in alphabetical order, but other times it just append the new methods to the end of the file.




回答4:


The IDE tries to create everything in alpahabetical order. But, if the methods become out of sequence (eg you rename a method) it gets in a muddle. The exact behaviour seems to depend on the version. Older versions would simply append the new method to the end of the file in any order. Newer versions seem a bit cleverer, but I haven't worked out exactly how yet.



来源:https://stackoverflow.com/questions/527938/in-what-order-does-class-completion-put-its-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!