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).append(" ");
29 build.append(method.getReturnType()).append(" ");
31 build.append(method.getName()).append("(");
32 boolean firstParam = true;
33 for (Field param : method.getParameters()) {
37 for (String mod : param.getModifiers()) {
38 build.append(mod).append(" ");
40 build.append(param.getType()).append(" ");
41 build.append(param.getName());
46 if (method instanceof MethodDeclaration) {
49 } else if (method instanceof MethodDefinition) {
50 MethodDefinition definition = (MethodDefinition) method;
51 if (!definition.getThrowsExceptions().isEmpty()) {
52 build.append(" throws ");
54 for (String ex : definition.getThrowsExceptions()) {
55 build.append(ex).append(" ");
60 build.append(definition.getBody());
67 return build.toString();