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;
    }
예제 #3
0
파일: Proto.java 프로젝트: akune/immutables
 public Visibility declaringVisibility() {
   if (declaringType().isPresent()) {
     return Visibility.of(declaringType().get().element());
   }
   return Visibility.PUBLIC;
 }
예제 #4
0
파일: Proto.java 프로젝트: akune/immutables
 @Value.Derived
 public Visibility visibility() {
   return Visibility.of(sourceElement());
 }