where can I read the source code? - smalltalk

I am using squeak4.1 for development, when I am looking up add method in method chain below: Kernel-Numbers -> Integer -> arithmetic -> + ,the method for adding is +, in + method I find
sample code like this :
ifTrue: [^ (self digitAdd: t1) normalize].
Can I know how I can trace into digitAdd and look the implementation of add method in smalltalk? thanks first!

As the message is send to self, you can query the Integer class itself for its definition. For this, right click Integer in the System Browser, select "find method" and enter `digitAdd' in the search window that appears. Click the "Accept" button. This will show you the message definition.
You can also use the search facility in Squeak. (the search box on the main menu bar).

Select string 'digitAdd:' in text editor, and press Alt-m shortcut or right-click and in opened menu find 'implementors of it'.
This will open a window with all methods in all classes in system which implement given message.

Related

Intellij shortcut directly go to any variable Class or method

SomeClass {
AbstractType/Interface instanceVariable = new SpecificType();
...
SomeFn(){
instanceVariable.instanceMethod();
| <- go to SpecificType.instanceMethod() directly
instanceVariable.instanceMethod();
| < go to SpecificType of instanceVariable directly
}
Looking for an Intellij shortcut to go to variable's Specific Class. To go to instanceVariable in a large code and want to go to its SpecificType class. It needs three commands, go to instanceVariable definition using Go to Declaration (F3), see its definition, move cursor to actual type new SpecificType();, go into it and come back where you were using (Command + [). We can also hover over "instanceVariable" definition using F2 to see what its type is, but, there is no direct shortcut to go to actual Class "SpecificType" defining this instance variable.
Same with instanceMethod(), there is "Go to Implementation" on this method of an instance (Shift+Command+I) and choose specific type whereas instance is already defined right in the class as "SpecificType" here. See method type using F2 to see which class, in this case, it will show "SpecificType" the method type belongs to, then choose the specific implementation and choose SpecificType from several drop downs.
It would be nice if there was a shortcut to directly to to exact SpecificType Class or its method instead of multiple commands.
Why Main Menu | Navigate | Go to Implementation(s) action (Alt+Cmd+B default shortcut) doesn't work for you? Invoke it on the method call and from drop-down choose the implementation you are interested in:

Reloading keyboard shortcut definitions in Pharo

I've been playing around with keyboard shortcuts in Pharo 7.0. I wanted to modify the binding for #jumpToNextKeywordOfIt in the Smalltalk editor and so I got the following change in the definition of buildShortcutsOn method:
(aBuilder shortcut: #jumpToNextKeywordOfIt)
category: RubSmalltalkEditor name
default: $y meta shift
do: [ :target | target editor jumpToNextKeywordOfIt: true ]
description: 'Jump to next keyword'.
My first thought was that just saving this definition should immediately take effect, but it was not the case. Then I thought, perhaps since this is part of a method definition, then calling this method on the editor class would do the trick. Now, the method takes an argument aBuilder and I don't really know what that is. So two questions arise:
Is this the proper way to apply keybinding changes to a running editor?
What is aBuilder in this context and how does one get it?
Let me give you some hints on how to find the solution (as this might be more valuable than giving the solution at once)
The problem is what's aBuilder right? Well, from the expression
(aBuilder shortcut: #jumpToNextKeywordOfIt)
we deduce that aBuilder is someone that responds to #shortcut:. Cmd+m and you will get 9 implementors of #shortcut:. One of them, KMBuilder has an interesting name. Moreover, its implementation of shortcut: is
shortcut: aKeymapName
^KMKeymapBuilder
for: aKeymapName
platform: platform
meaning that it will answer with an instance of KMKeymapBuilder. Browse this class and verify that it understands the next message from your expression:
category: RubSmalltalkEditor name
default: $y meta shift
do: [ :target | target editor jumpToNextKeywordOfIt: true ]
description: 'Jump to next keyword'.
It does! So this must be it! To check this, we still need an instance of KMBuilder. Browse the class, go to the class side and find the unary message #keymap.
This means that we can obtain aBuilder by evaluating
KMBuilder keymap
I love unary messages. Specially when they are on the class side!
Now go to the implementor of the method you already tweaked #buildShortcutsOn:. It is implemented in the class side and we can now evaluate:
RubTextEditor buildShortcutsOn: KMBuilder keymap
To make sure that it works, go now to the desired handler #jumpToNextKeywordOfIt: and insert a halt in it. This is in the same class, instance side.
Now lets press Cmd+Shift+y and see if we get the halt... Bingo! I mean, Halt!

How to search for constructor / method invocation of given signature in IntelliJ?

Is it possible to search for constructor / method invocation of given signature in IntelliJ?
For example, suppose I have two methods
void myMethod(int x, int y);
void myMethod(double x, double y);
How to search second one invocation?
Simplest way is the following:
Just invoke Find Usages (Alt+F7) on the second method. If the search results contain both methods, click on the cog and spanner Settings icon in the Find tool window. Deselect the Include overloaded methods checkbox and click on the Find button.
This settings dialog can also be reached directly via the menu Edit | Search | Find Usages Settings...
For reference I'm giving another option - structural search (Edit > Find > Search > Search Structurally).
The template you need is something like this:
$Instance$.$MethodCall$($Parameter$)
In "Edit Variables" dialog you need to adjust "MethodCall" to be "myMethod", "Parameter" count to be 2 and its "Expression type" to be "double"

How to generate a void method in IntelliJ IDEA?

In Eclipse, when I type main ctr+space, it will generate a static void main method for me. And when I type methodName ctr+space, smart code completion will suggest generating the method named methodName.
How can I auto-generate a void method in IntelliJ?
To create a new method from usage in the code like:
...
someMethodName()
...
AltEnter on the red code:
It's also possible to type void methodName() and use Complete Statement (CtrlShiftEnter), it will become:
void methodName() {
|
}
You could create your own Live Template as #Makoto answered, but programming by intention seems to be more natural. When you don't have a method, you write code that will use it, then create the method from the intention action - this way IDEA will generate the method signature automatically according to the parameters and return type in the not yet existing method usage, like String result = someMethod(stringParam);.
Finally, it is worth nothing that in IntelliJ IDEA main() method can be generated using psvmTab.
IntelliJ IDEA 15
Generate a main method
Default:
Type psvm (public static void main) > press Tab
Use the template from Eclipse (main instead of psvm)
File > Settings or press Ctrl + Alt + S
Editor > Live Templates
From the right side, click on the "+" sign > Live Template
Add the following details:
Abbreviation: main
Description: main() method declaration
Template text:
public static void main(String[] args){
$END$
}
You will see the new template added in Others.
Click on Define
Select Java > Press on OK
Type main in your Java code > press Tab
Generate a void method
Type your method name followed by parentheses (+ the arguments, if you use them) - E.g.: m() or m(1,2) > Press Alt + Enter > Click on "Create method ..." (or press Enter if it is already selected)
Type the abbreviation of the main() method template:
Press the template invocation key. By default, it is Tab. The abbreviation expands to the main() method.
IntelliJ makes use of Live Templates to do its code completion. It's then a matter of deciding what shorthand name you wish to use to name your void method.
Here's an example. Create a live template in Settings > Live Templates, then select the "Other" box. Hit the + on the right, then give your template a shorthand keystroke name.
Here's the one that I typed up. With the two different variables $NAME$ and $ARGS$, I can tab between them when I need to fill them in. $END$ is where the cursor ends when I'm done tabbing through the other two variables.
void $NAME$ ($ARGS$) {
$END$
}
The shorthand name I used is pmeth. So, every time I type pmeth into IntelliJ in a Java file, then hit Tab, this method is filled in, and my cursor automatically starts at $NAME$.
type psvm on the Java class and then Cntrl+Period key
Just type main and a suggestion will pop up. Press enter.
Simply Type the abbreviation of the main() method template:
psvm then Enter

Method Finder does not find a new method

I am currently following the Squeak By Example book.
It shows that when looking for an unknown method one can search the method by the correspondance between its input and its output in the Method Finder (it opens a Selector Browser window).
For example if I enter 'aaa' . 'AAA' it finds both Character asUppercase and String asUppercase.
SBE teaches how to add a new method shout to the class String that puts a string in upper case and adds a final exclamation mark. Prior to the method addition, it also shows how to add a test to verify the new method via the Test Runner.
If I search 'aaa' . 'AAA!' I get a No single method does that function.
If I test (print) it in the workspace I get the expected 'thing' shout --> 'THING!'. Why? Is there something to refresh?
Method Finder only tries known methods, otherwise the system could easily crash. See MethodFinder>>initialize.