Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically refactor wildcard imports into explicit imports in IntelliJ (for Scala/Java)

Consider the code below.

Is it possible to make InteliJ to automatically refactor each wildcard import into explicit imports (whatever is used in scope)?

For example import scalatags.JsDom.all._ into import scalatags.JsDom.all.{ol,li,div}?

My search suggests that it is not possible, but maybe I am wrong?

This is a related but different question.

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);
  }
like image 454
jhegedus Avatar asked Mar 14 '17 15:03

jhegedus


1 Answers

Open Dialog

Preferences > Editor > Code Style > Scala

Select tab Imports

In the field "Class count to use import with _", enter a ridiculously high number, e.g. 5000.

From now on, the "Optimize Imports" command will resolve wildcards to individual imports.

You probably also want to activate

Editor > General > Auto Import > Scala > Optimize Imports on the Fly
like image 72
Sean Patrick Floyd Avatar answered Oct 06 '22 01:10

Sean Patrick Floyd