Deprecated reportFromPlugin way to report diagnostics from plugin
Originally reportFromPlugin method was introduced to address the problem with loading of DefaultErrorMessages.Extension vis ServiceLoader. For some cases this extension was not loaded by ServiceLoader because classes was loaded via different class loader, common scenario here is compiler plugins. Ideally we should load such extension point via getService approach, but unfortunately to do that we need project and DefaultErrorMessages.render is static method for now. Also with reportFromPlugin approach is a problem -- all diagnostics reported via this method has the same id: PLUGIN_[WARNING|ERROR|INFO] and it isn't possible to suppress only one particular diagnostic. To bypass this problem the new method initializeFactoryNamesAndDefaultErrorMessages was introduced. It basically store DiagnosticRenderer inside DiagnosticFactory. It is not ideal, because one DiagnosticFactory could have different renderers for different scenarios -- for compiler and for IDE, but I think that it is better than reportByPlugin approach.
This commit is contained in:
+1
-2
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.noarg.diagnostic
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.reportFromPlugin
|
||||
import org.jetbrains.kotlin.extensions.AnnotationBasedExtension
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
@@ -40,7 +39,7 @@ abstract class AbstractNoArgDeclarationChecker : DeclarationChecker, AnnotationB
|
||||
val superClass = descriptor.getSuperClassOrAny()
|
||||
if (superClass.constructors.none { it.isNoArgConstructor() } && !superClass.hasSpecialAnnotation(declaration)) {
|
||||
val reportTarget = declaration.nameIdentifier ?: declaration.getClassOrInterfaceKeyword() ?: declaration
|
||||
context.trace.reportFromPlugin(ErrorsNoArg.NO_NOARG_CONSTRUCTOR_IN_SUPERCLASS.on(reportTarget), DefaultErrorMessagesNoArg)
|
||||
context.trace.report(ErrorsNoArg.NO_NOARG_CONSTRUCTOR_IN_SUPERCLASS.on(reportTarget))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface ErrorsNoArg {
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
{
|
||||
Errors.Initializer.initializeFactoryNames(ErrorsNoArg.class);
|
||||
Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages(ErrorsNoArg.class, DefaultErrorMessagesNoArg.INSTANCE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user