2 * Copyright (c) 2016 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
10 import static org.junit.Assert.assertEquals;
11 import com.github.javaparser.ast.Node;
12 import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
13 import com.github.javaparser.ast.body.MethodDeclaration;
14 import com.github.javaparser.ast.comments.Comment;
15 import com.github.javaparser.ast.comments.JavadocComment;
16 import com.github.javaparser.ast.expr.NormalAnnotationExpr;
17 import java.util.HashMap;
19 import org.opendaylight.controller.config.api.annotations.Description;
20 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
22 class SieASTVisitor extends AbstractVerifier {
23 private final Map<String, String> methodDescriptions = new HashMap<>();
24 protected String descriptionAnotValue;
25 protected String extnds;
26 protected String javadoc;
27 protected String sieAnnotValue;
28 protected String sieAnnotOsgiRegistrationType;
30 SieASTVisitor(final String expectedPackageName, final String fileName) {
31 super(expectedPackageName, fileName);
35 public void visit(final ClassOrInterfaceDeclaration n, final Void arg) {
36 extnds = n.getExtends().toString();
38 final Comment c = n.getComment();
39 if (c instanceof JavadocComment) {
40 javadoc = c.toString();
47 public void visit(final NormalAnnotationExpr expr, final Void arg) {
48 final String fqcn = expr.getName().toString();
49 if (fqcn.equals(Description.class.getCanonicalName())) {
50 final Node parent = expr.getParentNode();
51 final String value = expr.getPairs().get(0).toString();
52 if (parent instanceof ClassOrInterfaceDeclaration) {
53 descriptionAnotValue = value;
54 } else if (parent instanceof MethodDeclaration) {
55 methodDescriptions.put(((MethodDeclaration) parent).getName(), value);
57 } else if (fqcn.equals(ServiceInterfaceAnnotation.class.getCanonicalName())) {
58 String text1 = expr.getPairs().get(0).toString();
59 String text2 = expr.getPairs().get(1).toString();
60 if (text1.contains("value")) {
61 sieAnnotValue = text1;
62 sieAnnotOsgiRegistrationType = text2;
64 sieAnnotValue = text2;
65 sieAnnotOsgiRegistrationType = text1;
69 super.visit(expr, arg);
72 final void assertMethodDescriptions(final int expected) {
73 assertEquals("Incorrenct number of generated method descriptions", expected, methodDescriptions.size());