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

Allow extracting a constant as local const variable or enum

XMLWordPrintable

    • All

      The patch for QTCREATORBUG-9617 already allows to extract a constant as function parameter, which (almost) works great.

      I'm now requesting the same, but to extract the value as const local variable and/or as enum.

      The reason is, that in unit tests you often have to use magic numbers on several positions.

      For example, the code:

      void test_get()
      {
        RingBuffer buf;
        buf.add(42);
      
        QCOMPARE(buf.get(), 42));
      } 

      could be refactored to:

      void test_get()
      {
        enum { value = 42 };
        RingBuffer buf;
        buf.add(value);
      
        QCOMPARE(buf.get(), value));
      }

      by using the quickfix "Extract constant as enum" by using Alt+Enter on the number 42.

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

            kandeler Christian Kandeler
            aha_1980 André Hartmann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes