예제 #1
0
파일: Proto.java 프로젝트: akune/immutables
 /** 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());
   }
 }
예제 #2
0
파일: Proto.java 프로젝트: akune/immutables
    @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();
    }