Skip to content

Commit f4e85e8

Browse files
committed
chore: remove @jvm annotations, add fontFamily test, update README
- Remove @jvmoverloads, @JvmStatic, and @Suppress annotations (Java compat not needed) - Add test for addFontFamily with tools:ignore (covers dual-namespace path) - Document tools:ignore feature in README.md
1 parent 8390348 commit f4e85e8

5 files changed

Lines changed: 717 additions & 23 deletions

File tree

‎README.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,42 @@ val poet = ResourcesPoet.create()
8888

8989
We do not allow configuration of more complicated resources like `drawable` and `anim` in the creation sense.
9090

91+
## Suppressing Lint Warnings
92+
93+
You can add `tools:ignore` to suppress Android lint warnings on individual resources or at the top level:
94+
95+
```kotlin
96+
// Per-resource ignore
97+
val poet = ResourcesPoet.create()
98+
.addString("app_name", "Test", toolsIgnore = "UnusedResource")
99+
.addColor("color_primary", "#FF0000", toolsIgnore = "UnusedIds")
100+
```
101+
102+
```xml
103+
<resources xmlns:tools="http://schemas.android.com/tools">
104+
<string name="app_name" tools:ignore="UnusedResource">Test</string>
105+
<color name="color_primary" tools:ignore="UnusedIds">#FF0000</color>
106+
</resources>
107+
```
108+
109+
You can also set `tools:ignore` at the top-level `<resources>` element to suppress warnings for all resources in the file:
110+
111+
```kotlin
112+
val poet = ResourcesPoet.create()
113+
.toolsIgnore("UnusedResource,TypographyDashes")
114+
.addString("somekey", "something-else")
115+
.addString("anotherkey", "another-value")
116+
```
117+
118+
```xml
119+
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedResource,TypographyDashes">
120+
<string name="somekey">something-else</string>
121+
<string name="anotherkey">another-value</string>
122+
</resources>
123+
```
124+
125+
Top-level and per-element ignores can be combined — the top-level applies to all children, and per-element ignores override or add to it.
126+
91127
License
92128
--------
93129

