Move common jvm classes from :core:descriptors.jvm to :core:compiler.common.jvm
This commit is contained in:
@@ -8,6 +8,7 @@ javaHome = rootProject.extra["JDK_16"] as String
|
||||
|
||||
dependencies {
|
||||
api(project(":core:compiler.common"))
|
||||
api(project(":core:metadata.jvm"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.builtins.jvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
|
||||
import org.jetbrains.kotlin.load.kotlin.signatures
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
object JvmBuiltInsSignatures {
|
||||
val DROP_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
SignatureBuildingComponents.inJavaUtil(
|
||||
"Collection",
|
||||
"toArray()[Ljava/lang/Object;", "toArray([Ljava/lang/Object;)[Ljava/lang/Object;"
|
||||
) + "java/lang/annotation/Annotation.annotationType()Ljava/lang/Class;"
|
||||
|
||||
val BLACK_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
buildPrimitiveValueMethodsSet() +
|
||||
|
||||
inJavaUtil("List", "sort(Ljava/util/Comparator;)V") +
|
||||
|
||||
inJavaLang(
|
||||
"String",
|
||||
"codePointAt(I)I", "codePointBefore(I)I", "codePointCount(II)I", "compareToIgnoreCase(Ljava/lang/String;)I",
|
||||
"concat(Ljava/lang/String;)Ljava/lang/String;", "contains(Ljava/lang/CharSequence;)Z",
|
||||
"contentEquals(Ljava/lang/CharSequence;)Z", "contentEquals(Ljava/lang/StringBuffer;)Z",
|
||||
"endsWith(Ljava/lang/String;)Z", "equalsIgnoreCase(Ljava/lang/String;)Z", "getBytes()[B", "getBytes(II[BI)V",
|
||||
"getBytes(Ljava/lang/String;)[B", "getBytes(Ljava/nio/charset/Charset;)[B", "getChars(II[CI)V",
|
||||
"indexOf(I)I", "indexOf(II)I", "indexOf(Ljava/lang/String;)I", "indexOf(Ljava/lang/String;I)I",
|
||||
"intern()Ljava/lang/String;", "isEmpty()Z", "lastIndexOf(I)I", "lastIndexOf(II)I",
|
||||
"lastIndexOf(Ljava/lang/String;)I", "lastIndexOf(Ljava/lang/String;I)I", "matches(Ljava/lang/String;)Z",
|
||||
"offsetByCodePoints(II)I", "regionMatches(ILjava/lang/String;II)Z", "regionMatches(ZILjava/lang/String;II)Z",
|
||||
"replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "replace(CC)Ljava/lang/String;",
|
||||
"replaceFirst(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
|
||||
"replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;",
|
||||
"split(Ljava/lang/String;I)[Ljava/lang/String;", "split(Ljava/lang/String;)[Ljava/lang/String;",
|
||||
"startsWith(Ljava/lang/String;I)Z", "startsWith(Ljava/lang/String;)Z", "substring(II)Ljava/lang/String;",
|
||||
"substring(I)Ljava/lang/String;", "toCharArray()[C", "toLowerCase()Ljava/lang/String;",
|
||||
"toLowerCase(Ljava/util/Locale;)Ljava/lang/String;", "toUpperCase()Ljava/lang/String;",
|
||||
"toUpperCase(Ljava/util/Locale;)Ljava/lang/String;", "trim()Ljava/lang/String;",
|
||||
"isBlank()Z", "lines()Ljava/util/stream/Stream;", "repeat(I)Ljava/lang/String;"
|
||||
) +
|
||||
|
||||
inJavaLang("Double", "isInfinite()Z", "isNaN()Z") +
|
||||
inJavaLang("Float", "isInfinite()Z", "isNaN()Z") +
|
||||
|
||||
inJavaLang("Enum", "getDeclaringClass()Ljava/lang/Class;", "finalize()V")
|
||||
}
|
||||
|
||||
private fun buildPrimitiveValueMethodsSet(): Set<String> =
|
||||
signatures {
|
||||
listOf(JvmPrimitiveType.BOOLEAN, JvmPrimitiveType.CHAR).flatMapTo(LinkedHashSet()) {
|
||||
inJavaLang(it.wrapperFqName.shortName().asString(), "${it.javaKeywordName}Value()${it.desc}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val WHITE_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaLang(
|
||||
"CharSequence",
|
||||
"codePoints()Ljava/util/stream/IntStream;", "chars()Ljava/util/stream/IntStream;"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Iterator",
|
||||
"forEachRemaining(Ljava/util/function/Consumer;)V"
|
||||
) +
|
||||
|
||||
inJavaLang(
|
||||
"Iterable",
|
||||
"forEach(Ljava/util/function/Consumer;)V", "spliterator()Ljava/util/Spliterator;"
|
||||
) +
|
||||
|
||||
inJavaLang(
|
||||
"Throwable",
|
||||
"setStackTrace([Ljava/lang/StackTraceElement;)V", "fillInStackTrace()Ljava/lang/Throwable;",
|
||||
"getLocalizedMessage()Ljava/lang/String;", "printStackTrace()V", "printStackTrace(Ljava/io/PrintStream;)V",
|
||||
"printStackTrace(Ljava/io/PrintWriter;)V", "getStackTrace()[Ljava/lang/StackTraceElement;",
|
||||
"initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;", "getSuppressed()[Ljava/lang/Throwable;",
|
||||
"addSuppressed(Ljava/lang/Throwable;)V"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Collection",
|
||||
"spliterator()Ljava/util/Spliterator;", "parallelStream()Ljava/util/stream/Stream;",
|
||||
"stream()Ljava/util/stream/Stream;", "removeIf(Ljava/util/function/Predicate;)Z"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"List",
|
||||
"replaceAll(Ljava/util/function/UnaryOperator;)V"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Map",
|
||||
"getOrDefault(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"forEach(Ljava/util/function/BiConsumer;)V", "replaceAll(Ljava/util/function/BiFunction;)V",
|
||||
"merge(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"computeIfPresent(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;",
|
||||
"compute(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;"
|
||||
)
|
||||
}
|
||||
|
||||
val MUTABLE_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaUtil("Collection", "removeIf(Ljava/util/function/Predicate;)Z") +
|
||||
|
||||
inJavaUtil("List", "replaceAll(Ljava/util/function/UnaryOperator;)V", "sort(Ljava/util/Comparator;)V") +
|
||||
|
||||
inJavaUtil(
|
||||
"Map",
|
||||
"computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;",
|
||||
"computeIfPresent(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"compute(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"merge(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"remove(Ljava/lang/Object;Ljava/lang/Object;)Z", "replaceAll(Ljava/util/function/BiFunction;)V",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z"
|
||||
)
|
||||
}
|
||||
|
||||
val BLACK_LIST_CONSTRUCTOR_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
buildPrimitiveStringConstructorsSet() +
|
||||
inJavaLang("Float", *constructors("D")) +
|
||||
inJavaLang(
|
||||
"String", *constructors(
|
||||
"[C", "[CII", "[III", "[BIILjava/lang/String;",
|
||||
"[BIILjava/nio/charset/Charset;",
|
||||
"[BLjava/lang/String;",
|
||||
"[BLjava/nio/charset/Charset;",
|
||||
"[BII", "[B",
|
||||
"Ljava/lang/StringBuffer;",
|
||||
"Ljava/lang/StringBuilder;"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val WHITE_LIST_CONSTRUCTOR_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaLang("Throwable", *constructors("Ljava/lang/String;Ljava/lang/Throwable;ZZ"))
|
||||
}
|
||||
|
||||
private fun buildPrimitiveStringConstructorsSet(): Set<String> =
|
||||
signatures {
|
||||
listOf(
|
||||
JvmPrimitiveType.BOOLEAN, JvmPrimitiveType.BYTE, JvmPrimitiveType.DOUBLE, JvmPrimitiveType.FLOAT,
|
||||
JvmPrimitiveType.BYTE, JvmPrimitiveType.INT, JvmPrimitiveType.LONG, JvmPrimitiveType.SHORT
|
||||
).flatMapTo(LinkedHashSet()) {
|
||||
// java/lang/<Wrapper>.<init>(Ljava/lang/String;)V
|
||||
inJavaLang(it.wrapperFqName.shortName().asString(), *constructors("Ljava/lang/String;"))
|
||||
}
|
||||
}
|
||||
|
||||
fun isSerializableInJava(fqName: FqNameUnsafe): Boolean {
|
||||
if (isArrayOrPrimitiveArray(fqName)) {
|
||||
return true
|
||||
}
|
||||
val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(fqName) ?: return false
|
||||
val classViaReflection = try {
|
||||
Class.forName(javaClassId.asSingleFqName().asString())
|
||||
} catch (e: ClassNotFoundException) {
|
||||
return false
|
||||
}
|
||||
return Serializable::class.java.isAssignableFrom(classViaReflection)
|
||||
}
|
||||
|
||||
fun isArrayOrPrimitiveArray(fqName: FqNameUnsafe): Boolean {
|
||||
return fqName == StandardNames.FqNames.array || StandardNames.isPrimitiveArray(fqName)
|
||||
}
|
||||
}
|
||||
+2
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.java
|
||||
+10
-10
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
val NULLABLE_ANNOTATIONS = listOf(
|
||||
val NULLABLE_ANNOTATIONS: List<FqName> = listOf(
|
||||
JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION,
|
||||
FqName("androidx.annotation.Nullable"),
|
||||
FqName("android.support.annotation.Nullable"),
|
||||
@@ -34,10 +34,10 @@ val NULLABLE_ANNOTATIONS = listOf(
|
||||
FqName("io.reactivex.annotations.Nullable")
|
||||
)
|
||||
|
||||
val JAVAX_NONNULL_ANNOTATION = FqName("javax.annotation.Nonnull")
|
||||
val JAVAX_CHECKFORNULL_ANNOTATION = FqName("javax.annotation.CheckForNull")
|
||||
val JAVAX_NONNULL_ANNOTATION: FqName = FqName("javax.annotation.Nonnull")
|
||||
val JAVAX_CHECKFORNULL_ANNOTATION: FqName = FqName("javax.annotation.CheckForNull")
|
||||
|
||||
val NOT_NULL_ANNOTATIONS = listOf(
|
||||
val NOT_NULL_ANNOTATIONS: List<FqName> = listOf(
|
||||
JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION,
|
||||
FqName("edu.umd.cs.findbugs.annotations.NonNull"),
|
||||
FqName("androidx.annotation.NonNull"),
|
||||
@@ -50,11 +50,11 @@ val NOT_NULL_ANNOTATIONS = listOf(
|
||||
FqName("io.reactivex.annotations.NonNull")
|
||||
)
|
||||
|
||||
val COMPATQUAL_NULLABLE_ANNOTATION = FqName("org.checkerframework.checker.nullness.compatqual.NullableDecl")
|
||||
val COMPATQUAL_NONNULL_ANNOTATION = FqName("org.checkerframework.checker.nullness.compatqual.NonNullDecl")
|
||||
val COMPATQUAL_NULLABLE_ANNOTATION: FqName = FqName("org.checkerframework.checker.nullness.compatqual.NullableDecl")
|
||||
val COMPATQUAL_NONNULL_ANNOTATION: FqName = FqName("org.checkerframework.checker.nullness.compatqual.NonNullDecl")
|
||||
|
||||
val ANDROIDX_RECENTLY_NULLABLE_ANNOTATION = FqName("androidx.annotation.RecentlyNullable")
|
||||
val ANDROIDX_RECENTLY_NON_NULL_ANNOTATION = FqName("androidx.annotation.RecentlyNonNull")
|
||||
val ANDROIDX_RECENTLY_NULLABLE_ANNOTATION: FqName = FqName("androidx.annotation.RecentlyNullable")
|
||||
val ANDROIDX_RECENTLY_NON_NULL_ANNOTATION: FqName = FqName("androidx.annotation.RecentlyNonNull")
|
||||
|
||||
val NULLABILITY_ANNOTATIONS: Set<FqName> = mutableSetOf<FqName>() +
|
||||
NULLABLE_ANNOTATIONS +
|
||||
@@ -65,12 +65,12 @@ val NULLABILITY_ANNOTATIONS: Set<FqName> = mutableSetOf<FqName>() +
|
||||
ANDROIDX_RECENTLY_NULLABLE_ANNOTATION +
|
||||
ANDROIDX_RECENTLY_NON_NULL_ANNOTATION
|
||||
|
||||
val READ_ONLY_ANNOTATIONS = listOf(
|
||||
val READ_ONLY_ANNOTATIONS: List<FqName> = listOf(
|
||||
JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION,
|
||||
JvmAnnotationNames.READONLY_ANNOTATION
|
||||
)
|
||||
|
||||
val MUTABLE_ANNOTATIONS = listOf(
|
||||
val MUTABLE_ANNOTATIONS: List<FqName> = listOf(
|
||||
JvmAnnotationNames.JETBRAINS_MUTABLE_ANNOTATION,
|
||||
JvmAnnotationNames.MUTABLE_ANNOTATION
|
||||
)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.java.typeEnhancement
|
||||
|
||||
enum class TypeComponentPosition {
|
||||
FLEXIBLE_LOWER,
|
||||
FLEXIBLE_UPPER,
|
||||
INFLEXIBLE
|
||||
}
|
||||
+2
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
+2
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import java.util.*
|
||||
|
||||
inline fun <T> signatures(block: SignatureBuildingComponents.() -> T) = with(SignatureBuildingComponents, block)
|
||||
|
||||
object SignatureBuildingComponents {
|
||||
fun javaLang(name: String): String = "java/lang/$name"
|
||||
fun javaUtil(name: String): String = "java/util/$name"
|
||||
fun javaFunction(name: String): String = "java/util/function/$name"
|
||||
|
||||
fun constructors(vararg signatures: String): Array<String> = signatures.map { "<init>($it)V" }.toTypedArray()
|
||||
|
||||
fun inJavaLang(name: String, vararg signatures: String): Set<String> = inClass(javaLang(name), *signatures)
|
||||
fun inJavaUtil(name: String, vararg signatures: String): Set<String> = inClass(javaUtil(name), *signatures)
|
||||
|
||||
fun inClass(internalName: String, vararg signatures: String): Set<String> = signatures.mapTo(LinkedHashSet()) { "$internalName.$it" }
|
||||
fun signature(classId: ClassId, jvmDescriptor: String): String = signature(classId.internalName, jvmDescriptor)
|
||||
fun signature(internalName: String, jvmDescriptor: String): String = "$internalName.$jvmDescriptor"
|
||||
|
||||
fun jvmDescriptor(name: String, parameters: List<String>, ret: String = "V"): String =
|
||||
"$name(${parameters.joinToString("") { escapeClassName(it) }})${escapeClassName(internalName = ret)}"
|
||||
|
||||
private fun escapeClassName(internalName: String): String = if (internalName.length > 1) "L$internalName;" else internalName
|
||||
}
|
||||
|
||||
val ClassId.internalName: String
|
||||
get() {
|
||||
return JvmClassName.byClassId(JavaToKotlinClassMap.mapKotlinToJava(asSingleFqName().toUnsafe()) ?: this).internalName
|
||||
}
|
||||
+2
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin.header
|
||||
@@ -6,7 +6,14 @@
|
||||
package org.jetbrains.kotlin.builtins.jvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.BLACK_LIST_CONSTRUCTOR_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.BLACK_LIST_METHOD_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.DROP_LIST_METHOD_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.MUTABLE_METHOD_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.WHITE_LIST_CONSTRUCTOR_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.WHITE_LIST_METHOD_SIGNATURES
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.isArrayOrPrimitiveArray
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures.isSerializableInJava
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.annotations.createDeprecatedAnnotation
|
||||
@@ -20,14 +27,12 @@ import org.jetbrains.kotlin.load.java.components.JavaResolverCache
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
|
||||
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.signatures
|
||||
import org.jetbrains.kotlin.load.kotlin.signature
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||
@@ -38,7 +43,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.LazyWrappedType
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
open class JvmBuiltInsSettings(
|
||||
@@ -323,175 +327,6 @@ open class JvmBuiltInsSettings(
|
||||
private fun ConstructorDescriptor.isTrivialCopyConstructorFor(classDescriptor: ClassDescriptor): Boolean =
|
||||
valueParameters.size == 1 &&
|
||||
valueParameters.single().type.constructor.declarationDescriptor?.fqNameUnsafe == classDescriptor.fqNameUnsafe
|
||||
|
||||
companion object {
|
||||
fun isSerializableInJava(fqName: FqNameUnsafe): Boolean {
|
||||
if (isArrayOrPrimitiveArray(fqName)) {
|
||||
return true
|
||||
}
|
||||
val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(fqName) ?: return false
|
||||
val classViaReflection = try {
|
||||
Class.forName(javaClassId.asSingleFqName().asString())
|
||||
} catch (e: ClassNotFoundException) {
|
||||
return false
|
||||
}
|
||||
return Serializable::class.java.isAssignableFrom(classViaReflection)
|
||||
}
|
||||
|
||||
private fun isArrayOrPrimitiveArray(fqName: FqNameUnsafe): Boolean {
|
||||
return fqName == StandardNames.FqNames.array || StandardNames.isPrimitiveArray(fqName)
|
||||
}
|
||||
|
||||
val DROP_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
SignatureBuildingComponents.inJavaUtil(
|
||||
"Collection",
|
||||
"toArray()[Ljava/lang/Object;", "toArray([Ljava/lang/Object;)[Ljava/lang/Object;"
|
||||
) + "java/lang/annotation/Annotation.annotationType()Ljava/lang/Class;"
|
||||
|
||||
val BLACK_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
buildPrimitiveValueMethodsSet() +
|
||||
|
||||
inJavaUtil("List", "sort(Ljava/util/Comparator;)V") +
|
||||
|
||||
inJavaLang(
|
||||
"String",
|
||||
"codePointAt(I)I", "codePointBefore(I)I", "codePointCount(II)I", "compareToIgnoreCase(Ljava/lang/String;)I",
|
||||
"concat(Ljava/lang/String;)Ljava/lang/String;", "contains(Ljava/lang/CharSequence;)Z",
|
||||
"contentEquals(Ljava/lang/CharSequence;)Z", "contentEquals(Ljava/lang/StringBuffer;)Z",
|
||||
"endsWith(Ljava/lang/String;)Z", "equalsIgnoreCase(Ljava/lang/String;)Z", "getBytes()[B", "getBytes(II[BI)V",
|
||||
"getBytes(Ljava/lang/String;)[B", "getBytes(Ljava/nio/charset/Charset;)[B", "getChars(II[CI)V",
|
||||
"indexOf(I)I", "indexOf(II)I", "indexOf(Ljava/lang/String;)I", "indexOf(Ljava/lang/String;I)I",
|
||||
"intern()Ljava/lang/String;", "isEmpty()Z", "lastIndexOf(I)I", "lastIndexOf(II)I",
|
||||
"lastIndexOf(Ljava/lang/String;)I", "lastIndexOf(Ljava/lang/String;I)I", "matches(Ljava/lang/String;)Z",
|
||||
"offsetByCodePoints(II)I", "regionMatches(ILjava/lang/String;II)Z", "regionMatches(ZILjava/lang/String;II)Z",
|
||||
"replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "replace(CC)Ljava/lang/String;",
|
||||
"replaceFirst(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
|
||||
"replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;",
|
||||
"split(Ljava/lang/String;I)[Ljava/lang/String;", "split(Ljava/lang/String;)[Ljava/lang/String;",
|
||||
"startsWith(Ljava/lang/String;I)Z", "startsWith(Ljava/lang/String;)Z", "substring(II)Ljava/lang/String;",
|
||||
"substring(I)Ljava/lang/String;", "toCharArray()[C", "toLowerCase()Ljava/lang/String;",
|
||||
"toLowerCase(Ljava/util/Locale;)Ljava/lang/String;", "toUpperCase()Ljava/lang/String;",
|
||||
"toUpperCase(Ljava/util/Locale;)Ljava/lang/String;", "trim()Ljava/lang/String;",
|
||||
"isBlank()Z", "lines()Ljava/util/stream/Stream;", "repeat(I)Ljava/lang/String;"
|
||||
) +
|
||||
|
||||
inJavaLang("Double", "isInfinite()Z", "isNaN()Z") +
|
||||
inJavaLang("Float", "isInfinite()Z", "isNaN()Z") +
|
||||
|
||||
inJavaLang("Enum", "getDeclaringClass()Ljava/lang/Class;", "finalize()V")
|
||||
}
|
||||
|
||||
private fun buildPrimitiveValueMethodsSet(): Set<String> =
|
||||
signatures {
|
||||
listOf(JvmPrimitiveType.BOOLEAN, JvmPrimitiveType.CHAR).flatMapTo(LinkedHashSet()) {
|
||||
inJavaLang(it.wrapperFqName.shortName().asString(), "${it.javaKeywordName}Value()${it.desc}")
|
||||
}
|
||||
}
|
||||
|
||||
val WHITE_LIST_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaLang(
|
||||
"CharSequence",
|
||||
"codePoints()Ljava/util/stream/IntStream;", "chars()Ljava/util/stream/IntStream;"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Iterator",
|
||||
"forEachRemaining(Ljava/util/function/Consumer;)V"
|
||||
) +
|
||||
|
||||
inJavaLang(
|
||||
"Iterable",
|
||||
"forEach(Ljava/util/function/Consumer;)V", "spliterator()Ljava/util/Spliterator;"
|
||||
) +
|
||||
|
||||
inJavaLang(
|
||||
"Throwable",
|
||||
"setStackTrace([Ljava/lang/StackTraceElement;)V", "fillInStackTrace()Ljava/lang/Throwable;",
|
||||
"getLocalizedMessage()Ljava/lang/String;", "printStackTrace()V", "printStackTrace(Ljava/io/PrintStream;)V",
|
||||
"printStackTrace(Ljava/io/PrintWriter;)V", "getStackTrace()[Ljava/lang/StackTraceElement;",
|
||||
"initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;", "getSuppressed()[Ljava/lang/Throwable;",
|
||||
"addSuppressed(Ljava/lang/Throwable;)V"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Collection",
|
||||
"spliterator()Ljava/util/Spliterator;", "parallelStream()Ljava/util/stream/Stream;",
|
||||
"stream()Ljava/util/stream/Stream;", "removeIf(Ljava/util/function/Predicate;)Z"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"List",
|
||||
"replaceAll(Ljava/util/function/UnaryOperator;)V"
|
||||
) +
|
||||
|
||||
inJavaUtil(
|
||||
"Map",
|
||||
"getOrDefault(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"forEach(Ljava/util/function/BiConsumer;)V", "replaceAll(Ljava/util/function/BiFunction;)V",
|
||||
"merge(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"computeIfPresent(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;",
|
||||
"compute(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;"
|
||||
)
|
||||
}
|
||||
|
||||
val MUTABLE_METHOD_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaUtil("Collection", "removeIf(Ljava/util/function/Predicate;)Z") +
|
||||
|
||||
inJavaUtil("List", "replaceAll(Ljava/util/function/UnaryOperator;)V", "sort(Ljava/util/Comparator;)V") +
|
||||
|
||||
inJavaUtil(
|
||||
"Map",
|
||||
"computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;",
|
||||
"computeIfPresent(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"compute(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"merge(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;",
|
||||
"putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"remove(Ljava/lang/Object;Ljava/lang/Object;)Z", "replaceAll(Ljava/util/function/BiFunction;)V",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
"replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z"
|
||||
)
|
||||
}
|
||||
|
||||
val BLACK_LIST_CONSTRUCTOR_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
buildPrimitiveStringConstructorsSet() +
|
||||
inJavaLang("Float", *constructors("D")) +
|
||||
inJavaLang(
|
||||
"String", *constructors(
|
||||
"[C", "[CII", "[III", "[BIILjava/lang/String;",
|
||||
"[BIILjava/nio/charset/Charset;",
|
||||
"[BLjava/lang/String;",
|
||||
"[BLjava/nio/charset/Charset;",
|
||||
"[BII", "[B",
|
||||
"Ljava/lang/StringBuffer;",
|
||||
"Ljava/lang/StringBuilder;"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val WHITE_LIST_CONSTRUCTOR_SIGNATURES: Set<String> =
|
||||
signatures {
|
||||
inJavaLang("Throwable", *constructors("Ljava/lang/String;Ljava/lang/Throwable;ZZ"))
|
||||
}
|
||||
|
||||
private fun buildPrimitiveStringConstructorsSet(): Set<String> =
|
||||
signatures {
|
||||
listOf(
|
||||
JvmPrimitiveType.BOOLEAN, JvmPrimitiveType.BYTE, JvmPrimitiveType.DOUBLE, JvmPrimitiveType.FLOAT,
|
||||
JvmPrimitiveType.BYTE, JvmPrimitiveType.INT, JvmPrimitiveType.LONG, JvmPrimitiveType.SHORT
|
||||
).flatMapTo(LinkedHashSet()) {
|
||||
// java/lang/<Wrapper>.<init>(Ljava/lang/String;)V
|
||||
inJavaLang(it.wrapperFqName.shortName().asString(), *constructors("Ljava/lang/String;"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FallbackBuiltIns private constructor() : KotlinBuiltIns(LockBasedStorageManager("FallbackBuiltIns")) {
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.load.java.lazy.copyWithNewDefaultTypeQualifiers
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField
|
||||
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
|
||||
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.signature
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DEPRECATED_FUNCTION_KEY
|
||||
|
||||
-6
@@ -46,12 +46,6 @@ fun KotlinType.hasEnhancedNullability(): Boolean =
|
||||
fun TypeSystemCommonBackendContext.hasEnhancedNullability(type: KotlinTypeMarker): Boolean =
|
||||
type.hasAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)
|
||||
|
||||
enum class TypeComponentPosition {
|
||||
FLEXIBLE_LOWER,
|
||||
FLEXIBLE_UPPER,
|
||||
INFLEXIBLE
|
||||
}
|
||||
|
||||
class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings) {
|
||||
|
||||
private open class Result(open val type: KotlinType, val subtreeSize: Int, val wereChanges: Boolean) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import java.util.*
|
||||
|
||||
inline fun <T> signatures(block: SignatureBuildingComponents.() -> T) = with(SignatureBuildingComponents, block)
|
||||
|
||||
object SignatureBuildingComponents {
|
||||
fun javaLang(name: String) = "java/lang/$name"
|
||||
fun javaUtil(name: String) = "java/util/$name"
|
||||
fun javaFunction(name: String) = "java/util/function/$name"
|
||||
|
||||
fun constructors(vararg signatures: String) = signatures.map { "<init>($it)V" }.toTypedArray()
|
||||
|
||||
fun inJavaLang(name: String, vararg signatures: String) = inClass(javaLang(name), *signatures)
|
||||
fun inJavaUtil(name: String, vararg signatures: String) = inClass(javaUtil(name), *signatures)
|
||||
|
||||
fun inClass(internalName: String, vararg signatures: String) = signatures.mapTo(LinkedHashSet()) { "$internalName.$it" }
|
||||
|
||||
fun signature(classDescriptor: ClassDescriptor, jvmDescriptor: String) = signature(classDescriptor.internalName, jvmDescriptor)
|
||||
fun signature(classId: ClassId, jvmDescriptor: String) = signature(classId.internalName, jvmDescriptor)
|
||||
fun signature(internalName: String, jvmDescriptor: String) = "$internalName.$jvmDescriptor"
|
||||
|
||||
fun jvmDescriptor(name: String, parameters: List<String>, ret: String = "V") =
|
||||
"$name(${parameters.joinToString("") { escapeClassName(it) }})${escapeClassName(internalName = ret)}"
|
||||
|
||||
private fun escapeClassName(internalName: String) = if (internalName.length > 1) "L$internalName;" else internalName
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
fun SignatureBuildingComponents.signature(classDescriptor: ClassDescriptor, jvmDescriptor: String): String =
|
||||
signature(classDescriptor.internalName, jvmDescriptor)
|
||||
@@ -5,13 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature
|
||||
import org.jetbrains.kotlin.load.java.isFromJavaOrBuiltins
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
@@ -84,11 +83,6 @@ internal val ClassDescriptor.internalName: String
|
||||
return computeInternalName(this)
|
||||
}
|
||||
|
||||
val ClassId.internalName: String
|
||||
get() {
|
||||
return JvmClassName.byClassId(JavaToKotlinClassMap.mapKotlinToJava(asSingleFqName().toUnsafe()) ?: this).internalName
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendErasedType(type: KotlinType) {
|
||||
append(type.mapToJvmType())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user