private void checkAttributeNamesIllegalCharacters(ValueType type) { for (ValueAttribute a : type.attributes) { if (!ATTRIBUTE_NAME_CHARS.matchesAllOf(a.name())) { a.report() .error( "Name '%s' contains some unsupported or reserved characters, please use only A-Z, a-z, 0-9 and _ chars", a.name()); } } }
private void checkAttributeNamesForDuplicates(ValueType type, Protoclass protoclass) { if (!type.attributes.isEmpty()) { Multiset<String> attributeNames = HashMultiset.create(type.attributes.size()); for (ValueAttribute attribute : type.attributes) { attributeNames.add(attribute.name()); } List<String> duplicates = Lists.newArrayList(); for (Multiset.Entry<String> entry : attributeNames.entrySet()) { if (entry.getCount() > 1) { duplicates.add(entry.getElement()); } } if (!duplicates.isEmpty()) { protoclass .report() .error( "Duplicate attribute names %s. You should check if correct @Value.Style applied", duplicates); } } }
private void checkConstructability(ValueType type) { if (!type.isUseBuilder() || type.isUseConstructor()) { for (ValueAttribute a : type.getConstructorExcluded()) { if (a.isMandatory()) { a.report() .error( "Attribute '%s' is mandatory and should be a constructor" + " @Value.Parameter when builder is disabled or" + " there are other constructor parameters", a.name()); } } } if (!type.isUseBuilder() && !type.isUseCopyMethods()) { for (ValueAttribute a : type.getConstructorExcluded()) { if (!a.isMandatory()) { a.report() .warning( "There is no way to initialize '%s' attribute to non-default value." + " Enable builder=true or copy=true or add it as a constructor @Value.Parameter", a.name()); } } } if (type.isUseSingleton() && !type.getMandatoryAttributes().isEmpty()) { for (ValueAttribute a : type.getMandatoryAttributes()) { if (a.isMandatory()) { a.report() .error( "Attribute '%s' is mandatory and cannot be used with singleton enabled." + " Singleton instance require all attributes to have default value, otherwise" + " default instance could not be created", a.name()); } } } }