dynamic MenuContribution - Get a warning

2019-07-24 17:55发布

I am using dynamic MenuContribution and get a warning that two of my referenced identifiers "cannot be found". Even though the contribution works. These warnings bug me.

I have a CompoundContributionItem implementation defined in one of my plugins. Basically it looks like this:

public class ViewerHistoryMenuItems extends CompoundContributionItem
    implements IExecutableExtension { 

    private static final String PARAM_TYPE = "type";
    private static final String PARAM_COMMAND = "command";

    // some fields

    public void setInitializationData(final IConfigurationElement config,
            final String propertyName, final Object data) {
        /* set fields */
    }

    protected final IContributionItem[] getContributionItems() {
        /* create Items */ 
    }
}

In other plugins I use this ContributionItem implementation by declaring the following:

<menuContribution locationURI="menu:mylocationUri">
    <dynamic id="myId">
        <class class="ViewerHistoryMenuItems">
            <parameter
                     name="type"
                     value="someValue">
            </parameter>
            <parameter
                     name="command"
                     value="someCommandId">
            </parameter>
        </class>
    </dynamic>
    <command
        commandId="someCommandId"
        icon="anIcon.png">
    </command>
</menuContribution>

When looking at the Problems-View I get two entries there (for each plug-in, which uses this contribution):

**Referenced identifier 'type' in attribute 'name' cannot be found**

**Referenced identifier 'command' in attribute 'name' cannot be found**

What am I missing here? Any ideas, why I get this warning?

PS: It doesn't help, to make the two fields PARAM_TYPE & PARAM_COMMAND public

2条回答
甜甜的少女心
2楼-- · 2019-07-24 18:46

I do not think this is related to the presence of internal fields within a class.

If you look at a similar error (not the same since it includes annotationType), the correction involved the definition of said Referenced identifier:

Referenced identifier 'com.atlassian.connector.eclipse.cruicible.ui.comment.annotation' 
in attribute 'annotationType' cannot be found

Fixed with:

+   <extension
+         point="org.eclipse.ui.editors.annotationTypes">
+      <type
+            markerType="com.atlassian.connector.eclipse.crucible.ui.com.atlassian.connector.eclipse.cruicible.ui.comment.marker"
+            name="com.atlassian.connector.eclipse.cruicible.ui.comment.annotation">
+      </type>
+   </extension>
+   <extension
+         id="com.atlassian.connector.eclipse.cruicible.ui.comment.marker"
+         point="org.eclipse.core.resources.markers">
+   </extension>

Considering the extension point org.eclipse.ui.menus help page:

<!ELEMENT parameter  EMPTY>
<!ATTLIST parameter
  name  IDREF #REQUIRED
  value CDATA #REQUIRED
>

A parameter to either an executable extension or a command -- depending on where it appears in the extension.

  • name - The name is either the name of the parameter to pass to the executable extension, or the identifier of the parameter for the command.
  • value - The value to pass for this parameter.

You need to reference in the name attribute an id present somewhere else in your plugin.xml.

查看更多
我命由我不由天
3楼-- · 2019-07-24 18:49

Sure thing, VonC. Here we go:

Within the dynamic declaration (see above) there are two parameter references

<parameter
  name="type"
  value="someValue">
</parameter>
<parameter
  name="command"
  value="someCommandId">
</parameter>

These two parameter are meant to be passed to the command itself. The command declaration is within the same plugin.xml but wasn't declaring these two commandParameters.

What I did was adding these missing commandParameters, resolving the missing reference, which was clearly stated by the warning.

<command
  categoryId="aCategory"
               id="someCommandId"
               name="%theName">
  <commandParameter
    id="type"
    name="type"/>
  <commandParameter
    id="command"
    name="command">
  </commandParameter>
</command>

So, you were absolutely right by saying "the correction involved the definition of said reference identifier". The question just was where and what I had to define. I think, I wasn't thinking about the most obvious in this case.

查看更多
登录 后发表回答