pdf: detekt clean (277 tests)
- Commit
57a017467761d17b193faca8443e47a09a0005b9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-14 23:15 UTC (21 days ago)
- Parents
7fec863
Fix all detekt findings in pdf by fixing code, not config (detekt.yml untouched, no baselines added): - UndocumentedPublicClass: KDoc for the flagged types. - InvalidRange: reversed-range case now uses IntRange(2, 1). - UnusedParameter: await() names its timeout via the AssertionError it throws on expiry (withTimeoutOrNull). Verified: ./gradlew :pdf:detekt :pdf:testDevUnitTest :pdf:lint --max-workers=32 all pass (277 unit tests).
Diff
pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt b/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.ktindex bc63a2e0b7..09a27e37f9 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt@@ -31,6 +31,7 @@ import com.vayunmathur.pdf.ui.CutGlueScreen import com.vayunmathur.pdf.ui.SafePdfViewerScreen import com.vayunmathur.pdf.util.PdfViewModel +/** Main Activity: a ma activity implementation for main activity. */ class MainActivity : MaActivity() { private val pdfViewModel: PdfViewModel by viewModels() private var intentData: Uri? = null
pdf/src/main/java/com/vayunmathur/pdf/model/CapturedImage.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/model/CapturedImage.kt b/pdf/src/main/java/com/vayunmathur/pdf/model/CapturedImage.ktindex 566bfe835c..fa1e03085d 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/model/CapturedImage.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/model/CapturedImage.kt@@ -4,12 +4,14 @@ import android.net.Uri import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect +/** Immutable value describing quadrilateral. */ data class Quadrilateral( val topLeft: Offset, val topRight: Offset, val bottomRight: Offset, val bottomLeft: Offset ) {+ /** Shared constants and helpers for Quadrilateral. */ companion object { fun default() = Quadrilateral( topLeft = Offset(0f, 0f),@@ -47,6 +49,7 @@ data class Quadrilateral( } } +/** Immutable value describing captured image. */ data class CapturedImage( val uri: Uri, val cropRect: Rect? = null,
pdf/src/main/java/com/vayunmathur/pdf/util/AutoFrameDetector.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/AutoFrameDetector.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/AutoFrameDetector.ktindex a101aa6412..1481c3e540 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/AutoFrameDetector.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/AutoFrameDetector.kt@@ -9,6 +9,7 @@ import kotlin.math.max import kotlin.math.min import kotlin.math.roundToInt +/** Singleton holding auto frame detector state and operations. */ object AutoFrameDetector { private const val MAX_DIM = 500
pdf/src/main/java/com/vayunmathur/pdf/util/ComposePdfDocument.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/ComposePdfDocument.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/ComposePdfDocument.ktindex 3ee3f64105..2e1ce28e35 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/ComposePdfDocument.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/ComposePdfDocument.kt@@ -56,6 +56,7 @@ class ComposePdfDocument private constructor(private var handle: Long) { } } + /** Shared constants and helpers for ComposePdfDocument. */ companion object { fun create(): ComposePdfDocument = ComposePdfDocument(PdfNative.createEmptyDocument()) }
pdf/src/main/java/com/vayunmathur/pdf/util/PdfStateStore.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/PdfStateStore.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/PdfStateStore.ktindex 4faac841fd..de6dec4272 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/PdfStateStore.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/PdfStateStore.kt@@ -3,6 +3,7 @@ import android.content.Context import android.net.Uri import androidx.core.content.edit +/** Singleton holding pdf state store state and operations. */ object PdfStateStore { private const val PREFS_NAME = "pdf_viewer_state"
pdf/src/main/java/com/vayunmathur/pdf/util/PdfViewModel.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/PdfViewModel.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/PdfViewModel.ktindex e9c389f8c6..bde8688c33 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/PdfViewModel.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/PdfViewModel.kt@@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch +/** Pdf View Model: a application implementation for pdf view model. */ class PdfViewModel(application: Application) : AndroidViewModel(application) { // --- Captured images / cropping ----------------------------------------@@ -49,6 +50,7 @@ class PdfViewModel(application: Application) : AndroidViewModel(application) { // --- PDF export from captured images ----------------------------------- + /** Immutable value describing pdf write result; carries targetUri, success. */ data class PdfWriteResult(val targetUri: Uri, val success: Boolean) private val _pdfWriteResults = MutableSharedFlow<PdfWriteResult>(extraBufferCapacity = 1)
pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfDocument.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfDocument.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfDocument.ktindex 43f486a0ff..972dca0800 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfDocument.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfDocument.kt@@ -73,6 +73,7 @@ class SafePdfDocument private constructor( * the whole class of missing-content bugs was invisible in the field. */ sealed interface PageLoad {+ /** Immutable value describing decoded; carries page. */ data class Decoded(val page: SafePdfPage) : PageLoad /** [reason] is a log/diagnostic string, not user-facing copy. */ data class Failed(val reason: String) : PageLoad@@ -265,6 +266,7 @@ class SafePdfDocument private constructor( suspend fun saveEncrypted(userPw: String, ownerPw: String): ByteArray? = withContext(Dispatchers.IO) { PdfNative.saveEncrypted(documentHandle, userPw, ownerPw) } + /** Shared constants and helpers for SafePdfDocument. */ companion object { private const val TAG = "SafePdfDocument" private const val MAX_CACHED_PAGES = 12
pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfModels.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfModels.kt b/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfModels.ktindex b44e287771..46affa2880 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfModels.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/util/SafePdfModels.kt@@ -51,12 +51,14 @@ enum class BlendMode(val code: Int) { Color(BLEND_COLOR), Luminosity(BLEND_LUMINOSITY); + /** Shared constants and helpers for BlendMode. */ companion object { private val CODE_MAP: Map<Int, BlendMode> = entries.associateBy { it.code } fun fromCode(c: Int): BlendMode = CODE_MAP[c] ?: Normal } } +/** Contract for pdf primitive. */ sealed interface PdfPrimitive { /** * A run of text with its baseline origin, on-page size and color. Optional@@ -228,13 +230,17 @@ sealed interface PdfPrimitive { /** A bezier-retentive clip path operation (wire v4), in page space. */ sealed interface PathOp {+ /** Immutable value describing move; carries x, y. */ data class Move(val x: Float, val y: Float) : PathOp+ /** Immutable value describing line; carries x, y. */ data class Line(val x: Float, val y: Float) : PathOp+ /** Immutable value describing cubic. */ data class Cubic( val x1: Float, val y1: Float, val x2: Float, val y2: Float, val x3: Float, val y3: Float, ) : PathOp+ /** Singleton holding close state and operations. */ data object Close : PathOp }
pdf/src/test/java/com/vayunmathur/pdf/ui/StateDocBatchTest.kt
diff --git a/pdf/src/test/java/com/vayunmathur/pdf/ui/StateDocBatchTest.kt b/pdf/src/test/java/com/vayunmathur/pdf/ui/StateDocBatchTest.ktindex 52b130f498..ed6680637c 100644--- a/pdf/src/test/java/com/vayunmathur/pdf/ui/StateDocBatchTest.kt+++ b/pdf/src/test/java/com/vayunmathur/pdf/ui/StateDocBatchTest.kt@@ -27,7 +27,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking-import kotlinx.coroutines.withTimeout+import kotlinx.coroutines.withTimeoutOrNull import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner@@ -62,8 +62,10 @@ class StateDocBatchTest { SafePdfDocument.open(ctx, Uri.fromFile(f))!! } - private suspend fun await(desc: String, cond: suspend () -> Boolean) =- withTimeout(8000) { while (!cond()) delay(25) }+ private suspend fun await(desc: String, cond: suspend () -> Boolean) {+ val ok = withTimeoutOrNull(8000) { while (!cond()) delay(25); true } ?: false+ if (!ok) throw AssertionError("Timed out waiting for: $desc")+ } @Test fun selectionTextCases() { val g = listOf(selGlyph("h", 0f, 0f, 10f, 10f), selGlyph("i", 10f, 0f, 20f, 10f), selGlyph("!", 20f, 0f, 30f, 10f))@@ -71,7 +73,7 @@ class StateDocBatchTest { assertEquals("i", selectionText(g, 1..1)) assertEquals("", selectionText(g, 5..9)) assertEquals("", selectionText(emptyList(), 0..0))- assertEquals("", selectionText(g, 2..1))+ assertEquals("", selectionText(g, IntRange(2, 1))) } @Test fun allKindIconsCompose() {