public Validators(final String packageName) { this.validatorTypes = new EnumMap<>(Validation.class); this.validators = new ValidatorMap(); fillValidatorTypes(this.validatorTypes); final List<Class<?>> klasses = new ArrayList<>(); // Scan all classes in the given package with the Tag annotation try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages(packageName) .scan()) { final ClassInfoList tagClassInfoList = scanResult .getClassesWithAnnotation("org.openstreetmap.atlas.tags.annotations.Tag"); tagClassInfoList.loadClasses().forEach(klasses::add); } klasses.stream().forEach(this::processClass); }
public Optional<String> getTagInfo(final String tagName) { final Class<?> tagClass = this.validators.classFor(tagName); if (tagClass != null) { final Tag tag = tagClass.getAnnotation(Tag.class); if (tag.taginfo().equals("")) { return Optional.empty(); } else { return Optional.of(tag.taginfo()); } } return Optional.empty(); }
this.validators.put(tagClass, results.getKeyName(), results.getTagKey(), validator); });
/** * Is key a known tag? * * @param key * the type of tag we want to verify * @return true if we can handle [key] tags, false otherwise */ public boolean canValidate(final String key) { return this.validators.canValidate(key); }
boolean canValidate(final String name) { return validatorFor(name) != null; }
/** * Get the validator used for verifying tags named tagName * * @param key * the name of the tag we want to verify * @return the validator if we support it, null otherwise */ public TagValidator getValidatorFor(final String key) { return this.validators.validatorFor(key); }
/** * Sometimes we want to know where a tag found by Validators was defined. * * @param tag * the name of the tag we're searching for * @return an Optional containing the class reference if it exists, an empty optional otherwise */ public Optional<Class<?>> findClassDefining(final String tag) { return Optional.ofNullable(this.validators.classFor(tag)); }