reflection

How to read a Java class method annotation value with ASM

时光总嘲笑我的痴心妄想 提交于 2020-12-12 04:31:26
问题 How can I read read the value of a Java method annotation at runtime with ASM ? The Annotation has only a CLASS RetentionPolicy , so it's not possible to do that with Reflections. | Policy CLASS : Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time Example : I want to extract the value Carly Rae Jepsen out of the artist field at runtime: public class SampleClass { @MyAnnotation(artist = "Carly Rae Jepsen") public void callMeMaybe(){}

How to read a Java class method annotation value with ASM

放肆的年华 提交于 2020-12-12 04:28:29
问题 How can I read read the value of a Java method annotation at runtime with ASM ? The Annotation has only a CLASS RetentionPolicy , so it's not possible to do that with Reflections. | Policy CLASS : Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time Example : I want to extract the value Carly Rae Jepsen out of the artist field at runtime: public class SampleClass { @MyAnnotation(artist = "Carly Rae Jepsen") public void callMeMaybe(){}

AmbiguousMatchException in Expression.PropertyOrField

喜欢而已 提交于 2020-12-09 04:26:07
问题 I am using reflection to create a lambda function. It works with most items I try it with, however on one of the properties it keeps throwing an Ambiguous Match Exception. The code looks like this. The error happens when it hits Expression.PropertyOrField . The property I am using is of type decimal? . I think it might have to do with the fact that it is a nullable type, but I'm not sure. public static LambdaExpression CreateExpression(Type type, string propertyName, ref Type returnType) {

AmbiguousMatchException in Expression.PropertyOrField

感情迁移 提交于 2020-12-09 04:24:03
问题 I am using reflection to create a lambda function. It works with most items I try it with, however on one of the properties it keeps throwing an Ambiguous Match Exception. The code looks like this. The error happens when it hits Expression.PropertyOrField . The property I am using is of type decimal? . I think it might have to do with the fact that it is a nullable type, but I'm not sure. public static LambdaExpression CreateExpression(Type type, string propertyName, ref Type returnType) {

Why is a type of the member of the object different in a function?

廉价感情. 提交于 2020-12-04 10:19:49
问题 Code below produces following result: as member: nested: AnyRef{def x: Int; def x_=(x$1: Int): Unit} as local: nested: Object (Tested with Scala 2.12.12 and Scala 2.12.3) Can someone explain why? object Main extends App { def getNestedType(m: Any) = { import scala.reflect.runtime.currentMirror for { symbol <- currentMirror.classSymbol(m.getClass).toType.members if symbol.isTerm && !symbol.isMethod && !symbol.isModule } yield { s"{symbol.name.decodedName}: ${symbol.info}" } } object obj { var

Why is a type of the member of the object different in a function?

爱⌒轻易说出口 提交于 2020-12-04 10:18:27
问题 Code below produces following result: as member: nested: AnyRef{def x: Int; def x_=(x$1: Int): Unit} as local: nested: Object (Tested with Scala 2.12.12 and Scala 2.12.3) Can someone explain why? object Main extends App { def getNestedType(m: Any) = { import scala.reflect.runtime.currentMirror for { symbol <- currentMirror.classSymbol(m.getClass).toType.members if symbol.isTerm && !symbol.isMethod && !symbol.isModule } yield { s"{symbol.name.decodedName}: ${symbol.info}" } } object obj { var

Modify a method using Annotations

谁说我不能喝 提交于 2020-11-26 06:34:35
问题 How can I change what a method is doing in Java ? I mean, I am trying to use annotations to make the following code @Anno1(Argument = "Option1") public class TestClass { @Anno2 public void test() { } } Into public class TestClass { private static StaticReference z; public void test() { z.invokeToAll(); } } This is a very simplified example of what I am trying to do. Anno1 will have many possible combinations, but this is not my problem so far. My problem is how to add code to method test() I

Modify a method using Annotations

孤街浪徒 提交于 2020-11-26 06:31:00
问题 How can I change what a method is doing in Java ? I mean, I am trying to use annotations to make the following code @Anno1(Argument = "Option1") public class TestClass { @Anno2 public void test() { } } Into public class TestClass { private static StaticReference z; public void test() { z.invokeToAll(); } } This is a very simplified example of what I am trying to do. Anno1 will have many possible combinations, but this is not my problem so far. My problem is how to add code to method test() I

Modify a method using Annotations

↘锁芯ラ 提交于 2020-11-26 06:30:12
问题 How can I change what a method is doing in Java ? I mean, I am trying to use annotations to make the following code @Anno1(Argument = "Option1") public class TestClass { @Anno2 public void test() { } } Into public class TestClass { private static StaticReference z; public void test() { z.invokeToAll(); } } This is a very simplified example of what I am trying to do. Anno1 will have many possible combinations, but this is not my problem so far. My problem is how to add code to method test() I