本文整理汇总了Scala中scala.reflect.api.Universe类的典型用法代码示例。如果您正苦于以下问题:Scala Universe类的具体用法?Scala Universe怎么用?Scala Universe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Universe类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: InfoWithIndex
//设置package包名称以及导入依赖的类
package com.avsystem.scex.symboldsl
import com.avsystem.scex.util.MacroUtils
import scala.collection.immutable.{SortedSet, TreeSet}
import scala.reflect.api.Universe
trait SymbolInfoList[T] {
case class InfoWithIndex(info: SymbolInfo[T], index: Int)
val infoList: List[SymbolInfo[T]]
lazy val size = infoList.length
lazy val bySignaturesMap: Map[String, List[InfoWithIndex]] =
infoList.zipWithIndex.map {
case (info, index) => InfoWithIndex(info, index)
}.groupBy(_.info.memberSignature).map {
case (signature, infos) => (signature, infos.sortBy(_.index))
}.withDefaultValue(Nil)
def matchingInfos(u: Universe)(prefixTpe: u.Type, symbol: u.Symbol, implicitConv: Option[u.Tree]): List[InfoWithIndex] = {
val macroUtils = MacroUtils(u)
import macroUtils._
val signatures: List[String] =
withOverrides(symbol).map(memberSignature)
val implicitConvPath = implicitConv.map(path)
signatures.flatMap { signature =>
bySignaturesMap(signature).filter { case InfoWithIndex(symbolInfo, _) =>
signature == symbolInfo.memberSignature &&
prefixTpe <:< symbolInfo.typeInfo.typeIn(u) &&
implicitConvPath == symbolInfo.implicitConv
}
}
}
}
示例2: TypeWrapper
//设置package包名称以及导入依赖的类
package com.avsystem.scex.util
import java.util.Objects
import java.{lang => jl, util => ju}
import scala.collection.mutable.ListBuffer
import scala.reflect.api.Universe
class TypeWrapper(universeWithTpe: (u.type, u.Type) forSome {val u: Universe}) {
private val u = universeWithTpe._1
private val tpe = universeWithTpe._2.asInstanceOf[u.Type]
import u._
private def getSymbols(tpe: Type): List[Symbol] = {
val b = new ListBuffer[Symbol]
def symbolsIn(tpe: Type): Unit = tpe match {
case SingleType(pre, sym) =>
b += sym
symbolsIn(pre)
case TypeRef(pre, sym, args) =>
b += sym
symbolsIn(pre)
args.foreach(symbolsIn)
case _ =>
b += tpe.typeSymbol
}
symbolsIn(tpe)
b.result()
}
private val symbols = getSymbols(tpe)
override def equals(other: Any) = other match {
case other: TypeWrapper =>
(u eq other.u) && symbols == other.symbols && tpe =:= other.tpe.asInstanceOf[Type]
case _ => false
}
override val hashCode = Objects.hash(u, symbols)
}
object TypeWrapper {
def apply(u: Universe)(tpe: u.Type) = new TypeWrapper((u, tpe): (u.type, u.Type))
}