@Override public Map<String, RamlDataType> getTypes() { Map<String, RamlDataType> types = getAllTypes(api); // When searching for all libraries that other libraries use it's // possible to pull in same library multiple times. // In order to avoid IllegalStateException we'll add basic // mergeFunction. Map<String, RamlDataType> libOfLibTypes = api.uses().stream().flatMap(x -> x.uses().stream()).flatMap(x -> x.types().stream()) .collect(Collectors.toMap(this::nameType, this::typeDeclarationToRamlDataType, (x, y) -> x)); types.putAll(libOfLibTypes); return types; }
private void getTypesFromLib(Map<String, RamlDataType> types, Library lib) { lib.types().forEach(type -> types.put(type.name(), new RJP10V2RamlDataType(type))); lib.uses().forEach(inLib -> getTypesFromLib(types, inLib)); }
static List<TypeDeclaration> goThroughLibraries(List<TypeDeclaration> foundTypes, Set<String> visitedLibraries, List<Library> libraries) { for (Library library : libraries) { if (visitedLibraries.contains(library.name())) { continue; } else { visitedLibraries.add(library.name()); } goThroughLibraries(foundTypes, visitedLibraries, library.uses()); foundTypes.addAll(library.types()); } return foundTypes; }
private void goThroughLibraries(Set<String> visitedLibraries, List<Library> libraries, GFinderListener listener) { for (Library library : libraries) { if (visitedLibraries.contains(library.name())) { continue; } else { visitedLibraries.add(library.name()); } goThroughLibraries(visitedLibraries, library.uses(), listener); for (TypeDeclaration typeDeclaration : library.types()) { V10GType type = createTypeFromLibraryPart(typeDeclaration); listener.newTypeDeclaration(type); } } }
private void goThroughLibraries(Set<String> visitedLibraries, List<Library> libraries, GFinderListener listener) { for (Library library : libraries) { if (visitedLibraries.contains(library.name())) { continue; } else { visitedLibraries.add(library.name()); } goThroughLibraries(visitedLibraries, library.uses(), listener); for (TypeDeclaration typeDeclaration : library.types()) { V10GType type = registry.fetchType(typeDeclaration); listener.newTypeDeclaration(type); } } } }