<commit_before>package org.jetbrains.sbt
package annotator

import com.intellij.lang.annotation.{AnnotationHolder, Annotator}
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScInfixExpr, ScReferenceExpression}
import org.jetbrains.plugins.scala.lang.psi.impl.base.ScLiteralImpl
import org.jetbrains.sbt.annotator.quickfix.{SbtRefreshProjectQuickFix, SbtUpdateResolverIndexesQuickFix}
import org.jetbrains.sbt.resolvers.{SbtResolverIndexesManager, SbtResolverUtils}


/**
 * @author <NAME>
 * @since 8/4/14.
 */
class SbtDependencyAnnotator extends Annotator {

  private case class ArtifactInfo(group: String, artifact: String, version: String)

  def annotate(element: PsiElement, holder: AnnotationHolder) {

    if (ScalaPsiUtil.fileContext(element).getFileType.getName != Sbt.Name) return

    def isValidOperation(op: ScReferenceExpression) = op.getText == "%" || op.getText == "%%"

    def extractInfo(from: PsiElement): Option[ArtifactInfo] =
      for {
        ScInfixExpr(lexpr, _, rOp) <- Option(from)
        ScInfixExpr(llOp, _, lrOp) <- Option(lexpr)
        ScLiteralImpl.string(version)  <- Option(rOp)
        ScLiteralImpl.string(group)    <- Option(llOp)
        ScLiteralImpl.string(artifact) <- Option(lrOp)
      } yield ArtifactInfo(group, artifact, version)
<commit_msg>= fixed 'good code red' for '%%' deps<commit_after>package org.jetbrains.sbt
package annotator

import com.intellij.facet.FacetManager
import com.intellij.lang.annotation.{AnnotationHolder, Annotator}
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.config.ScalaFacet
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScInfixExpr, ScReferenceExpression}
import org.jetbrains.plugins.scala.lang.psi.impl.base.ScLiteralImpl
import org.jetbrains.sbt.annotator.quickfix.{SbtRefreshProjectQuickFix, SbtUpdateResolverIndexesQuickFix}
import org.jetbrains.sbt.resolvers.{SbtResolverIndexesManager, SbtResolverUtils}

import scala.util.Try


/**
 * @author <NAME>
 * @since 8/4/14.
 */
class SbtDependencyAnnotator extends Annotator {

  private case class ArtifactInfo(group: String, artifact: String, version: String)

  def annotate(element: PsiElement, holder: AnnotationHolder) {

    if (ScalaPsiUtil.fileContext(element).getFileType.getName != Sbt.Name) return

    val scalaFacet = Try(FacetManager.getInstance(ModuleUtilCore.findModuleForPsiElement(element))
                                     .getFacetByType(ScalaFacet.Id)).toOption
    val scalaVersion = scalaFacet.flatMap { facet =>
      facet.version.split('.').toSeq.map(Integer.parseInt) match {
        case Seq(major, minor, rest@_*) =>
          if (major == 2 && minor < 10) Some(facet.version) else Some(s"$major.$minor")
        case _ => None
      }
    }

    def isValidOperation(op: ScReferenceExpression) = op.getText == "%" || op.getText == "%%"

    def extractInfo(from: PsiElement): Option[ArtifactInfo] =
      for {
        ScInfixExpr(lexpr, _, rOp)     <- Option(from)
        ScInfixExpr(llOp, oper, lrOp)  <- Option(lexpr)
        ScLiteralImpl.string(version)  <- Option(rOp)
        ScLiteralImpl.string(group)    <- Option(llOp)
        ScLiteralImpl.string(artifact) <- Option(lrOp)
        appendScalaVersion = oper.getText == "%%"
      } yield {
        if (appendScalaVersion && scalaVersion.isDefined)
          ArtifactInfo(group, artifact + "_" + scalaVersion.get, version)
        else
          ArtifactInfo(group, artifact, version)
      }

{'fraction_non_alphanumeric': 0.11767810026385224, 'fraction_numerical': 0.0029023746701846965, 'mean_word_length': 4.088590604026845, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4942386', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1194, 'n_words': 201}