gpt4 book ai didi

intellij-idea - 我可以在同一个项目中同时在两种不同的代码格式配置之间切换吗?

转载 作者:行者123 更新时间:2023-12-03 17:29:54 25 4
gpt4 key购买 nike

我正在开发一个在 IntelliJ 中有一些严格代码格式要求的 Java 项目。我发现首选格式很难阅读,以至于影响了我的效率并且无法轻松查看我自己的代码。

我想知道是否有办法存储两种不同的代码格式配置或配置文件,我可以将它们应用到我的代码中。例如,我想在实现和调试期间将我的代码格式化回“我的风格”,然后在提交之前将其格式化为“公司风格”。我需要在多个提交中处理相同的代码,因此我需要随意从一种格式转换为另一种格式。

这可能吗?

企业风格,大量换行和空格:

private boolean scpLocalToRemote (String localIP, String remoteIP, String remoteUser,
String localFilePath, String remoteFilePath) {
String scpCommand = "scp " + localFilePath + " " + remoteUser + "@[" + remoteIP + "]:"
+ remoteFilePath;
log.info("SCP Command: '" + scpCommand + "'");

try {
MyProjectInterfaceUtils.runCommand(scpCommand);
} catch (IOException e) {
log.severe(e.toString());
return false;
}

return true;
}

我的风格 (这只是一种开发偏好,而不是寻求有关格式化最佳实践的建议):
private boolean scpLocalToRemote(String localIP, String remoteIP, String remoteUser, localFilePath, String remoteFilePath) 
{
String scpCommand = "scp " + localFilePath + " " + remoteUser + "@[" + remoteIP + "]:" + remoteFilePath;
log.info("SCP Command: '" + scpCommand + "'");

try
{
MyProjectInterfaceUtils.runCommand(scpCommand);
}
catch(IOException e)
{
log.severe(e.toString());
return false;
}

return true;
}

最佳答案

1) 在 Ctrl + Alt + S → 代码样式中创建不同的代码样式(您可能需要复制(复制)更改的方案并重命名)。

2) 按 Ctrl + `, 2,然后按与您的方案对应的数字。

3) 应用 Ctrl + Alt + L 重新格式化当前文件。

关于intellij-idea - 我可以在同一个项目中同时在两种不同的代码格式配置之间切换吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56639836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com