9

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);
  }
Community
  • 1
  • 1
jhegedus
  • 20,244
  • 16
  • 99
  • 167

2 Answers2

1

This is the solution that worked for me - however sub-optimal:

  1. Optimize imports
  2. Go to any import .* and press alt-enter (a menu-question will appear to replace the * import with individual imports) then press enter again. enter image description here
ntg
  • 12,950
  • 7
  • 74
  • 95
  • alt-enter on wildcard imports comes up with nothing on Android Studio Dolphin – urgentx Oct 14 '22 at 00:16
  • This is possible, I was using Intellij... However, the library was in the path right? (e.g. it could autocomplete the java.) ... Otherwise.... – ntg Oct 14 '22 at 14:19
0

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
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 4
    Thanks that was the first thing I tried, it did not work. Does it work for you ? I am on Mac, maybe there is some difference. Version 2016.3.4, result : https://snag.gy/Ca8jXK.jpg with settings : https://snag.gy/WSNolB.jpg – jhegedus Mar 14 '17 at 15:53
  • @jhegedus - It didn't work for me at first - until I realised that at some point a re-install of intelliJ had reset the "Class count to use import with *" setting back to the default of 5. Changing it to "9999" then made ctrl-alt-O work. – Andrew M Sep 22 '17 at 12:56