简体   繁体   English

IntelliJ 理念:用 package 中所有类中的实际值替换常量的用法

[英]IntelliJ Idea: Replace usages of constants by actual values in all classes in a package

In my Java project I was told to avoid the usage of integer and String constants in certain classes.在我的 Java 项目中,有人告诉我要避免在某些类中使用 integer 和字符串常量。 Is there any shortcut in IntelliJ Idea to replace all usages of String and integer constants by their actual values? IntelliJ Idea 中是否有任何快捷方式可以用实际值替换 String 和 integer 常量的所有用法? Something like "Extracting constants backwards".诸如“向后提取常量”之类的东西。 Because there are a lot of places to change and I wondered if there was some way to do it automatically.因为有很多地方需要改变,我想知道是否有某种方法可以自动完成。

Initial: Do you mean something like this: https://www.jetbrains.com/help/idea/extract-constant.html初始:你的意思是这样的吗: https://www.jetbrains.com/help/idea/extract-constant.html

Update: I will try with an example, I guess this is your case (sorry if i misunderstood again)更新:我会尝试一个例子,我想这是你的情况(对不起,如果我再次误解了)

Lets say I have:可以说我有:

private static final String PAGE = "page";
private static final String LIMIT = "size";
private static final String SORT = "sort";

Then do a right click on the PAGE String: Refactor > Inline Field然后右键单击 PAGE 字符串:重构 > 内联字段

在此处输入图像描述

and do the Refactor并进行重构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于使用的方法,IntelliJ IDEA“在所有地方都找不到用法” - IntelliJ IDEA "no usages found in all places" for methods that are used 有一种简单的方法可以代替常量的用法吗? - Is there an easy way to replace usages of constants? 使用 Intellij IDEA 查找所有可以被常量(静态最终)替换的字符串值 - Find all String values that can be replaced by constants (static final) with Intellij IDEA 如何在 Intellij Idea 中找到所有未使用的类? - How find all unused classes in Intellij Idea? 如何在IntelliJ Idea中找出方法的所有用法(直接用法,通过某些库的传递用法)? - How to find out all usages of a method (direct usage, transitive usage through some library) in IntelliJ Idea? Java:如何在Idea Intellij中将类移动到另一个包? - Java: How to move classes to another package in Idea Intellij? Intellij从方法中按包查找用法 - Intellij find usages by package from method 如何在IntelliJ IDEA中未经测试列出所有类? - How to list all classes without test in IntelliJ IDEA? intellij idea 结构搜索和替换 - 查找所有调用 api 的方法 - intellij idea structural search and replace - find all methods that call an api IntelliJ IDEA 代码检查 - 外部使用 - 花了这么长时间 - IntelliJ IDEA code inspection - external usages of - taking so long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM