2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
11 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
13 class MethodSerializer {
15 static String toString(Method method) {
16 StringBuilder build = new StringBuilder();
17 if (method.getJavadoc() != null) {
18 build.append(StringUtil.writeComment(method.getJavadoc(), true));
21 for(Annotation a: method.getAnnotations()) {
25 build.append(" " + "public ");
26 for (String mod : method.getModifiers()) {
27 build.append(mod + " ");
29 build.append(method.getReturnType() + " ");
31 build.append(method.getName() + "(");
32 for (Field param : method.getParameters()) {
33 for (String mod : param.getModifiers()) {
34 build.append(mod + " ");
36 build.append(param.getType() + " ");
37 build.append(param.getName() + ", ");
39 if (method.getParameters().isEmpty()) {
42 build.deleteCharAt(build.length() - 1);
43 build.deleteCharAt(build.length() - 1);
47 if (method instanceof MethodDeclaration) {
50 } else if (method instanceof MethodDefinition) {
51 if (!((MethodDefinition) method).getThrowsExceptions()
53 build.append(" throws ");
55 for (String ex : ((MethodDefinition) method)
56 .getThrowsExceptions()) {
57 build.append(ex + " ");
62 build.append(((MethodDefinition) method).getBody());
69 return build.toString();