views:

116

answers:

2

Hi folks,

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

I have a CompoundContributionItem implementation defined in one of my plugings. 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 & _COMMAND public

+1  A: 

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.

VonC
It says "The name is either the name of the parameter..." So I think I used that, and called one parameter "type" and the other "command". But I guess, I have to think more about your profound answer, VonC.
pimpf0r
@pimpf0r: that's just it: I am not sure "name of the parameter" can reference any *internal* field class. In a declarative mode such as a `plugin.xml`, I would expect the parameter being defined elsewhere within said `plugin.xml`
VonC
Okay, I think I found "elsewhere". Elsewhere in this case means: The location where the referenced command is defined/declared. I was referring within my dynamic declaration to a command within the same plugin.xml. But the added Parameter weren't declared there. Thanks for your help, VonC. *high5*
pimpf0r
@pimpf0r: thank you for this feedback. Could you post as an answer what you needed to add to your `plugin.xml` to solve this issue?
VonC
A: 

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.

pimpf0r