[Help] Can't instantiate plugin extensions

Answered

I am developing 2 plugins, 1 plugin is exposing extensionPoints, the other plugin is making extensions.

In myPlugin:

<extensionPoints>
<extensionPoint name="pdlCompletionBase" beanClass="com.linkedin.intellij.pegasusplugin.completion.PdlAnnotationCompletionBase">
<with attribute="implementationClass" implements="com.linkedin.intellij.pegasusplugin.completion.PdlAnnotationCompletionBase"/>
</extensionPoint>
</extensionPoints>

Where the `PdlAnnotationCompletionBase` is 

public abstract class PdlAnnotationCompletionBase extends LazyExtensionInstance {
@Attribute("key")
public String key;

@Attribute("implementationClass")
public String implementationClass;

public String getKey() {
return key;
}

}

Also where we get extension name:

public class PdlCompletionContributor extends CompletionContributor {
private static final ExtensionPointName<PdlAnnotationCompletionBase> EP_NAME =
ExtensionPointName.create("com.linkedin.pegasus-intellij-plugin.pegasusplugin.pdlCompletionBase");

public PdlCompletionContributor() {
useExtensions();
}

public void useExtensions() {
try {
for (PdlAnnotationCompletionBase extension: EP_NAME.getExtensionList(project)) {
// .....
}
} catch (Exception e) {
PluginManager.getLogger().error("Enumerate extension failed", e);
}
}
}

The error message:

2020-12-22 18:21:49,526 [  41058]  ERROR - nsions.impl.ExtensionPointImpl - IntelliJ IDEA 2020.3  Build #IU-203.5981.155
2020-12-22 18:21:49,526 [ 41058] ERROR - nsions.impl.ExtensionPointImpl - JDK: 11.0.9; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2020-12-22 18:21:49,526 [ 41058] ERROR - nsions.impl.ExtensionPointImpl - OS: Mac OS X
2020-12-22 18:21:49,527 [ 41059] ERROR - nsions.impl.ExtensionPointImpl - Plugin to blame: annotation version: 0.0.2
2020-12-22 18:21:49,527 [ 41059] ERROR - nsions.impl.ExtensionPointImpl - Last Action: EditorLeft

Exception

2020-12-22 18:21:49,525 [  41057]  ERROR - nsions.impl.ExtensionPointImpl - Cannot create class com.linkedin.intellij.pegasusplugin.completion.PdlAnnotationCompletionBase [Plugin: com.linkedin.pdl-plugin-extension-example.annotation]
com.intellij.diagnostic.PluginException: Cannot create class com.linkedin.intellij.pegasusplugin.completion.PdlAnnotationCompletionBase [Plugin: com.linkedin.pdl-plugin-extension-example.annotation]
at com.intellij.serviceContainer.ComponentManagerImpl.instantiateClass(ComponentManagerImpl.kt:725)
at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.instantiateClass(ExtensionComponentAdapter.java:51)
at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.createInstance(ExtensionComponentAdapter.java:43)
at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.java:69)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.java:501)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapters(ExtensionPointImpl.java:435)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.calcExtensionList(ExtensionPointImpl.java:246)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.java:240)
at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.java:42)
at com.linkedin.intellij.pegasusplugin.completion.PdlCompletionContributor.useExtensions(PdlCompletionContributor.java:41)
at com.linkedin.intellij.pegasusplugin.completion.PdlCompletionContributor.<init>(PdlCompletionContributor.java:36)

 

For thoroughness, the another plugin is

<extensions defaultExtensionNs="com.linkedin.pegasus-intellij-plugin.pegasusplugin">
<pdlCompletionBase key="entityRelationship" implementationClass="com.linkedin.intellij.annotation.SimpleCompletion"/>
</extensions>

 

And the extension class is

public class SimpleCompletion extends PdlAnnotationCompletionBase {
@java.lang.Override
public void init() {

}

@java.lang.Override
public java.lang.String getAnnotationKeyName() {
return null;
}

@java.lang.Override
public java.lang.String getFieldTypeBasedFormat(FieldType fieldType) {
return null;
}

@java.lang.Override
public void getCompletions(CompletionParameters completionParameters, ProcessingContext processingContext,
CompletionResultSet completionResultSet) {

}

@java.lang.Override
public java.lang.String insertCompletion(java.lang.String s) {
return null;
}
}

Hope I can get some help. Thank you

 

 

 

3 comments
Comment actions Permalink

Bpin, did you set proper dependencies in Gradle configuration/pugin.xml files within the second B?

0
Comment actions Permalink

Jakub, My second plugin's gradle file looks like

apply plugin: 'li-intellij-plugin'

intellij.plugins = ['gradle-java', 'java', 'com.linkedin.pegasus-intellij-plugin.pegasusplugin:0.1.38']

jacoco {
// Required for Java 11 support
toolVersion = "0.8.5"
}

And my plugin.xml looks like this:

<idea-plugin version="2">
<description>
annotation plugin for the IntelliJ IDE platform.
</description>

<change-notes>
</change-notes>

<!--
This is needed in order to use Java-related functionality.
See: https://blog.jetbrains.com/platform/2019/06/java-functionality-extracted-as-a-plugin/
-->
<depends>com.intellij.modules.java</depends>
<depends>com.linkedin.pegasus-intellij-plugin.pegasusplugin</depends>

<extensions defaultExtensionNs="com.linkedin.pegasus-intellij-plugin.pegasusplugin">
<pdlCompletionBase key="entityRelationship" implementationClass="com.linkedin.intellij.annotation.SimpleCompletion"/>
<pdlCompletionInterface implementation="com.linkedin.intellij.annotation.SimplePdlCompletions"/>
</extensions>

<application-components>
<!-- Add your application components here -->
</application-components>

<project-components>
<!-- Add your project components here -->
</project-components>

<actions>
<!-- Add your actions here -->
</actions>
</idea-plugin>

With the depends tag

<depends>com.linkedin.pegasus-intellij-plugin.pegasusplugin</depends>

I think I have set it ok?

Without setting it correctly will it happen to have exception like I saw?

0
Comment actions Permalink

In your EP declaration,

- beanClass should specify POJO class holding all attributes to configure extension point instance (declared via multiple declarations in any plugin.xml)

- whereas attribute "implementationClass" holding FQN of actual EP implementation should specify the Interface that must be implemented by the EP implementation (NOT the same as POJO).

0

Please sign in to leave a comment.