Unfortunately its not straightforward. Try searching for emails from Kevin Wright about plugins, you can run typers directly but there are other issues that follow.
Ah - what does this mean, exactly? Never call it within what context?
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
On 24 May 2011, at 17:04, Kevin Wright wrote:Ah - what does this mean, exactly? Never call it within what context?
> If you're willing to never call your generated method, then you can happily run the thing after typer.
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
Hmm - does that mean the file that's currently being compiled? Or all code within the entire codebase?
If the former, I might just be able to get away with it...
Thanks Kevin, is this an accurate summary of the discussion:
- it's extremely hard to generate new code in a compiler plugin
- using TreeDSL will definitely(?) or maybe(?) work if the code
calling the method is in a different module
- in the future a plugin will allow this (any idea on ETA?)
since i can override something on a trait, it doesn't matter to me
code completion isn't as important to me
create a trait that when extended by a class, automatically generates a val
on that class that returns an array of the default constructor
parameters used to instantiate the class.
for example:
trait AutoArgs {
val autoArgs: Array[Any]
}
hi kevin, i went through your AutoProxy example and adapted it to fit
my needs.
the plugin compiles ok, but when i use it to compile a test case, the
error i get is that no override method is detected on the test class -
but if i print out the tree after i add the new def, it shows the new
method is there. any obvious problems in what i'm doing? one issue i
saw was that the tree doesn't show the variables as scoped to the
class, e.g. it's "x" not "D.this.x", but i couldn't figure out how to
change that. thanks -
so it turns out my previous issue was due to cloning the abstract
symbol without removing the abstract flag. i just assumed this would
happen if it was assigned in a def, but that's not the case.
the issue i'm stuck on now seems similar to the params issue i
mentioned earlier -
the method is generated but there's a compiler error around the
params:
Error during sbt execution: java.lang.Error: symbol value x does not
<synthetic> def autoArgs: Array[Any] = scala.Array.apply[Any](x, y, v,
p)(reflect.this.Manifest.Any)
exist in Test$D.autoArgs
i think the problem lies in the way i'm generating those:
val finalParams = params map (x => Ident(x))
var params = tree.symbol.constrParamAccessors
val rhs: Tree = Apply(Ident("Array"), finalParams)is there a correct syntax that involves using "This" or something like
that? thanks!
Right now, I'm working on a patch to scalac that provides the necessary hooks for a plugin to inject synthesized methods during the namer & typer phases. Watch this space for news of further progress.