4d727ae5b7582176bd8670d434cc9bf92bc85c66
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / MethodSerializer.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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
10
11 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
12
13 class MethodSerializer {
14
15     static String toString(Method method) {
16         StringBuilder build = new StringBuilder();
17         if (method.getJavadoc() != null) {
18             build.append(StringUtil.writeComment(method.getJavadoc(), true));
19         }
20
21         for(Annotation a: method.getAnnotations()) {
22             build.append(a);
23         }
24
25         build.append("    ");
26         build.append(method.getVisibility()).append(" ");
27         for (String mod : method.getModifiers()) {
28             build.append(mod).append(" ");
29         }
30         build.append(method.getReturnType()).append(" ");
31
32         build.append(method.getName()).append("(");
33         boolean firstParam = true;
34         for (Field param : method.getParameters()) {
35             if (!firstParam) {
36                 build.append(", ");
37             }
38             for (String mod : param.getModifiers()) {
39                 build.append(mod).append(" ");
40             }
41             build.append(param.getType()).append(" ");
42             build.append(param.getName());
43             firstParam = false;
44         }
45         build.append(")");
46
47         if (method instanceof MethodDeclaration) {
48             build.append(";");
49             build.append("\n");
50         } else if (method instanceof MethodDefinition) {
51             MethodDefinition definition = (MethodDefinition) method;
52             if (!definition.getThrowsExceptions().isEmpty()) {
53                 build.append(" throws ");
54             }
55             for (String ex : definition.getThrowsExceptions()) {
56                 build.append(ex).append(" ");
57             }
58             build.append(" {");
59             build.append("\n");
60             build.append("        ");
61             build.append(definition.getBody());
62             build.append("\n");
63             build.append("    ");
64             build.append("}");
65             build.append("\n");
66         }
67         build.append("\n");
68         return build.toString();
69     }
70 }

©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.