1818package org .hibernate .tool .internal .export .java ;
1919
2020import java .util .HashMap ;
21- import java .util .Iterator ;
2221import java .util .Map ;
2322import java .util .Set ;
2423import java .util .TreeSet ;
@@ -57,13 +56,12 @@ public ImportContextImpl(String basePackage) {
5756 /**
5857 * Add fqcn to the import list. Returns fqcn as needed in source code.
5958 * Attempts to handle fqcn with array and generics references.
60- *
59+ * <p>
6160 * e.g.
6261 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
6362 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
6463 *
6564 *
66- * @param fqcn
6765 * @return import string
6866 */
6967 public String importType (String fqcn ) {
@@ -88,14 +86,9 @@ public String importType(String fqcn) {
8886 String simpleName = StringHelper .unqualify (fqcn );
8987 if (simpleNames .containsKey (simpleName )) {
9088 String existingFqcn = (String ) simpleNames .get (simpleName );
91- if (existingFqcn .equals (pureFqcn )) {
92- canBeSimple = true ;
93- } else {
94- canBeSimple = false ;
95- }
89+ canBeSimple = existingFqcn .equals (pureFqcn );
9690 } else {
97- canBeSimple = true ;
98- simpleNames .put (simpleName , pureFqcn );
91+ simpleNames .put (simpleName , pureFqcn );
9992 imports .add ( pureFqcn );
10093 }
10194
@@ -127,38 +120,32 @@ public String staticImport(String fqcn, String member) {
127120 }
128121
129122 private boolean inDefaultPackage (String className ) {
130- return className .indexOf ( "." ) < 0 ;
123+ return ! className .contains ( "." ) ;
131124 }
132125
133126 private boolean isPrimitive (String className ) {
134127 return PRIMITIVES .containsKey ( className );
135128 }
136129
137130 private boolean inSamePackage (String className ) {
138- String other = StringHelper .qualifier ( className );
139- return other == basePackage
140- || (other != null && other .equals ( basePackage ) );
131+ return StringHelper .qualifier ( className ).equals (basePackage );
141132 }
142133
143134 private boolean inJavaLang (String className ) {
144135 return "java.lang" .equals ( StringHelper .qualifier ( className ) );
145136 }
146137
147138 public String generateImports () {
148- StringBuffer buf = new StringBuffer ();
149-
150- for ( Iterator <String > imps = imports .iterator (); imps .hasNext (); ) {
151- String next = imps .next ();
152- if (isPrimitive (next ) || inDefaultPackage (next ) || inJavaLang (next ) || inSamePackage (next )) {
153- // dont add automatically "imported" stuff
154- } else {
155- if (staticImports .contains (next )) {
156- buf .append ("import static " + next + ";\r \n " );
157- } else {
158- buf .append ("import " + next + ";\r \n " );
159- }
160- }
161- }
139+ StringBuilder buf = new StringBuilder ();
140+ for (String next : imports ) {
141+ if (!(isPrimitive (next ) || inDefaultPackage (next ) || inJavaLang (next ) || inSamePackage (next ))) {
142+ if (staticImports .contains (next )) {
143+ buf .append ("import static " ).append (next ).append (";\r \n " );
144+ } else {
145+ buf .append ("import " ).append (next ).append (";\r \n " );
146+ }
147+ }
148+ }
162149
163150 if (buf .indexOf ( "$" )>=0 ) {
164151 return buf .toString ();
0 commit comments