Is it possible to automatically create a local variable from a method with IDEA - intellij-idea

Suppose I have an object of class RandomClass with a method doStuff() which returns an int.
I'd like to do something like this:
Type myObject.doStuff()
Do something which creates a local variable of the type returned by doStuff() (int in this case)
Right now I do that by first typing myObject.doStuff(), use Alt+enter to popup the "Introduce local variable" menu and then use that.
Can I do that faster ?
Thanks.

You can type myObject.doStuff() and then press Ctrl+Alt+V to immediately create the local variable. You will directly bypass the pop-up and that is really all you gain.
You can simplify the key mapping to reduce the number of keys to press for the Extract Variable if it is really necessary.

Generally, no, that's the quickest way to do it.
Given that the doStuff method already exists, I could do what you described with 6 keypresses in about a second and a half. That's pretty quick, I would think...
On the other hand, if it's boilerplate code that you'll be typing over and over, you could consider making a custom Live Template - hit ctrl-j and type something like sout or psvm to see some examples...
Good luck!

Related

VB.NET How do I pass parameters to a class?

Relatively new to coding and have taken up lots of small projects to help learn the basics, and I have now set myself a challenge of a "bigger" one. Essentially I want to recreate the Message Box but with my own styling and customisable elements.
I have got the basics in a class and created it, however I want the class to have two options.
1) load all the details from an XML file for the message, I have done this and that works.
2) I want it to be like the standard message box where you can pass in parameters.
My question is, How can I achieve number 2.
I have tried adding details into the Show/Load subs but no luck, the only way around it I can see is with properties but that would take too long.
I want to be something like the below.
classname.show("message","tittle",icon,"buttons",imagefile,"caption")
However alot of my code is done in the load method as opposed to show, so it needs to be visible / accessible there.
Any help / advice would be appreciated.
Properties are definitely the way to go. It also makes sense: Conceptually, the message being shown is a property of the message box.
Your Show method would look like this:
Public Shared Show(message As String, title As String, ...)
Dim box as New MyMessageBoxWindow()
box.Message = message
box.Title = title
...
box.ShowDialog()
End Sub
In the Load method of MyMessageBoxWindow, you access these properties and configure the UI elements.

AS2 AttachMovie from loaded swf movie

i'm facing one problem about attaching movieclip from loaded movie, so basically we have a Map
Map.loadMovie("SimpleMap.swf");
in this map there's a npc dialogue with its name "Dialogue1" I want to attach it to the client. It should be basically something like
_root.attachMovie("Map.Dialogue1", "dialogue", _root.getNextHighestDepth());
but it seems I can't get it to work. Anyone can help?
Note: Also I want to attach the movieclip to the client instead of the map, else I would use Map.attachMovie
it's been a while since I wrote any Actionscript 2 stuff, but have you tried removing the quotes around Map.Dialogue1 ? - If I remember correctly passing a string would make Flash look for the symbol in the library, not from the global or current scope...
_root.attachMovie(Map.Dialogue1, "dialogue", _root.getNextHighestDepth());
If you want you can import mx.core.UIObject and then use the method _root.createObject() (or if it is O-O use createClassObject()).
It is going to attach the "npc dialog" as an object... you need to specify the linkage name and give the instance a name. So for example if you called the dialog "npc_dialog" in the library then use:
_root.createObject("npc_dialog", "my_npc", _root.getNextHighestDepth());
Here is something else you can try... go to the library and drag a instance of the movie onto the stage somewhere where it will not be seen, like for instance on the next key frame or off the stage then try to run attachMovie().
What happens is flash will compile the clip in the most efficient way possible so if it sees you imported a package but did not use it then it will ignore this class in the compiled clip... so when you go to run and it tries to attach the movie it can't find it.

How to print a string that is sent as a parameter to class method in smalltalk

I'm trying to write a class method which recieves a string and prints it.
I've tried this:
log: aMessage
Transcript show: aMessage; cr.
and tried to use it as follows:
ContractObject log: 'aaa'.
(ContractObject is the name of class) but it didn't work.
I'm assuming it has something to do with the fact that it's a dynamic language and that it's not known that it's a string.
I tried to convert it etc. Nothing worked.
No, types are definitely not the problem here. What do you mean by "it didn't work"? What was the error message you got? Did you get any at all?
Do you have the Transcript open? If it's not open you wont see anything. You can open it programmatically by evaluating Transcript open or manually by using the menu.
Also, make sure that you have implemented #log: on the class side (that's what you see when you click the class button in the code browser).

How to make my own property attribute in objective-c?

I was thinking how could I make my own property attribute, for example:
#property(retain,nonatomic,'myAttribute') int numberOfWheels
#property('unique',nonatomic) NSString productCode
but when I try to get a help from Xcode pressing command button or option button nothing happens
I was looking in this page and many others but no one ask how to make your own attribute, most of then just asking about how to use property attributes or difference between them
I dont know if its possible to make a new attribute, but if its true, could someone help me
The only way to do this is to modify the compiler directly to add this functionality. I have no idea where you'd begin to do that, except to point you to http://llvm.org and say "good luck".

"No appropriate method" error generated when calling new function using class-defined object

I defined a class called "FilterCriteria" which has a bunch of function .m files (getAMask, getBMask, etc.) associated with it. When I create the FilterCriteria object and call the functions using it, I don't have any problems. However, recently I added another function (which, on a side note, is almost identical to another function that still works), and Matlab returns the error, "No appropriate method, property, or field getHMask for class FilterCriteria."
I've searched online for this problem, but I can't find anything. The file getHMask.m is definitely in the correct folder, so I don't understand why Matlab seems to have such a problem finding it.
Here's getHMask.m's header:
function mask = getHMask(object, quadrant, channel)
Any help would be greatly appreciated. Thanks in advance.
1) A mistake I make sometimes is not saving the file with the correct name. Make sure capital letters are in the right places etc!
2) Another layer of error checking here... You can call methods('object here') (see here) and make sure it lists the method (function) that you are trying to add to it. If it doesn't show up here you should check into the implementation of the method and make sure it's correctly being added to the class you're using for your object.
I had the same problem that's kind of suggested by Ben's bullet #2 and it was driving me crazy. Turns out MatLab wasn't loading the latest version of my class's m-file. I vaguely remembered it gave me a warning earlier about that, because there were old instances of the class in the workspace and to keep from invalidating them it said it wouldn't update the class until I cleared the workspace...
So if that's the problem, restarting MatLab will work, or you can just enter >> clear