1 package org.antlr.works.grammar; 2 3 import org.antlr.works.ate.syntax.misc.ATEScope; 4 import org.antlr.works.ate.syntax.misc.ATEToken; 5 import org.antlr.works.syntax.GrammarSyntaxLexer; 6 import org.antlr.works.syntax.element.*; 7 8 import java.util.List ; 9 39 40 public class RefactorEngine { 41 42 private List <ATEToken> tokens; 43 private RefactorMutator mutator; 44 45 public void setTokens(List <ATEToken> tokens) { 46 this.tokens = tokens; 47 } 48 49 public void setMutator(RefactorMutator mutator) { 50 this.mutator = mutator; 51 } 52 53 public boolean renameToken(ATEToken t, String name) { 54 String attr = t.getAttribute(); 55 56 boolean renameRefRule = t.type == GrammarSyntaxLexer.TOKEN_REFERENCE || t.type == GrammarSyntaxLexer.TOKEN_DECL; 57 58 for(int index = tokens.size()-1; index>0; index--) { 59 ATEToken token = tokens.get(index); 60 if(!token.getAttribute().equals(attr)) continue; 61 62 if(token.type == t.type || 63 renameRefRule && (token.type == GrammarSyntaxLexer.TOKEN_REFERENCE || token.type == GrammarSyntaxLexer.TOKEN_DECL)) 64 { 65 mutator.replace(token.getStartIndex(), token.getEndIndex(), name); 66 } 67 } 68 return true; 69 } 70 71 74 public static boolean ignoreScopeForDoubleQuoteLiteral(ATEScope scope) { 75 if(scope == null) return false; 76 77 Class <? extends Object > c = scope.getClass(); 78 return c.equals(ElementAction.class) || c.equals(ElementBlock.class) || c.equals(ElementRewriteBlock.class) 79 || c.equals(ElementRewriteFunction.class) || c.equals(ElementArgumentBlock.class); 80 } 81 82 83 } 84 | Popular Tags |