Example #1
0
 private void setPropertyType(PropertyBuilder builder, TypeMirror type) {
   if (builder.getType() == null) {
     builder.setType(type);
   } else {
     assert builder.getType().toString().equals(type.toString());
   }
 }
Example #2
0
  private void parseConstructorParameterAnnotations(PropertyBuilder property, Element element) {
    if (element.getAnnotation(Nullable.class) != null) {
      property.setNullable(true);
    }

    if (element.getAnnotation(Volatile.class) != null) {
      property.setVolatile(true);
    }
  }
Example #3
0
  private void parseSetter(ExecutableElement methodElement) {
    assert methodElement.getSimpleName().toString().startsWith("set");
    assert methodElement.getParameters().size() == 2;

    final boolean isFactorySetter =
        methodElement
            .getParameters()
            .get(0)
            .asType()
            .toString()
            .equals(DynamicObjectFactory.class.getName());
    final boolean isUnsafeSetter = methodElement.getSimpleName().toString().endsWith("Unsafe");

    assert !(isFactorySetter && isUnsafeSetter);

    if (isFactorySetter) {
      assert methodElement.getParameters().get(0).getSimpleName().toString().equals("factory");
    } else {
      assert methodElement
          .getParameters()
          .get(0)
          .asType()
          .toString()
          .equals(DynamicObject.class.getName());
      assert methodElement.getParameters().get(0).getSimpleName().toString().equals("object");
    }

    String name = titleToCamel(methodElement.getSimpleName().toString().substring("get".length()));

    if (isUnsafeSetter) {
      name = name.substring(0, name.length() - "Unsafe".length());
    }

    final PropertyBuilder property = getProperty(name);

    if (isFactorySetter) {
      property.setHasFactorySetter(true);
    } else {
      if (isUnsafeSetter) {
        property.setHasUnsafeSetter(isUnsafeSetter);
      } else {
        property.setHasSetter(true);
      }
    }

    setPropertyType(property, methodElement.getParameters().get(1).asType());
  }
Example #4
0
  private void parseGetter(ExecutableElement methodElement) {
    assert methodElement.getSimpleName().toString().startsWith("get");
    assert methodElement.getParameters().size() == 1;

    final boolean isFactoryGetter =
        methodElement
            .getParameters()
            .get(0)
            .asType()
            .toString()
            .equals(DynamicObjectFactory.class.getName());
    final boolean isObjectTypeGetter =
        methodElement.getParameters().get(0).asType().toString().equals(ObjectType.class.getName());

    assert !(isFactoryGetter & isObjectTypeGetter);

    if (isFactoryGetter) {
      assert methodElement.getParameters().get(0).getSimpleName().toString().equals("factory");
    } else if (isObjectTypeGetter) {
      assert methodElement.getParameters().get(0).getSimpleName().toString().equals("objectType");
    } else {
      assert methodElement
          .getParameters()
          .get(0)
          .asType()
          .toString()
          .equals(DynamicObject.class.getName());
      assert methodElement.getParameters().get(0).getSimpleName().toString().equals("object");
    }

    final String name =
        titleToCamel(methodElement.getSimpleName().toString().substring("get".length()));
    final PropertyBuilder property = getProperty(name);

    if (isFactoryGetter) {
      property.setHasFactoryGetter(true);
    } else if (isObjectTypeGetter) {
      property.setHasObjectTypeGetter(true);
    } else {
      property.setHasGetter(true);
    }

    setPropertyType(property, methodElement.getReturnType());
  }
Example #5
0
  private void parseShapeConstructor(ExecutableElement methodElement) {
    List<? extends VariableElement> parameters = methodElement.getParameters();

    if (superLayout != null) {
      assert parameters.size() >= superLayout.getAllShapeProperties().size();
      parameters =
          parameters.subList(superLayout.getAllShapeProperties().size(), parameters.size());
    }

    for (VariableElement element : parameters) {
      final String name = element.getSimpleName().toString();

      constructorProperties.add(name);
      final PropertyBuilder property = getProperty(name);
      setPropertyType(property, element.asType());
      parseConstructorParameterAnnotations(property, element);
      property.setIsShapeProperty(true);
      hasShapeProperties = true;
    }
  }
Example #6
0
  public LayoutModel build() {
    boolean hasShapeProperties = false;

    for (PropertyBuilder property : properties.values()) {
      if (property.isShapeProperty()) {
        hasShapeProperties = true;
      }
    }

    return new LayoutModel(
        objectTypeSuperclass,
        superLayout,
        name,
        packageName,
        hasObjectTypeGuard,
        hasObjectGuard,
        hasDynamicObjectGuard,
        buildProperties(),
        interfaceFullName,
        hasShapeProperties);
  }