| 1 19 20 package jode.obfuscator.modules; 21 import jode.obfuscator.*; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import java.lang.UnsupportedOperationException ; 25 26 public class KeywordRenamer implements Renamer, OptionHandler { 27 String keywords[]; 28 Renamer backup; 29 30 public KeywordRenamer() { 31 keywords = new String [] { 32 "if", "else", "for", "while", "throw", "return", 33 "class", "interface", "implements", "extends", 34 "instanceof", "new", 35 "int", "boolean", "long", "float", "double", "short", 36 "public", "protected", "private", 37 "static", "synchronized", "strict", "transient", "abstract", 38 "volatile", "final", 39 40 "Object", "String", "Thread", "Runnable", "StringBuffer", "Vector" 41 }; 42 backup = new StrongRenamer(); 43 } 44 45 public void setOption(String option, Collection values) { 46 if (option.startsWith("keywords")) { 47 keywords = (String []) values.toArray(new String [values.size()]); 48 } else if (option.startsWith("backup")) { 49 if (values.size() != 1) 50 throw new IllegalArgumentException  51 ("Only one backup is allowed"); 52 backup = (Renamer) values.iterator().next(); 53 } else 54 throw new IllegalArgumentException ("Invalid option `"+option+"'"); 55 } 56 57 public Iterator generateNames(final Identifier ident) { 58 return new Iterator () { 59 int pos = 0; 60 Iterator backing = null; 61 62 public boolean hasNext() { 63 return true; 64 } 65 public Object next() { 66 if (pos < keywords.length) 67 return keywords[pos++]; 68 69 if (backing == null) 70 backing = backup.generateNames(ident); 71 72 return backing.next(); 73 } 74 75 public void remove() { 76 throw new UnsupportedOperationException (); 77 } 78 }; 79 } 80 } 81 | Popular Tags |