Fixes and refactors
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
2e2e70fede
commit
19bfc43bee
+12
-10
@@ -24,22 +24,24 @@ import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.DeclarationReturnTypeSanitizer
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
import org.jetbrains.kotlin.types.replaceAnnotations
|
||||
|
||||
object JvmDeclarationReturnTypeSanitizer : DeclarationReturnTypeSanitizer {
|
||||
override fun sanitizeReturnType(
|
||||
inferred: UnwrappedType,
|
||||
wrappedTypeFactory: WrappedTypeFactory,
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
inferred: UnwrappedType,
|
||||
wrappedTypeFactory: WrappedTypeFactory,
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): UnwrappedType =
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) {
|
||||
// NB can't check for presence of EnhancedNullability here,
|
||||
// because it will also cause recursion in declaration type resolution.
|
||||
inferred.replaceAnnotations(
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) {
|
||||
// NB can't check for presence of EnhancedNullability here,
|
||||
// because it will also cause recursion in declaration type resolution.
|
||||
inferred.replaceAttributes(
|
||||
inferred.attributes.replaceAnnotations(
|
||||
FilteredAnnotations(inferred.annotations, languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
|
||||
it != JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION
|
||||
}
|
||||
)
|
||||
}
|
||||
else inferred
|
||||
)
|
||||
} else inferred
|
||||
}
|
||||
+4
-3
@@ -20,12 +20,12 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeAttributes
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
|
||||
class JavaClassOnCompanionChecker : CallChecker {
|
||||
@@ -44,8 +44,9 @@ class JavaClassOnCompanionChecker : CallChecker {
|
||||
val javaLangClass = actualType.constructor.declarationDescriptor as? ClassDescriptor ?: return
|
||||
|
||||
val arguments = listOf(TypeProjectionImpl(containingClass.defaultType))
|
||||
val expectedType = KotlinTypeFactory.simpleType(Annotations.EMPTY, javaLangClass.typeConstructor, arguments,
|
||||
actualType.isMarkedNullable)
|
||||
val expectedType = KotlinTypeFactory.simpleType(
|
||||
TypeAttributes.Empty, javaLangClass.typeConstructor, arguments,
|
||||
actualType.isMarkedNullable)
|
||||
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(reportOn, actualType, expectedType))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user