Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #129 from misto/issue/organize-imports-user-format…

…ting-preferences-1001073

Pass the user's formatting options to the refactoring library codegen.
  • Loading branch information...
commit be1fa94a683a1eaee40670a2eb72e68b27f64592 2 parents 6616140 + 6bea246
Mirko Stocker authored June 29, 2012
7  org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/OrganizeImportsAction.scala
@@ -9,9 +9,9 @@ import java.text.Collator
9 9
 import java.util.Comparator
10 10
 
11 11
 import org.eclipse.core.runtime.IProgressMonitor
  12
+import org.eclipse.jdt.core.IJavaElement
12 13
 import org.eclipse.jdt.core.compiler.IProblem
13 14
 import org.eclipse.jdt.core.search.{TypeNameMatch, SearchEngine, IJavaSearchConstants}
14  
-import org.eclipse.jdt.core.IJavaElement
15 15
 import org.eclipse.jdt.internal.corext.util.{TypeNameMatchCollector, QualifiedTypeNameHistory}
16 16
 import org.eclipse.jdt.internal.ui.actions.ActionMessages
17 17
 import org.eclipse.jdt.internal.ui.dialogs.MultiElementListSelectionDialog
@@ -20,8 +20,7 @@ import org.eclipse.jface.action.IAction
20 20
 import org.eclipse.jface.window.Window
21 21
 
22 22
 import scala.tools.eclipse.javaelements.{ScalaSourceFile, ScalaElement, LazyToplevelClass}
23  
-import scala.tools.eclipse.properties.OrganizeImportsPreferences._
24  
-import scala.tools.nsc.io.AbstractFile
  23
+import scala.tools.eclipse.properties.OrganizeImportsPreferences.{getWildcardImportsForProject, getOrganizeImportStrategy, getGroupsForProject, PreserveExistingGroups, ExpandImports, CollapseImports}
25 24
 import scala.tools.refactoring.implementations.{OrganizeImports, AddImportStatement}
26 25
 
27 26
 /**
@@ -216,7 +215,7 @@ class OrganizeImportsAction extends RefactoringAction with ActionWithNoWizard {
216 215
     
217 216
     lazy val compilationUnitHasProblems = file.getProblems != null && file.getProblems.exists(_.isError)
218 217
                   
219  
-    val refactoring = withCompiler( c => new OrganizeImports { val global = c })
  218
+    val refactoring = withCompiler( c => new OrganizeImports with FormattingOverrides { val global = c })
220 219
 
221 220
     override def checkInitialConditions(pm: IProgressMonitor) = {
222 221
       val status = super.checkInitialConditions(pm)
3  org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/ScalaIdeRefactoring.scala
@@ -42,7 +42,8 @@ import scala.tools.refactoring.MultiStageRefactoring
42 42
  * @param getName The displayable name of this refactoring.
43 43
  * @param file The file this refactoring started from.
44 44
  */
45  
-abstract class ScalaIdeRefactoring(val getName: String, val file: ScalaSourceFile, selectionStart: Int, selectionEnd: Int) extends LTKRefactoring {
  45
+abstract class ScalaIdeRefactoring(val getName: String, val file: ScalaSourceFile, selectionStart: Int, selectionEnd: Int) 
  46
+  extends LTKRefactoring with UserPreferencesFormatting {
46 47
       
47 48
   /**
48 49
    * Every refactoring subclass needs to provide a specific refactoring instance.
37  org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/UserPreferencesFormatting.scala
... ...
@@ -0,0 +1,37 @@
  1
+/*
  2
+ * Copyright 2012 LAMP/EPFL
  3
+ */
  4
+
  5
+package scala.tools.eclipse
  6
+package refactoring
  7
+
  8
+import scala.tools.eclipse.formatter.FormatterPreferences
  9
+import scala.tools.refactoring.Refactoring
  10
+
  11
+import scalariform.formatter.preferences.SpaceInsideParentheses
  12
+
  13
+/**
  14
+ * Enables passing the user's source formatting preferences to the refactoring library's
  15
+ * source code generation.
  16
+ */
  17
+trait UserPreferencesFormatting {
  18
+  this: ScalaIdeRefactoring =>
  19
+  
  20
+  /**
  21
+   * Refactoring actions should mix in this trait when creating a refactoring instance to
  22
+   * automatically pass the user's formatting preferences to the refactoring implementation.
  23
+   */
  24
+  trait FormattingOverrides {
  25
+    this: Refactoring =>
  26
+      
  27
+    override val spacingAroundMultipleImports: String = {
  28
+      for {
  29
+        javaProject <- Option(file.getJavaProject)
  30
+        val prefs = FormatterPreferences.getPreferences(javaProject)
  31
+        if  prefs(SpaceInsideParentheses)
  32
+      } yield " "
  33
+    } getOrElse ""
  34
+    
  35
+    // TODO: Create more overrides here and in the refactoring library.
  36
+  }
  37
+}

0 notes on commit be1fa94

Please sign in to comment.
Something went wrong with that request. Please try again.