@Value.Lazy
  public NameForms typeImplementationBuilder() {
    TypeNames names = names();

    boolean outside = isOutsideBuilder();
    boolean nested = protoclass().kind().isNested();

    String simple = typeBuilderSimpleName();
    String relative;

    if (outside && nested) {
      relative = inPackage(typeImmutableEnclosingSimpleName(), simple);
    } else if (outside) {
      relative = inPackage(simple);
    } else if (nested) {
      relative =
          inPackage(
              inPackage(typeImmutableEnclosingSimpleName(), names.typeImmutableNested(), simple));
    } else {
      relative = inPackage(inPackage(names.typeImmutable, simple));
    }

    Visibility visibility = builderVisibility();

    if (!outside) {
      visibility = visibility.min(implementationVisibility());
    }

    return ImmutableConstitution.NameForms.builder()
        .simple(simple)
        .relativeRaw(relative)
        .genericArgs(generics().args())
        .packageOf(implementationPackage())
        .visibility(visibility)
        .build();
  }
    InnerBuilderDefinition() {
      @Nullable TypeElement builderElement = findBuilderElement();
      // The following series of checks designed
      // to not validate inner builder if it's disabled,
      // but at the same time we need such validation
      // if we are using "extending" builder which is still allowed
      // on demand even if builder feature is disabled
      boolean extending = false;

      if (builderElement != null) {
        extending = isExtending(builderElement);
      }

      if (builderElement != null && !protoclass().features().builder() && !extending) {
        builderElement = null;
      }

      if (builderElement != null && !isValidInnerBuilder(builderElement)) {
        builderElement = null;
      }

      if (builderElement != null) {
        this.isPresent = true;
        this.isInterface = builderElement.getKind() == ElementKind.INTERFACE;
        this.isExtending = extending;
        this.isSuper = !extending;
        this.simpleName = builderElement.getSimpleName().toString();
        this.visibility = Visibility.of(builderElement);
        this.generics = new Generics(protoclass(), builderElement);
        if (isExtending) {
          lateValidateExtending(builderElement);
        }
        if (isSuper) {
          lateValidateSuper(builderElement);
        }
      } else {
        this.isPresent = false;
        this.isInterface = false;
        this.isExtending = false;
        this.isSuper = false;
        this.visibility = Visibility.PRIVATE;
        this.simpleName = null;
        this.generics = Generics.empty();
      }
    }
    private boolean hasAccessibleConstructor(Element type) {
      List<ExecutableElement> constructors =
          ElementFilter.constructorsIn(type.getEnclosedElements());

      if (constructors.isEmpty()) {
        // It is unclear (not checked) if we will have syntethic no-arg constructor
        // included, so we will assume no constructor to equate having a single constructors.
        return true;
      }

      for (ExecutableElement c : constructors) {
        if (c.getParameters().isEmpty()) {
          return !Visibility.of(c).isPrivate();
        }
      }

      return false;
    }
예제 #4
0
파일: Proto.java 프로젝트: akune/immutables
 public Visibility declaringVisibility() {
   if (declaringType().isPresent()) {
     return Visibility.of(declaringType().get().element());
   }
   return Visibility.PUBLIC;
 }
예제 #5
0
파일: Proto.java 프로젝트: akune/immutables
 @Value.Derived
 public Visibility visibility() {
   return Visibility.of(sourceElement());
 }