Skip to content

Commit

Permalink
Scala: support Enums in dependency inference (pantsbuild#19588)
Browse files Browse the repository at this point in the history
Dependency inference for Scala does not currently detect Enum types.
This PR fixes that. The newer Scalameta release also adds support for
the `fewerBraces` Syntax in Scala 3.3.0.

---------

Co-authored-by: Matthias Berndt <matthias.berndt@ttmzero.com>
  • Loading branch information
2 people authored and tdyas committed Aug 13, 2023
1 parent 3ff9998 commit 7222925
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 265 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/jvm/org/scalameta/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jvm_artifact(
name="scalameta",
group="org.scalameta",
artifact="scalameta_2.13",
version="4.4.30",
version="4.8.7",
packages=["scala.meta.**"],
resolve="scala_parser_dev",
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import io.circe.syntax._

import scala.meta._
import scala.meta.transversers.Traverser
import scala.meta.Stat.{WithMods, WithCtor, WithTemplate}
import scala.meta.Tree.WithTParamClause

import scala.collection.SortedSet
import scala.collection.mutable.{ArrayBuffer, HashMap, HashSet}
Expand Down Expand Up @@ -38,8 +40,6 @@ object Analysis {
}

case class ProvidedSymbol(
sawClass: Boolean,
sawTrait: Boolean,
sawObject: Boolean,
recursive: Boolean
)
Expand Down Expand Up @@ -119,8 +119,6 @@ class SourceAnalysisTraverser extends Traverser {

def recordProvidedName(
symbolName: String,
sawClass: Boolean = false,
sawTrait: Boolean = false,
sawObject: Boolean = false,
recursive: Boolean = false
): Unit = {
Expand All @@ -134,16 +132,12 @@ class SourceAnalysisTraverser extends Traverser {
if (providedSymbols.contains(symbolName)) {
val existingSymbol = providedSymbols(symbolName)
val newSymbol = ProvidedSymbol(
sawClass = existingSymbol.sawClass || sawClass,
sawTrait = existingSymbol.sawTrait || sawTrait,
sawObject = existingSymbol.sawObject || sawObject,
recursive = existingSymbol.recursive || recursive
)
providedSymbols(symbolName) = newSymbol
} else {
providedSymbols(symbolName) = ProvidedSymbol(
sawClass = sawClass,
sawTrait = sawTrait,
sawObject = sawObject,
recursive = recursive
)
Expand Down Expand Up @@ -237,23 +231,19 @@ class SourceAnalysisTraverser extends Traverser {
)
}

case Defn.Class(mods, nameNode, tparams, ctor, templ) => {
visitMods(mods)
val name = extractName(nameNode)
recordProvidedName(name, sawClass = true)
apply(tparams)
apply(ctor)
visitTemplate(templ, name)
}

case Defn.Trait(mods, nameNode, tparams, ctor, templ) => {
case defn: Member.Type with WithMods with WithTParamClause with WithCtor with WithTemplate => // traits, enums and classes
visitMods(defn.mods)
val name = extractName(defn.name)
recordProvidedName(name)
apply(defn.tparamClause)
apply(defn.ctor)
visitTemplate(defn.templ, name)
case Defn.EnumCase.After_4_6_0(mods, nameNode, tparamClause, ctor, _) =>
visitMods(mods)
val name = extractName(nameNode)
recordProvidedName(name, sawTrait = true)
apply(tparams)
recordProvidedName(name)
apply(tparamClause)
apply(ctor)
visitTemplate(templ, name)
}

case Defn.Object(mods, nameNode, templ) => {
visitMods(mods)
Expand Down
Loading

0 comments on commit 7222925

Please sign in to comment.