Report warning instead of error on incorrect -Xuse-experimental/-Xexperimental
#KT-27430 Fixed #KT-27709 Fixed
This commit is contained in:
+16
-18
@@ -217,29 +217,27 @@ class ExperimentalUsageChecker(project: Project) : CallChecker {
|
||||
val deprecationResolver =
|
||||
DeprecationResolver(LockBasedStorageManager(), languageVersionSettings, CoroutineCompatibilitySupport.ENABLED)
|
||||
|
||||
// Returns true if fqName refers to a valid experimental API marker.
|
||||
fun checkAnnotation(fqName: String): Boolean {
|
||||
val descriptor = module.resolveClassByFqName(FqName(fqName), NoLookupLocation.FOR_NON_TRACKED_SCOPE)
|
||||
val experimentality = descriptor?.loadExperimentalityForMarkerAnnotation()
|
||||
val message = when {
|
||||
descriptor == null ->
|
||||
"Experimental API marker $fqName is unresolved. Please make sure it's present in the module dependencies"
|
||||
experimentality == null ->
|
||||
"Class $fqName is not an experimental API marker annotation"
|
||||
else -> {
|
||||
for (deprecation in deprecationResolver.getDeprecations(descriptor)) {
|
||||
val report = when (deprecation.deprecationLevel) {
|
||||
DeprecationLevelValue.WARNING -> reportWarning
|
||||
DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> reportError
|
||||
}
|
||||
report("Experimental API marker $fqName is deprecated" + deprecation.message?.let { ". $it" }.orEmpty())
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (descriptor == null) {
|
||||
reportWarning("Experimental API marker $fqName is unresolved. Please make sure it's present in the module dependencies")
|
||||
return false
|
||||
}
|
||||
|
||||
reportError(message)
|
||||
if (descriptor.loadExperimentalityForMarkerAnnotation() == null) {
|
||||
reportWarning("Class $fqName is not an experimental API marker annotation")
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
for (deprecation in deprecationResolver.getDeprecations(descriptor)) {
|
||||
val report = when (deprecation.deprecationLevel) {
|
||||
DeprecationLevelValue.WARNING -> reportWarning
|
||||
DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> reportError
|
||||
}
|
||||
report("Experimental API marker $fqName is deprecated" + deprecation.message?.let { ". $it" }.orEmpty())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
val validExperimental = languageVersionSettings.getFlag(AnalysisFlags.experimental).filter(::checkAnnotation)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
error: class org.test.NotAnAnnotation1 is not an experimental API marker annotation
|
||||
error: class org.test.NotAnAnnotation2 is not an experimental API marker annotation
|
||||
COMPILATION_ERROR
|
||||
warning: class org.test.NotAnAnnotation1 is not an experimental API marker annotation
|
||||
warning: class org.test.NotAnAnnotation2 is not an experimental API marker annotation
|
||||
OK
|
||||
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
error: class org.test.NotAMarker1 is not an experimental API marker annotation
|
||||
error: class org.test.NotAMarker2 is not an experimental API marker annotation
|
||||
COMPILATION_ERROR
|
||||
warning: class org.test.NotAMarker1 is not an experimental API marker annotation
|
||||
warning: class org.test.NotAMarker2 is not an experimental API marker annotation
|
||||
OK
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
error: experimental API marker org.test.Unresolved2 is unresolved. Please make sure it's present in the module dependencies
|
||||
error: experimental API marker org.test.Unresolved1 is unresolved. Please make sure it's present in the module dependencies
|
||||
error: experimental API marker org.test.Unresolved3 is unresolved. Please make sure it's present in the module dependencies
|
||||
COMPILATION_ERROR
|
||||
warning: experimental API marker org.test.Unresolved2 is unresolved. Please make sure it's present in the module dependencies
|
||||
warning: experimental API marker org.test.Unresolved1 is unresolved. Please make sure it's present in the module dependencies
|
||||
warning: experimental API marker org.test.Unresolved3 is unresolved. Please make sure it's present in the module dependencies
|
||||
OK
|
||||
|
||||
Reference in New Issue
Block a user