From 25c16e2e6852e9261524e14851d6fd247f5f62d1 Mon Sep 17 00:00:00 2001 From: Omico Date: Tue, 16 May 2023 11:35:13 -0700 Subject: [PATCH] Omit protected modifier on override function --- .../src/main/java/com/squareup/kotlinpoet/CodeWriter.kt | 5 +++-- .../src/test/java/com/squareup/kotlinpoet/FunSpecTest.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/CodeWriter.kt b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/CodeWriter.kt index 2d9e523934..708064e149 100644 --- a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/CodeWriter.kt +++ b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/CodeWriter.kt @@ -161,12 +161,13 @@ internal class CodeWriter constructor( emit(KModifier.PUBLIC.keyword) emit(" ") } - val uniqueNonPublicExplicitOnlyModifiers = + val uniqueNonPublicOrProtectedExplicitOnlyModifiers = modifiers .filterNot { it == KModifier.PUBLIC } + .filterNot { it == KModifier.PROTECTED && modifiers.contains(KModifier.OVERRIDE) } .filterNot { implicitModifiers.contains(it) } .toEnumSet() - for (modifier in uniqueNonPublicExplicitOnlyModifiers) { + for (modifier in uniqueNonPublicOrProtectedExplicitOnlyModifiers) { emit(modifier.keyword) emit(" ") } diff --git a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FunSpecTest.kt b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FunSpecTest.kt index 1376cafc9b..8511f0231f 100644 --- a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FunSpecTest.kt +++ b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/FunSpecTest.kt @@ -96,7 +96,7 @@ class FunSpecTest { assertThat(funSpec.toString()).isEqualTo( """ |@kotlin.jvm.Throws(java.io.IOException::class, java.lang.SecurityException::class) - |protected override fun everything(arg0: java.lang.String, arg1: java.util.List): java.lang.Runnable where T : java.lang.Runnable, T : java.io.Closeable { + |override fun everything(arg0: java.lang.String, arg1: java.util.List): java.lang.Runnable where T : java.lang.Runnable, T : java.io.Closeable { |} | """.trimMargin(),