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

package scala.tools.eclipse;

import org.eclipse.jdt.core.{ IJavaProject, IJavaElement }
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.javaeditor.{ IClassFileEditorInput, ICompilationUnitDocumentProvider, JavaElementHyperlinkDetector }
import org.eclipse.jdt.internal.ui.text.ContentAssistPreference
import org.eclipse.jdt.internal.ui.text.java.{ JavaAutoIndentStrategy, JavaStringAutoIndentStrategy, SmartSemicolonAutoEditStrategy } 
import org.eclipse.jdt.internal.ui.text.java.hover.{ AbstractJavaEditorTextHover, BestMatchHover }
import org.eclipse.jdt.internal.ui.text.javadoc.JavaDocAutoIndentStrategy
import org.eclipse.jdt.ui.text.{ JavaSourceViewerConfiguration, IJavaPartitions }
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.jface.text.{ IAutoEditStrategy, IDocument, ITextHover }
import org.eclipse.jface.text.contentassist.ContentAssistant
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector
import org.eclipse.jface.text.presentation.PresentationReconciler
import org.eclipse.jface.text.source.ISourceViewer
import org.eclipse.ui.texteditor.{ HyperlinkDetectorDescriptor, ITextEditor }
import org.eclipse.swt.SWT

import scala.tools.eclipse.ui.{ JdtPreferenceProvider, ScalaAutoIndentStrategy, ScalaIndenter }
import scala.tools.eclipse.util.ReflectionUtils

