/** * Resolve a module info for the specified {@code pkgElt} argument, returns null for undertermined. * * @param elementUtils the element utils * @param pkgElt the package element * @return the module info */ public static ModuleInfo resolve(Elements elementUtils, PackageElement pkgElt) { String pkgQN = pkgElt.getQualifiedName().toString(); while (true) { if (pkgElt != null) { ModuleGen annotation = pkgElt.getAnnotation(ModuleGen.class); if (annotation != null) { return new ModuleInfo(pkgElt.getQualifiedName().toString(), annotation.name(), annotation.groupPackage()); } } int pos = pkgQN.lastIndexOf('.'); if (pos == -1) { break; } else { pkgQN = pkgQN.substring(0, pos); Set<PackageElement> pkgElts = getPackageElement.apply(elementUtils, pkgQN); pkgElt = pkgElts.isEmpty() ? null : pkgElts.iterator().next(); } } return null; }
ModuleGen annotation = pkg.getAnnotation(ModuleGen.class); if (annotation != null) { module = new ModuleInfo(pkg.getName(), annotation.name(), annotation.groupPackage()); break; } else {
public ModuleModel getModuleModel(String modulePackage) { PackageElement element = modules.get(modulePackage); ModuleGen annotation = element.getAnnotation(ModuleGen.class); String moduleName = annotation.name(); if (moduleName.isEmpty()) { throw new GenException(element, "A module name cannot be empty"); } try { Case.KEBAB.parse(moduleName); } catch (IllegalArgumentException e) { throw new GenException(element, "Module name '" + moduleName + "' does not follow the snake case format (dash separated name)"); } String groupPackage = annotation.groupPackage(); if (groupPackage.equals("")) { groupPackage = modulePackage; } else if (!modulePackage.startsWith(groupPackage)) { throw new GenException(element, "A module package (" + modulePackage + ") must be prefixed by the group package (" + groupPackage + ")"); } try { Case.QUALIFIED.parse(groupPackage); } catch (Exception e) { throw new GenException(element, "Invalid group package name " + groupPackage); } ModuleInfo info = new ModuleInfo(modulePackage, moduleName, groupPackage); AnnotationValueInfoFactory annotationFactory = new AnnotationValueInfoFactory(new TypeMirrorFactory(elementUtils,typeUtils)); List<AnnotationValueInfo> annotationValueInfos = element.getAnnotationMirrors().stream().map(annotationFactory::processAnnotation).collect(Collectors.toList()); return new ModuleModel(element, info, annotationValueInfos); }