代码格式:如何将多行代码与特殊字符对齐? [英] Code-formatting: How to align multiline code to special characters?

查看:177
本文介绍了代码格式:如何将多行代码与特殊字符对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IDEA或其中一个插件是否能够将代码与特殊字符对齐?

Is IDEA or one of its plugins capable of aligning code to special characters?

我的意思是代码

Map(
  'name -> "Peter",
  'age -> 27,
  'company -> "Foobar"
)

转换为

Map(
  'name    -> "Peter",
  'age     -> 27,
  'company -> "Foobar"
)

示例2:

execute("x", true, 27)
execute("foobar", false, 0)

转换为

execute("x"     , true , 27)
execute("foobar", false, 0 )


推荐答案

你可以对齐case语句,但是:

You can align case statements, however:

value match {
  case s: String => Some(java.lang.Long.parseLong(s))
  case bi: BigInt => Some(bi.longValue)
  case _ => None
}

如下所示:

value match {
  case s: String  => Some(java.lang.Long.parseLong(s))
  case bi: BigInt => Some(bi.longValue)
  case _          => None
}

使用选项:

设置 - >代码样式 - > Scala =>包装和大括号 - >'匹配'和'大小写'语句 - >在列'大小写'分支中对齐

Settings -> Code Style -> Scala => Wrapping and Braces -> 'match' and 'case' statements -> Align in columns 'case' branches

这篇关于代码格式:如何将多行代码与特殊字符对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