Why are default xml-plugin settings preferred over code-based component configuration?
已回答
Hi,
I'm struggling with the integration of inspections into the plugin.xml. I have a custom lang inspection extending the LocalInspectionTool that defines default-enabling and level via code:
public class UnusedParameterInspection extends RInspection {
@Override
public boolean isEnabledByDefault() {
return true;
}
@NotNull
@Override
public HighlightDisplayLevel getDefaultLevel() {
return HighlightDisplayLevel.WEAK_WARNING;
}
@Nls
@NotNull
@Override
public String getDisplayName() {
return "Unused Function Parameter";
}
...
To use it for my plugin, I've put it into my plugin.xml using:
<localInspection language="R"
implementationClass="com.r4intellij.inspections.UnusedParameterInspection"/>
However, the when running it, the inspection is not enabled nor is its level set to WEAK_WARNING. Also my overridden methods are never called. Only the display name method is called correctly.
Is it possible at all to use code-driven component configuration or is this only possible via XML? If so, what's the point of exposing those methods from above to extending classes?
Best regards,
Holger
请先登录再写评论。
Plugin.xml is used to reduce number of loaded classes on startup. When not all data is available in the xml and one need to check classes - the whole thing brings nothing, so defaults are used. As it was introduced after the api was mature and there were tons of implementations, there was no way just to remove the api.
Sorry for the inconvenience,
Anna
Thanks for the clarification Anna. So if those methods (like `getDefaultLevel` or `isEnabledByDefault`) are now not called at all, why aren't they at least Deprecated in com.intellij.codeInspection.InspectionProfileEntry?
Is there an easy way to check if a configuration can be done programmatically or is just possible via XML? It seems to be possible for some properties `displayName`, but not for others like `defaultLevel`, which makes it hard to configure components. Or is `displayName` the only property that is possible to set via code?
Thanks,
Holger
E.g. the method
com.intellij.codeInspection.InspectionProfileEntry#isEnabledByDefault
has javadoc which asks not to override the method. The same for getShortName and getDefaultLevel.
Anna
Ah I see, thanks a lot for your help.
Best regards,
Holger