【Eclipse】使用指南(6)添加新方法

 (翻译说明:http://my.oschina.net/ywlaker/blog/468911

添加新方法

  1. 在打开 VectorTest.java 文件的编辑器最后(在声明类的括号之前)输入以下内容:        
    public void testSizeIsThree()        
    当你输入完名称之后,该方法就会出现在 Outline 视图的底部。        

    image[14]          
    另外,

    这些错误提示表明编译有错。将鼠标悬停在错误文本处,会提示:“)”处语法错误,后面需要“{”,这是因为该方法还未声明方法体。这种错误提示会随着你继续输入而不断更新。这个过程是由 Java > Editor 首选页中的 Report problems as you type 选项控制的。          
    image[17]

  • 错误提示(红色长方形块)会出现在编辑器右边垂直标尺上,

  • 错误图标(红叉)会出现在编辑器左侧垂直标尺上,

  • 错误指示符(红色小方块)会出现在编辑器右上角 ,

  • 错误标记会出现在编辑器的文本中。

点击保存按钮,程序自动编译,错误将出现在包管理器视图、问题视图和垂直标尺(编辑器左边)。在包管理器视图中,错误会一直传播到项目的最上层。      
image[20]

输入以下内容完成方法添加:

{          
 //TODO: Check size            

闭合的花括号会自动添加。

保存文件。随着括号的添加,错误提示也消失了。

(完)

(原文)

Adding new methods

  1. Start adding a method by typing the following at the end of the VectorTest.java file (but before the closing brace of the type) in the Java editor:        
    public void testSizeIsThree()        
    As soon as you type the method name in the editor area, the new method appears at the bottom of the Outline view.

    New method in outline view

    In addition,

    These error annotations indicate that the compilation unit is currently not correct. If you hover over the error in the text, a tool tip appears: Syntax error on token ")", { expected after this token. This is correct since the method doesn't have a body yet. Note that error annotations in the editor are updated as you type. This behavior can be controlled via the Report problems as you type option located on the  Java > Editor preference page.

    Error annotations in vertical and overview ruler

  • error annotations (red boxes) appear in the overview ruler positioned on the right hand side of the editor,

  • error icons appear in the vertical ruler positioned on the left of the editor,

  • an error indicator appears in the top right corner of the editor,

  • errors are marked in the text.

Click the Save button. The compilation unit is compiled automatically and errors appear in the Package Explorer view, in the Problems view and on the vertical ruler (left hand side of the editor). In the Package Explorer view, the errors are propagated up to the project of the compilation unit containing the error.

Error propagation in package explorer

Complete the new method by typing the following:

{          
 //TODO: Check size            

Note that the closing curly brace has been inserted automatically.

Save the file. Notice that the error indicators disappear since the missing brace has been added.

(END)

转载于:https://my.oschina.net/ywlaker/blog/470753

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值