IntelliJ IDEA4新特性之動(dòng)態(tài)代碼分析
Intelligent error highlighting(智能突出顯示錯(cuò)誤)
All common syntax errors, as well as all other errors that would be detected during compilation, are highlighted in the source code so you do not need to compile your code in order to find all your mistakes. Each error is highlighted in the editor and has the corresponding red link on the right gutter area for easy navigation to the erroneous places, which is especially useful when working with large files.
所有常見的語法錯(cuò)誤以及其他一些可以被發(fā)現(xiàn)的編輯錯(cuò)誤,都會(huì)在源代碼里被突出顯示。這意味著,你不用編譯程序就可以發(fā)現(xiàn)你所有的錯(cuò)誤。錯(cuò)誤突出會(huì)用紅色的波浪下劃線標(biāo)示,你可以輕易的找到它,這個(gè)功能在大的源文件編輯時(shí)尤為突出。
JavaDoc error highlighting(JavaDoc錯(cuò)誤突出)
IDEA knows general javadoc rules, such as structure and syntax, and will detect any common inconsistencies found in your javadoc comments, e.g. wrong parameter references, return attributes in the field or void method comments, etc.
Having found an unknown javadoc tag, IDEA will suggests that you add this tag to the known tags list, so that you never get an error or warning indications about it.
IDEA曉得一般的JavaDoc一些關(guān)于結(jié)構(gòu)和語法的規(guī)則,而且會(huì)發(fā)現(xiàn)一些在你的JavaDoc中相矛盾的地方,比如,不一致的參數(shù)申明,返回局部變量或沒有返回值方法的注釋等等。當(dāng)發(fā)現(xiàn)一個(gè)未知的JavaDoc Tag 時(shí),IDEA會(huì)提醒你將這個(gè)Tag加入到已知Tag列表中,這樣就再也看不到關(guān)于這個(gè)Tag的錯(cuò)誤和警告提示了。
Detecting deprecated symbols(發(fā)現(xiàn)不合法的標(biāo)識(shí)符)
If any deprecated code is used in any class or interface, IDEA will recognize it and highlight the corresponding statements directly in the editor.
如果有任何不合法的代碼在你得class或interface里,IDEA會(huì)找出它,并在編輯器里直接標(biāo)記出它。
Highlighting unused imports, throws declarations and other unused symbols(突出顯示沒有被使用的import和 throw聲明以及其他沒有使用的標(biāo)識(shí)符)
IDEA will point out all redundant import statements, throws declarations and other unused symbols (like variables and methods), and will highlight them in the editor with the corresponding links on the right gutter area for easier navigation. More information on other code analysis features can be found here.
IDEA將會(huì)指出多余的import和throw聲明,以及其他的多余的方法和變量標(biāo)識(shí)符,并將在編輯器里突出顯示他們,并給出相應(yīng)的建議,你可以輕易找到它們。你也可以從提示意見里獲得更過的相關(guān)信息。
Import Assistant - helps to automatically insert import statements while typing code, and detects non-imported classes found in pasted blocks of code(Import助手——在編輯代碼時(shí)幫你自動(dòng)插入import聲明,并自動(dòng)找出你粘貼代碼時(shí)沒有導(dǎo)出的class)
When you use the name of a class from anywhere in a project library, but the class has not been imported into the current file, a hint with the suggestion to import the class pops up over the text. Pressing Alt + Enter inserts the import statement. Moreover, when you copy a block of text from one file and paste it into another, IDEA automatically detects all the classes that are used inside the copied block but have not been imported to the destination file. It then shows a list of all such classes and allows you to select classes you want to import into the new file.
當(dāng)你隨便使用一個(gè)package里的class時(shí),而且這個(gè)class沒有在當(dāng)前文件中聲明時(shí),就會(huì)有一個(gè)提示來建議你import一些有這個(gè)class聲明的package,你只需按下Alt + Enter就會(huì)import相應(yīng)package了。當(dāng)然,這個(gè)功能也會(huì)在你粘貼代碼時(shí)起作用,他會(huì)提示出所有需要import的package。IDEA還會(huì)給出一個(gè)列表讓你選擇呢?
Intention actions(意圖識(shí)別)
When you are typing your source code, know that IDEA is always one step ahead of you. For example, if you assign a value to a variable that represents an instance of one of its ancestors, IDEA will immediately interpret your intention as wanting either to cast the ancestor type to the variable type or to define the type of variable the same as the ancestor. A light bulb will appear suggesting that you perform one of these two operations. Also you can start using a method before it has been declared. When this occurs, IDEA’s light bulb popup will appear suggesting you create a new method from its usage. If you accept the suggestion, the new method will be created in the corresponding class. More features related to automatic code generation in IDEA are described here.
當(dāng)你在輸入源代碼時(shí),IDEA會(huì)知道你下一步將會(huì)做什么。例如,當(dāng)你成聲明一個(gè)繼承于某個(gè)父類的變量時(shí),IDEA會(huì)認(rèn)為是是不是需要繼承一些父類的聲明。有一個(gè)小燈泡出現(xiàn)會(huì)提示你完成這些操作。當(dāng)你寫一個(gè)方法時(shí)也是這樣。如果你接受了“小燈泡”的建議,你需一點(diǎn),他就會(huì)自動(dòng)幫你完成。(意譯,可能有出入,但易于理解)
Visual indication of overriding/overriden and implementing/implemented methods(醒目的指出override和implement的方法)
Special signs ( and ) on the left gutter area of the editor indicate that the current method overrides or implements the corresponding method of an ancestor class/interface. Moving the mouse to one of these symbols will bring up a tooltip with the base method details. If you click the symbol, the corresponding class/interface will be immediately opened in the editor, with the caret automatically positioned at the base method.
When icons or are shown, it means that the method is overriden or implemented in inheriting classes. Pressing the icon will open a lookup list with these classes, for selecting the desired one to open at the corresponding method.
?用符號(hào)(?和 ) 在代碼的左邊標(biāo)示出當(dāng)前方法是否是重載或?qū)崿F(xiàn)了父類或接口的相應(yīng)方法. 移動(dòng)鼠標(biāo)到這些符號(hào)上,將會(huì)顯示出父類是顯得的詳細(xì)細(xì)節(jié)。如果你點(diǎn)擊鼠標(biāo), 相應(yīng)的父類實(shí)現(xiàn)就會(huì)出現(xiàn)在編輯器里,并自動(dòng)定位到那個(gè)方法上。
當(dāng)符號(hào)??或 出現(xiàn)時(shí),就意味著這個(gè)方法需要重載或?qū)崿F(xiàn)與父類的方法。?點(diǎn)擊鼠標(biāo)就會(huì)彈出相應(yīng)的列表讓你在其中選擇一個(gè)方法。