自动将通配符导入重构为 IntelliJ 中的显式导入(适用于 Scala/Java)

jhe*_*dus 5 java scala intellij-idea

考虑下面的代码。

是否可以让 InteliJ 自动将每个通配符导入重构为显式导入(无论在范围内使用什么)?

例如import scalatags.JsDom.all._进入import scalatags.JsDom.all.{ol,li,div}

我的搜索表明这是不可能的,但也许我错了?

是一个相关但不同的问题。

package app.client

import app.client.components.RootReactComp
import app.client.pages.spatutorial.components.GlobalStyles
import japgolly.scalajs.react.ReactDOM
import org.scalajs.dom
import org.scalajs.dom.raw.Element

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExport
import scalacss.Defaults._
import scalatags.JsDom.all._
import scalatags.JsDom.implicits._
import scalatags.JsDom.svgAttrs.{fill, height, points, stroke, width,strokeWidth}
import scalatags.JsDom.svgTags._
@JSExport("Main")
  object Main extends js.JSApp {
@JSExport
         def main(): Unit = {
    //    log.warn("Application starting")
    //    // send log messages also to the server
    //    log.enableServerLogging("/logging")
    //    log.info("This message goes to server as well")

    // create stylesheet
    GlobalStyles.addToDocument()
    // tell React to render the router in the document body
    //ReactDOM.render(router(), dom.document.getElementById("root"))
    ReactDOM.render(RootReactComp.themedView(), dom.document.getElementById("joco"))
    val el: Element =dom.document.getElementById("svg-example")
     val l=     div( ol(
       li("Ordered List Item 1"),
       li("Ordered List Item 2"),
       li("Ordered List Item 3")
     )).render
  val s=    svg(height := "800", width := "500")(
                polyline(
                    points := "20,20 40,25 60,40 80,120 120,140 200,180",
                    fill := "none",
                    stroke := "black",
                    strokeWidth := "3"
                  )
           )
    el.appendChild(l);
  }
Run Code Online (Sandbox Code Playgroud)

Sea*_*oyd 0

打开对话框

Preferences > Editor > Code Style > Scala
Run Code Online (Sandbox Code Playgroud)

选择选项卡Imports

在“使用带 _ 导入的类数”字段中,输入一个高得离谱的数字,例如 5000。

从现在开始,“优化导入”命令将解析单个导入的通配符。

您可能还想激活

Editor > General > Auto Import > Scala > Optimize Imports on the Fly
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这是我尝试的第一件事,但没有成功。对你起作用吗 ?我用的是Mac,可能有一些区别。版本 2016.3.4,结果:https://snag.gy/Ca8jXK.jpg 设置:https://snag.gy/WSNolB.jpg (4认同)