11package org .hibernate .tool .internal .export .java ;
22
33import java .util .HashMap ;
4- import java .util .Iterator ;
54import java .util .Map ;
65import java .util .Set ;
76import java .util .TreeSet ;
@@ -40,13 +39,12 @@ public ImportContextImpl(String basePackage) {
4039 /**
4140 * Add fqcn to the import list. Returns fqcn as needed in source code.
4241 * Attempts to handle fqcn with array and generics references.
43- *
42+ * <p>
4443 * e.g.
4544 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
4645 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
4746 *
4847 *
49- * @param fqcn
5048 * @return import string
5149 */
5250 public String importType (String fqcn ) {
@@ -71,14 +69,9 @@ public String importType(String fqcn) {
7169 String simpleName = StringHelper .unqualify (fqcn );
7270 if (simpleNames .containsKey (simpleName )) {
7371 String existingFqcn = (String ) simpleNames .get (simpleName );
74- if (existingFqcn .equals (pureFqcn )) {
75- canBeSimple = true ;
76- } else {
77- canBeSimple = false ;
78- }
72+ canBeSimple = existingFqcn .equals (pureFqcn );
7973 } else {
80- canBeSimple = true ;
81- simpleNames .put (simpleName , pureFqcn );
74+ simpleNames .put (simpleName , pureFqcn );
8275 imports .add ( pureFqcn );
8376 }
8477
@@ -110,38 +103,32 @@ public String staticImport(String fqcn, String member) {
110103 }
111104
112105 private boolean inDefaultPackage (String className ) {
113- return className .indexOf ( "." ) < 0 ;
106+ return ! className .contains ( "." ) ;
114107 }
115108
116109 private boolean isPrimitive (String className ) {
117110 return PRIMITIVES .containsKey ( className );
118111 }
119112
120113 private boolean inSamePackage (String className ) {
121- String other = StringHelper .qualifier ( className );
122- return other == basePackage
123- || (other != null && other .equals ( basePackage ) );
114+ return StringHelper .qualifier ( className ).equals (basePackage );
124115 }
125116
126117 private boolean inJavaLang (String className ) {
127118 return "java.lang" .equals ( StringHelper .qualifier ( className ) );
128119 }
129120
130121 public String generateImports () {
131- StringBuffer buf = new StringBuffer ();
132-
133- for ( Iterator <String > imps = imports .iterator (); imps .hasNext (); ) {
134- String next = imps .next ();
135- if (isPrimitive (next ) || inDefaultPackage (next ) || inJavaLang (next ) || inSamePackage (next )) {
136- // dont add automatically "imported" stuff
137- } else {
138- if (staticImports .contains (next )) {
139- buf .append ("import static " + next + ";\r \n " );
140- } else {
141- buf .append ("import " + next + ";\r \n " );
142- }
143- }
144- }
122+ StringBuilder buf = new StringBuilder ();
123+ for (String next : imports ) {
124+ if (!(isPrimitive (next ) || inDefaultPackage (next ) || inJavaLang (next ) || inSamePackage (next ))) {
125+ if (staticImports .contains (next )) {
126+ buf .append ("import static " ).append (next ).append (";\r \n " );
127+ } else {
128+ buf .append ("import " ).append (next ).append (";\r \n " );
129+ }
130+ }
131+ }
145132
146133 if (buf .indexOf ( "$" )>=0 ) {
147134 return buf .toString ();
0 commit comments