【问题标题】:Highlighting Spock test keywords in Eclipse在 Eclipse 中突出显示 Spock 测试关键字
【发布时间】:2017-12-19 13:21:07
【问题描述】:

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

【问题讨论】:

  • 为您使用的语法安装插件。首选项 > 安装软件 >....
  • 你看过 Groovy Eclipse 插件吗?
  • @Pyves 是的,什么都没有

标签: eclipse syntax-highlighting spock


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2012-02-10
      • 2017-10-04
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多