S-JIS[2013-08-29/2013-08-30] 変更履歴

Xtext用更新サイト

Xtext用の更新サイトのメモ。


概要

XtextのプロジェクトもEclipseのプラグインプロジェクトなので、配布用のフィーチャーサイト更新サイトも普通のEclipseプラグインと同様に作れる。

しかし、気をつけないといけない事がいくつかある。


JDK1.5に関する注意点

Xtext(2.4.2)はJDK1.5でコンパイルするようになっている。
が、今どきJDK1.5なんかインストールしないので、JDK1.7かせいぜいJDK1.6を使うことがほとんどだろう。

自分がハマったのが、@Overrideの扱い。
JDK1.6以降はインターフェースのメソッドを実装するときにも@Overrideを付けるのだが、JDK1.5で付けるとコンパイルエラーになる。
しかしJDK1.6以降の文法を許す設定になっているEclipseでは、Javaエディター上ではエラーにならず、更新サイトのビルドを実行して初めてエラーになる。

さらに、更新サイトのビルドがエラーになってもプラグインのjarファイルは作られるので、一見問題ない。
が、更新サイト経由でインストールしたプラグインはエラーが発生して、使えない><


DMDLHighlightingConfiguration.java:

public class DMDLHighlightingConfiguration implements IHighlightingConfiguration {
〜
	@Override
	public void configure(IHighlightingConfigurationAcceptor acceptor) {
〜
	}
}

configure()はインターフェースの実装になるので、本来は@OverrideはJDK1.5ではコンパイルエラーになる。

logs.zip内の@dot.log:

1. ERROR in D:\workspace\xtext-dmdl-editor\jp.hishidama.xtext.dmdl_editor.ui\src\jp\hishidama\xtext\dmdl_editor\ui\highlighting\DMDLHighlightingConfiguration.java (at line 31)
	public void configure(IHighlightingConfigurationAcceptor acceptor) {
	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method configure(IHighlightingConfigurationAcceptor) of type DMDLHighlightingConfiguration must override a superclass method

更新サイトのビルドを行うと、エラーログが生成される。

このプラグインをインストールして実行すると、下記のようなエラーが出る。

プラグインをインストールしたEclipseでのエラー:

Guice provision errors:

1) Error injecting constructor, java.lang.Error: Unresolved compilation problem: 
	The method configure(IHighlightingConfigurationAcceptor) of type DMDLHighlightingConfiguration must override a superclass method

  at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.(Unknown Source)
  at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.class(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider
    for field at org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingHelper.textAttributeProvider(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingHelper
  while locating org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingHelper
    for field at org.eclipse.xtext.ui.editor.XtextEditor.highlightingHelper(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.XtextEditor
Caused by: java.lang.Error: Unresolved compilation problem: 
	The method configure(IHighlightingConfigurationAcceptor) of type DMDLHighlightingConfiguration must override a superclass method

	at jp.hishidama.xtext.dmdl_editor.ui.highlighting.DMDLHighlightingConfiguration.configure(DMDLHighlightingConfiguration.java:31)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider.initialize(TextAttributeProvider.java:48)
〜

このとき、対象のクラスは以下の様に生成されている。

インストールされたプラグインのDMDLHighlightingConfiguration.class:

public class DMDLHighlightingConfiguration implements IHighlightingConfiguration {

	public void configure(IHighlightingConfigurationAcceptor ihighlightingconfigurationacceptor) {
		throw new Error("Unresolved compilation problem: \n\tThe method configure(IHighlightingConfigurationAcceptor) of type DMDLHighlightingConfiguration must override a superclass method\n");
	}
〜
}

Errorをスローするようになってる!


UTF-8に関する注意点

Windowsで開発していて、Xtextの各プロジェクト(ワークスペース)内のファイルのエンコーディングをUTF-8にしている場合、
日本語のコメントやStringリテラルが文字化けして、場合によってはコンパイルエラーを誘発する。


ソース整形で遭遇したバグ。

DMDLFormatter.java(UTF-8):

public class DMDLFormatter extends AbstractDeclarativeFormatter {

	@Override
	protected void configureFormatting(FormattingConfig c) {
〜
		// カンマ
		for (Keyword comma : f.findKeywords(",")) {
			c.setNoSpace().before(comma); // 直前は詰める
		}
〜
	}
}

logs.zip内の@dot.log:

----------
1. ERROR in D:\workspace\xtext-dmdl-editor\jp.hishidama.xtext.dmdl_editor\src\jp\hishidama\xtext\dmdl_editor\formatting\DMDLFormatter.java (at line 51)
	c.setNoSpace().before(comma); // 直前�?詰める
	                      ^^^^^
comma cannot be resolved to a variable
----------
2. ERROR in D:\cygwin\home\hishidama\git\xtext-dmdl-editor\jp.hishidama.xtext.dmdl_editor\src\jp\hishidama\xtext\dmdl_editor\formatting\DMDLFormatter.java (at line 52)
	}
	^
Syntax error on token "}", { expected after this token
----------

「commaという変数が無い」というエラーと「"}"{の後でなければならない」というエラーだが、
原因は、「// カンマ」の「マ」が文字化けして、直後の改行を巻き込んでいることにあると思われる。
つまり以下の様なコードとしてコンパイルしているのだろう。

		// カン?		for (Keyword comma : f.findKeywords(",")) {
			c.setNoSpace().before(comma); // 直前は詰める
		}

これじゃ、commaという変数は定義されていないし、ブロックの開始も無いよな(苦笑)


対処法としては、エンコーディングをMS932にするか、プラグインプロジェクト/uiプロジェクトのbuild.propertiesにエンコードを指定する。[2013-08-30]

build.properties:

source.. = src/,\
          src-gen/,\
          xtend-gen/
bin.includes = META-INF/,\
               .,\
               plugin.xml

javacSource.. = 1.5
javacTarget.. = 1.5
javacDefaultEncoding.. = UTF-8

Xtext目次へ戻る / Eclipseへ戻る / 技術メモへ戻る
メールの送信先:ひしだま