Merge "Added YANG models for base concepts in the controller"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / controller / sal / java / api / generator / GeneratorUtil.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.java.api.generator;
9
10 import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.LinkedHashMap;
15 import java.util.List;
16 import java.util.Map;
17
18 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
19 import org.opendaylight.controller.sal.binding.model.api.Constant;
20 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
21 import org.opendaylight.controller.sal.binding.model.api.Enumeration.Pair;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
23 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
24 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
25 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
26 import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
27 import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
28 import org.opendaylight.controller.sal.binding.model.api.Type;
29 import org.opendaylight.controller.sal.binding.model.api.WildcardType;
30
31 public final class GeneratorUtil {
32
33     private GeneratorUtil() {
34     }
35
36     public static String createIfcDeclaration(final GeneratedType genType,
37             final String indent,
38             final Map<String, LinkedHashMap<String, Integer>> availableImports) {
39         return createFileDeclaration(IFC, genType, indent, availableImports,
40                 false);
41     }
42
43     public static String createClassDeclaration(
44             final GeneratedTransferObject genTransferObject,
45             final String indent,
46             final Map<String, LinkedHashMap<String, Integer>> availableImports,
47             boolean isIdentity) {
48         return createFileDeclaration(CLASS, genTransferObject, indent,
49                 availableImports, isIdentity);
50     }
51
52     public static String createPackageDeclaration(final String packageName) {
53         return PKG + GAP + packageName + SC;
54     }
55
56     private static String createFileDeclaration(final String type,
57             final GeneratedType genType, final String indent,
58             final Map<String, LinkedHashMap<String, Integer>> availableImports,
59             boolean isIdentity) {
60         final StringBuilder builder = new StringBuilder();
61         final String currentPkg = genType.getPackageName();
62
63         createComment(builder, genType.getComment(), indent);
64
65         if (!genType.getAnnotations().isEmpty()) {
66             final List<AnnotationType> annotations = genType.getAnnotations();
67             appendAnnotations(builder, annotations);
68             builder.append(NL);
69         }
70
71         if (isIdentity) {
72             if (!(CLASS.equals(type))) {
73                 throw new IllegalArgumentException(
74                         "'identity' has to be generated as a class");
75             }
76             builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP
77                     + genType.getName() + GAP);
78         } else {
79             builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
80         }
81
82         if (genType instanceof GeneratedTransferObject) {
83             GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
84
85             if (genTO.getExtends() != null) {
86                 builder.append(EXTENDS + GAP);
87                 String gtoString = getExplicitType(genTO.getExtends(), availableImports, currentPkg);
88                 builder.append(gtoString + GAP);
89             }
90         }
91
92         final List<Type> genImplements = genType.getImplements();
93         if (!genImplements.isEmpty()) {
94             if (genType instanceof GeneratedTransferObject) {
95                 builder.append(IMPLEMENTS + GAP);
96             } else {
97                 builder.append(EXTENDS + GAP);
98             }
99             builder.append(getExplicitType(genImplements.get(0),
100                     availableImports, currentPkg));
101
102             for (int i = 1; i < genImplements.size(); ++i) {
103                 builder.append(", ");
104                 builder.append(getExplicitType(genImplements.get(i),
105                         availableImports, currentPkg));
106             }
107         }
108
109         builder.append(GAP + LCB);
110         return builder.toString();
111     }
112
113     private static StringBuilder appendAnnotations(final StringBuilder builder,
114             final List<AnnotationType> annotations) {
115         if ((builder != null) && (annotations != null)) {
116             for (final AnnotationType annotation : annotations) {
117                 builder.append("@");
118                 builder.append(annotation.getPackageName());
119                 builder.append(".");
120                 builder.append(annotation.getName());
121
122                 if (annotation.containsParameters()) {
123                     builder.append("(");
124                     final List<AnnotationType.Parameter> parameters = annotation
125                             .getParameters();
126                     appendAnnotationParams(builder, parameters);
127                     builder.append(")");
128                 }
129             }
130         }
131         return builder;
132     }
133
134     private static StringBuilder appendAnnotationParams(
135             final StringBuilder builder,
136             final List<AnnotationType.Parameter> parameters) {
137         if (parameters != null) {
138             int i = 0;
139             for (final AnnotationType.Parameter param : parameters) {
140                 if (param == null) {
141                     continue;
142                 }
143                 if (i > 0) {
144                     builder.append(", ");
145                 }
146                 final String paramName = param.getName();
147                 if (param.getValue() != null) {
148                     builder.append(paramName);
149                     builder.append(" = ");
150                     builder.append(param.getValue());
151                 } else {
152                     builder.append(paramName);
153                     builder.append(" = {");
154                     final List<String> values = param.getValues();
155                     builder.append(values.get(0));
156                     for (int j = 1; j < values.size(); ++j) {
157                         builder.append(", ");
158                         builder.append(values.get(j));
159                     }
160                     builder.append("}");
161                 }
162                 i++;
163             }
164         }
165         return builder;
166     }
167
168     public static String createConstant(final Constant constant,
169             final String indent,
170             final Map<String, LinkedHashMap<String, Integer>> availableImports,
171             final String currentPkg) {
172         final StringBuilder builder = new StringBuilder();
173         builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
174         builder.append(getExplicitType(constant.getType(), availableImports,
175                 currentPkg) + GAP + constant.getName());
176         builder.append(GAP + "=" + GAP);
177         builder.append(constant.getValue() + SC);
178         return builder.toString();
179     }
180
181     public static String createField(final GeneratedProperty property,
182             final String indent,
183             Map<String, LinkedHashMap<String, Integer>> availableImports,
184             final String currentPkg) {
185         final StringBuilder builder = new StringBuilder();
186         if (!property.getAnnotations().isEmpty()) {
187             final List<AnnotationType> annotations = property.getAnnotations();
188             appendAnnotations(builder, annotations);
189             builder.append(NL);
190         }
191         builder.append(indent + PRIVATE + GAP);
192         builder.append(getExplicitType(property.getReturnType(),
193                 availableImports, currentPkg) + GAP + property.getName());
194         builder.append(SC);
195         return builder.toString();
196     }
197
198     /**
199      * Create method declaration in interface.
200      * 
201      * @param method
202      * @param indent
203      * @return
204      */
205     public static String createMethodDeclaration(final MethodSignature method,
206             final String indent,
207             Map<String, LinkedHashMap<String, Integer>> availableImports,
208             final String currentPkg) {
209         final StringBuilder builder = new StringBuilder();
210
211         if (method == null) {
212             throw new IllegalArgumentException(
213                     "Method Signature parameter MUST be specified and cannot be NULL!");
214         }
215
216         final String comment = method.getComment();
217         final String name = method.getName();
218         if (name == null) {
219             throw new IllegalStateException("Method Name cannot be NULL!");
220         }
221
222         final Type type = method.getReturnType();
223         if (type == null) {
224             throw new IllegalStateException(
225                     "Method Return type cannot be NULL!");
226         }
227
228         final List<Parameter> parameters = method.getParameters();
229
230         createComment(builder, comment, indent);
231         builder.append(NL);
232         builder.append(indent);
233
234         if (!method.getAnnotations().isEmpty()) {
235             final List<AnnotationType> annotations = method.getAnnotations();
236             appendAnnotations(builder, annotations);
237             builder.append(NL);
238         }
239
240         builder.append(indent
241                 + getExplicitType(type, availableImports, currentPkg) + GAP
242                 + name);
243         builder.append(LB);
244         for (int i = 0; i < parameters.size(); i++) {
245             Parameter p = parameters.get(i);
246             String separator = COMMA;
247             if (i + 1 == parameters.size()) {
248                 separator = "";
249             }
250             builder.append(getExplicitType(p.getType(), availableImports,
251                     currentPkg) + GAP + p.getName() + separator);
252         }
253         builder.append(RB);
254         builder.append(SC);
255
256         return builder.toString();
257     }
258
259     public static String createConstructor(
260             GeneratedTransferObject genTransferObject, final String indent,
261             Map<String, LinkedHashMap<String, Integer>> availableImports,
262             boolean isIdentity) {
263         final StringBuilder builder = new StringBuilder();
264
265         final String currentPkg = genTransferObject.getPackageName();
266         final List<GeneratedProperty> properties = genTransferObject
267                 .getProperties();
268         final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
269         for (final GeneratedProperty property : properties) {
270             if (property.isReadOnly()) {
271                 ctorParams.add(property);
272             }
273         }
274
275         builder.append(indent);
276         builder.append(isIdentity ? PROTECTED : PUBLIC);
277         builder.append(GAP);
278         builder.append(genTransferObject.getName());
279         builder.append(LB);
280
281         if (!ctorParams.isEmpty()) {
282             builder.append(getExplicitType(ctorParams.get(0).getReturnType(),
283                     availableImports, currentPkg));
284             builder.append(" ");
285             builder.append(ctorParams.get(0).getName());
286             for (int i = 1; i < ctorParams.size(); ++i) {
287                 final GeneratedProperty param = ctorParams.get(i);
288                 builder.append(", ");
289                 builder.append(getExplicitType(param.getReturnType(),
290                         availableImports, currentPkg));
291                 builder.append(GAP);
292                 builder.append(param.getName());
293             }
294         }
295         builder.append(RB + GAP + LCB + NL + indent + TAB + "super();" + NL);
296         if (!ctorParams.isEmpty()) {
297             for (final GeneratedProperty property : ctorParams) {
298                 builder.append(indent);
299                 builder.append(TAB);
300                 builder.append("this.");
301                 builder.append(property.getName());
302                 builder.append(" = ");
303                 builder.append(property.getName());
304                 builder.append(SC);
305                 builder.append(NL);
306             }
307         }
308         builder.append(indent);
309         builder.append(RCB);
310         return builder.toString();
311     }
312
313     public static String createGetter(final GeneratedProperty property,
314             final String indent,
315             Map<String, LinkedHashMap<String, Integer>> availableImports,
316             final String currentPkg) {
317         final StringBuilder builder = new StringBuilder();
318
319         final Type type = property.getReturnType();
320         final String varName = property.getName();
321         final char first = Character.toUpperCase(varName.charAt(0));
322         final String methodName = "get" + first + varName.substring(1);
323
324         builder.append(indent + PUBLIC + GAP
325                 + getExplicitType(type, availableImports, currentPkg) + GAP
326                 + methodName);
327         builder.append(LB + RB + LCB + NL);
328
329         String currentIndent = indent + TAB;
330
331         builder.append(currentIndent + "return " + varName + SC + NL);
332
333         builder.append(indent + RCB);
334         return builder.toString();
335     }
336
337     public static String createSetter(final GeneratedProperty property,
338             final String indent,
339             Map<String, LinkedHashMap<String, Integer>> availableImports,
340             String currentPkg) {
341         final StringBuilder builder = new StringBuilder();
342
343         final Type type = property.getReturnType();
344         final String varName = property.getName();
345         final char first = Character.toUpperCase(varName.charAt(0));
346         final String methodName = "set" + first + varName.substring(1);
347
348         builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
349         builder.append(LB + getExplicitType(type, availableImports, currentPkg)
350                 + GAP + varName + RB + LCB + NL);
351         String currentIndent = indent + TAB;
352         builder.append(currentIndent + "this." + varName + " = " + varName + SC
353                 + NL);
354         builder.append(indent + RCB);
355         return builder.toString();
356     }
357
358     public static String createHashCode(
359             final List<GeneratedProperty> properties, final String indent) {
360         StringBuilder builder = new StringBuilder();
361         builder.append(indent + "public int hashCode() {" + NL);
362         builder.append(indent + TAB + "final int prime = 31;" + NL);
363         builder.append(indent + TAB + "int result = 1;" + NL);
364
365         for (GeneratedProperty property : properties) {
366             String fieldName = property.getName();
367             builder.append(indent + TAB + "result = prime * result + (("
368                     + fieldName + " == null) ? 0 : " + fieldName
369                     + ".hashCode());" + NL);
370         }
371
372         builder.append(indent + TAB + "return result;" + NL);
373         builder.append(indent + RCB + NL);
374         return builder.toString();
375     }
376
377     public static String createEquals(final GeneratedTransferObject type,
378             final List<GeneratedProperty> properties, final String indent) {
379         StringBuilder builder = new StringBuilder();
380         final String indent1 = indent + TAB;
381         final String indent2 = indent1 + TAB;
382         final String indent3 = indent2 + TAB;
383
384         builder.append(indent + "public boolean equals(Object obj) {" + NL);
385         builder.append(indent1 + "if (this == obj) {" + NL);
386         builder.append(indent2 + "return true;" + NL);
387         builder.append(indent1 + "}" + NL);
388         builder.append(indent1 + "if (obj == null) {" + NL);
389         builder.append(indent2 + "return false;" + NL);
390         builder.append(indent1 + "}" + NL);
391         builder.append(indent1 + "if (getClass() != obj.getClass()) {" + NL);
392         builder.append(indent2 + "return false;" + NL);
393         builder.append(indent1 + "}" + NL);
394
395         String typeStr = type.getName();
396         builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;"
397                 + NL);
398
399         for (GeneratedProperty property : properties) {
400             String fieldName = property.getName();
401             builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
402             builder.append(indent2 + "if (other." + fieldName + " != null) {"
403                     + NL);
404             builder.append(indent3 + "return false;" + NL);
405             builder.append(indent2 + "}" + NL);
406             builder.append(indent1 + "} else if (!" + fieldName
407                     + ".equals(other." + fieldName + ")) {" + NL);
408             builder.append(indent2 + "return false;" + NL);
409             builder.append(indent1 + "}" + NL);
410         }
411
412         builder.append(indent1 + "return true;" + NL);
413
414         builder.append(indent + RCB + NL);
415         return builder.toString();
416     }
417
418     public static String createToString(final GeneratedTransferObject type,
419             final List<GeneratedProperty> properties, final String indent) {
420         StringBuilder builder = new StringBuilder();
421         builder.append(indent);
422         builder.append("public String toString() {");
423         builder.append(NL);
424         builder.append(indent);
425         builder.append(TAB);
426         builder.append("StringBuilder builder = new StringBuilder();");
427         builder.append(NL);
428         builder.append(indent);
429         builder.append(TAB);
430         builder.append("builder.append(\"");
431         builder.append(type.getName());
432         builder.append(" [");
433
434         boolean first = true;
435         for (GeneratedProperty property : properties) {
436             if (first) {
437                 builder.append(property.getName());
438                 builder.append("=\");");
439                 builder.append(NL);
440                 builder.append(indent);
441                 builder.append(TAB);
442                 builder.append("builder.append(");
443                 builder.append(property.getName());
444                 builder.append(");");
445                 first = false;
446             } else {
447                 builder.append(NL);
448                 builder.append(indent);
449                 builder.append(TAB);
450                 builder.append("builder.append(\", ");
451                 builder.append(property.getName());
452                 builder.append("=\");");
453                 builder.append(NL);
454                 builder.append(indent);
455                 builder.append(TAB);
456                 builder.append("builder.append(");
457                 builder.append(property.getName());
458                 builder.append(");");
459             }
460         }
461         builder.append(NL);
462         builder.append(indent);
463         builder.append(TAB);
464         builder.append("builder.append(\"]\");");
465         builder.append(NL);
466         builder.append(indent);
467         builder.append(TAB);
468         builder.append("return builder.toString();");
469
470         builder.append(NL);
471         builder.append(indent);
472         builder.append(RCB);
473         builder.append(NL);
474         return builder.toString();
475     }
476
477     public static String createEnum(final Enumeration enumeration,
478             final String indent) {
479         if (enumeration == null || indent == null)
480             throw new IllegalArgumentException();
481         final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP
482                 + ENUM + GAP + enumeration.getName() + GAP + LCB + NL);
483
484         String separator = COMMA + NL;
485         final List<Pair> values = enumeration.getValues();
486
487         for (int i = 0; i < values.size(); i++) {
488             if (i + 1 == values.size()) {
489                 separator = SC;
490             }
491             builder.append(indent + TAB + values.get(i).getName() + LB
492                     + values.get(i).getValue() + RB + separator);
493         }
494         builder.append(NL);
495         builder.append(NL);
496         final String ENUMERATION_NAME = "value";
497         final String ENUMERATION_TYPE = "int";
498         builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME
499                 + SC);
500         builder.append(NL);
501         builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName()
502                 + LB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + RB + GAP
503                 + LCB + NL);
504         builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP
505                 + "=" + GAP + ENUMERATION_NAME + SC + NL);
506         builder.append(indent + TAB + RCB + NL);
507
508         builder.append(indent + RCB);
509         builder.append(NL);
510         return builder.toString();
511     }
512
513     private static String getExplicitType(final Type type,
514             Map<String, LinkedHashMap<String, Integer>> availableImports,
515             final String currentPkg) {
516         if (type == null) {
517             throw new IllegalArgumentException(
518                     "Type parameter MUST be specified and cannot be NULL!");
519         }
520         String packageName = type.getPackageName();
521
522         LinkedHashMap<String, Integer> imports = availableImports.get(type
523                 .getName());
524
525         if ((imports != null && packageName
526                 .equals(findMaxValue(imports).get(0)))
527                 || packageName.equals(currentPkg)) {
528             final StringBuilder builder = new StringBuilder(type.getName());
529             if (type instanceof ParameterizedType) {
530                 ParameterizedType pType = (ParameterizedType) type;
531                 Type[] pTypes = pType.getActualTypeArguments();
532                 builder.append("<");
533                 builder.append(getParameters(pTypes, availableImports,
534                         currentPkg));
535                 builder.append(">");
536             }
537             if (builder.toString().equals("Void")) {
538                 return "void";
539             }
540             return builder.toString();
541         } else {
542             final StringBuilder builder = new StringBuilder();
543             if (packageName.startsWith("java.lang")) {
544                 builder.append(type.getName());
545             } else {
546                 if (!packageName.isEmpty()) {
547                     builder.append(packageName + "." + type.getName());
548                 } else {
549                     builder.append(type.getName());
550                 }
551
552             }
553             if (type instanceof ParameterizedType) {
554                 ParameterizedType pType = (ParameterizedType) type;
555                 Type[] pTypes = pType.getActualTypeArguments();
556                 builder.append("<");
557                 builder.append(getParameters(pTypes, availableImports,
558                         currentPkg));
559                 builder.append(">");
560             }
561             if (builder.toString().equals("Void")) {
562                 return "void";
563             }
564             return builder.toString();
565         }
566     }
567
568     private static String getParameters(final Type[] pTypes,
569             Map<String, LinkedHashMap<String, Integer>> availableImports,
570             String currentPkg) {
571         final StringBuilder builder = new StringBuilder();
572         for (int i = 0; i < pTypes.length; i++) {
573             Type t = pTypes[i];
574
575             String separator = COMMA;
576             if (i + 1 == pTypes.length) {
577                 separator = "";
578             }
579             
580             String wildcardParam = "";
581             if(t instanceof WildcardType) {
582                 wildcardParam = "? extends ";
583             }
584             
585             builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg)
586                     + separator);
587         }
588         return builder.toString();
589     }
590
591     private static List<String> findMaxValue(
592             LinkedHashMap<String, Integer> imports) {
593         final List<String> result = new ArrayList<String>();
594
595         int maxValue = 0;
596         int currentValue = 0;
597         for (Map.Entry<String, Integer> entry : imports.entrySet()) {
598             currentValue = entry.getValue();
599             if (currentValue > maxValue) {
600                 result.clear();
601                 result.add(entry.getKey());
602                 maxValue = currentValue;
603             } else if (currentValue == maxValue) {
604                 result.add(entry.getKey());
605             }
606         }
607         return result;
608     }
609
610     private static void createComment(final StringBuilder builder,
611             final String comment, final String indent) {
612         if (comment != null && comment.length() > 0) {
613             builder.append(indent + "/*" + NL);
614             builder.append(indent + comment + NL);
615             builder.append(indent + "*/" + NL);
616         }
617     }
618
619     public static Map<String, LinkedHashMap<String, Integer>> createImports(
620             GeneratedType genType) {
621         final Map<String, LinkedHashMap<String, Integer>> imports = new HashMap<String, LinkedHashMap<String, Integer>>();
622         final String genTypePkg = genType.getPackageName();
623
624         final List<Constant> constants = genType.getConstantDefinitions();
625                 final List<MethodSignature> methods = genType.getMethodDefinitions();
626         List<Type> impl = genType.getImplements();
627
628         // IMPLEMENTATIONS
629         if (impl != null) {
630             for (Type t : impl) {
631                 addTypeToImports(t, imports, genTypePkg);
632             }
633         }
634
635         // CONSTANTS
636         if (constants != null) {
637             for (Constant c : constants) {
638                 Type ct = c.getType();
639                 addTypeToImports(ct, imports, genTypePkg);
640             }
641         }
642
643         // METHODS
644         if (methods != null) {
645             for (MethodSignature m : methods) {
646                 Type ct = m.getReturnType();
647                 addTypeToImports(ct, imports, genTypePkg);
648                 for (MethodSignature.Parameter p : m.getParameters()) {
649                     addTypeToImports(p.getType(), imports, genTypePkg);
650                 }
651             }
652         }
653
654         // PROPERTIES
655         if (genType instanceof GeneratedTransferObject) {
656             GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
657
658             List<GeneratedProperty> props = genTO.getProperties();
659             if (props != null) {
660                 for (GeneratedProperty prop : props) {
661                     Type pt = prop.getReturnType();
662                     addTypeToImports(pt, imports, genTypePkg);
663                 }
664             }
665         }
666
667         return imports;
668     }
669
670     private static void addTypeToImports(Type type,
671             Map<String, LinkedHashMap<String, Integer>> importedTypes,
672             String genTypePkg) {
673         String typeName = type.getName();
674         String typePkg = type.getPackageName();
675                 if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) ||
676                 typePkg.isEmpty()) {
677             return;
678         }
679         LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);
680         if (packages == null) {
681             packages = new LinkedHashMap<String, Integer>();
682             packages.put(typePkg, 1);
683             importedTypes.put(typeName, packages);
684         } else {
685             Integer occurrence = packages.get(typePkg);
686             if (occurrence == null) {
687                 packages.put(typePkg, 1);
688             } else {
689                 occurrence++;
690                 packages.put(typePkg, occurrence);
691             }
692         }
693
694         if (type instanceof ParameterizedType) {
695             ParameterizedType pt = (ParameterizedType) type;
696             Type[] params = pt.getActualTypeArguments();
697             for (Type param : params) {
698                 addTypeToImports(param, importedTypes, genTypePkg);
699             }
700         }
701     }
702
703     public static List<String> createImportLines(
704             Map<String, LinkedHashMap<String, Integer>> imports) {
705         List<String> importLines = new ArrayList<String>();
706
707         for (Map.Entry<String, LinkedHashMap<String, Integer>> entry : imports
708                 .entrySet()) {
709             String typeName = entry.getKey();
710             LinkedHashMap<String, Integer> typePkgMap = entry.getValue();
711             String typePkg = typePkgMap.keySet().iterator().next();
712             importLines.add("import " + typePkg + "." + typeName + SC);
713         }
714         return importLines;
715     }
716
717 }