Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-24272

Class method refactor tool "Add definition..." doesn't always include class name in definition

    XMLWordPrintable

Details

    • All

    Description

      Summary
      The class method refactor tool "Add definition..." doesn't include class name in the definition if the previous method uses a function-try-block. For years I've been bothered by this bug in the QT creator refactoring tools, not being able to pinpoint the cause, and not investigating because it's a minor thing, and I just manually type it every time. And today I found the cause.

      Example
      Given the following header and source file:

      Foo.h
      class Foo
      {
      public:
          void method1();
      }
      
      Foo.cpp
      #include "Foo.h"
      

      Using the refactor tools on getValue, I'm provided with the option to "Add definition in Foo.cpp". The result:

      Foo.cpp
      #include "Foo.h"
      
      void Foo::method1()
      {
          
      }
      

      All is well. Declaring a new method, the header becomes:

      Foo.h
      class Foo
      {
      public:
          void method1();
          void method2();
      }
      

      Using the refactor tools again on method2, the cpp becomes:

      Foo.cpp
      #include "Foo.h"
      
      void Foo::method1()
      {
          
      }
      
      void Foo::method2()
      {
          
      }
      

      All is still well. Adding a function-try-block to method2, the cpp becomes:

      Foo.cpp
      #include "Foo.h"
      
      void Foo::method1()
      {
          
      }
      
      void Foo::method2()
      try
      {
          
      }
      catch (const std::exception& ex)
      {
      }
      

      Declaring one more method, the header becomes:

      Foo.h
      class Foo
      {
      public:
          void method1();
          void method2();
          void method3();
      }
      

      Using the refactor tools again on method3, the cpp shows the problem:

      Foo.cpp
      #include "Foo.h"
      
      void Foo::method1()
      {
          
      }
      
      void Foo::method2()
      try
      {
          
      }
      catch (const std::exception& ex)
      {
      }
      
      void method3()
      {
          
      }
      

      Note the missing class scope on the definition of method3.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            jdubb Jan Willem Silfhout
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes