Java 类com.sun.codemodel.JAnnotatable 实例源码

项目:hyperjaxb3    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);
}
项目:rest4j    文件:DataTemplateGenerator.java   
private void setDeprecatedAnnotationAndJavadoc(Object deprecatedProp,
                                               JAnnotatable annotatable,
                                               JDocCommentable commentable)
{
  if (Boolean.TRUE.equals(deprecatedProp) && annotatable != null)
  {
    annotatable.annotate(Deprecated.class);
  }
  else if (deprecatedProp instanceof String)
  {
    if (commentable != null)
    {
      String deprecatedReason = (String)deprecatedProp;
      commentable.javadoc().addDeprecated().append(deprecatedReason);
    }
    if (annotatable != null)
    {
      annotatable.annotate(Deprecated.class);
    }
  }
}
项目:jaxb2-annotate-plugin    文件:Annotator.java   
public void annotate(JCodeModel codeModel, JAnnotatable annotatable,
        XAnnotation<?> xannotation) {
    final JClass annotationClass = codeModel.ref(xannotation
            .getAnnotationClass());
    JAnnotationUse annotationUse = null;
    for (JAnnotationUse annotation : annotatable.annotations()) {
        if (annotationClass.equals(annotation.getAnnotationClass())) {
            annotationUse = annotation;
        }
    }
    if (annotationUse == null) {
        annotationUse = annotatable.annotate(annotationClass);
    }
    final XAnnotationFieldVisitor<?> visitor = createAnnotationFieldVisitor(
            codeModel, annotationUse);
    for (XAnnotationField<?> field : xannotation.getFieldsList()) {
        field.accept(visitor);
    }
}
项目:jaxb2-annotate-plugin    文件:AnnotatePlugin.java   
protected void annotateElementOutline(final JCodeModel codeModel,
        final ElementOutline elementOutline,
        final CCustomizations customizations,
        final ErrorHandler errorHandler) {
    for (final CPluginCustomization customization : customizations) {
        final Element element = customization.element;
        final QName name = new QName(element.getNamespaceURI(),
                element.getLocalName());
        if (Constants.NAMESPACE_URI.equals(name.getNamespaceURI())) {
            customization.markAsAcknowledged();
            final AnnotationTarget annotationTarget = AnnotationTarget
                    .getAnnotationTarget(element, AnnotationTarget.ELEMENT);
            try {
                final JAnnotatable annotatable = annotationTarget
                        .getAnnotatable(elementOutline.parent(),
                                elementOutline);
                annotate(codeModel, errorHandler, customization, element,
                        annotatable);
            } catch (IllegalArgumentException iaex) {
                logger.error("Error applying the annotation.", iaex);
            }
        }
    }
}
项目:jaxb2-annotate-plugin    文件:AnnotatePlugin.java   
protected void annotateEnumOutline(final JCodeModel codeModel,
        final EnumOutline enumOutline,
        final CCustomizations customizations,
        final ErrorHandler errorHandler) {
    for (final CPluginCustomization customization : customizations) {
        final Element element = customization.element;
        final QName name = new QName(element.getNamespaceURI(),
                element.getLocalName());
        if (Constants.NAMESPACE_URI.equals(name.getNamespaceURI())) {
            customization.markAsAcknowledged();
            final AnnotationTarget annotationTarget = AnnotationTarget
                    .getAnnotationTarget(element, AnnotationTarget.ENUM);
            try {
                final JAnnotatable annotatable = annotationTarget
                        .getAnnotatable(enumOutline.parent(), enumOutline);
                annotate(codeModel, errorHandler, customization, element,
                        annotatable);
            } catch (IllegalArgumentException iaex) {
                logger.error("Error applying the annotation.", iaex);
            }
        }
    }
}
项目:jaxb2-annotate-plugin    文件:AnnotatePlugin.java   
protected void annotateEnumConstantOutline(final JCodeModel codeModel,
        final Outline outline,
        final EnumConstantOutline enumConstantOutline,
        final CCustomizations customizations,
        final ErrorHandler errorHandler) {
    for (final CPluginCustomization customization : customizations) {
        final Element element = customization.element;
        final QName name = new QName(element.getNamespaceURI(),
                element.getLocalName());
        if (Constants.NAMESPACE_URI.equals(name.getNamespaceURI())) {
            customization.markAsAcknowledged();
            final AnnotationTarget annotationTarget = AnnotationTarget
                    .getAnnotationTarget(element,
                            AnnotationTarget.ENUM_CONSTANT);
            try {
                final JAnnotatable annotatable = annotationTarget
                        .getAnnotatable(outline, enumConstantOutline);
                annotate(codeModel, errorHandler, customization, element,
                        annotatable);
            } catch (IllegalArgumentException iaex) {
                logger.error("Error applying the annotation.", iaex);
            }

        }
    }
}
项目:jaxb2-annotate-plugin    文件:AnnotatePlugin.java   
protected void annotateClassOutline(final JCodeModel codeModel,
        final ClassOutline classOutline,
        final CCustomizations customizations, ErrorHandler errorHandler) {
    for (final CPluginCustomization customization : customizations) {
        final Element element = customization.element;
        final QName name = new QName(element.getNamespaceURI(),
                element.getLocalName());
        if (Constants.NAMESPACE_URI.equals(name.getNamespaceURI())) {
            customization.markAsAcknowledged();
            final AnnotationTarget annotationTarget = AnnotationTarget
                    .getAnnotationTarget(element, AnnotationTarget.CLASS);
            try {
                final JAnnotatable annotatable = annotationTarget
                        .getAnnotatable(classOutline.parent(), classOutline);
                annotate(codeModel, errorHandler, customization, element,
                        annotatable);
            } catch (IllegalArgumentException iaex) {
                logger.error("Error applying the annotation.", iaex);
            }
        }
    }
}
项目:libraries    文件:AbstractSourceFactory.java   
protected void annotate(final JAnnotatable annotatable, final Iterable<Annotation> annotationConfigurations)
    throws CreationException {
  ensureThatArgument(annotatable, notNull());
  ensureThatArgument(annotationConfigurations, notNull());
  for (final Annotation annotationConfiguration : annotationConfigurations) {
    annotate(annotatable, annotationConfiguration);
  }
}
项目:aml    文件:Context.java   
/**
 * <p>addHttpMethodAnnotation.</p>
 *
 * @param httpMethod a {@link java.lang.String} object.
 * @param annotatable a {@link com.sun.codemodel.JAnnotatable} object.
 * @return a {@link org.raml.jaxrs.codegen.core.Context} object.
 * @throws java.lang.Exception if any.
 */
