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

Loading…
Cancel
Save