突出显示 Eclipse 中的 Spock 测试关键字



我正在使用Eclipse进行Java项目,其中包含一些使用given:when:then:语法的Groovy/Spock编写的测试。 我希望这些关键字用一些颜色突出显示。 注意:spock 插件应该这样做,但不起作用。 所以想自己做这个。

given:when:等是语句标签。 目前不支持在 Groovy-Eclipse 中突出显示语句标签。 它们实际上有点难以确定,因为它们没有与源位置信息一起保存在 AST 中。org.codehaus.groovy.ast.stmt.Statement.getStatementLabels()返回List<String>. 因此,可以判断哪些语句具有标签,但是需要扫描语句的源范围以找到标签的范围。

似乎对Groovy 中的标签没有任何支持。我已经做了一些搜索,但正如@emilles所说,网络上什么都没有。

如果您有语法文件或可以在某个地方获得它(经过一些搜索后我没有找到它),请将其转换为HRC文件,然后按照下面的步骤操作。看那里 (http://colorer.sourceforge.net/hrc-ref/index.html)

现在,您可以为您的语言创建颜色。有很多插件可以做到这一点,比如EclipseColorer。我已经用过那个了,所以我要给你步骤:

1 - Install the software (Help -> Install New Software)
2 - Search http://colorer.sf.net/eclipsecolorer/
3 - Once the plugin is installed and Eclipse is restart
4 - Copy the HRC file in the eclipse's folder
5 - Add the prototype file

基本的:

<?xml version="1.0" encoding='Windows-1251'?>
<!DOCTYPE hrc PUBLIC
"-//Cail Lomecb//DTD Colorer HRC take5//EN"
"http://colorer.sf.net/2003/hrc.dtd"
>
<hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://colorer.sf.net/2003/hrc http://colorer.sf.net/2003/hrc.xsd"
><annotation><documentation>
'auto' is a place for include
to colorer your own HRCs
</documentation></annotation>
<prototype name="d" group="main" description="D">
<location link="types/d.hrc"/>
<filename>/.(d)$/i</filename>
</prototype>
</hrc>

6 - In Eclipse Window -> Preferences -> General -> Editors -> File Associations
7 - Add the filetype for your syntax
8 - Restart Eclipse and your good

如果你没有这种文件,将会很长很困难,它是一种特定于领域的语言,你必须从头开始。因此,唯一真正的方法是根据需要创建新的着色语法,但实现起来非常棘手。

你有一些关于它的信息:http://www.mo-seph.com/projects/syntaxhighlighting

最新更新