Example #1
0
 /** 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());
   }
 }
 private void checkStyleConflicts(ValueType type, Protoclass protoclass) {
   if (protoclass.features().prehash() && protoclass.styles().style().privateNoargConstructor()) {
     protoclass
         .report()
         .annotationNamed(ImmutableMirror.simpleName())
         .warning(
             "'prehash' feature is automatically disabled when 'privateNoargConstructor' style is turned on");
   }
   if (type.isUseConstructor() && protoclass.constitution().factoryOf().isNew()) {
     if (type.isUseValidation()) {
       protoclass
           .report()
           .annotationNamed(ImmutableMirror.simpleName())
           .error(
               "interning, singleton and validation will not work correctly with 'new' constructor configured in style");
     } else if (type.constitution.isImplementationHidden()
         && (type.kind().isEnclosing() || type.kind().isNested())) {
       protoclass
           .report()
           .annotationNamed(ImmutableMirror.simpleName())
           .error(
               "Enclosing with hidden implementation do not mix with 'new' constructor configured in style");
     }
   }
 }
 private static void scanAndReportInvalidInheritance(
     Protoclass protoclass, Element element, Iterable<DeclaredType> supertypes) {
   for (TypeElement supertype :
       Iterables.transform(supertypes, Proto.DeclatedTypeToElement.FUNCTION)) {
     if (!CachingElements.equals(element, supertype) && ImmutableMirror.isPresent(supertype)) {
       protoclass
           .report()
           .error(
               "Should not inherit %s which is a value type itself."
                   + " Avoid extending from another abstract value type."
                   + " Better to share common abstract class or interface which"
                   + " are not carrying @%s annotation",
               supertype, ImmutableMirror.simpleName());
     }
   }
 }
Example #4
0
 @Value.Lazy
 public Optional<ValueImmutableInfo> features() {
   return ImmutableMirror.find(element()).transform(ToImmutableInfo.FUNCTION);
 }
Example #5
0
 @Override
 public ValueImmutableInfo apply(ImmutableMirror input) {
   return ImmutableValueImmutableInfo.theOf(
           input.builder(), input.copy(), input.intern(), input.prehash(), input.singleton())
       .withIsDefault(input.getAnnotationMirror().getElementValues().isEmpty());
 }