Set
에서 LinkedHashSet
의 인스턴스로 인스턴스화하는 메서드 호출을 다시 작성하는 스칼라 컴파일러 플러그인을 작성하려고합니다. 불행히도 나는 이것을 이미 수행하고있는 실례를 찾을 수 없다. 다음 코드는 no-symbol does not have an owner
와 함께 실패메서드 호출을 다시 작성하기위한 스칼라 컴파일러 플러그인
object DemoErasureComponent extends PluginComponent with TypingTransformers with Transform {
val global: DemoPlugin.this.global.type = DemoPlugin.this.global
import global._
override val runsAfter = List("erasure")
val phaseName = "rewrite-sets"
def newTransformer(unit: CompilationUnit) = new SetTransformer(unit)
class SetTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
override def transform(tree: Tree): Tree = tree match {
case [email protected]([email protected]([email protected](predef, set), name), args) if name.toString == "Set" =>
localTyper.typed(treeCopy.Apply(tree, Ident(newTermName("LinkedHashSet")), args))
case t => super.transform(tree)
}
}
, 나는 지금까지 이러한 리소스를 발견했습니다
- Scalaxy 컴파일러 플러그인 : https://github.com/ochafik/Scalaxy
- 복서 컴파일러 플러그인 예 : https://github.com/retronym/boxer
- 스칼라 컴파일러 내에 오래된 컴파일러 플러그인 : http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/docs/examples/plugintemplate/src/plugintemplate/TemplateTransformComponent.scala
을 줄이 대해서 typeof [scala.collection.immutable.LinkedHashSet를' ] .typeSymbol'은 다음과 같이 실패합니다 :'[error (main/compile : compile) scala.ScalaReflectionException : class demo.DemoErasureComponent in compiler mirror not found. '... 그러나 이것은 작동하는 것 같습니다 :'rootMirror.getRequiredClass ("scala .collection.mutable.Set ")'... 내가 뭘 잘못하고 있는지 생각해?나는'typeOf'가 연속체 나 내가 체크 한 다른 컴파일러 플러그인에서 사용되지 않는다는 것을 알아 차렸다. – gbasler