• Eclipse plugin开发 —实现语法高亮


    1. 在public class XMLConfiguration中添加扫描函数:

    protected ValueScanner getValueScanner() {
    if (valuescanner == null) {
    valuescanner = new ValueScanner(colorManager);
    valuescanner.setDefaultReturnToken(
    new Token(
    new TextAttribute(
    colorManager.getColor(IXMLColorConstants.DEFAULT))));
    }
    return valuescanner;
    }

    2. 在getPresentationReconciler函数中添加:

    dr = new DefaultDamagerRepairer(getValueScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

    3. 最后添加两个类:ValueScanner和WordDetector:

    public class ValueScanner extends RuleBasedScanner{

    String[]keywords = {"continent","country","hi","int"};

    String[] funwords = {"short","long","double","long long",
    "char","float","boolean","octet","string",
    "unsigned short","unsigned long","unsigned long long"};

    public ValueScanner(ColorManager manager)
    {
    IToken keywordToken =
    new Token(
    new TextAttribute(manager.getColor(IXMLColorConstants.STRING)));//IXMLColorConstants.STRING指定颜色

    IToken funwordToken =
    new Token(
    new TextAttribute(manager.getColor(IXMLColorConstants.TAG)));

    WordRule keywordRule = new WordRule(new WordDetector());
    for(int i=0;i<keywords.length;i++)
    {
    keywordRule.addWord(keywords[i], keywordToken);
    }
    for(int i=0;i<funwords.length;i++)
    {
    keywordRule.addWord(funwords[i], funwordToken);
    }
    setRules(new IRule[]{keywordRule});
    }
    }

    //******************************************************************

    public class WordDetector implements IWordDetector{

    public boolean isWordStart(char c){
    return Character.isLetter(c);
    }

    public boolean isWordPart(char c){
    return Character.isLetterOrDigit(c);
    }
    }

    4. 打完手工。

  • 相关阅读:
    Winform打包Exe Inno Setup
    electron build慢
    electron解压app.asar文件
    input readonly 禁止获得焦点 和选择
    JS export
    数据库插件 red-gate SQLToolbelt
    DataGridView修改值后,最后一个修改项页面不会刷新
    DbDataReaderExtensions DbDataRender转换为实体
    反射获得实体
    LINQ Expression AndAlso,OrElse和And,Or的区别
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/texteditor3.html
Copyright © 2020-2023  润新知