Package com.sun.codemodel

Examples of com.sun.codemodel.JFieldVar


      wrappedOrDirect = "Wrapped";
    }
    String capitalizedName = capitalize(fieldName);

    String fieldFieldName = "FIELD_" + capitalizedName;
    JFieldVar fieldField = templateClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, RecordDataSchema.Field.class, fieldFieldName);
    fieldField.init(schemaField.invoke("getField").arg(field.getName()));

    // Generate has method.
    JMethod has = templateClass.method(JMod.PUBLIC, getCodeModel().BOOLEAN, "has" + capitalizedName);
    addAccessorDoc(has, field, "Existence checker");
    setDeprecatedAnnotationAndJavadoc(has, field);
View Full Code Here


  private JType getWrapperType(JType typeClass, String local) throws GenerationException {
    JDefinedClass cls = (JDefinedClass) typeClass;

    local = replaceAndUpperCase(new StringBuffer(local));
   
    JFieldVar var = cls.fields().get(local);
    if (var == null) {
      local = "_" + local;
      var = cls.fields().get(local);
    }
   
    if (var == null) {
      // fall back to original detection algorithm
      return null;
    }
    return var.type();
  }
View Full Code Here

       
        for (Service service : services)
        {
            JClass serviceIntf = (JClass) service.getProperty(ServiceInterfaceGenerator.SERVICE_INTERFACE);

            JFieldVar intfClass = servCls.field(JMod.STATIC + JMod.PUBLIC,
                                                Class.class,
                                                javify(serviceIntf.name()),
                                                JExpr.dotclass(serviceIntf));

            // hack to get local support
View Full Code Here

  }

  @NotNull
  public JFieldVar getOrCreateConstant( @NotNull JDefinedClass serializerClass, @NotNull Class<?> type, @NotNull @NonNls String constantName, @NotNull JExpression initExpression ) {
    //Get the constant if it still exists
    JFieldVar fieldVar = serializerClass.fields().get( constantName );
    if ( fieldVar != null ) {
      return fieldVar;
    }

    //Create
View Full Code Here

    return createConstant( serializerClass, type, constantName, initExpression );
  }

  @NotNull
  public JFieldVar createConstant( @NotNull JDefinedClass serializerClass, @NotNull Class<?> type, @NotNull @NonNls String constantName, @NotNull JExpression initExpression ) {
    JFieldVar constant = serializerClass.field( JMod.FINAL | JMod.PUBLIC | JMod.STATIC, type, constantName, initExpression );

    for ( Decorator decorator : decorators ) {
      decorator.decorateConstant( this, constant );
    }
View Full Code Here

      JClass iface = model.ref(DrillSimpleFuncInterpreter.class);
      clazz._implements(iface);

      Map<DrillFuncHolder.WorkspaceReference, JFieldVar> wsFieldVars = Maps.newHashMap();
      for (DrillFuncHolder.WorkspaceReference ws : holder.getWorkspaceVars()) {
        JFieldVar wsVar = clazz.field(JMod.PRIVATE, ws.getType(), ws.getName());
        wsFieldVars.put(ws, wsVar);
      }

      generateSetup(wsFieldVars);
View Full Code Here

        }

        cls._extends(javax.xml.ws.Service.class);
        String serviceFieldName = JAXBRIContext.mangleNameToClassName(service.getName().getLocalPart()).toUpperCase();
        String wsdlLocationName = serviceFieldName + "_WSDL_LOCATION";
        JFieldVar urlField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, URL.class, wsdlLocationName);

        JFieldVar exField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, WebServiceException.class, serviceFieldName+"_EXCEPTION");


        String serviceName = serviceFieldName + "_QNAME";
        cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, serviceName,
            JExpr._new(cm.ref(QName.class)).arg(service.getName().getNamespaceURI()).arg(service.getName().getLocalPart()));
