|
|
@ -23,7 +23,7 @@ import java.util.*; |
|
|
|
public class JodeEnvironment { |
|
|
|
public class JodeEnvironment { |
|
|
|
Hashtable imports; |
|
|
|
Hashtable imports; |
|
|
|
/* Classes that doesn't need to be qualified. */ |
|
|
|
/* Classes that doesn't need to be qualified. */ |
|
|
|
Hashtable goodClasses = new Hashtable(); |
|
|
|
Hashtable cachedClassNames = null; |
|
|
|
ClassAnalyzer main; |
|
|
|
ClassAnalyzer main; |
|
|
|
String className; |
|
|
|
String className; |
|
|
|
String pkg; |
|
|
|
String pkg; |
|
|
@ -66,7 +66,28 @@ public class JodeEnvironment { |
|
|
|
if (pkgName.equals(pkg)) |
|
|
|
if (pkgName.equals(pkg)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
name = name.substring(pkgdelim+1); |
|
|
|
// name without package, but _including_ leading dot.
|
|
|
|
|
|
|
|
name = name.substring(pkgdelim); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pkg.length() != 0) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Class.forName(pkg + name); |
|
|
|
|
|
|
|
/* UGLY: If class doesn't conflict, above |
|
|
|
|
|
|
|
* Instruction throws an exception and we |
|
|
|
|
|
|
|
* doesn't reach here. |
|
|
|
|
|
|
|
* XXX - Is there a better way to do it ??? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// System.err.println(""+pkgName+name
|
|
|
|
|
|
|
|
// + " conflicts with "
|
|
|
|
|
|
|
|
// + pkg+name);
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) { |
|
|
|
|
|
|
|
/* BTW: Exception generation is slow. I'm |
|
|
|
|
|
|
|
* really sad that this is the default. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Enumeration enum = imports.keys(); |
|
|
|
Enumeration enum = imports.keys(); |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
String importName = (String) enum.nextElement(); |
|
|
|
String importName = (String) enum.nextElement(); |
|
|
@ -75,14 +96,16 @@ public class JodeEnvironment { |
|
|
|
importName = importName.substring |
|
|
|
importName = importName.substring |
|
|
|
(0, importName.length()-2); |
|
|
|
(0, importName.length()-2); |
|
|
|
if (!importName.equals(pkgName)) { |
|
|
|
if (!importName.equals(pkgName)) { |
|
|
|
String checkName = importName + "." + name; |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
Class.forName(checkName); |
|
|
|
Class.forName(importName + name); |
|
|
|
/* UGLY: If class doesn't conflict, above |
|
|
|
/* UGLY: If class doesn't conflict, above |
|
|
|
* Instruction throws an exception and we |
|
|
|
* Instruction throws an exception and we |
|
|
|
* doesn't reach here. |
|
|
|
* doesn't reach here. |
|
|
|
* XXX - Is there a better way to do it ??? |
|
|
|
* XXX - Is there a better way to do it ??? |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
// System.err.println(""+pkgName+name
|
|
|
|
|
|
|
|
// + " conflicts with "
|
|
|
|
|
|
|
|
// + importName+name);
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} catch (ClassNotFoundException ex) { |
|
|
|
} catch (ClassNotFoundException ex) { |
|
|
|
/* BTW: Exception generation is slow. I'm |
|
|
|
/* BTW: Exception generation is slow. I'm |
|
|
@ -113,19 +136,20 @@ public class JodeEnvironment { |
|
|
|
if (pkgvote.intValue() >= Decompiler.importPackageLimit) |
|
|
|
if (pkgvote.intValue() >= Decompiler.importPackageLimit) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
/* This is a single Class import. Mark it for importation, |
|
|
|
/* This is a single Class import, that is not |
|
|
|
* but don't put it in newImports, yet. |
|
|
|
* superseeded by a package import. Mark it for |
|
|
|
|
|
|
|
* importation, but don't put it in newImports, yet. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
classImports.addElement(importName); |
|
|
|
classImports.addElement(importName); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (vote.intValue() < Decompiler.importPackageLimit) |
|
|
|
if (vote.intValue() < Decompiler.importPackageLimit) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
newImports.put(importName, dummyVote); |
|
|
|
newImports.put(importName, dummyVote); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
imports = newImports; |
|
|
|
imports = newImports; |
|
|
|
|
|
|
|
cachedClassNames = new Hashtable(); |
|
|
|
/* Now check if the class import conflict with any of the |
|
|
|
/* Now check if the class import conflict with any of the |
|
|
|
* package imports. |
|
|
|
* package imports. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -135,8 +159,12 @@ public class JodeEnvironment { |
|
|
|
* the same name, exactly the first (in hash order) will |
|
|
|
* the same name, exactly the first (in hash order) will |
|
|
|
* be imported. */ |
|
|
|
* be imported. */ |
|
|
|
String className = (String) enum.nextElement(); |
|
|
|
String className = (String) enum.nextElement(); |
|
|
|
if (!conflictsImport(className)) |
|
|
|
if (!conflictsImport(className)) { |
|
|
|
imports.put(className, dummyVote); |
|
|
|
imports.put(className, dummyVote); |
|
|
|
|
|
|
|
String name = |
|
|
|
|
|
|
|
className.substring(className.lastIndexOf('.')+1); |
|
|
|
|
|
|
|
cachedClassNames.put(className, name); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -201,22 +229,22 @@ public class JodeEnvironment { |
|
|
|
int pkgdelim = name.lastIndexOf('.'); |
|
|
|
int pkgdelim = name.lastIndexOf('.'); |
|
|
|
if (pkgdelim != -1) { |
|
|
|
if (pkgdelim != -1) { |
|
|
|
String pkgName = name.substring(0, pkgdelim); |
|
|
|
String pkgName = name.substring(0, pkgdelim); |
|
|
|
if (pkgName.equals(pkg) |
|
|
|
if (pkgName.equals(pkg)) |
|
|
|
|| pkgName.equals("java.lang")) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
Integer i = (Integer) imports.get(name); |
|
|
|
|
|
|
|
if (i == null) { |
|
|
|
|
|
|
|
/* This class wasn't imported before. Mark the package
|
|
|
|
|
|
|
|
* as used. */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = (Integer) imports.get(pkgName+".*"); |
|
|
|
Integer pkgVote = (Integer) imports.get(pkgName+".*"); |
|
|
|
if (i != null && i.intValue() >= Decompiler.importPackageLimit) |
|
|
|
if (pkgVote != null |
|
|
|
return; |
|
|
|
&& pkgVote.intValue() >= Decompiler.importPackageLimit) |
|
|
|
i = (i == null)? new Integer(1): new Integer(i.intValue()+1); |
|
|
|
|
|
|
|
imports.put(pkgName+".*", i); |
|
|
|
|
|
|
|
if (i.intValue() >= Decompiler.importPackageLimit) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer i = (Integer) imports.get(name); |
|
|
|
|
|
|
|
if (i == null) { |
|
|
|
|
|
|
|
/* This class wasn't imported before. Mark the whole package
|
|
|
|
|
|
|
|
* as used once more. */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pkgVote = (pkgVote == null) |
|
|
|
|
|
|
|
? new Integer(1): new Integer(pkgVote.intValue()+1); |
|
|
|
|
|
|
|
imports.put(pkgName+".*", pkgVote); |
|
|
|
i = new Integer(1); |
|
|
|
i = new Integer(1); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -250,23 +278,30 @@ public class JodeEnvironment { |
|
|
|
* @return a legal string representation of clazz. |
|
|
|
* @return a legal string representation of clazz. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String classString(String name) { |
|
|
|
public String classString(String name) { |
|
|
|
|
|
|
|
if (cachedClassNames == null) |
|
|
|
|
|
|
|
/* We are not yet clean, return the full name */ |
|
|
|
|
|
|
|
return name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* First look in our cache. */ |
|
|
|
|
|
|
|
String cached = (String) cachedClassNames.get(name); |
|
|
|
|
|
|
|
if (cached != null) |
|
|
|
|
|
|
|
return cached; |
|
|
|
|
|
|
|
|
|
|
|
int pkgdelim = name.lastIndexOf('.'); |
|
|
|
int pkgdelim = name.lastIndexOf('.'); |
|
|
|
if (pkgdelim != -1) { |
|
|
|
if (pkgdelim != -1) { |
|
|
|
/* First look in our cache. */ |
|
|
|
|
|
|
|
if (goodClasses.get(name) != null) |
|
|
|
|
|
|
|
return name.substring(pkgdelim+1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String pkgName = name.substring(0, pkgdelim); |
|
|
|
String pkgName = name.substring(0, pkgdelim); |
|
|
|
|
|
|
|
|
|
|
|
Integer i; |
|
|
|
Integer i; |
|
|
|
if (pkgName.equals(pkg) |
|
|
|
if (pkgName.equals(pkg) |
|
|
|
|| (( imports.get(pkgName+".*") != null |
|
|
|
|| (imports.get(pkgName+".*") != null |
|
|
|
|| imports.get(name) != null) |
|
|
|
|
|
|
|
&& !conflictsImport(name))) { |
|
|
|
&& !conflictsImport(name))) { |
|
|
|
goodClasses.put(name, name); |
|
|
|
String result = name.substring(pkgdelim+1); |
|
|
|
return name.substring(pkgdelim+1); |
|
|
|
cachedClassNames.put(name, result); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cachedClassNames.put(name, name); |
|
|
|
return name; |
|
|
|
return name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|