Examples of JAnnotationUse


Examples of com.helger.jcodemodel.JAnnotationUse

            this.typeEnvironment = typeEnvironment;
        }

        private void annotate(List<? extends AnnotationMirror> annotationMirrors) throws ProcessingException {
            for (AnnotationMirror annotation: annotationMirrors) {
                JAnnotationUse annotationUse = annotatable.annotate((AbstractJClass)toJType(annotation.getAnnotationType(), typeEnvironment));
                for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> annotationValueAssignment: annotation.getElementValues().entrySet()) {
                    String name = annotationValueAssignment.getKey().getSimpleName().toString();
                    Object value = annotationValueAssignment.getValue().getValue();
                    if (value instanceof String)
                        annotationUse.param(name, (String)value);
                    else if (value instanceof Integer)
                        annotationUse.param(name, (Integer)value);
                    else if (value instanceof Long)
                        annotationUse.param(name, (Long)value);
                    else if (value instanceof Short)
                        annotationUse.param(name, (Short)value);
                    else if (value instanceof Float)
                        annotationUse.param(name, (Float)value);
                    else if (value instanceof Double)
                        annotationUse.param(name, (Double)value);
                    else if (value instanceof Byte)
                        annotationUse.param(name, (Byte)value);
                    else if (value instanceof Character)
                        annotationUse.param(name, (Character)value);
                    else if (value instanceof Class)
                        annotationUse.param(name, (Class)value);
                    else if (value instanceof Enum)
                        annotationUse.param(name, (Enum)value);
                    else if (value instanceof String[])
                        annotationUse.paramArray(name, (String[])value);
                    else if (value instanceof int[])
                        annotationUse.paramArray(name, (int[])value);
                    else if (value instanceof long[])
                        annotationUse.paramArray(name, (long[])value);
                    else if (value instanceof short[])
                        annotationUse.paramArray(name, (short[])value);
                    else if (value instanceof float[])
                        annotationUse.paramArray(name, (float[])value);
                    else if (value instanceof double[])
                        annotationUse.paramArray(name, (double[])value);
                    else if (value instanceof byte[])
                        annotationUse.paramArray(name, (byte[])value);
                    else if (value instanceof char[])
                        annotationUse.paramArray(name, (char[])value);
                    else if (value instanceof Class[])
                        annotationUse.paramArray(name, (Class[])value);
                    else if (value instanceof Enum[])
                        annotationUse.paramArray(name, (Enum[])value);
                }
            }
        }
View Full Code Here

