修改 eclipse 默认的 toString 模板, 自动对敏感字段进行 *** 处理

本文介绍了如何修改Eclipse的源码,以实现自定义toString方法模板,包括选择StringBuilder/StringBuffer,每字段占一行,并自动对敏感字段进行***处理。涉及到的文件包括ToStringTemplateParser、ToStringGenerationSettings和StringBuilderGenerator。
摘要由CSDN通过智能技术生成
简介:
  eclipse 默认可以生成 toString 方法, 但是自动生成的代码有时候满足不了实际要求, 这里演示一下通过修改 eclipse 源码的方式来改变自动生成的 toString 方法.

1. 目标
1.1 将默认的 toString 模板修改为
  {${member.name()}=${member.value}, ${otherMembers}}
1.2 Code style 默认选中 StringBuilder/StringBuffer
1.3 toString 方法中每个字段占一行
1.4 toString 方法中自动对敏感字段进行 *** 处理
# 修改后截图如下:


2. 依赖 jar
eclipse_home\plugins\com.ibm.icu_50.1.1.v201304230130.jar
eclipse_home\plugins\org.eclipse.core.commands_3.6.100.v20130515-1857.jar
eclipse_home\plugins\org.eclipse.core.resources_3.8.101.v20130717-0806.jar
eclipse_home\plugins\org.eclipse.core.runtime_3.9.100.v20131218-1515.jar
eclipse_home\plugins\org.eclipse.equinox.common_3.6.200.v20130402-1505.jar
eclipse_home\plugins\org.eclipse.jdt.core_3.9.2.v20140114-1555.jar
eclipse_home\plugins\org.eclipse.jdt.ui_3.9.2.v20131106-1600.jar
eclipse_home\plugins\org.eclipse.jface_3.9.1.v20130725-1141.jar
eclipse_home\plugins\org.eclipse.swt.win32.win32.x86_3.102.1.v20140206-1358.jar
eclipse_home\plugins\org.eclipse.ui.workbench_3.105.2.v20140211-1711.jar


3. download eclipse source code
  http://archive.eclipse.org/eclipse/downloads/
  
4. 需要修改的文件
4.1 修改 toString 的默认模板
   org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.ToStringTemplateParser
   org.eclipse.jdt.internal.ui.dialogs.GenerateToStringDialog
   # GenerateToStringDialog 文件内容不需要修改, 只需要重新编译一下
   
4.2 Code style 默认选中 StringBuilder/StringBuffer
   org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.ToStringGenerationSettings
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值