class ScalaSourceViewerConfiguration(store : IPreferenceStore, editor : ITextEditor) 
  extends JavaSourceViewerConfiguration(JavaPlugin.getDefault.getJavaTextTools.getColorManager, store, editor, IJavaPartitions.JAVA_PARTITIONING) {
  
  import ScalaSourceViewerConfigurationUtils._
  
  private val codeScanner = new ScalaCodeScanner(getColorManager, store);
  
  override def getPresentationReconciler(sv : ISourceViewer) = {
    val reconciler = super.getPresentationReconciler(sv).asInstanceOf[PresentationReconciler]
    val dr = new ScalaDamagerRepairer(codeScanner)
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler
  }

  override def getConfiguredTextHoverStateMasks(sourceViewer : ISourceViewer, contentType : String) : Array[Int] =
    (Set.empty ++ super.getConfiguredTextHoverStateMasks(sourceViewer, contentType) ++ Seq(SWT.MOD3, SWT.MOD1|SWT.MOD3)).toArray
  
  override def getTextHover(sv : ISourceViewer, contentType : String, stateMask : Int) = {
    val javaHover = super.getTextHover(sv, contentType, stateMask)
    
    def addHover(hover : AbstractJavaEditorTextHover) = {
      hover.setEditor(editor)
      javaHover match {
        case bmh : BestMatchHover => addTextHover(bmh, hover) ; bmh
        case _ => hover
      }
    }
    
    stateMask match {
      case SWT.MOD3 => addHover(new ScalaDebugHover)
      case _ => javaHover
    }
  }
  
  override def getHyperlinkDetectors(sv : ISourceViewer) = {
    val shd = new ScalaHyperlinkDetector
    shd.setContext(editor)
    super.getHyperlinkDetectors(sv).map(d =>
      if (getHyperlinkDescriptor(d).getId == "org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector")
        shd
      else
        d)
  }
  
  
  /**
   * Direct copy+paste of getProject from SourceViewerConfiguration.
   * <grumble>No need for this to be _private_ in the parent class</grumble>
   */
  def getProject : IJavaProject = {
    if (editor == null)
      return null;

    val input = editor.getEditorInput();
    val provider = editor.getDocumentProvider();
    
    val element = if (provider.isInstanceOf[ICompilationUnitDocumentProvider]) {
      provider.asInstanceOf[ICompilationUnitDocumentProvider].getWorkingCopy(input)<commit_msg>Fixed #3012. No review.<commit_after>/*
 * Copyright 2005-2010 LAMP/EPFL
 */
// $Id$

package scala.tools.eclipse;

import org.eclipse.jdt.core.{ IJavaProject, IJavaElement }
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.javaeditor.{ IClassFileEditorInput, ICompilationUnitDocumentProvider, JavaElementHyperlinkDetector }
import org.eclipse.jdt.internal.ui.text.ContentAssistPreference
import org.eclipse.jdt.internal.ui.text.java.{ JavaAutoIndentStrategy, JavaStringAutoIndentStrategy, SmartSemicolonAutoEditStrategy } 
import org.eclipse.jdt.internal.ui.text.java.hover.{ AbstractJavaEditorTextHover, BestMatchHover }
import org.eclipse.jdt.internal.ui.text.javadoc.JavaDocAutoIndentStrategy
import org.eclipse.jdt.ui.text.{ JavaSourceViewerConfiguration, IJavaPartitions }
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.jface.text.{ IAutoEditStrategy, IDocument, ITextHover }
import org.eclipse.jface.text.contentassist.ContentAssistant
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector
import org.eclipse.jface.text.presentation.PresentationReconciler
import org.eclipse.jface.text.source.ISourceViewer
import org.eclipse.ui.texteditor.{ HyperlinkDetectorDescriptor, ITextEditor }
import org.eclipse.swt.SWT

import scala.tools.eclipse.ui.{ JdtPreferenceProvider, ScalaAutoIndentStrategy, ScalaIndenter }
import scala.tools.eclipse.util.ReflectionUtils

class ScalaSourceViewerConfiguration(store : IPreferenceStore, editor : ITextEditor) 
  extends JavaSourceViewerConfiguration(JavaPlugin.getDefault.getJavaTextTools.getColorManager, store, editor, IJavaPartitions.JAVA_PARTITIONING) {
  
  import ScalaSourceViewerConfigurationUtils._
  
  private val codeScanner = new ScalaCodeScanner(getColorManager, store);
  
  override def getPresentationReconciler(sv : ISourceViewer) = {
    val reconciler = super.getPresentationReconciler(sv).asInstanceOf[PresentationReconciler]
    val dr = new ScalaDamagerRepairer(codeScanner)
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler
  }

  override def getConfiguredTextHoverStateMasks(sourceViewer : ISourceViewer, contentType : String) : Array[Int] =
    (Set.empty ++ super.getConfiguredTextHoverStateMasks(sourceViewer, contentType) ++ Seq(SWT.MOD3, SWT.MOD1|SWT.MOD3)).toArray
  
  override def getTextHover(sv : ISourceViewer, contentType : String, stateMask : Int) = {
    val javaHover = super.getTextHover(sv, contentType, stateMask)
    
    def addHover(hover : AbstractJavaEditorTextHover) = {
      hover.setEditor(editor)
      javaHover match {
        case bmh : BestMatchHover => addTextHover(bmh, hover) ; bmh
        case _ => hover
      }
    }
    
    stateMask match {
      case SWT.MOD3 => addHover(new ScalaDebugHover)
      case _ => javaHover
    }
  }
  
  override def getHyperlinkDetectors(sv : ISourceViewer) = {
    val javaDetectors = super.getHyperlinkDetectors(sv)
    if (javaDetectors == null)
      null
    else {
      val shd = new ScalaHyperlinkDetector
      shd.setContext(editor)
      javaDetectors.map(d =>
        if (getHyperlinkDescriptor(d).getId == "org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector")
          shd
        else
          d)
    }
  }
  
  /**
   * Direct copy+paste of getProject from SourceViewerConfiguration.
   * <grumble>No need for this to be _private_ in the parent class</grumble>
   */
  def getProject : IJavaProject = {
    if (editor == null)
      return null;

    val input = editor.getEditorInput();
    val provider = editor.getDocumentProvider();
    
    val element = if (provider.isInstanceOf[ICompilationUnitDocumentProvider]) {
      provider.asInstanceOf[ICompilationUnitDocumentProvider].getWorkingCopy(input)
{'fraction_non_alphanumeric': 0.09033112582781457, 'fraction_numerical': 0.003708609271523179, 'mean_word_length': 4.681715575620768, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '5146982', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2372, 'n_words': 402}