Examples of com.helger.jcodemodel.JAnnotationUse

                }
            }

            int mods = annotation.valueClassIsPublic() ? JMod.PUBLIC: JMod.NONE;
            JDefinedClass valueClass = jpackage._class(mods, className, EClassType.CLASS);
            JAnnotationUse generatedAnnotation = valueClass.annotate(Generated.class);
            generatedAnnotation.param("value", GenerateValueClassForVisitorProcessor.class.getName());
            valueClass.annotate(ParametersAreNonnullByDefault.class);
            for (JTypeVar visitorTypeParameter: visitorInterface.getValueTypeParameters()) {
                Types.generifyWithBoundsFrom(valueClass, visitorTypeParameter.name(), visitorTypeParameter);
            }
            if (annotation.valueClassIsSerializable()) {
View Full Code Here

Examples of com.helger.jcodemodel.JAnnotationUse

        constructor.body().assign(JExpr.refthis(acceptorField.name()), JExpr.ref(acceptorField.name()));
    }

    void buildProtectedConstructor(JFieldVar acceptorField, Serialization serialization) throws JClassAlreadyExistsException {
        JMethod constructor = valueClass.constructor(JMod.PROTECTED);
        JAnnotationUse annotation = constructor.annotate(SuppressWarnings.class);
        annotation.paramArray("value", "null");
        AbstractJClass usedValueClassType = valueClass.narrow(valueClass.typeParams());
        JVar param = constructor.param(JMod.FINAL, usedValueClassType, "implementation");
        param.annotate(Nonnull.class);
        JConditional nullCheck = constructor.body()._if(JExpr.ref("implementation").eq(JExpr._null()));
        JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
View Full Code Here

Examples of com.helger.jcodemodel.JAnnotationUse

    JMethod buildFactory(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
        JDefinedClass factory = buildFactoryClass(constructorMethods);

        JFieldVar factoryField = valueClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, factory, "FACTORY");
        JAnnotationUse fieldAnnotationUse = factoryField.annotate(SuppressWarnings.class);
        JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
        paramArray.param("unchecked");
        paramArray.param("rawtypes");

        factoryField.init(JExpr._new(factory));
        JMethod factoryMethod = valueClass.method(JMod.PUBLIC | JMod.STATIC, types._void, "factory");
        factoryMethod.annotate(Nonnull.class);
        JAnnotationUse methodAnnotationUse = factoryMethod.annotate(SuppressWarnings.class);
        methodAnnotationUse.param("value", "unchecked");
        for (JTypeVar visitorTypeParameter: visitorInterface.getValueTypeParameters()) {
            Types.generifyWithBoundsFrom(factoryMethod, visitorTypeParameter.name(), visitorTypeParameter);
        }
        AbstractJClass usedValueClassType = valueClass.narrow(factoryMethod.typeParams());
        AbstractJClass usedFactoryType = factory.narrow(factoryMethod.typeParams());
View Full Code Here

Examples of com.helger.jcodemodel.JAnnotationUse

                        nullCheck._then()._throw(nullPointerExceptionConstruction);
                        hasNullChecks = true;
                    }
                }
                if (hasNullChecks) {
                    JAnnotationUse annotation = constructorMethod.annotate(SuppressWarnings.class);
                    annotation.paramArray("value", "null");
                }

                JInvocation caseClassConstructorInvocation = JExpr._new(usedCaseClassType);
                for (JVar param2: interfaceMethod.params()) {
                    caseClassConstructorInvocation.arg(JExpr.ref(param2.name()));
                }
                JVar param2 = interfaceMethod.listVarParam();
                if (param2 != null) {
                    caseClassConstructorInvocation.arg(JExpr.ref(param2.name()));
                }
                JInvocation constructorInvocation = JExpr._new(usedValueClassType);
                constructorInvocation.arg(caseClassConstructorInvocation);
                constructorMethod.body()._return(constructorInvocation);
            } else {
                JInvocation caseClassConstructorInvocation = JExpr._new(usedCaseClassType.erasure());
                JInvocation initializer = JExpr._new(usedValueClassType.erasure());
                initializer.arg(caseClassConstructorInvocation);
                JFieldVar singletonInstanceField = valueClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
                                                                    usedValueClassType.erasure(),
                                                                    interfaceMethod.name().toUpperCase(),
                                                                    initializer);
                JAnnotationUse fieldAnnotationUse = singletonInstanceField.annotate(SuppressWarnings.class);
                JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
                paramArray.param("unchecked");
                paramArray.param("rawtypes");

                JAnnotationUse methodAnnotationUse = constructorMethod.annotate(SuppressWarnings.class);
                methodAnnotationUse.param("value", "unchecked");
                IJExpression result = usedValueClassType.getTypeParameters().isEmpty() ? singletonInstanceField : JExpr.cast(usedValueClassType, singletonInstanceField);
                constructorMethod.body()._return(result);
            }
            constructorMethods.put(interfaceMethod.name(), constructorMethod);
        }
View Full Code Here