@SuppressWarnings("unchecked")
public Context addHttpMethodAnnotation(final String httpMethod, final JAnnotatable annotatable)
    throws Exception
{
    final Object annotationClass = httpMethodAnnotations.get(httpMethod.toUpperCase());
    if (annotationClass == null)
    {
        final JDefinedClass annotationClazz = createCustomHttpMethodAnnotation(httpMethod);
        annotatable.annotate(annotationClazz);
    }
    else if (annotationClass instanceof JClass)
    {
        annotatable.annotate((JClass) annotationClass);
    }
    else if (annotationClass instanceof Class)
    {
        annotatable.annotate((Class<? extends Annotation>) annotationClass);
    }
    else
    {
        throw new IllegalStateException("Found annotation: " + annotationClass + " for HTTP method: "
                                        + httpMethod);
    }

    return this;
}
项目:aml    文件:Context.java   
/**
 * <p>addHttpMethodAnnotation.</p>
 *
 * @param httpMethod a {@link java.lang.String} object.
 * @param annotatable a {@link com.sun.codemodel.JAnnotatable} object.
 * @return a {@link org.raml.jaxrs.codegen.core.Context} object.
 * @throws java.lang.Exception if any.
 */
@SuppressWarnings("unchecked")
public Context addHttpMethodAnnotation(final String httpMethod, final JAnnotatable annotatable)
    throws Exception
{
    final Object annotationClass = httpMethodAnnotations.get(httpMethod.toUpperCase());
    if (annotationClass == null)
    {
        final JDefinedClass annotationClazz = createCustomHttpMethodAnnotation(httpMethod);
        annotatable.annotate(annotationClazz);
    }
    else if (annotationClass instanceof JClass)
    {
        annotatable.annotate((JClass) annotationClass);
    }
    else if (annotationClass instanceof Class)
    {
        annotatable.annotate((Class<? extends Annotation>) annotationClass);
    }
    else
    {
        throw new IllegalStateException("Found annotation: " + annotationClass + " for HTTP method: "
                                        + httpMethod);
    }

    return this;
}
项目:aml    文件:FacetProcessingConfig.java   
protected void processConfig(AnnotationGenerationInfo annotationGenerationInfo, ISimpleFacet si,
        PropertyCustomizerParameters cp) {
    JAnnotatable annotable = cp.getter;
    JAnnotationUse use = null;
    for (JAnnotationUse u : annotable.annotations()) {
        if (u.getAnnotationClass().fullName().equals(annotationGenerationInfo.annotationClassName)) {
            use = u;
            break;
        }
    }
    if (use == null) {
        use = annotable.annotate(writer.getModel().ref(annotationGenerationInfo.annotationClassName));
    }
    writer.addParam(use, si.value(), annotationGenerationInfo.annotationMemberName);
}
项目:org.ops4j.ramler    文件:ResourceGeneratingApiVisitor.java   
private void addHttpMethodAnnotation(final String httpMethod, final JAnnotatable annotatable) {
    Class<? extends Annotation> annotationClass = httpMethodAnnotations
        .get(httpMethod.toUpperCase());
    if (annotationClass == null) {
        throw new IllegalArgumentException("unsupported HTTP method: " + httpMethod);
    }
    annotatable.annotate(annotationClass);
}
项目:hyperjaxb3    文件:AbstractField.java   
private XmlElementWriter getXew(boolean checkWrapper, JAnnotatable field) {
    XmlElementWriter xew;
    if(checkWrapper) {
        if(xesw==null) {
            xesw = field.annotate2(XmlElementsWriter.class);
        }
        xew = xesw.value();
    } else {
        xew = field.annotate2(XmlElementWriter.class);
    }
    return xew;
}
项目:hyperjaxb3    文件:AbstractField.java   
/**
 * Annotate the attribute property 'field'
 */
