myeclipse 多行注释 格式化 换行问题

写代码的时候喜欢格式化一下,但是很扯淡的是我的注释,单行的还行,格式化后既好看又实用,多行注释(/* */)就苦逼了。全乱了,都被折行了。



所以百度了一下,也没有解决方案,自己去百度词典搜了一下,注释原来是叫comments,就去myeclipse设置里面找到了这个选项卡,现在有一个解决方案。


Java->Code Style->Formatter 点击Edit 后在Tab上选择Comments,将General  settings中的"Enable Javadoc comment formatting"前面的勾去掉就可以了。


设置方法:



最后别忘记点ok 保存!

然后你继续格式化代码的时候就会发现,我去,代码终于听话了!


/*public void writeExcel() {         File file = new File("D:/testExcelPoi.xls");         ExcelBean bean; // 获得输出流 FileOutputStream fos = null; HSSFRow row = null;         HSSFCell cell = null;         try {             bean = new ExcelBean("99", "grpinv0500_e", "99", "");             List<ExcelHead> heads = bean.getExcelHeads();             System.out.println(bean.getExcelHeads().size()); // 创建工作薄 HSSFWorkbook wb =             new HSSFWorkbook();             String sheetName = "物料查询";                  int rownum = 3;// 从excel表格的第四行开始写记录 HSSFSheet sheet =             wb.createSheet(sheetName);             row = sheet.createRow(rownum);                  for (int i = 0; i < heads.size(); i++) {                 System.out.println("创建第" + i + "列");                 sheet.setColumnWidth(i, heads.get(i).getWidth() * 512);                 makeCell(wb, row, styles[i], i, heads.get(i).getDescMsg());             }                  fos = new FileOutputStream(file.getAbsolutePath());             wb.write(fos);         } catch (FileNotFoundException e) {             e.printStackTrace();         } catch (IOException e) {             e.printStackTrace();         } catch (ReportException e1) {             e1.printStackTrace();         } finally {             if (fos != null) {                 try {                     fos.close();                 } catch (IOException e) {                     e.printStackTrace();                 }             }         }         System.out.println("搞定!");     }*/


其实发布源码的时候,这种多行注释一般很少。主要是javaDoc,格式化后就不好看了。

另外转载 MyEclipse中防止代码格式化时出现换行的情况的设置 


 

编辑完成代码,用MyEclipse的代码格式化后,本来不长的代码也被自动转成了多行。虽然自动换行以后在编辑器中一眼就能看到全部的代码,但是可读性却大打折扣,避免出现这种情况的办法是:

1.Java代码

打开Eclipse的Window菜单,然后Preferences->Java->Code Style->Formatter->Edit/Show(根据不同版本可用的按钮会不一样) ->Line Wrapping->Maximum line 由默认的80改成自己想要设定的长度

2.Html代码

Window->Preferences->MyEclipse->Files and Editors->Html->Html Source->Line width->加个0以后保存。

3.xml代码

Window->Preferences->MyEclipse->Files and Editors->xml->xml Source->->Line width->999

原文地址:https://www.cnblogs.com/ae6623/p/4416598.html