Examples of com.helger.jcodemodel.JAnnotationUse

    void buildEqualsMethod() throws SourceException {
        JMethod equalsMethod = valueClass.method(JMod.PUBLIC | JMod.FINAL, types._boolean, "equals");
        VariableNameSource nameSource = new VariableNameSource();
        equalsMethod.annotate(Override.class);
        JAnnotationUse annotationUse = equalsMethod.annotate(SuppressWarnings.class);
        annotationUse.param("value", "unchecked");
        JVar thatObject = equalsMethod.param(types._Object, nameSource.get("thatObject"));
        JConditional _if = equalsMethod.body()._if(JExpr._this().eq(thatObject));
        _if._then()._return(JExpr.TRUE);
        JConditional elseif = _if._elseif(thatObject._instanceof(valueClass).not());
        elseif._then()._return(JExpr.FALSE);
View Full Code Here

Examples of com.sun.codemodel.JAnnotationUse

    private void annotateEntity( final Outline outline, final Entity entity )
    {
        final JCodeModel cm = outline.getCodeModel();
        final ClassOutline c = this.getClassOutline( outline, entity.getClazz() );
        final JAnnotationUse a = c.implClass.annotate( cm.ref( javax.persistence.Entity.class ) );

        if ( entity.getName() != null )
        {
            a.param( "name", entity.getName() );
        }

        if ( !entity.getAssociationOverride().isEmpty() )
        {
            final JAnnotationUse aolst = c.implClass.annotate( cm.ref( javax.persistence.AssociationOverrides.class ) );
            final JAnnotationArrayMember value = aolst.paramArray( "value" );
            for ( AssociationOverride o : entity.getAssociationOverride() )
            {
                final JAnnotationUse ao = value.annotate( cm.ref( javax.persistence.AssociationOverride.class ) );
                if ( o.getName() != null )
                {
                    ao.param( "name", o.getName() );
                }

                if ( !o.getJoinColumn().isEmpty() )
                {
                    final JAnnotationArrayMember joinColumns = ao.paramArray( "joinColumns" );
                    for ( JoinColumn jc : o.getJoinColumn() )
                    {
                        final JAnnotationUse jca = joinColumns.annotate( cm.ref( javax.persistence.JoinColumn.class ) );
                        this.annotate( jca, jc );
                    }
                }
            }
        }

        if ( !entity.getAttributeOverride().isEmpty() )
        {
            final JAnnotationUse aolst = c.implClass.annotate( cm.ref( javax.persistence.AttributeOverrides.class ) );
            final JAnnotationArrayMember value = aolst.paramArray( "value" );
            for ( AttributeOverride o : entity.getAttributeOverride() )
            {
                final JAnnotationUse ao = value.annotate( cm.ref( javax.persistence.AttributeOverride.class ) );
                if ( o.getColumn() != null )
                {
                    final JAnnotationUse ac = ao.param( "column", cm.ref( javax.persistence.Column.class ) );
                    this.annotate( ac, o.getColumn() );
                }
                if ( o.getName() != null )
                {
                    ao.param( "name", o.getName() );
                }
            }
        }

        if ( entity.getAttributes() != null )
        {
            this.annotate( cm, c, entity.getAttributes() );
        }

        if ( entity.getDiscriminatorColumn() != null )
        {
            final JAnnotationUse dc = c.implClass.annotate( cm.ref( javax.persistence.DiscriminatorColumn.class ) );
            if ( entity.getDiscriminatorColumn().getColumnDefinition() != null )
            {
                dc.param( "columnDefinition", entity.getDiscriminatorColumn().getColumnDefinition() );
            }
            if ( entity.getDiscriminatorColumn().getDiscriminatorType() != null )
            {
                dc.param( "discriminatorType", javax.persistence.DiscriminatorType.valueOf(
                    entity.getDiscriminatorColumn().getDiscriminatorType().value() ) );

            }
            if ( entity.getDiscriminatorColumn().getLength() != null )
            {
                dc.param( "length", entity.getDiscriminatorColumn().getLength().intValue() );
            }
            if ( entity.getDiscriminatorColumn().getName() != null )
            {
                dc.param( "name", entity.getDiscriminatorColumn().getName() );
            }
        }

        if ( entity.getDiscriminatorValue() != null )
        {
            final JAnnotationUse dv = c.implClass.annotate( cm.ref( javax.persistence.DiscriminatorValue.class ) );
            dv.param( "value", entity.getDiscriminatorValue() );
        }

        if ( entity.getEntityListeners() != null )
        {
            this.annotate( c, entity.getEntityListeners() );
        }

        if ( entity.getExcludeDefaultListeners() != null )
        {
            c.implClass.annotate( cm.ref( javax.persistence.ExcludeDefaultListeners.class ) );
        }
        if ( entity.getExcludeSuperclassListeners() != null )
        {
            c.implClass.annotate( cm.ref( javax.persistence.ExcludeSuperclassListeners.class ) );
        }
        if ( entity.getIdClass() != null )
        {
            this.annotate( c, entity.getIdClass() );
        }
        if ( entity.getInheritance() != null )
        {
            final JAnnotationUse ih = c.implClass.annotate( cm.ref( javax.persistence.Inheritance.class ) );
            ih.param( "strategy",
                      javax.persistence.InheritanceType.valueOf( entity.getInheritance().getStrategy().value() ) );

        }
        if ( !entity.getNamedNativeQuery().isEmpty() )
        {
            final JAnnotationUse nnqlst = c.implClass.annotate( cm.ref( javax.persistence.NamedNativeQueries.class ) );
            final JAnnotationArrayMember value = nnqlst.paramArray( "value" );
            for ( NamedNativeQuery q : entity.getNamedNativeQuery() )
            {
                final JAnnotationUse qa = value.annotate( cm.ref( javax.persistence.NamedNativeQuery.class ) );
                qa.param( "name", q.getName() );
                qa.param( "query", q.getQuery() );

                if ( q.getResultClass() != null )
                {
                    qa.param( "resultClass", cm.ref( q.getResultClass() ) );
                }
                if ( q.getResultSetMapping() != null )
                {
                    qa.param( "resultSetMapping", q.getResultSetMapping() );
                }
                if ( !q.getHint().isEmpty() )
                {
                    final JAnnotationArrayMember hints = qa.paramArray( "hints" );
                    for ( QueryHint hint : q.getHint() )
                    {
                        final JAnnotationUse qh = hints.annotate( javax.persistence.QueryHint.class );
                        qh.param( "name", hint.getName() );
                        qh.param( "value", hint.getValue() );
                    }
                }
            }
        }
        if ( !entity.getNamedQuery().isEmpty() )
        {
            final JAnnotationUse nqlst = c.implClass.annotate( cm.ref( javax.persistence.NamedQueries.class ) );
            final JAnnotationArrayMember value = nqlst.paramArray( "value" );
            for ( NamedQuery q : entity.getNamedQuery() )
            {
                final JAnnotationUse nq = value.annotate( cm.ref( javax.persistence.NamedQuery.class ) );
                nq.param( "name", q.getName() );
                nq.param( "query", q.getQuery() );

                if ( !q.getHint().isEmpty() )
                {
                    final JAnnotationArrayMember hints = nq.paramArray( "hints" );
                    for ( QueryHint hint : q.getHint() )
                    {
                        final JAnnotationUse qh = hints.annotate( javax.persistence.QueryHint.class );
                        qh.param( "name", hint.getName() );
                        qh.param( "value", hint.getValue() );
                    }
                }
            }
        }
        if ( entity.getPostLoad() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPostLoad().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PostLoad.class ) );
        }
        if ( entity.getPostPersist() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPostPersist().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PostPersist.class ) );
        }
        if ( entity.getPostRemove() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPostRemove().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PostRemove.class ) );
        }
        if ( entity.getPostUpdate() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPostUpdate().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PostUpdate.class ) );
        }
        if ( entity.getPrePersist() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPreUpdate().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PrePersist.class ) );
        }
        if ( entity.getPreRemove() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPreRemove().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PreRemove.class ) );
        }
        if ( entity.getPreUpdate() != null )
        {
            final JMethod m = this.getMethod( c, entity.getPreUpdate().getMethodName() );
            m.annotate( cm.ref( javax.persistence.PreUpdate.class ) );
        }
        if ( !entity.getPrimaryKeyJoinColumn().isEmpty() )
        {
            final JAnnotationUse pkjcs = c.implClass.annotate( cm.ref( javax.persistence.PrimaryKeyJoinColumns.class ) );
            final JAnnotationArrayMember pkjc = pkjcs.paramArray( "value" );
            this.annotate( cm, pkjc, entity.getPrimaryKeyJoinColumn() );
        }
        if ( !entity.getSecondaryTable().isEmpty() )
        {
            final JAnnotationUse stlst = c.implClass.annotate( cm.ref( javax.persistence.SecondaryTables.class ) );
            final JAnnotationArrayMember value = stlst.paramArray( "value" );
            for ( SecondaryTable t : entity.getSecondaryTable() )
            {
                final JAnnotationUse st = value.annotate( cm.ref( javax.persistence.SecondaryTable.class ) );
                if ( t.getCatalog() != null )
                {
                    st.param( "catalog", t.getCatalog() );
                }
                if ( t.getName() != null )
                {
                    st.param( "name", t.getName() );
                }
                if ( !t.getPrimaryKeyJoinColumn().isEmpty() )
                {
                    final JAnnotationArrayMember pkjc = st.paramArray( "pkJoinColumns" );
                    this.annotate( cm, pkjc, entity.getPrimaryKeyJoinColumn() );
                }
                if ( t.getSchema() != null )
                {
                    st.param( "schema", t.getSchema() );
                }
                if ( !t.getUniqueConstraint().isEmpty() )
                {
                    final JAnnotationArrayMember uca = st.paramArray( "uniqueConstraints" );
                    for ( UniqueConstraint uc : t.getUniqueConstraint() )
                    {
                        final JAnnotationUse u = uca.annotate( javax.persistence.UniqueConstraint.class );
                        final JAnnotationArrayMember colNames = u.paramArray( "columnNames" );
                        for ( String cn : uc.getColumnName() )
                        {
                            colNames.param( cn );
                        }
                    }
                }
            }
        }
        if ( entity.getSequenceGenerator() != null )
        {
            final JAnnotationUse sg = c.implClass.annotate( cm.ref( javax.persistence.SequenceGenerator.class ) );
            this.annotate( sg, entity.getSequenceGenerator() );
        }
        if ( !entity.getSqlResultSetMapping().isEmpty() )
        {
            final JAnnotationUse lst = c.implClass.annotate( cm.ref( javax.persistence.SqlResultSetMappings.class ) );
            final JAnnotationArrayMember value = lst.paramArray( "value" );
            for ( SqlResultSetMapping m : entity.getSqlResultSetMapping() )
            {
                final JAnnotationUse srsm = value.annotate( cm.ref( javax.persistence.SqlResultSetMapping.class ) );
                if ( !m.getColumnResult().isEmpty() )
                {
                    final JAnnotationArrayMember cols = srsm.paramArray( "columns" );
                    for ( ColumnResult cr : m.getColumnResult() )
                    {
                        final JAnnotationUse cra = cols.annotate( javax.persistence.ColumnResult.class );
                        cra.param( "name", cr.getName() );
                    }
                }
                if ( !m.getEntityResult().isEmpty() )
                {
                    final JAnnotationArrayMember entities = srsm.paramArray( "entities" );
                    for ( EntityResult er : m.getEntityResult() )
                    {
                        final JAnnotationUse era = entities.annotate( javax.persistence.EntityResult.class );
                        if ( er.getDiscriminatorColumn() != null )
                        {
                            era.param( "discriminatorColumn", er.getDiscriminatorColumn() );
                        }
                        if ( er.getEntityClass() != null )
                        {
                            era.param( "entityClass", cm.ref( er.getEntityClass() ) );
                        }
                        if ( !er.getFieldResult().isEmpty() )
                        {
                            final JAnnotationArrayMember fields = era.paramArray( "fields" );
                            for ( FieldResult fr : er.getFieldResult() )
                            {
                                final JAnnotationUse fra = fields.annotate( javax.persistence.FieldResult.class );
                                if ( fr.getColumn() != null )
                                {
                                    fra.param( "column", fr.getColumn() );
                                }
                                if ( fr.getName() != null )
                                {
                                    fra.param( "name", fr.getName() );
                                }
                            }
                        }
                    }
                }
                if ( m.getName() != null )
                {
                    srsm.param( "name", m.getName() );
                }
            }
        }
        if ( entity.getTable() != null )
        {
            final JAnnotationUse ta = c.implClass.annotate( cm.ref( javax.persistence.Table.class ) );
            if ( entity.getTable().getCatalog() != null )
            {
                ta.param( "catalog", entity.getTable().getCatalog() );
            }
            if ( entity.getTable().getName() != null )
            {
                ta.param( "name", entity.getTable().getName() );
            }
            if ( entity.getTable().getSchema() != null )
            {
                ta.param( "schema", entity.getTable().getSchema() );
            }
            if ( !entity.getTable().getUniqueConstraint().isEmpty() )
            {
                final JAnnotationArrayMember uclst = ta.paramArray( "uniqueConstraints" );
                for ( UniqueConstraint uc : entity.getTable().getUniqueConstraint() )
                {
                    final JAnnotationUse uca = uclst.annotate( javax.persistence.UniqueConstraint.class );
                    final JAnnotationArrayMember colNames = uca.paramArray( "columnNames" );
                    for ( String cn : uc.getColumnName() )
                    {
                        colNames.param( cn );
                    }
                }
            }
        }
        if ( entity.getTableGenerator() != null )
        {
            final JAnnotationUse tg = c.implClass.annotate( cm.ref( javax.persistence.TableGenerator.class ) );
            this.annotate( tg, entity.getTableGenerator() );
        }
    }
