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;
}
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();
}
Aggregations