【Eclipse】使用指南(8)识别代码中的问题

编程入门 行业动态 更新时间:2024-10-08 00:33:57

【Eclipse】<a href=https://www.elefans.com/category/jswz/34/1765634.html style=使用指南(8)识别代码中的问题"/>

【Eclipse】使用指南(8)识别代码中的问题

 (翻译说明:)

Identifying problems in your code

识别代码中的问题

In this section, you will review the different indicators for identifying problems in your code.

本小节将回顾多种用于识别代码错误的指示符。

Build problems are displayed in the Problems view and annotated in the vertical ruler of your source code.

编译问题会出现在问题视图,以及源码左侧垂直标尺上。

  1. Open junit.framework/TestCase.java in the editor from the Package Explorer view.      
    在编辑器中打开junit.framework/TestCase.java文件

  2. Add a syntax error by deleting the semicolon at the end of the package declaration in the source code.    
    删除包声明最后的分号

  3. Click the Save button. The project is rebuilt and the problem is indicated in several ways:      
    点击保存按钮(或者CTRL + S),项目重新编译并在如下几个地方提示错误:      

  • In the Problems view, the problems are listed,          
    问题视图出现错误列表

  • In the Package Explorer view, the Type Hierarchy or the Outline view, problem ticks appear on the affected Java elements and their parent elements,        
    包管理器视图、类层次结构和Outline视图中,错误提示出现在受影响的元素以及它们的父元素上,

  • In the editor's vertical ruler, a problem marker is displayed near the affected line,          
    编辑器垂直标尺的相应行出现错误提示

  • Squiggly lines appear under the word which might have caused the error, and          
    可能导致错误的单词下面出现红色波浪线

  • The editor tab is annotated with a problem marker.        
    编辑器的选项卡出现错误提示

You can hover over the marked word in the editor to view a description of the problem. You can also hover over the problem markers in the vertical or overview rulers.    
鼠标悬停在错误提示处,可以看到问题的详细描述信息      

Click the Close ("X") button on the editor's tab to close the editor.      
点击编辑器选项卡的关闭按钮("X")关闭该编辑器

In the Problems view, select a problem in the list. Open its context menu and select Go To. The file is opened in the editor at the location of the problem.      
在问题视图中选择列表中的一项,右键菜单然后选择Go To,错误所在文件将在编辑器中打开并定位到错误所在处      

Correct the problem in the editor by adding the semicolon. Click the Save button. The project is rebuilt and the problem indicators disappear.      
在包声明最后加上分号,点击保存,错误提示消失。

In the Outline view, select the method getName(). The editor will scroll to this method.      
选择Outline视图中的getName()方法,编辑器将会定位到该方法所在处

On the first line of the method change the returned variable fName to fTestName. While you type, a problem highlight underline appears on fTestName, to indicate a problem. Hovering over the highlighted problem will display a description of the problem and applicable quick fixes.      
把返回值由fName改成fTestName,出现错误提示,鼠标悬停在错误处可以看到描述信息和可用的快速修复方法

On the marker bar a light bulb marker appears. The light bulb signals that correction proposals are available for this problem.    
标记栏出现电灯泡标记,意味着该错误有可用的修复建议      

Click to place the cursor onto the highlighted error, and choose Quick Fix from the Edit menu bar. You can also pressCtrl+1or left click the light bulb. A selection dialog appears with possible corrections.      
将光标置于错误处,选择Edit 菜单中的Quick Fix(或使用Ctrl+1快捷键,或左键点击电灯泡),带有修复建议的对话框就出现了      

Select 'Change to fName' to fix the problem. The problem highlight line will disappear as the correction is applied.    
选择'Change to fName', 问题得到解决,错误提示消失

Close the file without saving.      
关闭文件

You can configure how problems are indicated on the General > Editors > Text Editors > Annotations preference page.      
可以在General > Editors > Text Editors > Annotations 首选项中配置错误提示的方式

转载于:

更多推荐

【Eclipse】使用指南(8)识别代码中的问题

本文发布于:2024-02-28 13:08:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:使用指南   代码   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!