‎src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import javax.xml.transform.stream.StreamResult
1515
/**
1616
* Helps generate XML resource files for Android
1717
*/
18-
@Suppress("MemberVisibilityCanBePrivate", "unused")
1918
class ResourcesPoet private constructor(
2019
private val document: Document,
2120
private val resourceElement: Element,
@@ -47,7 +46,6 @@ class ResourcesPoet private constructor(
4746
*
4847
* @return poet
4948
*/
50-
@JvmStatic
5149
fun create(indent: Boolean = INDENT_DEFAULT, elementType: ELEMENT = ELEMENT.RESOURCES): ResourcesPoet {
5250
val document = documentBuilder.newDocument()
5351
val element = document.createElement(elementType.elementName)
@@ -68,7 +66,6 @@ class ResourcesPoet private constructor(
6866
* @param file the resources file you want to add to
6967
* @return poet
7068
*/
71-
@JvmStatic
7269
fun create(file: File, indent: Boolean = INDENT_DEFAULT): ResourcesPoet {
7370
try {
7471
return create(FileInputStream(file), indent)
@@ -86,7 +83,6 @@ class ResourcesPoet private constructor(
8683
* @param inputStream the input stream of the resources file you want to add to
8784
* @return poet
8885
*/
89-
@JvmStatic
9086
fun create(
9187
inputStream: InputStream,
9288
indent: Boolean = INDENT_DEFAULT,
@@ -144,7 +140,6 @@ class ResourcesPoet private constructor(
144140
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource,TypographyDashes")
145141
* @return poet
146142
*/
147-
@JvmOverloads
148143
fun toolsIgnore(toolsIgnore: String): ResourcesPoet {
149144
ensureToolsNamespace()
150145
resourceElement.setAttribute("tools:ignore", toolsIgnore)
@@ -158,7 +153,6 @@ class ResourcesPoet private constructor(
158153
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
159154
* @return poet
160155
*/
161-
@JvmOverloads
162156
fun addAttr(attr: Attr, toolsIgnore: String? = null): ResourcesPoet {
163157
//<attr name="gravityX" format="float"/>
164158
val element = document.createElement(Type.ATTR.toString())
@@ -185,7 +179,6 @@ class ResourcesPoet private constructor(
185179
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
186180
* @return poet
187181
*/
188-
@JvmOverloads
189182
fun addBool(name: String, value: Boolean, toolsIgnore: String? = null): ResourcesPoet {
190183
addBool(name, value.toString(), toolsIgnore)
191184
return this
@@ -199,7 +192,6 @@ class ResourcesPoet private constructor(
199192
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
200193
* @return poet
201194
*/
202-
@JvmOverloads
203195
fun addBool(name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
204196
//<bool name="is_production">false</bool>
205197
val element = document.createElement(Type.BOOL.toString())
@@ -218,7 +210,6 @@ class ResourcesPoet private constructor(
218210
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
219211
* @return poet
220212
*/
221-
@JvmOverloads
222213
fun addColor(name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
223214
//<color name="color_primary">#7770CB</color>
224215
val element = document.createElement(Type.COLOR.toString())
@@ -249,7 +240,6 @@ class ResourcesPoet private constructor(
249240
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
250241
* @return poet
251242
*/
252-
@JvmOverloads
253243
fun addDrawable(name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
254244
//<drawable name="logo">@drawable/logo</drawable>
255245
val bool = document.createElement(Type.DRAWABLE.toString())
@@ -268,7 +258,6 @@ class ResourcesPoet private constructor(
268258
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
269259
* @return poet
270260
*/
271-
@JvmOverloads
272261
fun addDimension(name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
273262
//<dimen name="logo">@dimen/logo</dimen>
274263
val bool = document.createElement(Type.DIMENSION.toString())
@@ -286,7 +275,6 @@ class ResourcesPoet private constructor(
286275
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
287276
* @return poet
288277
*/
289-
@JvmOverloads
290278
fun addId(id: String, toolsIgnore: String? = null): ResourcesPoet {
291279
// <item
292280
// type="id"
@@ -307,7 +295,6 @@ class ResourcesPoet private constructor(
307295
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
308296
* @return poet
309297
*/
310-
@JvmOverloads
311298
fun addInteger(name: String, value: Int?, toolsIgnore: String? = null): ResourcesPoet {
312299
addInteger(name, value.toString(), toolsIgnore)
313300
return this
@@ -321,7 +308,6 @@ class ResourcesPoet private constructor(
321308
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
322309
* @return poet
323310
*/
324-
@JvmOverloads
325311
fun addInteger(name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
326312
//<integer name="logo">@integer/logo</integer>
327313
val bool = document.createElement(Type.INTEGER.toString())
@@ -340,7 +326,6 @@ class ResourcesPoet private constructor(
340326
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
341327
* @return poet
342328
*/
343-
@JvmOverloads
344329
fun addIntegerArray(name: String, values: List<Int>, toolsIgnore: String? = null): ResourcesPoet {
345330
val integers = ArrayList<String>()
346331
for (value in values) {
@@ -358,7 +343,6 @@ class ResourcesPoet private constructor(
358343
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
359344
* @return poet
360345
*/
361-
@JvmOverloads
362346
fun addIntegerArrayStrings(name: String, values: List<String>, toolsIgnore: String? = null): ResourcesPoet {
363347
// <integer-array name="numbers">
364348
// <item>0</item>
@@ -385,7 +369,6 @@ class ResourcesPoet private constructor(
385369
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
386370
* @return poet
387371
*/
388-
@JvmOverloads
389372
fun addPlurals(name: String, plurals: List<Plural>, toolsIgnore: String? = null): ResourcesPoet {
390373
// <plurals name="numberOfSongsAvailable">
391374
// <item quantity="one">Znaleziono %d piosenkę.</item>
@@ -416,7 +399,6 @@ class ResourcesPoet private constructor(
416399
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
417400
* @return poet
418401
*/
419-
@JvmOverloads
420402
fun addString(name: String, value: String, translatable: Boolean = true, toolsIgnore: String? = null): ResourcesPoet {
421403
//<string name="app_name" translatable="false">Cool</string>
422404
val element = document.createElement(Type.STRING.toString())
@@ -438,7 +420,6 @@ class ResourcesPoet private constructor(
438420
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
439421
* @return poet
440422
*/
441-
@JvmOverloads
442423
fun addStringArray(name: String, values: List<String>, toolsIgnore: String? = null): ResourcesPoet {
443424
//<string-array name="country_names">
444425
// <item>Country</item>
@@ -466,7 +447,6 @@ class ResourcesPoet private constructor(
466447
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
467448
* @return poet
468449
*/
469-
@JvmOverloads
470450
fun addStyle(name: String, parentRef: String? = null, styleItems: List<StyleItem>? = null, toolsIgnore: String? = null): ResourcesPoet {
471451
//<style name="AppTheme.Dark" parent="Base.AppTheme.Dark"/>
472452
val element = document.createElement(Type.STYLE.toString())
@@ -495,7 +475,6 @@ class ResourcesPoet private constructor(
495475
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
496476
* @return poet
497477
*/
498-
@JvmOverloads
499478
fun addTypedArray(name: String, values: List<String>, toolsIgnore: String? = null): ResourcesPoet {
500479
//<array name="country_names">
501480
// <item>Country</item>
@@ -520,7 +499,6 @@ class ResourcesPoet private constructor(
520499
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
521500
* @return poet
522501
*/
523-
@JvmOverloads
524502
fun addFontFamily(fontFamily: FontFamily, toolsIgnore: String? = null): ResourcesPoet {
525503
val element = document.createElement(Type.FONT.toString())
526504
element.setAttribute("android:fontStyle", fontFamily.fontStyle)
@@ -554,7 +532,6 @@ class ResourcesPoet private constructor(
554532
* @param toolsIgnore lint rule names to suppress (e.g., "UnusedResource")
555533
* @return poet
556534
*/
557-
@JvmOverloads
558535
fun add(type: Type, name: String, value: String, toolsIgnore: String? = null): ResourcesPoet {
559536
return when (type) {
560537
Type.BOOL -> addBool(name, value, toolsIgnore)

0 commit comments

Comments
 (0)