private void annotateAttribute(JAnnotatable field) {
    CAttributePropertyInfo ap = (CAttributePropertyInfo) prop;
    QName attName = ap.getXmlName();

    // [RESULT]
    // @XmlAttribute(name="foo", required=true, namespace="bar://baz")
    XmlAttributeWriter xaw = field.annotate2(XmlAttributeWriter.class);

    final String generatedName = attName.getLocalPart();
    final String generatedNS = attName.getNamespaceURI();

    // generate name property?
    if(!generatedName.equals(ap.getName(false))) {
        xaw.name(generatedName);
    }

    // generate namespace property?
    if(!generatedNS.equals("")) { // assume attributeFormDefault == unqualified
        xaw.namespace(generatedNS);
    }

    // generate required property?
    if(ap.isRequired()) {
        xaw.required(true);
    }
}
项目:jaxb2-annotate-plugin    文件:Annotator.java   
public void annotate(JCodeModel codeModel, JAnnotatable annotatable,
        Collection<XAnnotation<?>> xannotations) {
    for (final XAnnotation<?> xannotation : xannotations) {
        if (xannotation != null) {
            annotate(codeModel, annotatable, xannotation);
        }
    }
}
项目:jaxb2-annotate-plugin    文件:AnnotatePlugin.java   
protected void annotate(final JCodeModel codeModel,
        final FieldOutline fieldOutline,
        final CCustomizations customizations, ErrorHandler errorHandler) {
    for (final CPluginCustomization customization : customizations) {
        final Element element = customization.element;
        final QName name = new QName(element.getNamespaceURI(),
                element.getLocalName());
        if (Constants.NAMESPACE_URI.equals(name.getNamespaceURI())) {
            customization.markAsAcknowledged();

            final AnnotationTarget annotationTarget = AnnotationTarget
                    .getAnnotationTarget(element, AnnotationTarget
                            .getAnnotationTarget(getDefaultFieldTarget()));

            try {
                final JAnnotatable annotatable = annotationTarget
                        .getAnnotatable(fieldOutline.parent().parent(),
                                fieldOutline);
                annotate(codeModel, errorHandler, customization, element,
                        annotatable);
            } catch (IllegalArgumentException iaex) {
                logger.error("Error applying the annotation.", iaex);
            }

        }
    }
}
项目:jaxb2-basics    文件:AbstractPropertyOutline.java   
protected void annotate(JAnnotatable annotatable) {
    this.propertyInfo
            .acceptPropertyInfoVisitor(new AnnotatePropertyVisitor(
                    annotatable));
}
项目:jaxb2-basics    文件:AnnotatePropertyVisitor.java   
public AnnotatePropertyVisitor(final JAnnotatable annotatable) {
    Validate.notNull(annotatable);
    this.annotatable = annotatable;
}
项目:jaxb2-basics    文件:AnyAttributePropertyOutline.java   
protected void annotate(JAnnotatable annotatable) {
    annotatable.annotate(XmlAnyAttribute.class);
}
项目:hyperjaxb3    文件:AbstractField.java   
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String mostUsedURI = parent()._package().getMostUsedNamespaceURI();
    String propName = prop.getName(false);

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(mostUsedURI)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (parent().parent().getModel().options.runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
项目:hyperjaxb3    文件:TransientSingleField.java   
@Override
protected void annotate(JAnnotatable field) {
    field.annotate(XmlTransient.class);
}
项目:alchemy-rest-client-generator    文件:ServiceStubGenerator.java   
/**
 * Add a list valued annotation the annotatable.
 *
 * @param jAnnotatable
 *            the annotatable
 * @param annotation
 *            the annotation
 * @param param
 *            the name of the parameter
 * @param values
 *            the values.
 */
private void addListAnnotation(final JAnnotatable jAnnotatable,
        final Class<? extends Annotation> annotation, final String param,
        final Collection<String> values) {
    if (!values.isEmpty()) {
        final JAnnotationArrayMember annotationValues =
                jAnnotatable.annotate(annotation).paramArray(param);
        for (final String value : values) {
            annotationValues.param(value);
        }
    }
}
项目:alchemy-rest-client-generator    文件:ServiceStubGenerator.java   
/**
 * Add a single valued annotation to the annotatable.
 *
 * @param jAnnotatable
 *            the annotatable.
 * @param annotation
 *            the annotation class.
 * @param param
 *            the name of the param
 * @param value
 *            the value of the param
 */
private void addSingleValueAnnotation(final JAnnotatable jAnnotatable,
        final Class<? extends Annotation> annotation, final String param, final String value) {
    if (!StringUtils.isBlank(value)) {
        jAnnotatable.annotate(annotation).param(param, value);
    }
}
项目:alchemy-rest-client-generator    文件:ServiceStubGenerator.java   
/**
 * Add annotation to the annotatable.
 *
 * @param jAnnotatable
 *            the annotatable.
 * @param annotation
 *            the annotation class.
 */
private void addAnnotation(final JAnnotatable jAnnotatable,
        final Class<? extends Annotation> annotation) {
    jAnnotatable.annotate(annotation);
}