Fixed
Status Update
Comments
tn...@google.com <tn...@google.com> #2
Fixed for 3.6 by Change-Id: I45e7c8ee73e43a086f546efe7edbd519a661500f. Thanks for the report!
lb...@gmail.com <lb...@gmail.com> #3
@2 Did you fix it for similar cases too? Each time there is @IntDef, for example?
tn...@google.com <tn...@google.com> #4
Yes, the bug was that the quickfix for that lint check had only been implemented for Java, not for Kotlin. It's now implemented for both.
tn...@google.com <tn...@google.com> #5
(I'm making my way through the various quickfixes for lint and making sure all of them are implemented, and have tests, for both java and kotlin.)
lb...@gmail.com <lb...@gmail.com> #6
OK thank you.
I think there are also Lint stuff that don't do anything.
I think there are also Lint stuff that don't do anything.
Description
Build #AI-171.4333198, built on September 13, 2017
JRE: 1.8.0_152-release-915-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Suppose you wish to convert the next Java code:
public enum AppComponentState {
ENABLED, DISABLED, DEFAULT
}
public static AppComponentState getAppComponentState(final Context context, final Class<?> appComponentClass) {
final ComponentName componentName = new ComponentName(context, appComponentClass);
final PackageManager pm = context.getPackageManager();
final int result = pm.getComponentEnabledSetting(componentName);
switch (result) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return AppComponentState.DISABLED;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return AppComponentState.ENABLED;
default:
// other values aren't supposed to be returned, according to the documentation
return AppComponentState.DEFAULT;
}
}
You get this:
enum class AppComponentState {
ENABLED, DISABLED, DEFAULT
}
@JvmStatic
fun getAppComponentState(context: Context, appComponentClass: Class<*>): AppComponentState {
val componentName = ComponentName(context, appComponentClass)
val pm = context.packageManager
val result = pm.getComponentEnabledSetting(componentName)
when (result) {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED -> return AppComponentState.DISABLED
PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> return AppComponentState.ENABLED
else ->
// other values aren't supposed to be returned, according to the documentation
return AppComponentState.DEFAULT
}
}
However, as opposed to Java, that offers you to add missing cases to the switch-case, on Kotlin it only warns you.
Attached screenshots to show issue.