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 25 years ago
parent de5d631370
commit 058eb11e6a
  1. 91
      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) {
String pkgName = name.substring(0, pkgdelim);
if (pkgName.equals(pkg))
return;
Integer pkgVote = (Integer) imports.get(pkgName+".*");
if (pkgVote != null
&& pkgVote.intValue() >= importPackageLimit)
return;
Integer i = (Integer) imports.get(name); Integer i = (Integer) imports.get(name);
if (i == null) { if (i == null) {
/* This class wasn't imported before. Mark the whole package /* This class wasn't imported before. Mark the whole package
* as used once more. */ * as used once more. */
pkgVote = (pkgVote == null) int pkgdelim = name.lastIndexOf('.');
? new Integer(1): new Integer(pkgVote.intValue()+1); if (pkgdelim != -1) {
imports.put(pkgName+".*", pkgVote); String pkgName = name.substring(0, pkgdelim);
i = new Integer(1); if (pkgName.equals(pkg))
return;
} else {
if (i.intValue() >= importClassLimit) Integer pkgVote = (Integer) imports.get(pkgName+".*");
return; if (pkgVote != null
i = new Integer(i.intValue()+1); && pkgVote.intValue() >= importPackageLimit)
} return;
imports.put(name, i);
} pkgVote = (pkgVote == null)
? new Integer(1): new Integer(pkgVote.intValue()+1);
imports.put(pkgName+".*", pkgVote);
}
i = new Integer(1);
} else {
if (i.intValue() >= importClassLimit)
return;
i = new Integer(i.intValue()+1);
}
imports.put(name, i);
} }
public final void useType(Type type) { public final void useType(Type type) {

Loading…
Cancel
Save