<commit_before>/*
 * Copyright 2005-2010 LAMP/EPFL
 */
// $Id$

package scala.tools.eclipse.ui


import org.eclipse.core.runtime.Assert
import org.eclipse.jface.text.BadLocationException
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.IRegion
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.text.DocumentCharacterIterator
import org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner
import org.eclipse.jdt.internal.ui.text.Symbols
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil
import org.eclipse.jdt.ui.PreferenceConstants
import java.lang.Math.min
import scala.collection.mutable.Map
import scala.annotation.tailrec
import scala.tools.eclipse.ScalaPlugin
import scala.tools.eclipse.formatter.FormatterPreferences

// TODO Move this out into a new file
trait PreferenceProvider {
  private val preferences = Map.empty[String, String]

  def updateCache : Unit
  
  def put(key : String, value : String) {
    preferences(key) = value
  }
  
  def get(key : String) : String = {
    preferences(key)
  }
  
  def getBoolean(key : String) : Boolean = {
    get(key).toBoolean
  }
  
  def getInt(key : String) : Int = {
    get(key).toInt
  }
}


// TODO Move this out into a new file
class JdtPreferenceProvider(val project : IJavaProject) extends PreferenceProvider {
  private def preferenceStore = JavaPlugin.getDefault().getCombinedPreferenceStore()
  
  def updateCache : Unit = {
    put(PreferenceConstants.EDITOR_CLOSE_BRACES, 
        preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACES).toString)
    put(PreferenceConstants.EDITOR_SMART_TAB, 
        preferenceStore.getBoolean(PreferenceConstants.EDITOR_SMART_TAB).toString)

    // TODO: Matt -- use better pref lookup when merged with formatter-preferences-page branch        
    val scalaPrefs = ScalaPlugin.plugin.getPreferenceStore
    val key = FormatterPreferences.PREFIX + scalariform.formatter.preferences.IndentSpaces.key
    val indent = scalaPrefs.getInt(key)
    put(ScalaIndenter.TAB_SIZE, indent.toString)
    put(ScalaIndenter.INDENT_SIZE, indent.toString)
    
    def populateFromProject(key : String) = {<commit_msg>Clean-up formatter preference access<commit_after>/*
 * Copyright 2005-2010 LAMP/EPFL
 */
// $Id$

package scala.tools.eclipse.ui


import org.eclipse.core.runtime.Assert
import org.eclipse.jface.text.BadLocationException
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.IRegion
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.text.DocumentCharacterIterator
import org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner
import org.eclipse.jdt.internal.ui.text.Symbols
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil
import org.eclipse.jdt.ui.PreferenceConstants
import java.lang.Math.min
import scala.collection.mutable.Map
import scala.annotation.tailrec
import scala.tools.eclipse.ScalaPlugin
import scala.tools.eclipse.formatter.FormatterPreferences._
import scalariform.formatter.preferences.IndentSpaces

// TODO Move this out into a new file
trait PreferenceProvider {
  private val preferences = Map.empty[String, String]

  def updateCache : Unit
  
  def put(key : String, value : String) {
    preferences(key) = value
  }
  
  def get(key : String) : String = {
    preferences(key)
  }
  
  def getBoolean(key : String) : Boolean = {
    get(key).toBoolean
  }
  
  def getInt(key : String) : Int = {
    get(key).toInt
  }
}


// TODO Move this out into a new file
class JdtPreferenceProvider(val project : IJavaProject) extends PreferenceProvider {
  private def preferenceStore = JavaPlugin.getDefault().getCombinedPreferenceStore()
  
  def updateCache : Unit = {
    put(PreferenceConstants.EDITOR_CLOSE_BRACES, 
        preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACES).toString)
    put(PreferenceConstants.EDITOR_SMART_TAB, 
        preferenceStore.getBoolean(PreferenceConstants.EDITOR_SMART_TAB).toString)

    val scalaPrefs = ScalaPlugin.plugin.getPreferenceStore
    val indent = scalaPrefs(IndentSpaces)
    put(ScalaIndenter.TAB_SIZE, indent.toString)
    put(ScalaIndenter.INDENT_SIZE, indent.toString)
    
    def populateFromProject(key : String) = {
{'fraction_non_alphanumeric': 0.09160977758203039, 'fraction_numerical': 0.0035234529839242457, 'mean_word_length': 4.4855072463768115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '259261', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1404, 'n_words': 262}