Bug 81243 - encapsulate fields: take configurable prefixes into account
encapsulate fields: take configurable prefixes into account
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Refactoring
5.x
All All
: P3 with 2 votes (vote)
: 7.4
Assigned To: Ralph Ruijs
issues@java
: PLAN
: 49911 (view as bug list)
Depends on: 228870
Blocks:
  Show dependency treegraph
 
Reported: 2006-07-27 11:44 UTC by klosels
Modified: 2013-05-02 14:12 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description klosels 2006-07-27 11:44:14 UTC
In several projects I've been working on, there have been strict guidelines
about the naming of e.g. fields. One example was to name all instance fields
with a m_ prefix, all static fields with s_ and all method parameters with u_.

In a situation like this the "encapsulate field" refactoring is almost unusable
because for a field

  private int m_foo;

it produces the following code which doesn't comply to the coding standard:

  public void setM_foo(int m_foo) {
    this.m_foo = m_foo;
  }
  public int getM_foo() {
    return this.m_foo;
  }

It takes approximately the same amount of work to fix this (even when correcting
the method names in the refactoring dialog) as for writing the methods manually.
Instead, the code should look like this:

  public void setFoo(int u_foo) {
    m_foo = m_foo;
  }
  public int getFoo() {
    return m_foo;
  }

My suggestion is to provide advanced options for the refactoring to be able to
specify these prefixes (preferrably on a per-project basis) and take them into
account when generating the getter/setter methods. If instance field and method
parameter name prefixes are set and different from each other, the "this."
prefix can also be omitted.
Comment 1 Ralph Ruijs 2013-04-22 21:49:39 UTC
*** Bug 49911 has been marked as a duplicate of this bug. ***
Comment 2 Ralph Ruijs 2013-04-30 21:53:52 UTC
Fixed by 80f139ccdada
Comment 3 Quality Engineering 2013-05-02 14:12:40 UTC
Integrated into 'main-golden', will be available in build *201305021042* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/80f139ccdada
User: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Log: #228870 - New API to support CodeStyle's prefix/suffix
#65315 #81243 #224242 - Use CodeStyle's prefix and suffix configuration


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo