我是Eclipse插件开发的新手,但我已经能够拼凑出一个定义内容类型和相应编辑器的插件。我已经获得了自定义内容辅助功能,因此我知道编辑器即将推出。
我的问题是我需要为这种内容类型的文件创建一些自定义验证,而且我发现了很少的信息。我能找到的唯一有Java代码的例子是:http://www.eclipse.org/webtools/wst/components/sse/tutorials/source-validation.html。
不幸的是,复制此技术不会产生任何结果。我甚至都没有调用我的验证器类。
以下是我plugin.xml
的相关部分:
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.xml"
file-extensions="xml"
id="com.palantir.eclipse.kite.contenttype.kite"
name="Kite File"
priority="normal">
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
<parameter name="element" value="kite"></parameter>
</describer>
</content-type>
</extension>
<extension point="org.eclipse.ui.editors">
<editor name="Kite XML Editor"
icon="icons/smalllogo.gif"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="com.palantir.eclipse.kite.plugin.editor.KiteXmlEditor"
id="com.palantir.eclipse.kite.plugin.editor.KiteXmlEditor">
<contentTypeBinding contentTypeId="com.palantir.eclipse.kite.contenttype.kite">
</contentTypeBinding>
</editor>
</extension>
<extension point="org.eclipse.wst.sse.ui.sourcevalidation">
<validator scope="total"
class="com.palantir.eclipse.kite.plugin.validator.KiteValidator"
id="com.palantir.eclipse.kite.plugin.validator.KiteValidator">
<contentTypeIdentifier id="com.palantir.eclipse.kite.contenttype.kite">
<partitionType id="org.eclipse.wst.sse.ST_DEFAULT" />
</contentTypeIdentifier>
</validator>
</extension>
验证器文件:
package com.palantir.eclipse.kite.plugin.validator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
public class KiteValidator implements ISourceValidator, IValidator {
public KiteValidator() {
System.out.println("Initialized KiteValidator");
}
public void cleanup(IReporter reporter) {
System.out.println("Inside KiteValidator");
}
public void validate(IValidationContext context, IReporter reporter) {
System.out.println("Inside KiteValidator");
}
public void connect(IDocument document) {
System.out.println("Inside KiteValidator");
}
public void disconnect(IDocument document) {
System.out.println("Inside KiteValidator");
}
public void validate(IRegion region, IValidationContext context, IReporter reporter) {
System.out.println("Inside KiteValidator");
}
}