make use of collection classes

use Renamer and IdentifierMatcher#


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@978 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 0f95c6338a
commit 8cffa60d13
  1. 86
      jode/jode/obfuscator/ClassBundle.java

@ -22,21 +22,34 @@ import jode.GlobalOptions;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
import jode.bytecode.Reference; import jode.bytecode.Reference;
import java.io.*; import java.io.*;
import java.util.*;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
///#ifdef JDK12
///import java.util.Collection;
///import java.util.Iterator;
///import java.util.Set;
///import java.util.HashSet;
///import java.util.Map;
///import java.util.TreeMap;
///import java.util.WeakHashMap;
///#else
import jode.util.Collection;
import jode.util.Iterator;
import jode.util.Set;
import jode.util.HashSet;
import jode.util.Map;
import jode.util.TreeMap;
import jode.util.HashMap;
///#endif
public class ClassBundle { public class ClassBundle {
int preserveRule; ModifierMatcher preserveRule = null;
PackageIdentifier basePackage; PackageIdentifier basePackage;
/** /**
* the identifiers that must be analyzed. * the identifiers that must be analyzed.
*/ */
///#ifdef JDK12 Set toAnalyze = new HashSet();
/// Set toAnalyze = new HashSet();
///#else
Stack toAnalyze = new Stack();
///#endif
public ClassBundle() { public ClassBundle() {
basePackage = new PackageIdentifier(this, null, "", false); basePackage = new PackageIdentifier(this, null, "", false);
@ -47,8 +60,9 @@ public class ClassBundle {
///#ifdef JDK12 ///#ifdef JDK12
/// private static final Map aliasesHash = new WeakHashMap(); /// private static final Map aliasesHash = new WeakHashMap();
///#else ///#else
private static final Hashtable aliasesHash = new Hashtable(); private static final Map aliasesHash = new HashMap();
///#endif ///#endif
public Reference getReferenceAlias(Reference ref) { public Reference getReferenceAlias(Reference ref) {
Reference alias = (Reference) aliasesHash.get(ref); Reference alias = (Reference) aliasesHash.get(ref);
if (alias == null) { if (alias == null) {
@ -86,7 +100,9 @@ public class ClassBundle {
} }
public ClassIdentifier getClassIdentifier(String name) { public ClassIdentifier getClassIdentifier(String name) {
return (ClassIdentifier) basePackage.getIdentifier(name); ClassIdentifier ident
= (ClassIdentifier) basePackage.getIdentifier(name);
return ident;
} }
public Identifier getIdentifier(Reference ref) { public Identifier getIdentifier(Reference ref) {
@ -103,6 +119,7 @@ public class ClassBundle {
} }
public void loadClasses(String wildcard) { public void loadClasses(String wildcard) {
System.err.println("Loading: "+wildcard);
basePackage.loadMatchingClasses(new WildCard(wildcard)); basePackage.loadMatchingClasses(new WildCard(wildcard));
} }
@ -110,70 +127,53 @@ public class ClassBundle {
basePackage.reachableIdentifier(fqn, isVirtual); basePackage.reachableIdentifier(fqn, isVirtual);
} }
public void setPreserved(int preserveRule, Vector fullqualifiednames) { public void setPreserved(ModifierMatcher preserveRule,
Collection fullqualifiednames) {
this.preserveRule = preserveRule; this.preserveRule = preserveRule;
basePackage.applyPreserveRule(preserveRule); basePackage.applyPreserveRule(preserveRule);
Enumeration enum = fullqualifiednames.elements(); for (Iterator i = fullqualifiednames.iterator(); i.hasNext(); ) {
while (enum.hasMoreElements()) {
basePackage.preserveMatchingIdentifier basePackage.preserveMatchingIdentifier
(new WildCard((String) enum.nextElement())); (new WildCard((String) i.next()));
} }
analyze(); analyze();
} }
///#ifdef JDK12
/// public void analyzeIdentifier(Identifier i) {
/// if (!toAnalyze.contains(i))
/// toAnalyze.add(i);
/// }
///
/// public void analyze() {
/// while(!toAnalyze.isEmpty()) {
/// Identifier ident = (Identifier) toAnalyze.iterator().next();
/// toAnalyze.remove(ident);
/// ident.analyze();
/// }
/// }
///#else
public void analyzeIdentifier(Identifier i) { public void analyzeIdentifier(Identifier i) {
if (!toAnalyze.contains(i)) toAnalyze.add(i);
toAnalyze.addElement(i);
} }
public void analyze() { public void analyze() {
while (!toAnalyze.isEmpty()) while(!toAnalyze.isEmpty()) {
((Identifier) toAnalyze.pop()).analyze(); Identifier ident = (Identifier) toAnalyze.iterator().next();
toAnalyze.remove(ident);
ident.analyze();
}
} }
///#endif
public void buildTable(int renameRule) { public void buildTable(Renamer renameRule) {
basePackage.buildTable(renameRule); basePackage.buildTable(renameRule);
} }
public void readTable(String filename) { public void readTable(String filename) {
Properties prop = new Properties();
try { try {
TranslationTable table = new TranslationTable();
InputStream input = new FileInputStream(filename); InputStream input = new FileInputStream(filename);
prop.load(input); table.load(input);
input.close(); input.close();
basePackage.readTable(table);
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
GlobalOptions.err.println("Can't read rename table "+filename); GlobalOptions.err.println("Can't read rename table "+filename);
ex.printStackTrace(GlobalOptions.err); ex.printStackTrace(GlobalOptions.err);
} }
basePackage.readTable(prop);
} }
public void writeTable(String filename) { public void writeTable(String filename) {
Properties prop = new Properties(); TranslationTable table = new TranslationTable();
basePackage.writeTable(prop); basePackage.writeTable(table);
try { try {
OutputStream out = new FileOutputStream(filename); OutputStream out = new FileOutputStream(filename);
///#ifdef JDK12 table.store(out);
/// prop.store(out, "Reverse renaming table");
///#else
prop.save(out, "Reverse renaming table");
///#endif
out.close(); out.close();
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
GlobalOptions.err.println("Can't write rename table "+filename); GlobalOptions.err.println("Can't write rename table "+filename);

Loading…
Cancel
Save