Report warning instead of error on incorrect -Xuse-experimental/-Xexperimental

#KT-27430 Fixed
 #KT-27709 Fixed
This commit is contained in:
Alexander Udalov
2018-10-26 17:44:40 +02:00
parent 43895f43d4
commit 5bc2178040
4 changed files with 26 additions and 28 deletions
@@ -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)
+3 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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