Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tools to generator field constant string in java? [closed]

I need a Eclipse or IDEA plugin to generate field name constant string in java. For example, in ORM we often define a class Like this:

class DealDB {
    public String dealId;
}

We can generate get and set method with eclipse or IDEA, but we cannot generate field name constant string. When we write query code in java, we often need this constant string.

class DealDB {
    public String dealId;

    // to generate this
    public static final String FIELD_DEALID="dealId";
}

Maybe extend lombok (https://projectlombok.org/) can implement this.

like image 854
xufan Avatar asked Jul 20 '26 09:07

xufan


1 Answers

In IntelliJ, I can suggest something that is not exactly what you are asking for, but it comes close.

Take the following code sample, containing the String "dealId".

public static void main(String[] args) {
    System.out.println("dealId");
}

Position the cursor on "dealId" and hit Ctrl - Alt - C (refactor: Create Constant).

IntelliJ will pop up with a dialog and then create the following for you:

    public static final String DEAL_ID = "dealId";

You also have option to "Replace all occurences" and "Move to another class".

like image 57
vikingsteve Avatar answered Jul 21 '26 21:07

vikingsteve