=====================
代码的自动完成:
=====================
(1)
Windows->Preference->General->Keys
是管理快捷键的地方
在这里的type filter text处输入Content
Assist,
找到要修改的"Content Assist"
在下面会出现"Content Assist",用鼠标选中"Content
Assist",
在下面的"Binding"处按自己需要的快捷键组合,比如Alt+/
在"When"中选择"Editing Text"
(2)
Windows->Preference->Java->Editor->Templates
这里是管理Java编辑器模板的地方
比如找到"Name"为sysout的,可以看到其"Preview:"处有:
System.out.println(${word_selection}${});${cursor}
其表示在输入sysout后,按Alt+/就可以自动完成System.out.println();的输入
再比如找到"Name"为main的,可以看到其"Preview:"处有:
public static void main(String[]
args) {
${cursor}
}
表示在输入main后,按Alt+/就可以在弹出的选项中选择main方法,
自动完成main方法的格式化输入
自定义抽取局部变量为成员变量:
Windows->Preference->General->Keys
在这里的type filter text处输入Convert a
local variable to a field,
如果看到Binding一栏处还没有绑定快捷键,
就将光标移到下面的Binding文本框内,然后按Alt+Shift+F,
然后OK即可.
====================
26. 防止代码格式化时出现换行
=====================
辛苦写完的代码,被MyEclipse格式化后,
想放在一行上的东西被自动转成了多行,
如果想避免这个情况,可:
1.
Java代码
Window->Preferences->Java->Code
Style->Formatter->Edit
在弹出的界面中:
Line Wrapping->Maximum line
width
这个值是设置一行的宽度,默认值为80,可以在这里把这个值根据自己需要改大;
2.
HTML/JSP代码
Window->Preferences->MyEclipse->Files
and Editors->Html->Html Source->Line width
默认值为72,把这个值根据自己需要改大;
3.
XML代码
Window->Preferences->MyEclipse->Files
and Editors->xml->xml Source->->Line width
默认值为72,把这个值根据自己需要改大;
=====================
22. 为MyEclipse添加XML文档所使用的DTD或XML
Schema,
从而使用Content Assistant可进行代码提示:
=========================
(1)
DTD
1)
定位到:
WIndow->Preferences->MyEclipse->XML->XML
Catalog
2)
在右边的界面中,选择"User Specified Entries",点击右边的"Add...";
3)
在弹出的对话框中点击"File System...",为Location输入框添加DTD文件所在路径;
4)
使用别的文本编辑器打开此DTD文件,找到相应的<!DOCTYPE ...>文档类型声明,
比如说Hibernate的配置文件:hibernate.cfg.xml所需要的DTD文件为:
hibernate-configuration-3.0.dtd
打开hibernate-configuration-3.0.dtd后,找到如下内容:
<!DOCTYPE hibernate-configuration
PUBLIC
"-//Hibernate/Hibernate Configuration
DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
4)
"Key Type:"右边的下拉框中(有三个类型:Public ID,System ID,URI),
根据hibernate-configuration-3.0.dtd中的<!DOCTYPE...>中的PUBLIC,
选择Public ID(或者直接选择"URI"也可);
5)
"Key:"右边的文本框中,将hibernate-configuration-3.0.dtd中的<!DOCTYPE...>
中的PUBLIC后的双引号内的内容COPY,然后粘贴到"Key:"右边的文本框中,
注意,COPY的内容不带双引号"";
(如果上面第(4)步中选择的是URI,则需要填入的是dtd文件中的http://...部分)
6)
点击"OK",即可看到"User Specified Entries"已有了所增加的DTD(的KEY);
同样,hibernate-mapping-3.0.dtd这个DTD的加入,也可以如法炮制;
7)
重启MyEclipse即可,注意如果提示不出来,
并在状态栏的左下出现"Content Assist not
available at the current location",
请在光标位置键入一个空格再使用Alt+/试试;
(2)
XSD(XML Schema)
1)
定位到:
WIndow->Preferences->MyEclipse->XML->XML
Catalog
2)
在右边的界面中,选择"User Specified Entries",点击右边的"Add...";
3)
在弹出的对话框中点击"File System...",为Location输入框添加XSD文件所在路径;
4)
.xsd文件添加后,在下面的Key:右边的文本框会自动添加一个URI,如Spring的:
http://www.springframework.org/schema/beans
如果没有自动添加,使用别的文本编辑器打开此.xsd文件,
找到相应的<xsd:schema
xmlns...>名称空间声明,比如说spring-beans-2.5.xsd
<xsd:schema
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/schema/beans">
4)
"Key Type:"右边的下拉框中有Namespace Name与Schema Location两个选项,
如果是DTD,这里有有三个类型:Public ID,System
ID,URI;
将Key Type置为Schema Location
5)
在Key:右边的文本框中的URI后面加上/,再加上此xsd的名字,
如spring-beans-2.5.xsd的key为:
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
6)
点击"OK",即可看到"User Specified Entries"已有了所增加的xsd(的KEY);
选中此xsd条目,下面的Details为:
Location:D:/Programs/Java/spring-framework-2.5.6.SEC01/dist/resources/spring-beans-2.5.xsd
URI:
file:///D:/Programs/Java/spring-framework-2.5.6.SEC01/dist/resources/spring-beans-2.5.xsd
Key Type:Schema Location
Key:
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7)
重启MyEclipse即可,注意如果提示不出来,
并在状态栏的左下出现"Content Assist not
available at the current location",
请在光标位置键入一个空格再使用Alt+/试试;
=====================
代码的自动完成:
=====================
(1)
Windows->Preference->General->Keys
是管理快捷键的地方
在这里的type filter text处输入Content
Assist,
找到要修改的"Content Assist"
在下面会出现"Content Assist",用鼠标选中"Content
Assist",
在下面的"Binding"处按自己需要的快捷键组合,比如Alt+/
在"When"中选择"Editing Text"
(2)
Windows->Preference->Java->Editor->Templates
这里是管理Java编辑器模板的地方
比如找到"Name"为sysout的,可以看到其"Preview:"处有:
System.out.println(${word_selection}${});${cursor}
其表示在输入sysout后,按Alt+/就可以自动完成System.out.println();的输入
再比如找到"Name"为main的,可以看到其"Preview:"处有:
public static void main(String[]
args) {
${cursor}
}
表示在输入main后,按Alt+/就可以在弹出的选项中选择main方法,
自动完成main方法的格式化输入
自定义抽取局部变量为成员变量:
Windows->Preference->General->Keys
在这里的type filter text处输入Convert a
local variable to a field,
如果看到Binding一栏处还没有绑定快捷键,
就将光标移到下面的Binding文本框内,然后按Alt+Shift+F,
然后OK即可.
====================
26. 防止代码格式化时出现换行
=====================
辛苦写完的代码,被MyEclipse格式化后,
想放在一行上的东西被自动转成了多行,
如果想避免这个情况,可:
1.
Java代码
Window->Preferences->Java->Code
Style->Formatter->Edit
在弹出的界面中:
Line Wrapping->Maximum line
width
这个值是设置一行的宽度,默认值为80,可以在这里把这个值根据自己需要改大;
2.
HTML/JSP代码
Window->Preferences->MyEclipse->Files
and Editors->Html->Html Source->Line width
默认值为72,把这个值根据自己需要改大;
3.
XML代码
Window->Preferences->MyEclipse->Files
and Editors->xml->xml Source->->Line width
默认值为72,把这个值根据自己需要改大;
=====================
22. 为MyEclipse添加XML文档所使用的DTD或XML
Schema,
从而使用Content Assistant可进行代码提示:
=========================
(1)
DTD
1)
定位到:
WIndow->Preferences->MyEclipse->XML->XML
Catalog
2)
在右边的界面中,选择"User Specified Entries",点击右边的"Add...";
3)
在弹出的对话框中点击"File System...",为Location输入框添加DTD文件所在路径;
4)
使用别的文本编辑器打开此DTD文件,找到相应的<!DOCTYPE ...>文档类型声明,
比如说Hibernate的配置文件:hibernate.cfg.xml所需要的DTD文件为:
hibernate-configuration-3.0.dtd
打开hibernate-configuration-3.0.dtd后,找到如下内容:
<!DOCTYPE hibernate-configuration
PUBLIC
"-//Hibernate/Hibernate Configuration
DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
4)
"Key Type:"右边的下拉框中(有三个类型:Public ID,System ID,URI),
根据hibernate-configuration-3.0.dtd中的<!DOCTYPE...>中的PUBLIC,
选择Public ID(或者直接选择"URI"也可);
5)
"Key:"右边的文本框中,将hibernate-configuration-3.0.dtd中的<!DOCTYPE...>
中的PUBLIC后的双引号内的内容COPY,然后粘贴到"Key:"右边的文本框中,
注意,COPY的内容不带双引号"";
(如果上面第(4)步中选择的是URI,则需要填入的是dtd文件中的http://...部分)
6)
点击"OK",即可看到"User Specified Entries"已有了所增加的DTD(的KEY);
同样,hibernate-mapping-3.0.dtd这个DTD的加入,也可以如法炮制;
7)
重启MyEclipse即可,注意如果提示不出来,
并在状态栏的左下出现"Content Assist not
available at the current location",
请在光标位置键入一个空格再使用Alt+/试试;
(2)
XSD(XML Schema)
1)
定位到:
WIndow->Preferences->MyEclipse->XML->XML
Catalog
2)
在右边的界面中,选择"User Specified Entries",点击右边的"Add...";
3)
在弹出的对话框中点击"File System...",为Location输入框添加XSD文件所在路径;
4)
.xsd文件添加后,在下面的Key:右边的文本框会自动添加一个URI,如Spring的:
http://www.springframework.org/schema/beans
如果没有自动添加,使用别的文本编辑器打开此.xsd文件,
找到相应的<xsd:schema
xmlns...>名称空间声明,比如说spring-beans-2.5.xsd
<xsd:schema
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/schema/beans">
4)
"Key Type:"右边的下拉框中有Namespace Name与Schema Location两个选项,
如果是DTD,这里有有三个类型:Public ID,System
ID,URI;
将Key Type置为Schema Location
5)
在Key:右边的文本框中的URI后面加上/,再加上此xsd的名字,
如spring-beans-2.5.xsd的key为:
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
6)
点击"OK",即可看到"User Specified Entries"已有了所增加的xsd(的KEY);
选中此xsd条目,下面的Details为:
Location:D:/Programs/Java/spring-framework-2.5.6.SEC01/dist/resources/spring-beans-2.5.xsd
URI:
file:///D:/Programs/Java/spring-framework-2.5.6.SEC01/dist/resources/spring-beans-2.5.xsd
Key Type:Schema Location
Key:
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7)
重启MyEclipse即可,注意如果提示不出来,
并在状态栏的左下出现"Content Assist not
available at the current location",
请在光标位置键入一个空格再使用Alt+/试试;