View Full Code Here

     * @param fieldName the name of the <code>JavaField</code> to return.
     *
     * @return the <code>JavaField</code> named <code>fieldName</code> from this <code>JavaClass</code>.
     */
    public JavaField getDeclaredField(String fieldName) {
        JFieldVar xjcField = xjcClass.fields().get(fieldName);

        return new XJCJavaFieldImpl(xjcField, jCodeModel, dynamicClassLoader, this);
    }
View Full Code Here

     * @param fieldName the name of the <code>JavaField</code> to return.
     *
     * @return the <code>JavaField</code> named <code>fieldName</code> from this <code>JavaClass</code>.
     */
    public JavaField getDeclaredField(String fieldName) {
        JFieldVar xjcField = xjcClass.fields().get(fieldName);

        return new XJCJavaFieldImpl(xjcField, jCodeModel, dynamicClassLoader, this);
    }
View Full Code Here

                        + targetClass.fullName() + "#" + fieldName + " and hence won't be removed.");
            c.unmarkForRemoval();
          }
        }

        JFieldVar originalImplField = targetClass.fields().get(fieldName);

        if (candidate == null) {
          checkAnnotationReference(candidatesMap, originalImplField);

          continue;
        }

        // We have a candidate field to be replaced with a wrapped version. Report finding to summary file.
        writeSummary("\tReplacing field [" + fieldType.name() + " " + targetClass.fullName() + "#" + fieldName
                    + "]");
        candidate.incrementSubstitutions();
        modificationCount++;

        // The container class has to be deleted. Check that inner class has to be moved to it's parent.
        if (moveInnerClassToParent(outline, candidate)) {
          modificationCount++;
        }

        Configuration fieldConfiguration = applyConfigurationFromCustomizations(classConfiguration,
                    CustomizationUtils.getCustomizations(field));

        List<JClass> fieldTypeParametrisations = candidate.getFieldClass().getTypeParameters();

        // Create the new interface and collection classes using the specified interface and
        // collection classes (configuration) with an element type corresponding to
        // the element type from the collection present in the candidate class (narrowing).
        JClass collectionInterfaceClass = codeModel.ref(fieldConfiguration.getCollectionInterfaceClass())
                    .narrow(fieldTypeParametrisations);
        JClass collectionImplClass = codeModel.ref(fieldConfiguration.getCollectionImplClass()).narrow(
                    fieldTypeParametrisations);

        boolean pluralFormWasApplied = false;

        // Apply the plural form if there are no customizations. Assuming that customization is correct as may define the
        // plural form in more correct way, e.g. "field[s]OfScience" instead of "fieldOfScience[s]".
        if (fieldConfiguration.isApplyPluralForm() && !hasPropertyNameCustomization(fieldPropertyInfo)) {
          String oldFieldName = fieldName;

          // Taken from com.sun.tools.xjc.reader.xmlschema.ParticleBinder#makeJavaName():
          fieldName = JJavaName.getPluralForm(fieldName);

          // The field e.g. "return" was escaped as "_return", but after conversion to plural
          // it became valid Java identifier, so we remove the leading "_":
          if (fieldName.startsWith("_") && JJavaName.isJavaIdentifier(fieldName.substring(1))) {
            fieldName = fieldName.substring(1);
          }

          if (!fieldName.equals(oldFieldName)) {
            pluralFormWasApplied = true;

            originalImplField.name(fieldName);
            fieldPropertyInfo.setName(false, fieldName);

            // Correct the @XmlType class-level annotation:
            JAnnotationArrayMember propOrderValue = (JAnnotationArrayMember) getAnnotation(targetClass,
                        xmlTypeModelClass).getAnnotationMembers().get("propOrder");

            if (propOrderValue != null) {
              for (JAnnotationValue annotationValue : propOrderValue.annotations()) {
                if (oldFieldName.equals(generableToString(annotationValue))) {
                  setPrivateField(annotationValue, "value", JExpr.lit(fieldName));
                  break;
                }
              }
            }
          }
        }

        // Transform the field accordingly.
        originalImplField.type(collectionInterfaceClass);

        // If instantiation is specified to be "early", add code for creating new instance of the collection class.
        if (fieldConfiguration.getInstantiationMode() == Configuration.InstantiationMode.EARLY) {
          logger.debug("Applying EARLY instantiation...");
          // GENERATED CODE: ... fieldName = new C<T>();
          originalImplField.init(JExpr._new(collectionImplClass));
        }

        // Annotate the field with the @XmlElementWrapper annotation using the original field name.
        JAnnotationUse xmlElementWrapperAnnotation = originalImplField.annotate(xmlElementWrapperModelClass);
        JAnnotationUse xmlElementOriginalAnnotation = getAnnotation(originalImplField, xmlElementModelClass);

        // xmlElementOriginalAnnotation can be null:
        JExpression wrapperXmlName = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "name");
        if (wrapperXmlName != null) {
          xmlElementWrapperAnnotation.param("name", wrapperXmlName);
        }
        else if (fieldConfiguration.isApplyPluralForm()) {
          xmlElementWrapperAnnotation.param("name", getXsdDeclaration(fieldPropertyInfo).getName());
        }

        JExpression wrapperXmlRequired = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "required");
        if (wrapperXmlRequired != null) {
          xmlElementWrapperAnnotation.param("required", wrapperXmlRequired);
        }

        JExpression wrapperXmlNillable = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "nillable");
        if (wrapperXmlNillable != null) {
          xmlElementWrapperAnnotation.param("nillable", wrapperXmlNillable);
        }

        // Namespace of the wrapper element
        JExpression wrapperXmlNamespace = getAnnotationMemberExpression(xmlElementOriginalAnnotation,
                    "namespace");
        if (wrapperXmlNamespace != null) {
          xmlElementWrapperAnnotation.param("namespace", wrapperXmlNamespace);
        }

        if (xmlElementOriginalAnnotation != null) {
          removeAnnotation(originalImplField, xmlElementOriginalAnnotation);
        }

        boolean xmlElementInfoWasTransferred = false;

        // Transfer @XmlAnyElement, @XmlElementRefs, @XmlElements:
        for (JClass annotationModelClass : new JClass[] { xmlAnyElementModelClass, xmlMixedModelClass,
                xmlElementRefModelClass, xmlElementRefsModelClass, xmlElementsModelClass }) {
          JAnnotationUse annotation = getAnnotation(candidate.getField(), annotationModelClass);

          if (annotation != null) {
            if (candidate.getFieldTargetNamespace() != null) {
              JAnnotationArrayMember annotationArrayMember = (JAnnotationArrayMember) getAnnotationMember(
                          annotation, "value");

              if (annotationArrayMember != null) {
                for (JAnnotationUse subAnnotation : annotationArrayMember.annotations()) {
                  if (getAnnotationMemberExpression(subAnnotation, "namespace") == null) {
                    subAnnotation.param("namespace", candidate.getFieldTargetNamespace());
                  }
                }
              }
            }

            xmlElementInfoWasTransferred = true;

            addAnnotation(originalImplField, annotation);
          }
        }

        if (!xmlElementInfoWasTransferred) {
          // Annotate the field with the @XmlElement annotation using the field name from the wrapped type as name.
          // We cannot just re-use the same annotation object instance, as for example, we need to set XML name and this
          // will impact the candidate field annotation in case candidate is unmarked from removal.
          JAnnotationUse xmlElementAnnotation = originalImplField.annotate(xmlElementModelClass);
          xmlElementOriginalAnnotation = getAnnotation(candidate.getField(), xmlElementModelClass);

          // xmlElementOriginalAnnotation can be null:
          JExpression xmlName = getAnnotationMemberExpression(xmlElementOriginalAnnotation, "name");
          if (xmlName != null) {
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JFieldVar

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.