Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yilinwei committed Dec 20, 2023
1 parent cf63cd3 commit 005a28b
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ private[focus] trait SelectParserBase extends ParserBase {
case None => FocusError.NotAConcreteClass(tpe.show).asResult
}

import scala.util.matching.Regex

private val tupleFieldPattern = "^_[0-9]+$".r

def getFieldType(fromType: TypeRepr, fieldName: String, pos: Position): FocusResult[TypeRepr] = {
def getFieldSymbol(fromTypeSymbol: Symbol): Symbol = {
// We need to do this to support tuples, because even though they conform as case classes in other respects,
// for some reason their field names (_1, _2, etc) have a space at the end, ie `_1 `.
val f: String => String =
if (fromType <:< TypeRepr.of[Tuple])
s => if (tupleFieldPattern.matches(fieldName)) s.trim else s
if (fromType <:< TypeRepr.of[Tuple] && tupleFieldPattern.matches(fieldName))
_.trim
else
identity
fromTypeSymbol.fieldMembers.find(s => f(s.name) == fieldName).getOrElse(Symbol.noSymbol)
Expand Down

0 comments on commit 005a28b

Please sign in to comment.