I'm overriding TRTTIEnvironment and am implementing function FindUnknownName(). I'd like to return a Symbol that is already exposed to the program by ExposeInstanceToUnit().
In some of my scripts the property of a global object is in the script but without the object.
Eg.
Global object "User" has property UserName. "UserName" is in the script NOT "User.UserName".
The code in FindUnknownName is
sym := compiler.CurrentProg.Table.FindSymbol("User", cvMagic);
result := TPropertySymbol(TClassSymbol(sym.Typ).Members.FindSymbol(name, cvMagic)).ReadSym;
Problem here is that it returns the class Symbol for the property and since it is not a class property it will AV.
Any help getting the property symbol for the instance of User greatly appreciated.
Related
I'm writing an intellij plugin where I'm refactoring a class, changing its getters (e.g., fun name(): String) to fields (e.g., val name: String).
However, I don't know how best to update the corresponding PsiReference instances. A Kotlin caller needs to change from myObj.name() to myObj.name without the parenthesis.
Currently, I'm doing the following:
ReferencesSearch.search(function).findAll().forEach {
val nextSibling = it.element.nextSibling
if ((nextSibling as? KtValueArgumentList)?.arguments?.isEmpty() == true) {
nextSibling.delete()
}
}
The above works somewhat. That is, the conversion happens correctly. However, the IDE still thinks it is calling a function. It underlines an error in the converted myObj.name with the following message:
Expression 'name' of type String cannot be invoked as a function. The function 'invoke()' is not found
Manually rewriting name in the editor forces intellij to refresh the reference and error disappears.
What should I do instead to prevent this from happening?
You are getting that error message because you are not modifying the reference to the old method. Intellij still thinks your call myObj.name is trying to access some method called name() that doesn't exist anymore.
Also, the search result is going to point to the leaf node in the AST that uses your method. In this case name() has a parent PSI object that holds a reference to name and to (). That's why calling element.nextSibling gives you the () which you can then call delete() on. But this doesn't change the parent's reference.
I'm not sure what is the best way to do what you want but you could try to replace the parent's reference directly. Try:
element.parent.replace(<reference to your the data class field>)
I am writing a jvmti agent for java programs.I am trying to read objects on the stack.Using jnienv pointer received on VMinit/vmstart event.
I succeeded in reading objects upon methodexit event using the foll:
get varaible (slot) from getlocalvariableentry() ;
from the variable signature use jni functions to get object, use getlocalobject function for a reference object/subclass of object.Then if its a subclass of object; jni::getobjectclass(); use returned class and obtain fields in the class;
using getclassfields(); then get field signature from getfieldname(); then call appropriate function for the field as per its signature eg getintfield() for int field.
Howver once I try this upon Objects created within a try block within the function for which methodexit event is raised; I get a crash(SIGSEGV) everytime at Getobjectclass() .Is this because the object has gotten destroyed being out of scope; If so how to read values of variables in a try block of a function at function exit.
obtain crash when upon reading a jobject for Integer (from localvariabletableentry) object , I call getintfield() for its int field member MIN_VALUE which is its first member.If I just try to read member "value" of Integer class then calling getintfield() does not crash.
Is this crash because Im trying to read a static final member of a class ie. member MIN_VALUE Of integer class.
How to come around this and avoid the crashes?
This question already has answers here:
Difference between . and : in Lua
(3 answers)
Closed 8 years ago.
I'm still playing around with lua modules and I've found the following "interesting" issue that occurs depending on how you create your methods / functions inside a module.
Note the following code in a file called test_suite.lua:
local mtests = {} -- public interface
function mtests:create_widget(arg1)
print(arg1)
-- does something
assert(condition)
print("TEST PASSED")
end
return mtests
Using the above code, arg1 is always nil, no matter what I pass in when calling create_widget(). However, if I change the definition of the function to look like this:
function mtests.create_widget(arg1) -- notice the period instead of colon
print(arg1)
-- does something
assert(condition)
print("TEST PASSED")
end
then, the system displays arg1 properly.
This is how I call the method:
execute_test.lua
local x = require "test_suite"
x.create_widget(widgetname)
Can you tell me what the difference is? I've been reading: http://lua-users.org/wiki/ModuleDefinition
But I haven't come across anything that explains this to me.
Thanks.
All a colon does in a function declaration is add an implicit self argument. It's just a bit of syntactic sugar.
So if you're calling this with (assuming you assign the mtests table to foo), foo.create_widget(bar), then bar is actually assigned to self, and arg1 is left unassigned, and hence nil.
foo = {}
function foo:bar(arg)
print(self)
print(arg)
end
Calling it as foo.bar("Hello") prints this:
Hello
nil
However, calling it as foo:bar("Hello") or foo.bar(foo, "Hello") gives you this:
table: 0xDEADBEEF (some hex identifier)
Hello
It's basically the difference between static and member methods in a language like Java, C#, C++, etc.
Using : is more or less like using a this or self reference, and your object (table) does not have a arg1 defined on it (as something like a member). On the other way, using . is just like defining a function or method that is part of the table (maybe a static view if you wish) and then it uses the arg1 that was defined on it.
. defines a static method / member, a static lib, Which means you can't create a new object of it. static methods / libs are just for having some customized functions like printing or download files from the web, clearing memory and...
: Is used for object members, members that are not static. These members change something in an object, for example clearing a specified textbox, deleting an object and...
Metamethod functions(Functions that have :) can be made in lua tables or C/C++ Bindings. a metamethod function is equal to something like this on a non-static object:
function meta:Print()
self:Remove()
end
function meta.Print(self)
self:Remove()
end
Also, with . you can get a number/value that doesn't require any call from a non-static or static object. For example:
-- C:
int a = 0;
-- Lua:
print(ent.a)
-- C:
int a()
{
return 0;
}
-- Lua:
print(ent:a())
same function on a static member would be:
print(entlib.a())
Basically, each non-static object that has a function that can be called will be converted to : for better use.
Is there a way I can get a attribute set in ServletContext in EL so that it ends up as a JavaScript variable?
I am setting it as
context.setAttribute("testing.port", "9000");
I tried retrieving it like
alert("port" +'${testing.port}');
I am just getting a blank.
The problem is the period (.) in the key name. EL interprets the period as a call to an accessor method named getPort1 on whatever object testing references. Fetch the value from the appropriate implicit object:
${applicationScope['testing.port']}
or just use a different key:
${testingPort}
1Yes, this is a simplification of what really happens. It may also look for a predicate getter named isPort, or try Map#get("port").
can anyone help me in ActionScript!
I created a movieclip called holder in my Stage and I name it, inside them i put a variable called
name = "whatever"
Now I can't access the variable from root timeline, I try this:
trace(holder.name);
The result gives me undefined! what mean this?
Have you actually declared the instance name of holder? If not, you have to make sure the holder's instance name is set. Also, I believe that 'name' is a reserved property for objects in Actionscript. In fact, there really is no need to even set it within the movieclip. Calling Object.name will return it's instance name anyway.