You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.5 KiB
81 lines
2.5 KiB
/* KeywordRenamer Copyright (C) 1999 Jochen Hoenicke.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
package jode.obfuscator.modules;
|
|
import jode.obfuscator.*;
|
|
import @COLLECTIONS@.Collection;
|
|
import @COLLECTIONS@.Iterator;
|
|
import @COLLECTIONEXTRA@.UnsupportedOperationException;
|
|
|
|
public class KeywordRenamer implements Renamer, OptionHandler {
|
|
String keywords[];
|
|
Renamer backup;
|
|
|
|
public KeywordRenamer() {
|
|
keywords = new String[] {
|
|
"if", "else", "for", "while", "throw", "return",
|
|
"class", "interface", "implements", "extends",
|
|
"instanceof", "new",
|
|
"int", "boolean", "long", "float", "double", "short",
|
|
"Object", "String", "Thread",
|
|
"public", "protected", "private",
|
|
"static", "synchronized", "strict", "transient", "abstract",
|
|
"volatile", "final",
|
|
/* Not really keywords, but very confusing anyway. */
|
|
"Object", "String", "Runnable", "StringBuffer", "Vector"
|
|
};
|
|
backup = new StrongRenamer();
|
|
}
|
|
|
|
public void setOption(String option, Collection values) {
|
|
if (option.startsWith("keywords")) {
|
|
keywords = (String[]) values.toArray(new String[values.size()]);
|
|
} else if (option.startsWith("backup")) {
|
|
if (values.size() != 1)
|
|
throw new IllegalArgumentException
|
|
("Only one backup is allowed");
|
|
backup = (Renamer) values.iterator().next();
|
|
} else
|
|
throw new IllegalArgumentException("Invalid option `"+option+"'");
|
|
}
|
|
|
|
public Iterator generateNames(final Identifier ident) {
|
|
return new Iterator() {
|
|
int pos = 0;
|
|
Iterator backing = null;
|
|
|
|
public boolean hasNext() {
|
|
return true;
|
|
}
|
|
public Object next() {
|
|
if (pos < keywords.length)
|
|
return keywords[pos++];
|
|
|
|
if (backing == null)
|
|
backing = backup.generateNames(ident);
|
|
|
|
return backing.next();
|
|
}
|
|
|
|
public void remove() {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|