更改moreunit在workspace中查找Test类

本文介绍如何通过修改 Moreunit 插件中的 TestCaseDiviner 类,实现从编辑器跨项目跳转到测试类的功能,并增加了在工作区范围内搜索的能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

moreunit 可以从一个类的editor中跳转到测试类(ctrl+J).

 

如果测试类是在另外一个project中, 需要修改project的properties . 因为项目中的其它人员没有使用moreunit插件,所以不想check in 这个配置文件到snv中。

 

修改moreunit的方法org.moreunit.util.TestCaseDiviner.findPotentialTargets,增加从workspace这个scope中查找

 

for (String element : prefixes)
{
	//this.matches.addAll(SearchTools.searchFor(getSearchTerm(this.source
	// , element, true), this.compilationUnit));
	Set<IType> origionalPrefixMatch = SearchTools.searchFor(getSearchTerm(this.source, element, true), this.compilationUnit, getSearchScope());
	this.matches.addAll(origionalPrefixMatch);
	if(origionalPrefixMatch.isEmpty())//add search in workspace
	{
		IJavaSearchScope workSpaceScop = SearchEngine.createWorkspaceScope();
		this.matches.addAll(SearchTools.searchFor(getSearchTerm(this.source, element, true), this.compilationUnit, workSpaceScop));
	}
}

String[] suffixes = this.preferences.getSuffixes(getJavaProject());
for (String element : suffixes)
{
	// this.matches.addAll(SearchTools.searchFor(getSearchTerm(this.source
	// , element, false), this.compilationUnit));
	Set<IType> origionalPostfixMatch = SearchTools.searchFor(getSearchTerm(this.source, element, false), this.compilationUnit, getSearchScope());
	this.matches.addAll(origionalPostfixMatch);
	if(origionalPostfixMatch.isEmpty())//add search in workspace
	{
		IJavaSearchScope workSpaceScop = SearchEngine.createWorkspaceScope();
		this.matches.addAll(SearchTools.searchFor(getSearchTerm(this.source, element, false), this.compilationUnit, workSpaceScop));
	}
}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值