This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 81243

Summary: encapsulate fields: take configurable prefixes into account
Product: java Reporter: klosels <klosels>
Component: RefactoringAssignee: Ralph Ruijs <ralphbenjamin>
Status: RESOLVED FIXED    
Severity: blocker CC: dtrebbien, serff
Priority: P3 Keywords: PLAN
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 228870    
Bug Blocks:    

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