Import classes from unnamed packages correctly

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1236 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
hoenicke 24 years ago
parent de5d631370
commit 058eb11e6a
  1. 93
      jode/jode/decompiler/ImportHandler.java.in

@ -132,7 +132,8 @@ public class ImportHandler {
} }
} else { } else {
/* Is this a class import with same name? */ /* Is this a class import with same name? */
if (importName.endsWith(name)) if (importName.endsWith(name)
|| importName.equals(name.substring(1)))
return true; return true;
} }
} }
@ -153,18 +154,25 @@ public class ImportHandler {
continue; continue;
int delim = importName.lastIndexOf("."); int delim = importName.lastIndexOf(".");
/* Since the imports are sorted, newImports already if (delim != -1) {
* contains the package if it should be imported. /* Since the imports are sorted, newImports already
*/ * contains the package if it should be imported.
if (newImports.containsKey */
(importName.substring(0, delim)+".*")) if (newImports.containsKey
continue; (importName.substring(0, delim)+".*"))
continue;
/* This is a single Class import, that is not
* superseeded by a package import. Mark it for /* This is a single Class import, that is not
* importation, 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.add(importName); */
classImports.add(importName);
} else if (pkg.length() != 0) {
/* This is a Class import from the unnamed
* package. It must always be imported.
*/
newImports.put(importName, dummyVote);
}
} else { } else {
if (vote.intValue() < importPackageLimit) if (vote.intValue() < importPackageLimit)
continue; continue;
@ -181,7 +189,8 @@ public class ImportHandler {
while (iter.hasNext()) { while (iter.hasNext()) {
/* If there are more than one single class imports with /* If there are more than one single class imports with
* the same name, exactly the first (in sorted order) will * the same name, exactly the first (in sorted order) will
* be imported. */ * be imported.
*/
String classFQName = (String) iter.next(); String classFQName = (String) iter.next();
if (!conflictsImport(classFQName)) { if (!conflictsImport(classFQName)) {
imports.put(classFQName, dummyVote); imports.put(classFQName, dummyVote);
@ -257,34 +266,34 @@ public class ImportHandler {
} }
String name = clazz.getName(); String name = clazz.getName();
int pkgdelim = name.lastIndexOf('.');
if (pkgdelim != -1) { Integer i = (Integer) imports.get(name);
String pkgName = name.substring(0, pkgdelim); if (i == null) {
if (pkgName.equals(pkg)) /* This class wasn't imported before. Mark the whole package
return; * as used once more. */
Integer pkgVote = (Integer) imports.get(pkgName+".*"); int pkgdelim = name.lastIndexOf('.');
if (pkgVote != null if (pkgdelim != -1) {
&& pkgVote.intValue() >= importPackageLimit) String pkgName = name.substring(0, pkgdelim);
return; if (pkgName.equals(pkg))
return;
Integer i = (Integer) imports.get(name);
if (i == null) { Integer pkgVote = (Integer) imports.get(pkgName+".*");
/* This class wasn't imported before. Mark the whole package if (pkgVote != null
* as used once more. */ && pkgVote.intValue() >= importPackageLimit)
return;
pkgVote = (pkgVote == null)
? new Integer(1): new Integer(pkgVote.intValue()+1); pkgVote = (pkgVote == null)
imports.put(pkgName+".*", pkgVote); ? new Integer(1): new Integer(pkgVote.intValue()+1);
i = new Integer(1); imports.put(pkgName+".*", pkgVote);
}
} else { i = new Integer(1);
if (i.intValue() >= importClassLimit) } else {
return; if (i.intValue() >= importClassLimit)
i = new Integer(i.intValue()+1); return;
} i = new Integer(i.intValue()+1);
imports.put(name, i); }
} imports.put(name, i);
} }
public final void useType(Type type) { public final void useType(Type type) {

Loading…
Cancel
Save