在netbeans中,我可以 Ctrl +单击变量名称以跳转到该变量的声明。这适用于普通变量。但是,当我将它用于类属性时,它会将我跳到类的顶部,如
private $myVar;
这在技术上是正确的,但几乎没用。如果它跳到我首先为变量赋值的行,即
,会更有帮助 $this->$myVar=7;
这可能吗?如果是这样,怎么样?
在Windows 7上使用NetBeans 8.0.2
答案 0 :(得分:5)
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.
答案 1 :(得分:4)
好吧,我无法弄清楚NetBeans宏语言,因为我不知道如何获取选择,修改它,并进行正则表达式搜索,这似乎是需要的。我能够用AutoHotKey做到这一点。我们的想法是创建一个执行以下操作的宏:
双击插入位置以突出显示属性名称。 Netbeans没有报告其插入位置,所以我不得不满足于使用鼠标位置,这很好。
创建以下正则表达式,以确定 propName
何时获得分配值:
\$this\s*\->\s*propName\s*=
这不是完美的,但它是一个开始,似乎对我有用。它目前不适用于嵌套属性($this->someProp->subProp
)可以找到someProp
但不能subProp
(它会错误地搜索$this->subProp
)但它应该能够处理这些也可以通过调整正则表达式。
我已将宏指定给 Alt + 点击以下:
!~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