Last active
August 29, 2015 14:25
-
-
Save tarao/d1f3dd438df8907cd376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. | |
// Jad home page: http://www.geocities.com/kpdus/jad.html | |
// Decompiler options: packimports(3) | |
// Source File Name: test.scala | |
package dynamic; | |
// Referenced classes of package dynamic: | |
// Sample | |
public class Main | |
{ | |
public void main(String args[]) | |
{ | |
Sample s = new Sample(); | |
s.cap("hoge"); | |
} | |
public Main() | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from: http://stackoverflow.com/questions/15653550/calling-instance-method-in-macro-implementation-for-selectdynamic | |
package mymacro | |
import scala.reflect.macros.blackbox.Context | |
object MyMacros { | |
def selectDynamic(c: Context)(name: c.Expr[String]): c.Expr[String] = { | |
import c.universe._ | |
c.Expr[String](Apply(Select(c.prefix.tree, newTermName("cap")), List(name.tree))) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from: http://stackoverflow.com/questions/15653550/calling-instance-method-in-macro-implementation-for-selectdynamic | |
package dynamic | |
import language.dynamics | |
import scala.language.experimental.macros | |
class Sample extends Dynamic { | |
def cap(name: String): String = name.toUpperCase | |
def selectDynamic(name: String): String = macro mymacro.MyMacros.selectDynamic | |
} | |
class Main { | |
def main(args: Array[String]) { | |
val s = new Sample | |
s.hoge | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment