Merge "Bug 615: Removed xtend from Topology Manager"
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / AnnotationSerializer.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.ftl.model.Annotation.Parameter;
12
13 class AnnotationSerializer {
14
15     static String toString(Annotation annotation) {
16         StringBuilder builder = new StringBuilder();
17         builder.append("@");
18         builder.append(annotation.getName());
19         if (!annotation.getParams().isEmpty()) {
20             builder.append("(");
21             for (Parameter param : annotation.getParams()) {
22                 builder.append(param.getKey());
23                 builder.append(" = ");
24                 builder.append(fixString(param.getValue()));
25                 builder.append(", ");
26             }
27             builder.setCharAt(builder.length() - 2, ')');
28         }
29         builder.append("\n");
30         return builder.toString();
31     }
32
33     private static String fixString(String value) {
34         // TODO replace with compress single line if possible
35         return value.replaceAll("\\r\\n|\\r|\\n", " ").replaceAll(" +", " ");
36     }
37
38 }