2017-03-14 37 views
1

請考慮下面的代碼。自動將通配符導入IntelliJ中的顯式導入(對於Scala/Java)

是否有可能使InteliJ自動重構每個通配符導入到顯式導入(無論在範圍中使用什麼)?

例如import scalatags.JsDom.all._分成import scalatags.JsDom.all.{ol,li,div}

我的搜索建議,這是不可能的,但也許我錯了?

This是一個相關但不同的問題。

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); 
    } 

回答

0

打開對話框

Preferences > Editor > Code Style > Scala 

選擇選項卡Imports

在域 「類中的計數使用導入與_」,輸入一個高的離譜數,例如5000.

從現在開始,「優化導入」命令會將通配符解析爲單個導入。

您可能還需要激活

Editor > General > Auto Import > Scala > Optimize Imports on the Fly 
+0

謝謝,這是我想的第一件事,它沒有工作。對你起作用嗎 ?我在Mac上,也許有一些區別。版本2016.3.4,結果:https://snag.gy/Ca8jXK.jpg設置:https://snag.gy/WSNolB.jpg – jhegedus

+0

@jhegedus - 起初我不適用 - 直到我意識到在某些時候重新安裝的intelliJ重置了「使用導入*的類別數量」設置回缺省值5.將其更改爲「9999」,然後使ctrl-alt-O工作。 –