Skip to content

Commit

Permalink
139: added missing overrides to extra list
Browse files Browse the repository at this point in the history
  • Loading branch information
HPSudip authored Jul 19, 2024
2 parents 5adc7d3 + 46a8369 commit 2595c60
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
22 changes: 13 additions & 9 deletions jipp-core/bin/collection.kt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import com.hp.jipp.encoding.* // ktlint-disable no-wildcard-imports
import com.hp.jipp.encoding.AttributeGroup.Companion.groupOf
{%- endif %}
{%- endif %}

{%- if obverse %}
{% set reversed=False %}
{%- else %}
{% set reversed=True %}
{%- endif %}
/**
* Data object corresponding to a "{{ collection.name }}" collection{%- if collection.specs %} as defined in:{%- for spec in collection.specs | sort %}
* [{{ spec | upper }}]({{ specs[spec] }}){{ "," if not loop.last }}{%- endfor %}{%- else %}{%- endif %}.{%- if collection['refs']%}
Expand All @@ -24,7 +28,7 @@ import com.hp.jipp.encoding.AttributeGroup.Companion.groupOf
@Suppress("RedundantCompanionReference", "unused")
data class {{ collection.name | camel_class }}
constructor(
{%- for name, member in collection.members | dictsort %}
{%- for name, member in collection.members | dictsort(reverse=reversed) %}
{%- if member.kdoc %}
/** {{ member.kdoc }} */
{%- endif %}
Expand All @@ -41,17 +45,17 @@ constructor(

/** Produce an attribute list from members. */
override val attributes: List<Attribute<*>>
get() ={%- if collection.extras %} extras +{%- endif %} listOfNotNull(
{%- for name, member in collection.members | dictsort %}
get() = listOfNotNull(
{%- for name, member in collection.members | dictsort(reverse=reversed) %}
{{ name | camel_member }}?.let { {{ collection.name | camel_class }}.{{ name | camel_member }}.of(it{%- if member.set and member.kbase %}.map { v -> {{ member.kbase }}(v) }{%- endif %}) },
{%- endfor %}
)
) {%- if collection.extras %} + extras {%- endif %}

/** Defines types for each member of [{{ collection.name | camel_class }}]. */
companion object : AttributeCollection.Converter<{{ collection.name | camel_class }}> {
override fun convert(attributes: List<Attribute<*>>): {{ collection.name | camel_class }} =
{{ collection.name | camel_class }}(
{%- for name, member in collection.members | dictsort %}
{%- for name, member in collection.members | dictsort(reverse=reversed) %}
{%- if member.set %}
extractAll(attributes, {{ name | camel_member }})
{%- if member.ktype_accessor %}?.map { it.{{ member.ktype_accessor }} }{%- endif %},
Expand All @@ -64,14 +68,14 @@ constructor(
groupOf(
Tag.{{ collection.extras }},
attributes{%- if collection.members %}.filterNot {
{%- for name, member in collection.members | dictsort %} it.name == {{ name | camel_member }}.name{{ " ||" if not loop.last }}{%- endfor %} }{%- endif %}
{%- for name, member in collection.members | dictsort(reverse=reversed) %} it.name == {{ name | camel_member }}.name{{ " ||" if not loop.last }}{%- endfor %} }{%- endif %}
),
{%- endif %}
)
override val cls = {{ collection.name | camel_class }}::class.java
@Deprecated("Remove this symbol")
@JvmField val Types = this
{%- for name, member in collection.members | dictsort %}
{%- for name, member in collection.members | dictsort(reverse=reversed) %}
{%- if member.syntax == 'enum' %}
/**
* "{{ member.name }}" member type. {%- if member.kdoc %}
Expand All @@ -82,7 +86,7 @@ constructor(
{%- endfor %}
}

{%- for name, member in collection.members | dictsort %}{%- if member.kimpl %}
{%- for name, member in collection.members | dictsort(reverse=reversed) %}{%- if member.kimpl %}

{{ member.kimpl }}{%- endif %}{%- endfor %}
override fun toString() = "{{ collection.name | camel_class }}(${attributes.joinToString()})"
Expand Down
11 changes: 9 additions & 2 deletions jipp-core/bin/genTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'job-resolvers-supported': 'jobAttributes',
'job-constraints-supported': 'jobAttributes',
'printer-icc-profiles': 'jobAttributes',
'overrides': 'jobAttributes',
}

special_ref_logic = ('media-col-database', 'media-col-ready')
Expand Down Expand Up @@ -1023,13 +1024,19 @@ def emit_collection(env, type):
if member['members']:
member['kimpl'] = ' ' + collection_template.render(
name=member['name'], collection=member, app=os.path.basename(sys.argv[0]), updated=updated,
specs=specs, noheader=True).replace('\n', '\n ').strip()
specs=specs, noheader=True, obverse=True).replace('\n', '\n ').strip()

original_type['emitted'] = True

# Maintain sequence of overrides attributes
flag = True
if name == "overrides":
flag = False

with open(prep_file(name), 'w') as file:
file.write(rstrip_all(collection_template.render(
name=name, collection=type, app=os.path.basename(sys.argv[0]),
updated=updated, specs=specs)))
updated=updated, specs=specs, obverse=flag)))

def rstrip_all(text):
return re.sub(' +\n', '\n', text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ constructor(

/** Produce an attribute list from members. */
override val attributes: List<Attribute<*>>
get() = extras + listOfNotNull(
get() = listOfNotNull(
resolverName?.let { JobConstraintsSupported.resolverName.of(it) },
)
) + extras

/** Defines types for each member of [JobConstraintsSupported]. */
companion object : AttributeCollection.Converter<JobConstraintsSupported> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ constructor(

/** Produce an attribute list from members. */
override val attributes: List<Attribute<*>>
get() = extras + listOfNotNull(
get() = listOfNotNull(
resolverName?.let { JobResolversSupported.resolverName.of(it) },
)
) + extras

/** Defines types for each member of [JobResolversSupported]. */
companion object : AttributeCollection.Converter<JobResolversSupported> {
Expand Down
25 changes: 16 additions & 9 deletions jipp-core/src/main/java/com/hp/jipp/model/Overrides.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.hp.jipp.model

import com.hp.jipp.encoding.* // ktlint-disable no-wildcard-imports
import com.hp.jipp.encoding.AttributeGroup.Companion.groupOf

/**
* Data object corresponding to a "overrides" collection as defined in:
Expand All @@ -16,9 +17,11 @@ import com.hp.jipp.encoding.* // ktlint-disable no-wildcard-imports
@Suppress("RedundantCompanionReference", "unused")
data class Overrides
constructor(
var documentCopies: List<IntRange>? = null,
var documentNumbers: List<IntRange>? = null,
var pages: List<IntRange>? = null,
var documentNumbers: List<IntRange>? = null,
var documentCopies: List<IntRange>? = null,
/** Additional attributes (see specification for valid values). */
var extras: AttributeGroup = groupOf(Tag.jobAttributes),
) : AttributeCollection {

/** Construct an empty [Overrides]. */
Expand All @@ -27,25 +30,29 @@ constructor(
/** Produce an attribute list from members. */
override val attributes: List<Attribute<*>>
get() = listOfNotNull(
documentCopies?.let { Overrides.documentCopies.of(it) },
documentNumbers?.let { Overrides.documentNumbers.of(it) },
pages?.let { Overrides.pages.of(it) },
)
documentNumbers?.let { Overrides.documentNumbers.of(it) },
documentCopies?.let { Overrides.documentCopies.of(it) },
) + extras

/** Defines types for each member of [Overrides]. */
companion object : AttributeCollection.Converter<Overrides> {
override fun convert(attributes: List<Attribute<*>>): Overrides =
Overrides(
extractAll(attributes, documentCopies),
extractAll(attributes, documentNumbers),
extractAll(attributes, pages),
extractAll(attributes, documentNumbers),
extractAll(attributes, documentCopies),
groupOf(
Tag.jobAttributes,
attributes.filterNot { it.name == pages.name || it.name == documentNumbers.name || it.name == documentCopies.name }
),
)
override val cls = Overrides::class.java
@Deprecated("Remove this symbol")
@JvmField val Types = this
@JvmField val documentCopies = IntRangeType.Set("document-copies")
@JvmField val documentNumbers = IntRangeType.Set("document-numbers")
@JvmField val pages = IntRangeType.Set("pages")
@JvmField val documentNumbers = IntRangeType.Set("document-numbers")
@JvmField val documentCopies = IntRangeType.Set("document-copies")
}
override fun toString() = "Overrides(${attributes.joinToString()})"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ constructor(

/** Produce an attribute list from members. */
override val attributes: List<Attribute<*>>
get() = extras + listOfNotNull(
get() = listOfNotNull(
profileName?.let { PrinterIccProfiles.profileName.of(it) },
profileUrl?.let { PrinterIccProfiles.profileUrl.of(it) },
)
) + extras

/** Defines types for each member of [PrinterIccProfiles]. */
companion object : AttributeCollection.Converter<PrinterIccProfiles> {
Expand Down

0 comments on commit 2595c60

Please sign in to comment.