- assertContains(reqIfc, PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX
- + ".threads.ThreadFactoryServiceInterface");
-
- assertEquals("Incorrenct number of generated methods", 27,
- visitor.methods.size());
- assertEquals("Incorrenct number of generated method descriptions", 3,
- visitor.methodDescriptions.size());
- assertEquals("Incorrenct number of generated method javadoc", 3,
- visitor.methodJavadoc.size());
- assertNotNull("Missing javadoc for setMaximumSize method " + visitor.methodJavadoc,
- visitor.methodJavadoc.get("void setMaximumSize(java.lang.Long maximumSize)"));
- }
-
- private void assertDeclaredField(Set<String> fieldDeclarations,
- String declaration) {
- assertTrue("Missing field " + declaration + ", got: "
- + fieldDeclarations,
- fieldDeclarations.contains(declaration + ";\n"));
- }
-
- private static class SieASTVisitor extends ASTVisitor {
- protected String packageName, descriptionAnotValue, sieAnnotValue,
- sieAnnotOsgiRegistrationType, type, extnds, javadoc;
- protected Map<String, String> methodDescriptions = Maps.newHashMap();
-
- @Override
- public boolean visit(PackageDeclaration node) {
- packageName = node.getName().toString();
- return super.visit(node);
- }
-
- @Override
- public boolean visit(NormalAnnotation node) {
- if (node.getTypeName().toString()
- .equals(Description.class.getCanonicalName())) {
- if (node.getParent() instanceof TypeDeclaration) {
- descriptionAnotValue = node.values().get(0).toString();
- } else if (node.getParent() instanceof MethodDeclaration) {
- String descr = node.values().get(0).toString();
- methodDescriptions.put(((MethodDeclaration) node
- .getParent()).getName().toString(), descr);
- }
- } else if (node
- .getTypeName()
- .toString()
- .equals(ServiceInterfaceAnnotation.class.getCanonicalName())) {
- String text1 = node.values().get(0).toString();
- String text2 = node.values().get(1).toString();
- if (text1.contains("value")) {
- sieAnnotValue = text1;
- sieAnnotOsgiRegistrationType = text2;
- } else {
- sieAnnotValue = text2;
- sieAnnotOsgiRegistrationType = text1;
- }
- }
- return super.visit(node);
- }
-
- @Override
- public boolean visit(TypeDeclaration node) {
- javadoc = node.getJavadoc() == null ? null : node.getJavadoc()
- .toString();
- type = node.getName().toString();
- List<?> superIfcs = node.superInterfaceTypes();
- extnds = superIfcs != null && !superIfcs.isEmpty() ? superIfcs
- .toString() : null;
- return super.visit(node);
- }
- }
-
- private static class MbeASTVisitor extends SieASTVisitor {
- private String implmts;
- private final Set<String> fieldDeclarations = Sets.newHashSet();
- private final Set<String> constructors = Sets.newHashSet();
- private final Set<String> methods = new HashSet<String>();
- private final Map<String, String> requireIfc = Maps.newHashMap();
- private final Map<String, String> methodJavadoc = Maps.newHashMap();
-
- @Override
- public boolean visit(NormalAnnotation node) {
- boolean result = super.visit(node);
- if (node.getTypeName().toString()
- .equals(RequireInterface.class.getCanonicalName())
- && node.getParent() instanceof MethodDeclaration) {
- // remember only top level description annotation
- String reqVal = node.values().get(0).toString();
- requireIfc.put(((MethodDeclaration) node.getParent()).getName()
- .toString(), reqVal);
- }
- return result;
- }