View Full Code Here

Examples of com.sun.codemodel.JAnnotationUse

        }
    }

    private void annotate( final ClassOutline c, final IdClass id )
    {
        final JAnnotationUse a =
            c.implClass.annotate( c.parent().getCodeModel().ref( javax.persistence.IdClass.class ) );

        a.param( "value", c.parent().getCodeModel().ref( id.getClazz() ) );
    }
View Full Code Here

Examples of com.sun.codemodel.JAnnotationUse

        a.param( "value", c.parent().getCodeModel().ref( id.getClazz() ) );
    }

    private void annotate( final ClassOutline c, final EntityListeners l )
    {
        final JAnnotationUse lst =
            c.implClass.annotate( c.parent().getCodeModel().ref( javax.persistence.EntityListeners.class ) );

        final JAnnotationArrayMember value = lst.paramArray( "value" );
        for ( EntityListener el : l.getEntityListener() )
        {
            value.param( c.parent().getCodeModel().ref( el.getClazz() ) );
        }
    }
View Full Code Here

Examples of com.sun.codemodel.JAnnotationUse

        if ( !jt.getInverseJoinColumn().isEmpty() )
        {
            final JAnnotationArrayMember ijclst = a.paramArray( "inverseJoinColumns" );
            for ( JoinColumn jc : jt.getInverseJoinColumn() )
            {
                final JAnnotationUse ijc = ijclst.annotate( cm.ref( javax.persistence.JoinColumn.class ) );
                this.annotate( ijc, jc );
            }
        }
        if ( !jt.getJoinColumn().isEmpty() )
        {
            final JAnnotationArrayMember jclst = a.paramArray( "joinColumns" );
            for ( JoinColumn jc : jt.getJoinColumn() )
            {
                final JAnnotationUse jca = jclst.annotate( cm.ref( javax.persistence.JoinColumn.class ) );
                this.annotate( jca, jc );
            }
        }
        if ( !jt.getUniqueConstraint().isEmpty() )
        {
            final JAnnotationArrayMember uclst = a.paramArray( "uniqueConstraints" );
            for ( UniqueConstraint uc : jt.getUniqueConstraint() )
            {
                final JAnnotationUse uca = uclst.annotate( javax.persistence.UniqueConstraint.class );
                final JAnnotationArrayMember colNames = uca.paramArray( "columnNames" );
                for ( String cn : uc.getColumnName() )
                {
                    colNames.param( cn );
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.