Package java.beans

Examples of java.beans.ConstructorProperties


   * Inner class to avoid a Java 6 dependency.
   */
  private static class ConstructorPropertiesChecker {

    public static String[] evaluateAnnotation(Constructor<?> candidate, int paramCount) {
      ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
      if (cp != null) {
        String[] names = cp.value();
        if (names.length != paramCount) {
          throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
              "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
        }
        return names;
View Full Code Here


        // [#1837] If any java.beans.ConstructorProperties annotations are
        // present use those rather than matching constructors by the number of
        // arguments
        for (Constructor<E> constructor : constructors) {
            ConstructorProperties properties = constructor.getAnnotation(ConstructorProperties.class);

            if (properties != null) {
                delegate = new ImmutablePOJOMapperWithConstructorProperties(constructor, properties);
                return;
            }
View Full Code Here

   * Delegate for checking Java 6's {@link ConstructorProperties} annotation.
   */
  private static class ConstructorPropertiesChecker {

    public static String[] evaluate(Constructor<?> candidate, int paramCount) {
      ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
      if (cp != null) {
        String[] names = cp.value();
        if (names.length != paramCount) {
          throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
              "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
        }
        return names;
View Full Code Here

   * Inner class to avoid a Java 6 dependency.
   */
  private static class ConstructorPropertiesChecker {

    public static String[] evaluateAnnotation(Constructor<?> candidate, int paramCount) {
      ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
      if (cp != null) {
        String[] names = cp.value();
        if (names.length != paramCount) {
          throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
              "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
        }
        return names;
View Full Code Here

   * Inner class to avoid a Java 6 dependency.
   */
  private static class ConstructorPropertiesChecker {

    public static String[] evaluateAnnotation(Constructor<?> candidate, int paramCount) {
      ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
      if (cp != null) {
        String[] names = cp.value();
        if (names.length != paramCount) {
          throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
              "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
        }
        return names;
View Full Code Here

    this.javaModelAnalyzerUtil = javaModelAnalyzerUtil;
    this.typeMFactory = typeMFactory;
  }

  public void scan(ExecutableElement constrEl, Output output) {
    ConstructorProperties constrPropsAnno = constrEl.getAnnotation(ConstructorProperties.class);
    if (constrPropsAnno == null) {
      // use declared parameter names to map parameters to property names
      List<? extends VariableElement> parameters = constrEl.getParameters();
      int i = 0;
      for (VariableElement paramEl : parameters) {
        String propertyName = paramEl.getSimpleName().toString();
        TypeMirror propertyTypeMirror = paramEl.asType();
        TypeM propertyType = typeMFactory.getTypeM(propertyTypeMirror);
        output
            .getBuilderModel()
            .getProperties()
            .getOrCreate(propertyName, propertyType)
            .writableVia(
                new ConstructorParameterM(i).withName(propertyName).withVarArgs(
                    constrEl.isVarArgs() && i == parameters.size() - 1));
        i++;
      }
    } else {
      // use @ConstructorProperties to map parameters to property names
      String[] propertyNames = constrPropsAnno.value();
      List<? extends VariableElement> parameters = constrEl.getParameters();
      if (propertyNames.length != parameters.size()) {
        String message =
            String.format("Incorrect number of values in annotation @%s! Expected %d, but was %d.",
                ConstructorProperties.class.getSimpleName(), parameters.size(), propertyNames.length);
View Full Code Here

                        Object javaValue = fromOpenData(itemType, classLoader, itemValue);
                        invokeSetter(result, key, javaValue);
                    }
                } else {
                    List<Object> params = new ArrayList<>();
                    ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
                    for (String key : props.value()) {
                        OpenType<?> itemType = ctype.getType(key);
                        Object itemValue = cdata.get(key);
                        Object javaValue = fromOpenData(itemType, classLoader, itemValue);
                        params.add(javaValue);
                    }
View Full Code Here

TOP

Related Classes of java.beans.ConstructorProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.