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 - encapsulate fields: take configurable prefixes into account
Summary: encapsulate fields: take configurable prefixes into account
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker with 2 votes (vote)
Assignee: Ralph Ruijs
Keywords: PLAN
: 49911 (view as bug list)
Depends on: 228870
  Show dependency tree
Reported: 2006-07-27 11:44 UTC by klosels
Modified: 2013-05-02 14:12 UTC (History)
2 users (show)

See Also:
Exception Reporter:


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 (upload may still be in progress)
User: Ralph Benjamin Ruijs <>
Log: #228870 - New API to support CodeStyle's prefix/suffix
#65315 #81243 #224242 - Use CodeStyle's prefix and suffix configuration