Any way to expand Scala import automatically in IntelliJ? - scala

I am using IntelliJ IDEA 13.1 in our scala project.
Our project code style defined that import statements should not collapse into one line.
For example,
prefered:
import com.example.domain.A
import com.example.domain.B
import com.example.domain.C
not prefered:
import com.example.domain.{A, B, C}
However, I could not find any options to make codes be prefered style when optimize import.
Are there an option? or should I use some plug-in?

I would argue that your project code style guide doesn't quite align with Scala. "import com.example.domain.{A, B, C}" would achieve the same thing you are trying but in a concise manner. Some would argue that this is the preferred way.
Maybe you should question your project code style?

I found the newest version of IntellJ IDEA(13.1.3) and Scala plugin(0.38.437) supports multi-line import.
Install and uncheck the option Preferences -> Code Style -> Scala -> Imports -> Collect Imports with the same prefix into one import

Related

eclipse organize import not working with kotlin files

When I try to use the organize inputs in a Kotlin class, it does not add missing imports like in Java.
Specific case:
create a new Kotlin class file with the following contents:
data class Foo (
public var fileEncoding: String = StandardCharsets.UTF_8.name()
)
Eclipse complains that it can't find StandardCharsets
use organize inputs, but StandardCharsets is not added to the import statements.
I would have expected that it added the line import java.nio.charset.StandardCharsets
Update: since 0.7.0 Kotlin Eclipse plugin supports organize imports.
At present, Kotlin Eclipse plugin does not support "Organize imports" feature: KT-3962. Please feel free to upvote for this issue.
For now, you can try to invoke quick fix action (Ctrl+1) to import StandardCharsets class.

Dart library import shortcuts

In cases where I have to import the main file from a library in dart I have to do:
import 'package:<package_name>/<package_name>.dart';
Is there a shorthand for doing this in Dart?
Something like
import 'package:<package_name>';
Cause mentioning the package name twice seems redundant.
Seems redundant but there is no way around.
The new "add import" quick fix makes this mostly a non-issue IMHO.
DartEditor ctrl+1
WebStorm/IntelliJ ctrl+Enter
You have to wait until analyzing is done and a hint/warning (wiggled underline) is shown.

Is there a way to import packages from your current project into a worksheet

I like worksheets as an alternative to the REPL, but I keep implementing functions in the worksheet and then copying them back into the actual project. How do I import a package from the current project so that I can call those functions in the worksheet?
There is nothing special to do. Just do regular import of the packages you need in the worksheet. For instance:
import com.acme.myproject._
The worksheet is a totally regular source file, that simply gets evaluated in a fancy manner on save.

Import customization in Groovy-Eclipse for DSL

I'm using Groovy for a calculation engine DSL and really like the support we now have in Eclipse with STS and the Groovy-Eclipse plug-in (I'm on STS 2.8.0M2 with latest milestone of Groovy-Eclipse 2.5.2).
One issue I have is I don't know how to get the Groovy editor to 'know' the automatic imports I've added to my script runner, meaning Eclipse gives me a whole bunch of false errors. If you use the Groovy class loader, you can add additional import for 'free', so you avoid needing to do imports in your script.
I've had a play with the DSLD support in Groovy-Eclipse (which can be used to add auto-completion support) but it's not obvious to me that this is something I could do with it - I don't find the DSLD documentation the simplest to follow.
The inferencing settings for Groovy in Eclipse didn't look like the right thing either.
For example:
def result = new CalculationResult()
gives me an error on the CalculationResult class as it's not imported, but the script will execute correctly in my environment because of the customized imports on the Groovy class loader. I'm using the standard import customization provided by Groovy, for example:
import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.codehaus.groovy.control.CompilerConfiguration
def importCustomizer = new ImportCustomizer()
importCustomizer.addImport 'CalculationResult', 'ch.hedgesphere.core.type.CalculationResult'
def configuration = new CompilerConfiguration()
configuration.addCompilationCustomizers(importCustomizer)
...
Any pointers appreciated.
This seems to be in their bugtracker as coming in the 2.6 release of the plugin.
But the comment from Andrew Eisenberg doesn't bode well:
Unfortunately, this is not something that DSLDs can do. Since a
missing import could mean compile errors, we would need a way to
augment the compiler lookup for this. There might be a way to specify
this information inside of a DSLD, but that would mean hooking into
DSLDs in a very different way. More likely, this will have to be
specified through an Eclipse plugin (like the gradle tooling).
Another possibility is that we can ensure that certain kinds of AST
Transforms are applied during a reconcile and so the editor would just
"magically" know about these extra imports. We will have to look into
the feasibility of this, however.
Still, maybe a vote on that issue wouldn't go amiss?

How to import scala class automatically in eclipse?

I use eclipse as my scala ide. And I know that in java I can use short cut by content assistent to import classes. So I do not need type in the whole class name. Just need to type the first several characters.
But in scala, I can not import classes automatically. Do I need to do some set up or it is just because scala plugin do not support this.
Ctrl + 1
on symbol works for me :)
There is Scala IDE for Eclipse however it is not very mature these days, however improving day by day. As far as I remember it can import automatically, or you can use Eclipse global fix import hotkey ctrl+shift+o.