/** * Returns all the methods of this service, including the ones declared in base types. The returned list is a copy * of the one used internally, so it is safe to modify it. */ public List<Method> getMethods() { List<Method> result = new ArrayList<>(methods); if (base != null) { result.addAll(base.getMethods()); } return result; }
private String getServiceRef(Service service) { return service.getName().toString(); } }
/** * Returns a stream that delivers all the locators of this service, including the ones declared in base services. */ public Stream<Locator> locators() { Stream<Locator> result = declaredLocators(); if (base != null) { result = concat(base.locators(), result); } return result; }
/** * Returns a stream that delivers all the constraints of this service, including the ones declared in base services. */ public Stream<Constraint> constraints() { Stream<Constraint> result = declaredConstraints(); if (base != null) { result = concat(base.constraints(), result); } return result; }
/** * Returns a stream that delivers all the methods of this service, including the ones declared in base services. */ public Stream<Method> methods() { Stream<Method> result = declaredMethods(); if (base != null) { result = concat(base.methods(), result); } return result; }
Service base = service.getBase(); if (base != null) { JavaClassName baseInterfaceName = jaxrsNames.getInterfaceName(base); extendsList.add(baseInterfaceName.getSimpleName()); if (ASYNCHRONOUS.contains(service.getName())) { javaBuffer.addImport(javaPackages.getJaxrsPackageName(), "AsynchronouslyCreatedResource"); extendsList.add("AsynchronouslyCreatedResource"); boolean isRoot = service == service.getModel().getRoot(); List<Method> methods = service.getDeclaredMethods(); Map<Method, Set<Method>> baseMethods = jaxrsGeneratorUtils.getBaseMethodsMap(methods); methods.forEach(x -> generateMethod(x, helperClassName, baseMethods)); List<Locator> locators = service.getDeclaredLocators(); locators.forEach(x -> generateLocator(x)); for (Method method : service.getMethods()) { if (method.isAction()) { actions.add(method);
/** * Calculates the name of the JAX-RS interface that corresponds to the given service. */ public JavaClassName getInterfaceName(Service service) { JavaClassName name = new JavaClassName(); String packageName = javaPackages.getJaxrsPackageName(service.getModule()); String simpleName = javaNames.getJavaClassStyleName(service.getName()) + RESOURCE_SUFFIX; name.setPackageName(packageName); name.setSimpleName(simpleName); return name; }
/** * Checks if this service or any of its base services have a method with the given name. * * @param name the name of the method to check * @return {@code true} if the method exists, {@code false} otherwise */ public boolean hasMethod(Name name) { return methods().anyMatch(named(name)); }
/** * Analyze a nested interface in a Service. A nested interface in a * service represents a method of the service. */ private void analyzeNestedClass(JavaClass javaClass, Service service) { // Create the method: Method method = analyzeMethod(javaClass, service); // After all other members have been analyzed, handle input detail information. analyzeInputDetail(javaClass, method, service); // Add the method to the model service.addMethod(method); }
private void analyzeServiceLocator(JavaMethod javaMethod, Service service) { // Create the locator: Locator locator = new Locator(); analyzeName(javaMethod, locator); analyzeAnnotations(javaMethod, locator); analyzeDocumentation(javaMethod, locator); // Analyze the parameters: javaMethod.getParameters().forEach(x -> analyzeLocatorParameter(x, locator)); // Get the referenced service: assignServiceReference(javaMethod.getReturns(), locator::setService); // Add the parameter to the method: service.addLocator(locator); }
/** * Calculates the name of the JAX-RS helper class for the given service. */ public JavaClassName getHelperName(Service service) { JavaClassName name = new JavaClassName(); name.setPackageName(javaPackages.getJaxrsPackageName(service.getModule())); name.setSimpleName(javaNames.getJavaClassStyleName(service.getName()) + RESOURCE_SUFFIX + HELPER_SUFFIX); return name; } }
private void generateRows(Concept concept) { csvBuffer.addRow( getKind(concept), getName(concept), String.valueOf(countItems(concept)), String.valueOf(countDocuments(concept)), getAnnotation(concept, AREA), getAnnotation(concept, AUTHOR), getAnnotation(concept, DATE), getAnnotation(concept, STATUS) ); if (concept instanceof StructType) { StructType type = (StructType) concept; type.attributes().sorted().forEach(this::generateRows); } else if (concept instanceof Service) { Service service = (Service) concept; service.methods().sorted().forEach(this::generateRows); } }
public void createSignatures(JavaClass javaClass, Service service, Method method) { for (JavaClass innerClass : javaClass.getNestedClasses()) { //an inner class is expected to be an interface assert innerClass.isInterface(); Method childMethod = analyzeMethod(innerClass, service); copyParameters(childMethod, method); analyzeInputDetail(innerClass, childMethod, service); childMethod.setBase(method); service.addMethod(childMethod); } }
/** * Counts the total items that can be potentially documented in a concept. For example, in a struct type with two * attributes there are three items: the type itself and the two attributes. */ private int countItems(Concept concept) { int count = 1; if (concept instanceof StructType) { StructType type = (StructType) concept; count += type.attributes().mapToInt(this::countItems).sum(); count += type.links().mapToInt(this::countItems).sum(); } else if (concept instanceof EnumType) { EnumType type = (EnumType) concept; count += type.values().mapToInt(this::countItems).sum(); } else if (concept instanceof Service) { Service service = (Service) concept; count += service.methods().mapToInt(this::countItems).sum(); count += service.locators().mapToInt(this::countItems).sum(); } else if (concept instanceof Method) { Method method = (Method) concept; count += method.parameters().mapToInt(this::countItems).sum(); } return count; }
private String getServiceRef(Service service) { return service.getName().toString(); } }
private void documentService(Service service) { // General description: docBuffer.addId(getId(service)); docBuffer.addLine("=== %s", getName(service)); docBuffer.addLine(); addDoc(service); // Table of methods: List<Method> methods = service.methods() .filter(method -> method.getBase() == null) .sorted() .collect(Collectors.toList()); if (!methods.isEmpty()) { docBuffer.addLine(".Methods summary"); docBuffer.addLine("[cols=\"20,80\"]"); docBuffer.addLine("|==="); docBuffer.addLine("|Name |Summary"); docBuffer.addLine(); methods.forEach(method -> { docBuffer.addLine("|`%s`", getName(method)); docBuffer.addLine("|%s", getSummary(method)); docBuffer.addLine(); }); docBuffer.addLine("|==="); docBuffer.addLine(); } // Methods detail: methods.forEach(method -> documentMethod(service, method)); }
for (Method method : service.getMethods()) { if (jaxrsNames.isActionName(method.getName())) { for (Parameter parameter : method.getParameters()) {
/** * Counts the number of items in a concept tha are documented. */ private int countDocuments(Concept concept) { int count = 0; if (concept.getDoc() != null) { count++; } if (concept instanceof StructType) { StructType type = (StructType) concept; count += type.attributes().mapToInt(this::countDocuments).sum(); count += type.links().mapToInt(this::countDocuments).sum(); } else if (concept instanceof EnumType) { EnumType type = (EnumType) concept; count += type.values().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Service) { Service service = (Service) concept; count += service.methods().mapToInt(this::countDocuments).sum(); count += service.locators().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Method) { Method method = (Method) concept; count += method.parameters().mapToInt(this::countDocuments).sum(); } return count; }