在netbeans中,我可以Ctrl+单击变量名跳转到该变量的声明。这对正常变量非常有效。然而,当我将它用于类属性时,它会将我跳到类的顶部,跳到类似的行
private $myVar;
这在技术上是正确的,但几乎没有用。如果它能让我跳到变量第一次被赋值的那一行,那将更有帮助,即
$this->$myVar=7;
这可能吗?如果是,如何
在Windows 7上使用NetBeans 8.0.2
据我所知,正如我所尝试的,这是不可能的。
因为,一个变量可以定义一次,但可以在多个位置初始化/赋值。您将如何判断哪个是第一个?
例如,我可能正在初始化构造函数方法中的变量,或者我可能有一个setter法来设置没有构造器的变量,也可能有一种完全不同的方法,而不是特定的构造器,我可能调用它来设置变量的值。因此,我的代码中可能包含了所有这些。
因此,这是不可能的。
嗯,我无法用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