/** Some validations, not exhaustive. */ @Value.Check protected void validate() { if (hasInclude() && !isTopLevel()) { report() .annotationNamed(IncludeMirror.simpleName()) .error("@%s could not be used on nested types.", IncludeMirror.simpleName()); } if (isEnclosing() && !isTopLevel()) { report() .annotationNamed(EnclosingMirror.simpleName()) .error("@%s should only be used on a top-level types.", EnclosingMirror.simpleName()); } if (isImmutable() && element().getKind() == ElementKind.ENUM) { report() .annotationNamed(ImmutableMirror.simpleName()) .error("@%s is not supported on enums", ImmutableMirror.simpleName()); } if (isModifiable() && (isEnclosed() || isEnclosing())) { report() .annotationNamed(ModifiableMirror.simpleName()) .error( "@%s could not be used with or within @%s", ModifiableMirror.simpleName(), EnclosingMirror.simpleName()); } }
@Value.Lazy public List<TypeElement> includedTypes() { Optional<IncludeMirror> includes = include(); ImmutableList<TypeMirror> typeMirrors = includes.isPresent() ? ImmutableList.copyOf(includes.get().valueMirror()) : ImmutableList.<TypeMirror>of(); FluentIterable<TypeElement> typeElements = FluentIterable.from(typeMirrors) .filter(DeclaredType.class) .transform(DeclatedTypeToElement.FUNCTION); ImmutableSet<String> uniqueTypeNames = typeElements.filter(IsPublic.PREDICATE).transform(ElementToName.FUNCTION).toSet(); if (uniqueTypeNames.size() != typeMirrors.size()) { report() .annotationNamed(IncludeMirror.simpleName()) .warning( "Some types were ignored, non-supported for inclusion: duplicates, non declared reference types, non-public"); } return typeElements.toList(); }
@Value.Lazy protected Optional<IncludeMirror> include() { return IncludeMirror.find(element()); }