private static void verifyNamesUnique(TypeSystemData typeSystem) { Set<String> usedNames = new HashSet<>(); for (TypeMirror type : typeSystem.getLegacyTypes()) { String boxedName = ElementUtils.getSimpleName(typeSystem.boxType(type)); String primitiveName = ElementUtils.getSimpleName(type); if (usedNames.contains(boxedName)) { typeSystem.addError("Two types result in the same boxed name: %s.", boxedName); } else if (usedNames.contains(primitiveName)) { typeSystem.addError("Two types result in the same primitive name: %s.", primitiveName); } usedNames.add(boxedName); usedNames.add(primitiveName); } }
private void verifyExclusiveMethodAnnotation(Template template, Class<?>... annotationTypes) { List<ExecutableElement> methods = ElementFilter.methodsIn(template.getTemplateType().getEnclosedElements()); for (ExecutableElement method : methods) { List<AnnotationMirror> foundAnnotations = new ArrayList<>(); for (int i = 0; i < annotationTypes.length; i++) { Class<?> annotationType = annotationTypes[i]; AnnotationMirror mirror = ElementUtils.findAnnotationMirror(context.getEnvironment(), method, annotationType); if (mirror != null) { foundAnnotations.add(mirror); } } if (foundAnnotations.size() > 1) { List<String> annotationNames = new ArrayList<>(); for (AnnotationMirror mirror : foundAnnotations) { annotationNames.add("@" + ElementUtils.getSimpleName(mirror.getAnnotationType())); } template.addError("Non exclusive usage of annotations %s.", annotationNames); } } }