<commit_before>package org.jetbrains.plugins.scala.codeInspection.unusedInspections


import annotator.importsTracker.ImportTracker
import collection.mutable.{HashSet, Set}
import com.intellij.codeHighlighting.TextEditorHighlightingPass
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
import com.intellij.codeInsight.daemon.impl.{HighlightInfo, UpdateHighlightersUtil, HighlightInfoFilter, AnnotationHolderImpl}
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.Annotation
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.psi.util.{PsiTreeUtil, PsiUtilBase}
import com.intellij.psi.{PsiElement, PsiFile}
import java.util.ArrayList
import lang.lexer.ScalaTokenTypes
import lang.psi.api.ScalaFile
import lang.psi.api.toplevel.imports.usages.{ImportWildcardSelectorUsed, ImportSelectorUsed, ImportExprUsed, ImportUsed}
import lang.psi.{ScalaPsiElementImpl, ScalaPsiElement}
/**
 * User: <NAME>
 * Date: 15.06.2009
 */

class ScalaUnusedImportPass(file: PsiFile, editor: Editor) extends TextEditorHighlightingPass(file.getProject, editor.getDocument) {
  private var unusedImports: Set[ImportUsed] = new HashSet[ImportUsed]

  def doApplyInformationToEditor: Unit = {
    val annotationHolder = new AnnotationHolderImpl()
    val annotations: Seq[Annotation] = unusedImports.filter({
      imp: ImportUsed => {
        imp match {
          case expr: ImportExprUsed if !PsiTreeUtil.hasErrorElements(expr.expr)=> true
          case sel: ImportSelectorUsed => true
          case wild: ImportWildcardSelectorUsed if wild.e.selectors.length > 0 => true
          case wild: ImportWildcardSelectorUsed if !PsiTreeUtil.hasErrorElements(wild.e) => true
          case _ => false
        }
      }
    }).map({
      imp: ImportUsed => {
        //todo: add fix action
        val psi: PsiElement = imp match {
          case expr: ImportExprUsed if !PsiTreeUtil.hasErrorElements(expr.expr)=> expr.expr.getParent
          case sel: ImportSelectorUsed => sel.sel
          case wild: ImportWildcardSelectorUsed if wild.e.selectors.length > 0 => wild.e.wildcardElement match {case Some(p) => p}
          case wild: ImportWildcardSelectorUsed if !PsiTreeUtil.hasErrorElements(wild.e) => wild.e.getParent
        }
        val annotation: Annotation = annotationHolder.createWarningAnnotation(psi, "Unused import statement")
        annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL)
        annotation
      }
    }).toSeq<commit_msg>property call -> pattern matching for case classes<commit_after>package org.jetbrains.plugins.scala.codeInspection.unusedInspections


import annotator.importsTracker.ImportTracker
import collection.mutable.{HashSet, Set}
import com.intellij.codeHighlighting.TextEditorHighlightingPass
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
import com.intellij.codeInsight.daemon.impl.{HighlightInfo, UpdateHighlightersUtil, HighlightInfoFilter, AnnotationHolderImpl}
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.Annotation
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.psi.util.{PsiTreeUtil, PsiUtilBase}
import com.intellij.psi.{PsiElement, PsiFile}
import java.util.ArrayList
import lang.lexer.ScalaTokenTypes
import lang.psi.api.ScalaFile
import lang.psi.api.toplevel.imports.usages.{ImportWildcardSelectorUsed, ImportSelectorUsed, ImportExprUsed, ImportUsed}
import lang.psi.{ScalaPsiElementImpl, ScalaPsiElement}
/**
 * User: <NAME>
 * Date: 15.06.2009
 */

class ScalaUnusedImportPass(file: PsiFile, editor: Editor) extends TextEditorHighlightingPass(file.getProject, editor.getDocument) {
  private var unusedImports: Set[ImportUsed] = new HashSet[ImportUsed]

  def doApplyInformationToEditor: Unit = {
    val annotationHolder = new AnnotationHolderImpl()
    val annotations: Seq[Annotation] = unusedImports.filter({
      imp: ImportUsed => {
        imp match {
          case ImportExprUsed(expr) if !PsiTreeUtil.hasErrorElements(expr)=> true
          case ImportSelectorUsed(_) => true
          case ImportWildcardSelectorUsed(e) if e.selectors.length > 0 => true
          case ImportWildcardSelectorUsed(e) if !PsiTreeUtil.hasErrorElements(e) => true
          case _ => false
        }
      }
    }).map({
      imp: ImportUsed => {
        //todo: add fix action
        val psi: PsiElement = imp match {
          case ImportExprUsed(expr) if !PsiTreeUtil.hasErrorElements(expr)=> expr.getParent
          case ImportSelectorUsed(sel) => sel
          case ImportWildcardSelectorUsed(e) if e.selectors.length > 0 => e.wildcardElement match {case Some(p) => p}
          case ImportWildcardSelectorUsed(e) if !PsiTreeUtil.hasErrorElements(e) => e.getParent
        }
        val annotation: Annotation = annotationHolder.createWarningAnnotation(psi, "Unused import statement")
        annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL)
        annotation
      }
    }).toSeq
{'fraction_non_alphanumeric': 0.09126365054602184, 'fraction_numerical': 0.0039001560062402497, 'mean_word_length': 4.359456635318704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '3441534', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1478, 'n_words': 299}