Do not report deprecation on readBytes with API version < 1.3

#KT-26667 Fixed
This commit is contained in:
Alexander Udalov
2018-09-12 16:57:56 +03:00
parent 044419eda5
commit 863c0051ce
7 changed files with 83 additions and 0 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.resolve.deprecation
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.MavenComparableVersion
@@ -134,6 +135,11 @@ class DeprecationResolver(
return emptyList()
}
// This is a temporary workaround before @DeprecatedSinceKotlin is introduced, see KT-23575
if (shouldSkipDeprecationOnKotlinIoReadBytes(this, languageVersionSettings)) {
return emptyList()
}
val result = SmartList<Deprecation>()
addDeprecationIfPresent(result)
@@ -183,6 +189,15 @@ class DeprecationResolver(
private val DeclarationDescriptor.isBuiltInOperatorMod: Boolean
get() = this is FunctionDescriptor && this.isOperatorMod() && KotlinBuiltIns.isUnderKotlinPackage(this)
private fun shouldSkipDeprecationOnKotlinIoReadBytes(
descriptor: DeclarationDescriptor, languageVersionSettings: LanguageVersionSettings
): Boolean =
descriptor.name.asString() == "readBytes" &&
(descriptor.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == "kotlin.io" &&
descriptor is FunctionDescriptor &&
descriptor.valueParameters.singleOrNull()?.type?.let(KotlinBuiltIns::isInt) == true &&
languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
private fun getDeprecationByCoroutinesVersion(target: DeclarationDescriptor): DeprecatedExperimentalCoroutine? {
if (target !is DeserializedMemberDescriptor) return null
@@ -0,0 +1,7 @@
import java.io.InputStream
fun InputStream.test() {
readBytes()
<!DEPRECATION!>readBytes<!>(1)
}
@@ -0,0 +1,3 @@
package
public fun java.io.InputStream.test(): kotlin.Unit
@@ -0,0 +1,9 @@
// !API_VERSION: 1.2
import java.io.InputStream
fun InputStream.test() {
readBytes()
readBytes(1)
}
@@ -0,0 +1,3 @@
package
public fun java.io.InputStream.test(): kotlin.Unit
@@ -2226,6 +2226,29 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/deprecated")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Deprecated extends AbstractDiagnosticsTestWithStdLib {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInDeprecated() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/deprecated"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("deprecationOnReadBytes.kt")
public void testDeprecationOnReadBytes() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt");
}
@TestMetadata("noDeprecationOnReadBytes.kt")
public void testNoDeprecationOnReadBytes() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -2226,6 +2226,29 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/deprecated")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Deprecated extends AbstractDiagnosticsTestWithStdLibUsingJavac {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInDeprecated() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/deprecated"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("deprecationOnReadBytes.kt")
public void testDeprecationOnReadBytes() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt");
}
@TestMetadata("noDeprecationOnReadBytes.kt")
public void testNoDeprecationOnReadBytes() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)