Merge "Treat more generated Kotlin paramaters as unnamed" am: 1b1da72783
Original change: https://android-review.googlesource.com/c/platform/tools/metalava/+/2042743
Change-Id: Ib909df842613dcc56529da1b93e846402c80460e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 00a3df3..b3becf1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -19,6 +19,7 @@
<item index="10" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
<item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
<item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
+ <item index="13" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
@@ -38,11 +39,12 @@
<item index="10" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
<item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
<item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
+ <item index="13" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11 (3)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>
\ No newline at end of file
diff --git a/src/main/java/com/android/tools/metalava/model/psi/PsiParameterItem.kt b/src/main/java/com/android/tools/metalava/model/psi/PsiParameterItem.kt
index 03edfab..17ddda2 100644
--- a/src/main/java/com/android/tools/metalava/model/psi/PsiParameterItem.kt
+++ b/src/main/java/com/android/tools/metalava/model/psi/PsiParameterItem.kt
@@ -52,16 +52,25 @@
override fun publicName(): String? {
if (isKotlin(psiParameter)) {
- // Don't print out names for extension function receiver parameters
+ // Omit names of some special parameters in Kotlin. None of these parameters may be
+ // set through Kotlin keyword arguments, so there's no need to track their names for
+ // compatibility. This also helps avoid signature file churn if PSI or the compiler
+ // change what name they're using for these parameters.
+
+ // Receiver parameter of extension function
if (isReceiver()) {
return null
}
- // Hardcode parameter name for the generated suspend function continuation parameter
+ // Property setter parameter
+ if (containingMethod.isKotlinProperty()) {
+ return null
+ }
+ // Continuation parameter of suspend function
if (containingMethod.modifiers.isSuspend() &&
"kotlin.coroutines.Continuation" == type.asClass()?.qualifiedName() &&
containingMethod.parameters().size - 1 == parameterIndex
) {
- return "p"
+ return null
}
return name
} else {
diff --git a/src/test/java/com/android/tools/metalava/ApiFileTest.kt b/src/test/java/com/android/tools/metalava/ApiFileTest.kt
index 7129904..131071a 100644
--- a/src/test/java/com/android/tools/metalava/ApiFileTest.kt
+++ b/src/test/java/com/android/tools/metalava/ApiFileTest.kt
@@ -337,7 +337,7 @@
method @NonNull public String getProperty1();
method @Nullable public String getProperty2();
method public void otherMethod(boolean ok, int times);
- method public void setProperty2(@Nullable String value);
+ method public void setProperty2(@Nullable String);
property @NonNull public final String property1;
property @Nullable public final String property2;
field @NonNull public static final test.pkg.Kotlin.Companion Companion;
@@ -454,8 +454,8 @@
api = """
package test.pkg {
public final class TestKt {
- method @Nullable public static suspend inline Object hello(int foo, @NonNull kotlin.coroutines.Continuation<? super kotlin.Unit> p);
- method @Nullable public static suspend Object helloTwoContinuations(@NonNull kotlin.coroutines.Continuation<java.lang.Object> myContinuation, @NonNull kotlin.coroutines.Continuation<? super kotlin.Unit> p);
+ method @Nullable public static suspend inline Object hello(int foo, @NonNull kotlin.coroutines.Continuation<? super kotlin.Unit>);
+ method @Nullable public static suspend Object helloTwoContinuations(@NonNull kotlin.coroutines.Continuation<java.lang.Object> myContinuation, @NonNull kotlin.coroutines.Continuation<? super kotlin.Unit>);
}
}
"""
@@ -1081,7 +1081,7 @@
public final class SimpleClass {
ctor public SimpleClass();
method public int getNonJvmField();
- method public void setNonJvmField(int value);
+ method public void setNonJvmField(int);
property public final int nonJvmField;
field public int jvmField;
}
@@ -1115,8 +1115,8 @@
ctor public SimpleClass();
method public int getAnotherProperty();
method public int myPropertyJvmGetter();
- method public void setAnotherProperty(int value);
- method public void setMyProperty(int value);
+ method public void setAnotherProperty(int);
+ method public void setMyProperty(int);
property public final int anotherProperty;
property public final int myProperty;
}
@@ -4651,4 +4651,28 @@
"""
)
}
+
+ @Test
+ fun `property setter parameters are unnamed`() {
+ check(
+ sourceFiles = arrayOf(
+ kotlin(
+ """
+ package test.pkg
+ class Foo(var bar: Int)
+ """
+ )
+ ),
+ api = """
+ package test.pkg {
+ public final class Foo {
+ ctor public Foo(int bar);
+ method public int getBar();
+ method public void setBar(int);
+ property public final int bar;
+ }
+ }
+ """
+ )
+ }
}