1 16 package com.google.gwt.dev.js; 17 18 import com.google.gwt.dev.js.ast.JsName; 19 import com.google.gwt.dev.js.ast.JsProgram; 20 import com.google.gwt.dev.js.ast.JsRootScope; 21 import com.google.gwt.dev.js.ast.JsScope; 22 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 30 public class JsVerboseNamer { 31 32 public static void exec(JsProgram program) { 33 new JsVerboseNamer(program).execImpl(); 34 } 35 36 private final JsProgram program; 37 38 public JsVerboseNamer(JsProgram program) { 39 this.program = program; 40 } 41 42 private void execImpl() { 43 visit(program.getRootScope()); 44 } 45 46 private boolean isLegal(JsScope scope, String newIdent) { 47 return !JsKeywords.isKeyword(newIdent); 49 } 50 51 private void visit(JsScope scope) { 52 List children = scope.getChildren(); 54 for (Iterator it = children.iterator(); it.hasNext();) { 55 visit((JsScope) it.next()); 56 } 57 58 JsRootScope rootScope = program.getRootScope(); 59 if (scope == rootScope) { 60 return; 61 } 62 63 for (Iterator it = scope.getAllNames(); it.hasNext();) { 65 JsName name = (JsName) it.next(); 66 if (!name.isObfuscatable()) { 67 name.setShortIdent(name.getIdent()); 69 continue; 70 } 71 72 String fullIdent = name.getIdent(); 73 if (!isLegal(scope, fullIdent)) { 74 String checkIdent = fullIdent; 75 for (int i = 0; true; ++i) { 76 checkIdent = fullIdent + "_" + i; 77 if (isLegal(scope, checkIdent)) { 78 break; 79 } 80 } 81 name.setShortIdent(checkIdent); 82 } else { 83 name.setShortIdent(fullIdent); 85 } 86 } 87 } 88 } 89 | Popular Tags |