寻找有用的 Eclipse Java 代码模板 [英] Seeking useful Eclipse Java code templates

查看:32
本文介绍了寻找有用的 Eclipse Java 代码模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以通过

窗口 > 首选项 > Java > 编辑器 > 模板

例如

sysout 扩展为:

System.out.println(${word_selection}${});${cursor}

您可以通过键入 sysout 后跟 CTRL+SPACE

You can activate this by typing sysout followed by CTRL+SPACE

您目前使用哪些有用的 Java 代码模板?包括它的名称和描述以及它为什么很棒.

What useful Java code templates do you currently use? Include the name and description of it and why it's awesome.

我正在寻找模板的原始/新颖用途,而不是内置的现有功能.

I am looking for an original/novel use of a template rather than a built-in existing feature.

  • 创建 Log4J 记录器
  • 从显示中获取 swt 颜色
  • Syncexec - Eclipse 框架
  • 单例模式/枚举单例生成
  • 读取文件
  • 常量
  • 追踪
  • 格式字符串
  • 评论代码审查
  • 字符串格式
  • 尝试最后锁定
  • 消息格式 i18n 和日志
  • 平等建设者
  • 哈希码生成器
  • Spring 对象注入
  • 创建文件输出流

推荐答案

以下代码模板将创建记录器并在需要时创建正确的导入.

The following code templates will both create a logger and create the right imports, if needed.

SLF4J

${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);

Log4J 2

${:import(org.apache.logging.log4j.LogManager,org.apache.logging.log4j.Logger)} 
private static final Logger LOG = LogManager.getLogger(${enclosing_type}.class); 

Log4J

${:import(org.apache.log4j.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);

来源.

七月

${:import(java.util.logging.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class.getName());

这篇关于寻找有用的 Eclipse Java 代码模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