0

I want to know how to create nodes so that they instantiate classes in the code. Currently it's not able to recognize the nodes if I modify the code.

object Test{
def main(args: Array[String]) {
    val a= new Avi;
}

}

class Avi{}
class pra{}

In the AST I've created the following node and replaced the ValDef node for the parameter a

val newRhs = Select(New(Ident("pra")),newTermName("<init>"));
retTree = treeCopy.ValDef(vd, mods, name, tpt, newRhs);

I'm getting the following error

error: not found: value pra

I want to know if the way I've created the node is wrong and there is something else I need to do. I passing this retTree in the Transformer class to transform the AST. The type is not being found in the Typer phase of the compiler. Any help will be greatly appreciated.

  • Could you post an end-to-end example at say github? – Eugene Burmako Apr 22 '14 at 19:58
  • @EugeneBurmako I've added the files to this repo https://github.com/bnavarma/ScalaAst The Explugin.scala contains the plugin code and asdf.scala is the file i'm running it on. Although Avi is being called in asdf.scala I'm trying to call the pra class from the plugin. For this I've transformed the node but it's not picking up the symbol and it's checking for value pra instead and throwing an error. – Avinash Varma Apr 24 '14 at 10:57

1 Answers1

0

Change Ident("pra") to Ident(newTypeName("pra")).

Eugene Burmako
  • 13,028
  • 1
  • 46
  • 59