Skip to content

Commit e50a0bb

Browse files
Enable explicit API mode.
1 parent 2b05179 commit e50a0bb

File tree

65 files changed

+434
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+434
-415
lines changed

build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ subprojects {
106106

107107
apply(from = rootProject.file(".buildscript/binary-validation.gradle"))
108108

109+
// Require explicit public modifiers and types for actual library modules, not samples.
110+
allprojects.filterNot { it.path.startsWith(":samples") }
111+
.forEach {
112+
it.tasks.withType<KotlinCompile>().configureEach {
113+
// Tests and benchmarks aren't part of the public API, don't turn explicit API mode on for
114+
// them.
115+
if (!name.contains("test", ignoreCase = true) &&
116+
!name.contains("jmh", ignoreCase = true)
117+
) {
118+
kotlinOptions {
119+
// TODO this should be moved to `kotlin { explicitApi() }` once that's working for android
120+
// projects, see https://youtrack.jetbrains.com/issue/KT-37652.
121+
@Suppress("SuspiciousCollectionReassignment")
122+
freeCompilerArgs += "-Xexplicit-api=strict"
123+
}
124+
}
125+
}
126+
}
127+
109128
// This is intentionally *not* applied to subprojects. When building subprojects' kdoc for maven
110129
// javadocs artifacts, we want to use the default config. This config is for the
111130
// statically-generated documentation site.

internal-testing-utils/src/main/java/com/squareup/workflow1/internal/util/UncaughtExceptionGuard.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import java.util.concurrent.atomic.AtomicReference
1616
* thrown after the block returns. If the block itself throws, that exception will be rethrown
1717
* directly with uncaught exceptions added to its [suppressed list][Throwable.addSuppressed].
1818
*/
19-
class UncaughtExceptionGuard {
19+
public class UncaughtExceptionGuard {
2020
private val uncaughtException = AtomicReference<Throwable>()
2121

22-
fun reportUncaught(e: Throwable) {
22+
public fun reportUncaught(e: Throwable) {
2323
if (!uncaughtException.compareAndSet(null, e)) {
2424
// If another thread beat us to it, add this exception to the suppressed list.
2525
// addSuppressed is thread-safe so we don't need to do any explicit synchronization.
2626
uncaughtException.get()!!.addSuppressedSafely(e)
2727
}
2828
}
2929

30-
fun <T> runRethrowingUncaught(block: () -> T): T {
30+
public fun <T> runRethrowingUncaught(block: () -> T): T {
3131
val result = try {
3232
block()
3333
} catch (e: Throwable) {
@@ -60,7 +60,7 @@ class UncaughtExceptionGuard {
6060
*
6161
* This allows the normal JUnit exception assertion mechanisms to work with uncaught exceptions.
6262
*/
63-
fun rethrowingUncaughtExceptions(block: () -> Unit) {
63+
public fun rethrowingUncaughtExceptions(block: () -> Unit) {
6464
val oldHandler = Thread.getDefaultUncaughtExceptionHandler()
6565
val guard = UncaughtExceptionGuard()
6666

trace-encoder/src/main/java/com/squareup/tracing/TraceEncoder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.time.TimeSource
3030
* background thread.
3131
*/
3232
@OptIn(ExperimentalTime::class)
33-
class TraceEncoder(
33+
public class TraceEncoder(
3434
scope: CoroutineScope,
3535
private val start: TimeMark = TimeSource.Monotonic.markNow(),
3636
ioDispatcher: CoroutineDispatcher = IO,
@@ -65,7 +65,7 @@ class TraceEncoder(
6565
* Note this does not do anything with _actual_ threads, it just affects the thread ID used in
6666
* trace events.
6767
*/
68-
fun createLogger(
68+
public fun createLogger(
6969
processName: String = "",
7070
threadName: String = ""
7171
): TraceLogger {

trace-encoder/src/main/java/com/squareup/tracing/TraceEvent.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,66 +28,66 @@ import com.squareup.tracing.TraceEvent.ObjectSnapshot
2828
/**
2929
* Represents a single event in a trace.
3030
*/
31-
sealed class TraceEvent {
31+
public sealed class TraceEvent {
3232

33-
open val category: String? get() = null
33+
public open val category: String? get() = null
3434

35-
data class DurationBegin(
35+
public data class DurationBegin(
3636
val name: String,
3737
val args: Map<String, Any?> = emptyMap(),
3838
override val category: String? = null
3939
) : TraceEvent()
4040

41-
data class DurationEnd(
41+
public data class DurationEnd(
4242
val name: String,
4343
val args: Map<String, Any?> = emptyMap(),
4444
override val category: String? = null
4545
) : TraceEvent()
4646

47-
data class Instant(
47+
public data class Instant(
4848
val name: String,
4949
val args: Map<String, Any?> = emptyMap(),
5050
val scope: InstantScope = THREAD,
5151
override val category: String? = null
5252
) : TraceEvent() {
53-
enum class InstantScope {
53+
public enum class InstantScope {
5454
THREAD,
5555
PROCESS,
5656
GLOBAL
5757
}
5858
}
5959

60-
data class AsyncDurationBegin(
60+
public data class AsyncDurationBegin(
6161
val id: Any,
6262
val name: String,
6363
val args: Map<String, Any?> = emptyMap(),
6464
override val category: String? = null
6565
) : TraceEvent()
6666

67-
data class AsyncDurationEnd(
67+
public data class AsyncDurationEnd(
6868
val id: Any,
6969
val name: String,
7070
val args: Map<String, Any?> = emptyMap(),
7171
override val category: String? = null
7272
) : TraceEvent()
7373

74-
data class ObjectCreated(
74+
public data class ObjectCreated(
7575
val id: Long,
7676
val objectType: String
7777
) : TraceEvent()
7878

79-
data class ObjectDestroyed(
79+
public data class ObjectDestroyed(
8080
val id: Long,
8181
val objectType: String
8282
) : TraceEvent()
8383

84-
data class ObjectSnapshot(
84+
public data class ObjectSnapshot(
8585
val id: Long,
8686
val objectType: String,
8787
val snapshot: Any
8888
) : TraceEvent()
8989

90-
data class Counter(
90+
public data class Counter(
9191
val name: String,
9292
val series: Map<String, Number>,
9393
val id: Long? = null

trace-encoder/src/main/java/com/squareup/tracing/TraceLogger.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ package com.squareup.tracing
55
*
66
* Create with [TraceEncoder.createLogger].
77
*/
8-
interface TraceLogger {
8+
public interface TraceLogger {
99

1010
/**
1111
* Tags all events with the current timestamp and then enqueues them to be written to the trace
1212
* file.
1313
*/
14-
fun log(eventBatch: List<TraceEvent>)
14+
public fun log(eventBatch: List<TraceEvent>)
1515

1616
/**
1717
* Tags event with the current timestamp and then enqueues it to be written to the trace
1818
* file.
1919
*/
20-
fun log(event: TraceEvent)
20+
public fun log(event: TraceEvent)
2121
}

workflow-core/src/main/java/com/squareup/workflow1/BaseRenderContext.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ import kotlin.reflect.typeOf
4040
*
4141
* See [renderChild].
4242
*/
43-
interface BaseRenderContext<out PropsT, StateT, in OutputT> {
43+
public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
4444

4545
/**
4646
* Accepts a single [WorkflowAction], invokes that action by calling [WorkflowAction.apply]
4747
* to update the current state, and optionally emits the returned output value if it is non-null.
4848
*/
49-
val actionSink: Sink<WorkflowAction<PropsT, StateT, OutputT>>
49+
public val actionSink: Sink<WorkflowAction<PropsT, StateT, OutputT>>
5050

5151
/**
5252
* Ensures [child] is running as a child of this workflow, and returns the result of its
@@ -69,7 +69,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
6969
* @param key An optional string key that is used to distinguish between workflows of the same
7070
* type.
7171
*/
72-
fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(
72+
public fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(
7373
child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>,
7474
props: ChildPropsT,
7575
key: String = "",
@@ -96,7 +96,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
9696
* @param sideEffect The suspend function that will be launched in a coroutine to perform the
9797
* side effect.
9898
*/
99-
fun runningSideEffect(
99+
public fun runningSideEffect(
100100
key: String,
101101
sideEffect: suspend () -> Unit
102102
)
@@ -113,7 +113,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
113113
* as a debugging aid
114114
* @param update Function that defines the workflow update.
115115
*/
116-
fun eventHandler(
116+
public fun eventHandler(
117117
name: () -> String = { "eventHandler" },
118118
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.() -> Unit
119119
): () -> Unit {
@@ -122,7 +122,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
122122
}
123123
}
124124

125-
fun <EventT> eventHandler(
125+
public fun <EventT> eventHandler(
126126
name: () -> String = { "eventHandler" },
127127
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(EventT) -> Unit
128128
): (EventT) -> Unit {
@@ -131,7 +131,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
131131
}
132132
}
133133

134-
fun <E1, E2> eventHandler(
134+
public fun <E1, E2> eventHandler(
135135
name: () -> String = { "eventHandler" },
136136
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2) -> Unit
137137
): (E1, E2) -> Unit {
@@ -140,7 +140,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
140140
}
141141
}
142142

143-
fun <E1, E2, E3> eventHandler(
143+
public fun <E1, E2, E3> eventHandler(
144144
name: () -> String = { "eventHandler" },
145145
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3) -> Unit
146146
): (E1, E2, E3) -> Unit {
@@ -149,7 +149,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
149149
}
150150
}
151151

152-
fun <E1, E2, E3, E4> eventHandler(
152+
public fun <E1, E2, E3, E4> eventHandler(
153153
name: () -> String = { "eventHandler" },
154154
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3, E4) -> Unit
155155
): (E1, E2, E3, E4) -> Unit {
@@ -158,7 +158,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
158158
}
159159
}
160160

161-
fun <E1, E2, E3, E4, E5> eventHandler(
161+
public fun <E1, E2, E3, E4, E5> eventHandler(
162162
name: () -> String = { "eventHandler" },
163163
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3, E4, E5) -> Unit
164164
): (E1, E2, E3, E4, E5) -> Unit {
@@ -167,7 +167,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
167167
}
168168
}
169169

170-
fun <E1, E2, E3, E4, E5, E6> eventHandler(
170+
public fun <E1, E2, E3, E4, E5, E6> eventHandler(
171171
name: () -> String = { "eventHandler" },
172172
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3, E4, E5, E6) -> Unit
173173
): (E1, E2, E3, E4, E5, E6) -> Unit {
@@ -176,7 +176,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
176176
}
177177
}
178178

179-
fun <E1, E2, E3, E4, E5, E6, E7> eventHandler(
179+
public fun <E1, E2, E3, E4, E5, E6, E7> eventHandler(
180180
name: () -> String = { "eventHandler" },
181181
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3, E4, E5, E6, E7) -> Unit
182182
): (E1, E2, E3, E4, E5, E6, E7) -> Unit {
@@ -185,7 +185,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
185185
}
186186
}
187187

188-
fun <E1, E2, E3, E4, E5, E6, E7, E8> eventHandler(
188+
public fun <E1, E2, E3, E4, E5, E6, E7, E8> eventHandler(
189189
name: () -> String = { "eventHandler" },
190190
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(E1, E2, E3, E4, E5, E6, E7, E8) -> Unit
191191
): (E1, E2, E3, E4, E5, E6, E7, E8) -> Unit {
@@ -194,7 +194,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
194194
}
195195
}
196196

197-
fun <E1, E2, E3, E4, E5, E6, E7, E8, E9> eventHandler(
197+
public fun <E1, E2, E3, E4, E5, E6, E7, E8, E9> eventHandler(
198198
name: () -> String = { "eventHandler" },
199199
update: WorkflowAction<PropsT, StateT, OutputT>
200200
.Updater.(E1, E2, E3, E4, E5, E6, E7, E8, E9) -> Unit
@@ -204,7 +204,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
204204
}
205205
}
206206

207-
fun <E1, E2, E3, E4, E5, E6, E7, E8, E9, E10> eventHandler(
207+
public fun <E1, E2, E3, E4, E5, E6, E7, E8, E9, E10> eventHandler(
208208
name: () -> String = { "eventHandler" },
209209
update: WorkflowAction<PropsT, StateT, OutputT>
210210
.Updater.(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10) -> Unit
@@ -217,7 +217,7 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
217217

218218
@Deprecated("Use eventHandler.")
219219
@Suppress("DEPRECATION")
220-
fun <EventT : Any, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.onEvent(
220+
public fun <EventT : Any, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.onEvent(
221221
handler: (EventT) -> WorkflowAction<PropsT, StateT, OutputT>
222222
): (EventT) -> Unit = EventHandler { event ->
223223
// Run the handler synchronously, so we only have to emit the resulting action and don't
@@ -230,7 +230,7 @@ fun <EventT : Any, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, Ou
230230
* Convenience alias of [RenderContext.renderChild] for workflows that don't take props.
231231
*/
232232
/* ktlint-disable parameter-list-wrapping */
233-
fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT>
233+
public fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT>
234234
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
235235
child: Workflow<Unit, ChildOutputT, ChildRenderingT>,
236236
key: String = "",
@@ -242,7 +242,7 @@ fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT>
242242
* Convenience alias of [RenderContext.renderChild] for workflows that don't emit output.
243243
*/
244244
/* ktlint-disable parameter-list-wrapping */
245-
fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT>
245+
public fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT>
246246
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
247247
child: Workflow<ChildPropsT, Nothing, ChildRenderingT>,
248248
props: ChildPropsT,
@@ -255,7 +255,7 @@ fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT>
255255
* output.
256256
*/
257257
/* ktlint-disable parameter-list-wrapping */
258-
fun <PropsT, StateT, OutputT, ChildRenderingT>
258+
public fun <PropsT, StateT, OutputT, ChildRenderingT>
259259
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
260260
child: Workflow<Unit, Nothing, ChildRenderingT>,
261261
key: String = ""
@@ -271,7 +271,7 @@ fun <PropsT, StateT, OutputT, ChildRenderingT>
271271
* @param key An optional string key that is used to distinguish between identical [Worker]s.
272272
*/
273273
/* ktlint-disable parameter-list-wrapping */
274-
inline fun <reified W : Worker<Nothing>, PropsT, StateT, OutputT>
274+
public inline fun <reified W : Worker<Nothing>, PropsT, StateT, OutputT>
275275
BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(
276276
worker: W,
277277
key: String = ""
@@ -300,7 +300,7 @@ inline fun <reified W : Worker<Nothing>, PropsT, StateT, OutputT>
300300
*/
301301
@OptIn(ExperimentalStdlibApi::class)
302302
/* ktlint-disable parameter-list-wrapping */
303-
inline fun <T, reified W : Worker<T>, PropsT, StateT, OutputT>
303+
public inline fun <T, reified W : Worker<T>, PropsT, StateT, OutputT>
304304
BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(
305305
worker: W,
306306
key: String = "",
@@ -338,7 +338,7 @@ internal fun <T, PropsT, StateT, OutputT>
338338
* event types to be mapped to anonymous [WorkflowAction]s.
339339
*/
340340
@Deprecated("Use BaseRenderContext.eventHandler")
341-
fun <EventT, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.makeEventSink(
341+
public fun <EventT, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.makeEventSink(
342342
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.(EventT) -> Unit
343343
): Sink<EventT> = actionSink.contraMap { event ->
344344
action({ "eventSink($event)" }) { update(event) }
@@ -355,8 +355,8 @@ fun <EventT, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>
355355
"Use runningWorker",
356356
ReplaceWith("runningWorker(worker, key, handler)", "com.squareup.workflow1.runningWorker")
357357
)
358-
inline fun <PropsT, StateT, OutputT, reified T> BaseRenderContext<PropsT, StateT, OutputT>.onWorkerOutput(
358+
public inline fun <PropsT, StateT, OutputT, reified T> BaseRenderContext<PropsT, StateT, OutputT>.onWorkerOutput(
359359
worker: Worker<T>,
360360
key: String = "",
361361
noinline handler: (T) -> WorkflowAction<PropsT, StateT, OutputT>
362-
) = runningWorker(worker, key, handler)
362+
): Unit = runningWorker(worker, key, handler)

workflow-core/src/main/java/com/squareup/workflow1/EventHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ package com.squareup.workflow1
1515
* entire rendering types at once and not field-by-field.
1616
*/
1717
@Deprecated("Use RenderContext.actionSink")
18-
class EventHandler<in EventT>(private val handler: (EventT) -> Unit) : (EventT) -> Unit {
18+
public class EventHandler<in EventT>(private val handler: (EventT) -> Unit) : (EventT) -> Unit {
1919

20-
override fun invoke(event: EventT) = handler(event)
20+
override fun invoke(event: EventT): Unit = handler(event)
2121

2222
/**
2323
* Returns `true` iff `other` is an [EventHandler] – all [EventHandler]s are considered equal.
@@ -40,4 +40,4 @@ class EventHandler<in EventT>(private val handler: (EventT) -> Unit) : (EventT)
4040
* [EventHandler]s of type `Unit` are effectively no-arg functions, so this override lets you
4141
* invoke them without passing the `Unit` argument.
4242
*/
43-
operator fun EventHandler<Unit>.invoke() = invoke(Unit)
43+
public operator fun EventHandler<Unit>.invoke(): Unit = invoke(Unit)

0 commit comments

Comments
 (0)