Method can be hidden if it is annotated with kotlin.internal.PlatformDependent,

or is a Java method from a Kotlin built-in class (transitively).

https://github.com/Kotlin/KEEP/blob/master/proposals/jdk-dependent-built-ins.md#backward-compatibility-of-overrides
This commit is contained in:
Dmitry Petrov
2016-12-21 10:49:57 +03:00
parent d9271b54fb
commit 8d16bd1215
22 changed files with 661 additions and 12 deletions
@@ -48,9 +48,14 @@ import static org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityI
public class OverrideResolver {
private final BindingTrace trace;
private final OverridesBackwardCompatibilityHelper overridesBackwardCompatibilityHelper;
public OverrideResolver(@NotNull BindingTrace trace) {
public OverrideResolver(
@NotNull BindingTrace trace,
@NotNull OverridesBackwardCompatibilityHelper overridesBackwardCompatibilityHelper
) {
this.trace = trace;
this.overridesBackwardCompatibilityHelper = overridesBackwardCompatibilityHelper;
}
public void check(@NotNull TopDownAnalysisContext c) {
@@ -650,7 +655,7 @@ public class OverrideResolver {
}
});
}
else if (!overriddenDescriptors.isEmpty()) {
else if (!overriddenDescriptors.isEmpty() && !overridesBackwardCompatibilityHelper.overrideCanBeOmitted(declared)) {
CallableMemberDescriptor overridden = overriddenDescriptors.iterator().next();
trace.report(VIRTUAL_MEMBER_HIDDEN.on(member, declared, overridden, overridden.getContainingDeclaration()));
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
interface OverridesBackwardCompatibilityHelper {
fun overrideCanBeOmitted(overridingDescriptor: CallableMemberDescriptor): Boolean
object DEFAULT : OverridesBackwardCompatibilityHelper {
override fun overrideCanBeOmitted(overridingDescriptor: CallableMemberDescriptor): Boolean =
false
}
}
@@ -51,7 +51,8 @@ abstract class TargetPlatform(val platformName: String) {
override val platformConfigurator =
object : PlatformConfigurator(
DynamicTypesSettings(), listOf(), listOf(), listOf(), listOf(), listOf(),
IdentifierChecker.DEFAULT, OverloadFilter.DEFAULT, PlatformToKotlinClassMap.EMPTY, DelegationFilter.DEFAULT
IdentifierChecker.DEFAULT, OverloadFilter.DEFAULT, PlatformToKotlinClassMap.EMPTY, DelegationFilter.DEFAULT,
OverridesBackwardCompatibilityHelper.DEFAULT
) {
override fun configureModuleComponents(container: StorageComponentContainer) {
container.useInstance(SyntheticScopes.Empty)
@@ -97,7 +98,8 @@ abstract class PlatformConfigurator(
private val identifierChecker: IdentifierChecker,
private val overloadFilter: OverloadFilter,
private val platformToKotlinClassMap: PlatformToKotlinClassMap,
private val delegationFilter: DelegationFilter
private val delegationFilter: DelegationFilter,
private val overridesBackwardCompatibilityHelper: OverridesBackwardCompatibilityHelper
) {
private val declarationCheckers: List<DeclarationChecker> = DEFAULT_DECLARATION_CHECKERS + additionalDeclarationCheckers
private val callCheckers: List<CallChecker> = DEFAULT_CALL_CHECKERS + additionalCallCheckers
@@ -117,6 +119,7 @@ abstract class PlatformConfigurator(
useInstance(overloadFilter)
useInstance(platformToKotlinClassMap)
useInstance(delegationFilter)
useInstance(overridesBackwardCompatibilityHelper)
}
}