Skip to content

Commit cfeff11

Browse files
committed
Avoids importing all inner classes to avoid a compilation error when importing a private inner class.
1 parent 2190a8e commit cfeff11

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

codemodel/src/main/java/com/sun/codemodel/JFormatter.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
package com.sun.codemodel;
4242

43+
import com.sun.org.apache.xml.internal.security.encryption.ReferenceList;
44+
4345
import java.io.PrintWriter;
4446
import java.io.Writer;
4547
import java.util.ArrayList;
@@ -473,17 +475,26 @@ private boolean supressImport(JClass clazz, JClass c) {
473475
if(packageName.equals("java.lang"))
474476
return true; // no need to explicitly import java.lang classes
475477

476-
if (clazz._package() == c._package()){
478+
if (clazz._package() == c._package()) {
477479
// inner classes require an import stmt.
478480
// All other pkg local classes do not need an
479481
// import stmt for ref.
480-
if(clazz.outer()==null) {
481-
return true; // no need to explicitly import a class into itself
482-
}
482+
// no need to explicitly import a class into itself
483+
return clazz.outer() == null || isInnerClass(clazz, c);
483484
}
484485
return false;
485486
}
486487

488+
private boolean isInnerClass(JClass clazz, JClass c){
489+
if(clazz.outer() == null){
490+
return false;
491+
}
492+
else if(clazz.outer().equals(c)){
493+
return true;
494+
}
495+
return isInnerClass(clazz.outer(), c);
496+
}
497+
487498
private JPackage javaLang;
488499

489500

0 commit comments

Comments
 (0)