Given a Module Creation setting, automatically add "Ignore unused method" with dependency specific annotations

Answered

So, in some development environments, methods annotated with dependency provided annotations such as `Listener`, it'd be useful if the plugin providing support for such dependency projects would be able to automatically add the annotation as ignored, in which I've found in the xml files of the Project Settings as such in the misc.xml

```

<?xml version="1.0" encoding="UTF-8"?>

<project version="4">

  <component name="ASMPluginConfiguration">

    <asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />

    <groovy codeStyle="LEGACY" />

  </component>

  <component name="EntryPointsManager">

    <entry_points version="2.0" />

    <list size="6">

      <item index="0" class="java.lang.String" itemvalue="org.spongepowered.api.event.Listener" />

      <item index="1" class="java.lang.String" itemvalue="org.spongepowered.asm.mixin.Intrinsic" />

      <item index="2" class="java.lang.String" itemvalue="org.spongepowered.asm.mixin.Mixin" />

      <item index="3" class="java.lang.String" itemvalue="org.spongepowered.asm.mixin.Shadow" />

      <item index="4" class="java.lang.String" itemvalue="org.spongepowered.asm.mixin.injection.Inject" />

      <item index="5" class="java.lang.String" itemvalue="org.spongepowered.asm.mixin.injection.Redirect" />

    </list>

  </component>

  <component name="ProjectLevelVcsManager" settingsEditedManually="false">

    <OptionsSetting value="true" id="Add" />

    <OptionsSetting value="true" id="Remove" />

    <OptionsSetting value="true" id="Checkout" />

    <OptionsSetting value="true" id="Update" />

    <OptionsSetting value="true" id="Status" />

    <OptionsSetting value="true" id="Edit" />

    <ConfirmationsSetting value="0" id="Add" />

    <ConfirmationsSetting value="0" id="Remove" />

  </component>

  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8_60" project-jdk-type="JavaSDK">

    <output url="file://$PROJECT_DIR$/classes" />

  </component>

</project>

```

 

Now, I've no idea how the EntryPointsManager figures this sort of thing out, but those are the annotations I've marked as ignored for various reasons (since there's a lot of runtime dependent things that happen), but it'd be neat again if this IntelliJ plugin could programmatically automatically add annotations on the fly for module creation.

 

I figure though that it'd be doable through the EntryPointsManager.getInstance(Project) and cast to EntryPointsManagerBase and use the field to add such entries. Is this the correct way to go about it?

0
3 comments

I'm not at all sure how to use markdown on these forums yet, but I do know Markdown according to GitHub etc.

0

Correction, I figured out how to manually add them on module creation from the plugin:

 

JDOMExternalizableStringList annotations = ((EntryPointsManagerBase) EntryPointsManager.getInstance(module.getProject())).ADDITIONAL_ANNOTATIONS;

if (!annotations.contains("org.spongepowered.api.event.Listener")) {

    annotations.add("org.spongepowered.api.event.Listener");

}

 

0

Hi Gabriel,

In a plugin you need to provide an implementation for com.intellij.codeInspection.reference.EntryPoint. It allows you to provide annotations which would be treated as 'stop show unused code here' marks.

 

Anna

0

Please sign in to leave a comment.