<commit_before>package dotty.tools.dotc
package transform

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer
import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core._
import dotty.tools.dotc.transform.TreeTransforms._

/** Removes selects that would be compiled into GetStatic
 * otherwise backend needs to be aware that some qualifiers need to be dropped.
 * Similar transformation seems to be performed by flatten in nsc
 *
 * @author <NAME>
 */
class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
  import ast.tpd._

  override def phaseName: String = "selectStatic"
  private val isPackage = FlagConjunction(PackageCreationFlags.bits)

  override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
    val sym = tree.symbol
    if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
      (
         ((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
         (sym is Flags.JavaStatic) ||
         (sym.maybeOwner is Flags.ImplClass) ||
         sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
        )
    )
      Block(List(tree.qualifier), ref(sym))
    else tree
  }
}<commit_msg>Fix SelectStatic: do not lift java statics to free idents.<commit_after>package dotty.tools.dotc
package transform

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer
import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core._
import dotty.tools.dotc.transform.TreeTransforms._

/** Removes selects that would be compiled into GetStatic
 * otherwise backend needs to be aware that some qualifiers need to be dropped.
 * Similar transformation seems to be performed by flatten in nsc
 *
 * @author <NAME>
 */
class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
  import ast.tpd._

  override def phaseName: String = "selectStatic"
  private val isPackage = FlagConjunction(PackageCreationFlags.bits)

  override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
    val sym = tree.symbol
    if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
      (
         ((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
         (sym is Flags.JavaStatic) ||
         (sym.maybeOwner is Flags.ImplClass) ||
         sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
        )
    )
      if (!tree.qualifier.symbol.is(JavaModule))
        Block(List(tree.qualifier), ref(sym))
      else tree
    else tree
  }
}
{'fraction_non_alphanumeric': 0.09857142857142857, 'fraction_numerical': 0.0, 'mean_word_length': 3.8968531468531467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '128867', 'n_tokens_mistral': 848, 'n_tokens_neox': 838, 'n_words': 211}