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. 27
      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,6 +154,7 @@ public class ImportHandler {
continue; continue;
int delim = importName.lastIndexOf("."); int delim = importName.lastIndexOf(".");
if (delim != -1) {
/* Since the imports are sorted, newImports already /* Since the imports are sorted, newImports already
* contains the package if it should be imported. * contains the package if it should be imported.
*/ */
@ -165,6 +167,12 @@ public class ImportHandler {
* importation, but don't put it in newImports, yet. * 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,6 +266,12 @@ public class ImportHandler {
} }
String name = clazz.getName(); String name = clazz.getName();
Integer i = (Integer) imports.get(name);
if (i == null) {
/* This class wasn't imported before. Mark the whole package
* as used once more. */
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);
@ -268,16 +283,11 @@ public class ImportHandler {
&& pkgVote.intValue() >= importPackageLimit) && pkgVote.intValue() >= 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) pkgVote = (pkgVote == null)
? new Integer(1): new Integer(pkgVote.intValue()+1); ? new Integer(1): new Integer(pkgVote.intValue()+1);
imports.put(pkgName+".*", pkgVote); imports.put(pkgName+".*", pkgVote);
}
i = new Integer(1); i = new Integer(1);
} else { } else {
if (i.intValue() >= importClassLimit) if (i.intValue() >= importClassLimit)
return; return;
@ -285,7 +295,6 @@ public class ImportHandler {
} }
imports.put(name, i); imports.put(name, i);
} }
}
public final void useType(Type type) { public final void useType(Type type) {
if (type instanceof ArrayType) if (type instanceof ArrayType)

Loading…
Cancel
Save