Intellij (Android studio) member variable prefix

JavaIntellij IdeaCoding StyleAndroid Studio

Java Problem Overview


How do I configure Android Studio (or Intellij generally) to correctly generate getters and setters for member variables with prefixes?

If I have a class

public class Foo{
    int mBar;
}

I want it to create getBar() instead of getMBar when I do Refactor->Encapsulate or Generate

EDIT

I found the way to do it per-project basis: You just go File->Settings->Project Settings->Code Style

But it created a settings file somewhere in my project directory.

I want a solution which allows me to do it once for all projects, present and future.

Java Solutions


Solution 1 - Java

In Mac OS

  • Android Studio -> Preferences -> Code Style -> Java
  • on the right panel, click on the right arrow until you see code generation tab
  • Click ok

enter image description here

Solution 2 - Java

Try going to File-->Other Settings-->Default Settings. Your should be able to make prefixes for every other project that you do if you change prefix settings with the scheme set to default instead of Project. The prefix change would be in Java and Code Generation. That will fix setters and getters.

Solution 3 - Java

In AS 2.2.1:

File > Settings > Editor > Code Style> Java > Code Generation > Naming > Name Prefix Field / Name Prefix Static Field

enter image description here

Solution 4 - Java

  1. Open Android Studio's preferences (from the Android Studio menu on Mac and from File -> Settings on Windows and Linux).
  2. Expand Editor and then expand Code Style.
  3. Select Java, then choose the Code Generation tab.
  4. In the Naming table, select the Field row and add m as the name prefix for fields. Then add s as the name prefix for static fields.

Code Generation Setting in Android Studio 3.x

  1. Click Ok

Solution 5 - Java

You need go to Setting > Editor > Code Style > Java and just specify s-prefix in static field, then click OK

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSergo PasoeviView Question on Stackoverflow
Solution 1 - JavaEmil Reña EnriquezView Answer on Stackoverflow
Solution 2 - JavaDavisView Answer on Stackoverflow
Solution 3 - JavaGraemeView Answer on Stackoverflow
Solution 4 - Javauser6419437View Answer on Stackoverflow
Solution 5 - JavaDyno CrisView Answer on Stackoverflow