Search in sources :

Example 1 with ElementTemplateRule

use of org.antlr.works.stringtemplate.element.ElementTemplateRule in project antlrworks by antlr.

the class STRefactorMenu method renameToken.

public boolean renameToken(ATEToken t, String name) {
    String attr = t.getAttribute();
    List<ATEToken> tokens = window.getTokens();
    boolean isArg = t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE;
    boolean renameRefRule = t.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || t.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL;
    if (renameRefRule) {
        for (int index = tokens.size() - 1; index > 0; index--) {
            ATEToken token = tokens.get(index);
            if (!token.getAttribute().equals(attr))
                continue;
            if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || token.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL) {
                mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
            }
        }
    } else if (isArg) {
        ElementTemplateRule rule = getRuleAtPosition(window.getCaretPosition());
        for (int index = tokens.size() - 1; index > 0; index--) {
            ATEToken token = tokens.get(index);
            if (!token.getAttribute().equals(attr))
                continue;
            if (rule.containsIndex(token.start)) {
                if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE) {
                    mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
                }
            }
        }
    } else {
        mutator.replace(t.getStartIndex(), t.getEndIndex(), name);
    }
    return true;
}
Also used : ElementTemplateRule(org.antlr.works.stringtemplate.element.ElementTemplateRule) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 2 with ElementTemplateRule

use of org.antlr.works.stringtemplate.element.ElementTemplateRule in project antlrworks by antlr.

the class STRulePanel method refreshRules.

public void refreshRules() {
    model.clear();
    List<ElementTemplateRule> rules = ((ATEStringTemplateSyntaxParser) window.getTextEditor().getParserEngine().getParser()).templateRules;
    for (ElementTemplateRule rule : rules) {
        model.addRule(rule);
    }
    model.fireSort();
    tableView.getTable().setModel(model);
    tableView.autoresizeColumns();
}
Also used : ElementTemplateRule(org.antlr.works.stringtemplate.element.ElementTemplateRule) ATEStringTemplateSyntaxParser(org.antlr.works.stringtemplate.syntax.ATEStringTemplateSyntaxParser)

Aggregations

ElementTemplateRule (org.antlr.works.stringtemplate.element.ElementTemplateRule)2 ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)1 ATEStringTemplateSyntaxParser (org.antlr.works.stringtemplate.syntax.ATEStringTemplateSyntaxParser)1