Gen. Abstract*ModuleFactory with WORKING handleChangedClass()
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / java / GeneratedObjectBuilder.java
1 /*
2  * Copyright (c) 2013, 2015 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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
10
11 import static org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil.prefixAndJoin;
12
13 import com.google.common.base.Optional;
14 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
15
16 public class GeneratedObjectBuilder {
17     private final JavaFileInput input;
18
19     public GeneratedObjectBuilder(JavaFileInput input) {
20         this.input = input;
21     }
22
23
24     public GeneratedObject toGeneratedObject() {
25         FullyQualifiedName fqn = input.getFQN();
26         StringBuilder content = new StringBuilder();
27
28
29         content.append(maybeAddComment(input.getCopyright()));
30         content.append(maybeAddComment(input.getHeader()));
31
32         if (!input.getFQN().getPackageName().isEmpty()) {
33             content.append("package ");
34             content.append(input.getFQN().getPackageName());
35             content.append(";\n");
36         }
37
38         if (!input.getImports().isEmpty())
39             content.append('\n');
40         for (FullyQualifiedName importedType : input.getImports()) {
41             content.append("import ");
42             content.append(importedType.toString());
43             content.append(";\n");
44         }
45         if (!input.getImports().isEmpty())
46             content.append('\n');
47
48         content.append(maybeAddComment(input.getClassJavaDoc(), true));
49
50         for (String classAnnotation : input.getClassAnnotations()) {
51             content.append(classAnnotation);
52             content.append("\n");
53         }
54
55         content.append("public ");
56         content.append(input.getType());
57         content.append(" ");
58         content.append(input.getFQN().getTypeName());
59         content.append(prefixAndJoin(input.getExtends(), "extends"));
60         content.append(prefixAndJoin(input.getImplements(), "implements"));
61         content.append(" {\n");
62
63         for (String method : input.getBodyElements()) {
64             content.append(method);
65             content.append("\n");
66         }
67
68         content.append("\n}\n");
69
70         return new GeneratedObject(fqn, content.toString());
71     }
72
73     private static String maybeAddComment(Optional<String> comment) {
74         return maybeAddComment(comment, false);
75     }
76
77     private static String maybeAddComment(Optional<String> comment, boolean isJavadoc) {
78         if (comment.isPresent()) {
79             String input = comment.get();
80             return StringUtil.writeComment(input, isJavadoc);
81         } else {
82             return "";
83         }
84     }
85
86 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.