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

package scala.tools.eclipse.javaelements

import scala.concurrent.SyncVar
import scala.reflect.NameTransformer

import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.jdt.internal.compiler.env
import org.eclipse.jdt.core.{
  CompletionContext, CompletionProposal, CompletionRequestor, ITypeRoot, JavaCore, WorkingCopyOwner }
import org.eclipse.jdt.core.compiler.CharOperation
import org.eclipse.jdt.internal.codeassist.{ InternalCompletionContext, InternalCompletionProposal }
import org.eclipse.jdt.internal.core.JavaProject
import org.eclipse.jdt.ui.text.java.CompletionProposalCollector
import ch.epfl.lamp.fjbg.JType

import scala.tools.nsc.symtab.Flags

import scala.tools.eclipse.ScalaWordFinder
import scala.tools.eclipse.util.ReflectionUtils

class ScalaCompletionEngine {
  private var debug = true
	
  def complete
    (cu : env.ICompilationUnit, unitToSkip : env.ICompilationUnit,
     position : Int,  requestor : CompletionRequestor, owner : WorkingCopyOwner, typeRoot : ITypeRoot,
     monitor : IProgressMonitor) {

    import InternalCompletionProposalUtils._

    val scu = cu.asInstanceOf[ScalaCompilationUnit]
    val javaProject = scu.getJavaProject.asInstanceOf[JavaProject]
    val environment = javaProject.newSearchableNameEnvironment(owner)
    
    scu.withCompilerResult({ crh =>
    
      import crh._
      import compiler.{ encodedJavaType, mapModifiers, mapTypeName, mapParamTypeName, mapParamTypePackageName, nme }
      
      val pos = compiler.rangePos(sourceFile, position, position, position)
      
      val typed = new SyncVar[Either[compiler.Tree, Throwable]]
      compiler.askTypeAt(pos, typed)
      val t1 = typed.get.left.toOption
      val t0 = t1 match {
        case Some(tt : compiler.TypeTree) => Some(tt.original)
        case t => t 
      }
      
      val completed = new SyncVar[Either[List[compiler.Member], Throwable]]
      val (start, end) = t0 match {
        case Some(s@compiler.Select(qualifier, name)) if qualifier.pos.isDefined =>
          val cpos0 = qualifier.pos.endOrPoint 
          val cpos = compiler.rangePos(sourceFile, cpos0, cpos0, cpos0)
          compiler.askTypeCompletion(cpos, completed)
          (s.pos.point min s.pos.endOrPoint, s.pos.endOrPoint)
        case Some(i@compiler.Import(expr, selectors)) =>
          def qual(tree : compiler.Tree): compiler.Tree = tree.symbol.info match {
            case compiler.analyzer.ImportType(expr) => expr
            case _ => tree
          }
          val cpos0 = qual(i).pos.endOrPoint
          val cpos = compiler.rangePos(sourceFile, cpos0, cpos0, cpos0)
          compiler.askTypeCompletion(cpos, completed)
          ((cpos0 + 1) min position, position)
        case _ =>
          val region = ScalaWordFinder.findCompletionPoint(scu.getBuffer, position)
          val cpos = if (region == null) pos else {
            val start = region.getOffset
            compiler.rangePos(sourceFile, start, start, start)
          }
          compiler.askScopeCompletion(cpos, completed)
          if (region == null)<commit_msg>Select with point-ranged qualifier is not really a select. Request scopeMembers in this case<commit_after>/*
 * Copyright 2005-2010 LAMP/EPFL
 */
// $Id$

package scala.tools.eclipse.javaelements

import scala.concurrent.SyncVar
import scala.reflect.NameTransformer

import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.jdt.internal.compiler.env
import org.eclipse.jdt.core.{
  CompletionContext, CompletionProposal, CompletionRequestor, ITypeRoot, JavaCore, WorkingCopyOwner }
import org.eclipse.jdt.core.compiler.CharOperation
import org.eclipse.jdt.internal.codeassist.{ InternalCompletionContext, InternalCompletionProposal }
import org.eclipse.jdt.internal.core.JavaProject
import org.eclipse.jdt.ui.text.java.CompletionProposalCollector
import ch.epfl.lamp.fjbg.JType

import scala.tools.nsc.symtab.Flags

import scala.tools.eclipse.ScalaWordFinder
import scala.tools.eclipse.util.ReflectionUtils

class ScalaCompletionEngine {
  private var debug = true
	
  def complete
    (cu : env.ICompilationUnit, unitToSkip : env.ICompilationUnit,
     position : Int,  requestor : CompletionRequestor, owner : WorkingCopyOwner, typeRoot : ITypeRoot,
     monitor : IProgressMonitor) {

    import InternalCompletionProposalUtils._

    val scu = cu.asInstanceOf[ScalaCompilationUnit]
    val javaProject = scu.getJavaProject.asInstanceOf[JavaProject]
    val environment = javaProject.newSearchableNameEnvironment(owner)
    
    scu.withCompilerResult({ crh =>
    
      import crh._
      import compiler.{ encodedJavaType, mapModifiers, mapTypeName, mapParamTypeName, mapParamTypePackageName, nme }
      
      val pos = compiler.rangePos(sourceFile, position, position, position)
      
      val typed = new SyncVar[Either[compiler.Tree, Throwable]]
      compiler.askTypeAt(pos, typed)
      val t1 = typed.get.left.toOption
      val t0 = t1 match {
        case Some(tt : compiler.TypeTree) => Some(tt.original)
        case t => t 
      }
      
      val completed = new SyncVar[Either[List[compiler.Member], Throwable]]
      val (start, end) = t0 match {
        case Some(s@compiler.Select(qualifier, name)) if qualifier.pos.isDefined && qualifier.pos.isRange =>
          val cpos0 = qualifier.pos.endOrPoint 
          val cpos = compiler.rangePos(sourceFile, cpos0, cpos0, cpos0)
          compiler.askTypeCompletion(cpos, completed)
          (s.pos.point min s.pos.endOrPoint, s.pos.endOrPoint)
        case Some(i@compiler.Import(expr, selectors)) =>
          def qual(tree : compiler.Tree): compiler.Tree = tree.symbol.info match {
            case compiler.analyzer.ImportType(expr) => expr
            case _ => tree
          }
          val cpos0 = qual(i).pos.endOrPoint
          val cpos = compiler.rangePos(sourceFile, cpos0, cpos0, cpos0)
          compiler.askTypeCompletion(cpos, completed)
          ((cpos0 + 1) min position, position)
        case _ =>
          val region = ScalaWordFinder.findCompletionPoint(scu.getBuffer, position)
          val cpos = if (region == null) pos else {
            val start = region.getOffset
            compiler.rangePos(sourceFile, start, start, start)
          }
          compiler.askScopeCompletion(cpos, completed)
          if (region == null)
{'fraction_non_alphanumeric': 0.09284818067754078, 'fraction_numerical': 0.006900878293601004, 'mean_word_length': 3.22317880794702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '5835894', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1878, 'n_words': 407}