Code-formatting: How to align multiline code to special characters?

后端 未结 3 1403
悲哀的现实
悲哀的现实 2021-02-04 12:42

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

I mean so that the code

Map(
  \'name -> \"Peter\",
  \'age -> 27,
           


        
相关标签:
3条回答
  • 2021-02-04 13:10

    In IDEA 12 if you're using the Scala plugin you can configure "Align when multiline" for many things, including method parenthesis. Your particular example of multiple invokations on separate lines is not supported however.

    0 讨论(0)
  • 2021-02-04 13:13

    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
    }
    

    Like so:

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

    Use option:

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

    0 讨论(0)
  • 2021-02-04 13:20

    Code formatter seems to be a solution.

    0 讨论(0)
提交回复
热议问题