Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "CDT/Obsolete/C editor enhancements/Easy method override"

(Details)
Line 4: Line 4:
  
 
Overriding a method from a base class is a very common scenario. The programmer has to do a lot of redundant activities to perform this task: look up and then either copy or rewrite the method signature both in the module and in its header file.
 
Overriding a method from a base class is a very common scenario. The programmer has to do a lot of redundant activities to perform this task: look up and then either copy or rewrite the method signature both in the module and in its header file.
 +
 +
===Ranking===
 +
 +
5/5 [[Kirstin Weber]]
  
 
==Solution==
 
==Solution==

Revision as of 03:53, 10 June 2010

This is a problem page. Please treat it as a discussion page and feel free to insert your comments anywhere. My open questions are in bold--Tomasz Wesołowski 11:32, 5 May 2010 (UTC)

Problem

Overriding a method from a base class is a very common scenario. The programmer has to do a lot of redundant activities to perform this task: look up and then either copy or rewrite the method signature both in the module and in its header file.

Ranking

5/5 Kirstin Weber

Solution

Idea

A simple and probably optimal solution to this problem is to introduce a feature analogous to JDT - give proposals for automatic method override in Context Assist. A proposal would look like in JDT - name of the method followed by a gray comment override method in XYZ.

Details

When Context Assist is invoked from the context of a class body, the proposals (preferably high-ranked proposals) of overriding would appear. Selection of a proposal would trigger the following: - Code generation of method declaration in the class body: the same declaration as in parent class and with the current access specifier (as access specifiers don't influcence the overriding rules) - Code generation of method stub in appropriate place.

Jens Elmenthaler If I want to do that in JDT, I use Context Menu -> Source -> Override/implement method.

Where is the place for the method stub?

File:

  • If the context is a header and there exists a matching module (matching as in ctrl+tab), append the stub to that module.
  • If the context is a header and there's no matching module: ask whether to create one, create inline method stub?
  • If the context is a module: append the stub to that module.

Location in module:

  • If there's a preceding method in the header and it has a definition in this module, insert the stub after that method
  • Otherwise if there are any method definitions of this class in this module, insert the stub before them
  • Otherwise insert the stub at the end of module.

References

Bug 303870 requests some functionality to automate overriding virtual methods.

Back to the top