Find method in scala reflect by it's bytecode name - scala

Is there a way to find a method by it's bytecode name?
For example, I would like to find a reference to println(Object) by string "_root_.scala.Predef.println(Ljava/lang/Object;)V."

There is no direct way to do it.
You have to parse string to extract class name. Load class by name and iterate thru its method to find required method.

Related

Collect all annotated class name in some scala object

We have various class annotated with a scala macro annotation that add a method to that class. At compile time, We want to add a list of these annotated class in some other object . So that we can access that list at run time. Is there any way to achieve this?
I didn't find a straight way to do this but what I did was pretty simple. Whenever my macro finds my annotated class, It writes the name of the class to a file in resources. At runtime, I made that file content available as a list through a new class method.

Scala how to get object property value given name of property in string?

I wondering how to get object property value given name of property in string in Scala? I saw examples when you get all fields of object using Reflection and iterate over it. But is it possible to call it without iteration? Or may be there is a way to pass object.field to another function without evaluation and evaluate it there and return result?
Kolmar comment give me right direction to call by name function.

Intersystems caché - programmatically create new class

Is it possible to write ObjectScript method, which will create new class in namespace and compile it? I mean programmatically create new class and store it. If so, can I edit this class using ObjectScript later(and recompile)?
Reason: I have class structure defined in string variable and I need to add new class to namespace according this string.
Nothing is impossible. Everything in Caché can be created programmatically. And, Classes is not a execution. There are at least two ways to do it:
simple SQL Query CREATE TABLE, will create a class.
and as you already mentioned ObjectScript Code, which can do this.
All of definition of any classes defined in other classes. Which you can find in package %Dictionary.
The class itself defined in %Dictionary.ClassDefinition. Which have some properties, for defining any parts of classes. So, this is a simple code which create some class, with one property.
set clsDef=##class(%Dictionary.ClassDefinition).%New()
set clsDef.Name="package.classname"
set clsDef.Super="%Persistent"
set propDef=##class(%Dictionary.PropertyDefinition).%New()
set propDef.Name="SomeProperty"
set propDef.Type="%String"
do clsDef.Properties.Insert(propDef)
do clsDef.%Save()
And in latest versions, there is one more way for create/change class. If you have text of class as you can see it in Studio. Then, you can load it in Caché, with class %Compiler.UDL.TextServices
Yes, it is. You likely want to make use of %Dictionary.ClassDefinition and the related %Dictionary.*Definition classes (especially %Dictionary.PropertyDefinition, %Dictionary.MethodDefinition and %Dictionary.IndexDefinition) to create and/or modify your class. Provided your string contains some reasonable representation of the data, you should be able to create the class this way.
The actual class documentation is available at http://docs.intersystems.com/cache20141/csp/documatic/%25CSP.Documatic.cls?CLASSNAME=%25Dictionary.ClassDefinition
You can then compile the class by calling $system.OBJ.Compile("YourPackage.YourClass","ck").
(Note: If your string contains the exported XML definition of the class, you could also write the XML representation to a stream and then call $system.OBJ.LoadStream() to import the XML definition. I would only recommend this if you have an exported class definition to start with.)

Using a class function to find a file, and include it so the class in that file can be used

So far this one seems to go against the grain of Php OOP. Let me explain further with an example.
class main has a function called get($name), what I would like get to do is based on the value of $name, (e.g. 'path/file') would find the corresponding file and include it, so the class in path/file can be used.
My goal with this and the reason I want to do this, is when I call $main->get('path/file'), I'd like an object returned of the class within the file, so far the only solution I can figure out is to use
include($main->get('path/file'));
And within said file would be an object defined outside the class body within path/file.php, but that doesn't really solve the issue as it limits me to using the object defined in that file, and I can only use this include call outside a class body. Does anyone have any ideas on how this can be approached?

Eclipse JDT AST: how to find a calling method returns value of an instance variable?

I'm using Eclipse JDT AST to parse a given java source code. While parsing the code, when it hits a method invocation, I want to find out whether that particular method returns or sets a value of an instance variable (basically to find out whether the callee method is a getter/setter of the same class of caller method).
E.g.:
public void test(){
//when parsing the following line I want to check whether "getName"
//returns a value of an instance variable.
String x = getName();
//when parsing the following line I want to check whether "setName"
//sets the value of an instance variable.
setName("some-name");
}
I've used the AST plugin also find out a possible path which would help me to refer it from the API, but couldn't.
Please let me know whether this is possible and if so, which approach that would help me to get the required information.
Don't think that there is an api which tells you whether a method is a getter or a setter.
You will have to write code to do this. For a getter, you can probably simply check if the last statement in the method is a return statement which returns an instance variable.