package org.scalaide.refactoring.internal

import org.scalaide.core.internal.formatter.FormatterPreferences
import scala.tools.refactoring.Refactoring

import scalariform.formatter.preferences.SpaceInsideParentheses

/**
 * Enables passing the user's source formatting preferences to the refactoring library's
 * source code generation.
 */
trait UserPreferencesFormatting {
  this: ScalaIdeRefactoring =>

  /**
   * Refactoring actions should mix in this trait when creating a refactoring instance to
   * automatically pass the user's formatting preferences to the refactoring implementation.
   */
  trait FormattingOverrides {
    this: Refactoring =>

    override val spacingAroundMultipleImports: String = {
      for {
        javaProject <- Option(file.getJavaProject)
        prefs = FormatterPreferences.getPreferences(javaProject)
        if  prefs(SpaceInsideParentheses)
      } yield " "
    } getOrElse ""

    // TODO: Create more overrides here and in the refactoring library.
  }
}

package org.scalaide.refactoring.internal

import org.scalaide.core.internal.formatter.FormatterPreferences
import scala.tools.refactoring.Refactoring

import scalariform.formatter.preferences.SpaceInsideParentheses

/**
 * Enables passing the user's source formatting preferences to the refactoring library's
 * source code generation.
 */
trait UserPreferencesFormatting {
  this: ScalaIdeRefactoring =>

  /**
   * Refactoring actions should mix in this trait when creating a refactoring instance to
   * automatically pass the user's formatting preferences to the refactoring implementation.
   */
  trait FormattingOverrides {
    this: Refactoring =>

    override val spacingAroundMultipleImports: String = " "

    // TODO: Create more overrides here and in the refactoring library.
  }
}

Make organize imports format consistent with scalariform
Make organize imports format consistent with scalariform

We used to pass the IDE's SpaceInsideParentheses setting to scala-refactoring to control the spaces inside the braces of multiple imports, like this:

import a.b.{ c, d }

Unfortunately, in scalariform SpaceInsideParentheses only affects the space around regular parenthesis, and there is no setting for the spaces in imports. So to make the code generated by scala-refactoring consistent with the formatting of scalariform, we always print a space inside multiple imports.

Fixes scala-ide/scala-refactoring#81.