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 java.util.Optional;
12 import java.util.function.Consumer;
13 import java.util.stream.Collectors;
14 import javax.lang.model.element.Modifier;
15 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
17 class MethodSerializer {
19 static String toString(Method method) {
20 StringBuilder build = new StringBuilder();
21 Consumer<Modifier> appendWithSpace = string -> build.append(string).append(" ");
23 if (method.getJavadoc() != null) {
24 build.append(StringUtil.writeComment(method.getJavadoc(), true));
27 method.getAnnotations().forEach(build::append);
30 method.getVisibility().ifPresent(appendWithSpace);
31 method.getModifiers().forEach(appendWithSpace);
32 build.append(method.getReturnType()).append(" ");
34 build.append(method.getName()).append("(");
35 boolean firstParam = true;
36 for (Field param : method.getParameters()) {
40 param.getModifiers().forEach(appendWithSpace);
41 build.append(param.getType()).append(" ");
42 build.append(param.getName());
47 if (!method.getThrowsExceptions().isEmpty()) {
48 build.append(" throws ");
49 build.append(method.getThrowsExceptions().stream().collect(Collectors.joining(", ")));
52 Optional<String> body = method.getBody();
53 if (!body.isPresent()) {
60 build.append(body.get());
67 return build.toString();