In netbeans, I can Ctrl+Click a variable name to jump to the declaration of that variable. This works great for normal variables. However, when I use it for a class attribute, it jumps me to the top of the class to a line like
private $myVar;
which is technically correct, but pretty much useless. It would be much more helpful if it jumped me to the line where the variable is first assigned a value, ie
$this->$myVar=7;
Is this possible? If so, how?
Using NetBeans 8.0.2 on Windows 7
as far as I know and as I have tried, this is not possible.
Because, a variable can be defined once, but can be initialized/assigned at multiple places. How will you say as which one is first?
For Example, I may be initializing the variable in the constructor method or I may be having a setter method to set the variable without the contructor too, or I may be having entirely a different method, not specifically constructor, which I may be calling to set values for variables. So there may be a chance that I have all these in my code.
Hence it's not possible.
Well, I couldn't figure it out with NetBeans macro language since I don't know how to grab the selection, modify it, and do a regex search for it, which seems like that is needed. I was able to do it with AutoHotKey. The idea is to make a macro which does the following:
Double click at the caret position to highlight the property name. Netbeans wasn't reporting its caret position, so I have to settle for using the mouse position, which is fine.
Create the following regex to locate when propName
gets a value assigned:
\$this\s*\->\s*propName\s*=
It's not perfect, but its a start and it seems to be working out for me. It currently won't work for nested properties ($this->someProp->subProp
) could locate someProp
but not subProp
(it would incorrectly search for $this->subProp
) but it should be able to handle those too by adjusting the regex.
I have assigned the macro to Alt+Click in the following:
!~LButton Up::
; //save the old clipboard
oldClipboard := Clipboard
; //Sleep a while. Without this, the double click overlaps with the
; //original click used to trigger the macro,
; //and the wrong text is highlighted (usually the thole line)
Sleep 500
Click 2 ;
; //Copy the text
Send ^c
searchText := Clipboard
; //prefix it with this regex: "\$this\s*\-\>\s*" and add "\s*=" to the end so varName becomes \$this\s*\-\>\s*varName\s*=
searchText := "\$this\s*\-\>\s*" . searchText . "\s*="
Sleep 50
; //Toggle search dialog
Send ^f
Sleep 50
; //write the text into the form
Send %searchText%
Loop, 2 {
Sleep 100
Send !g ; //turn regex on or off
; //since the state of whether regex is on or off is not known, cycle thru both
Sleep 100
Send {Enter}
}
; //restore the clipboard
Clipboard := oldClipboard
return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With