HowTo: debug eclipse expressions
HowTo: get current selection
Tabs:
See the following eclipse expression
<extension point="org.eclipse.ui.menus"> <menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions"> <command commandId="net.sf.yari.howto.command.open_yari_editor" icon="$nl$/icons/user1.png" label="%menu.openyarieditor.label" mnemonic="O"> <visibleWhen> <reference definitionId="net.sf.yari.howto.expressions.definitions.AdaptableToIYariObject"> </reference> </visibleWhen> </command> </menuContribution> </extension> <extension point="org.eclipse.core.expressions.definitions"> <definition id="net.sf.yari.howto.expressions.definitions.AdaptableToIYariObject"> <with variable="selection"> <and> <count value="+"> </count> <iterate operator="and"> <adapt type="net.sf.yari.howto.pblic.types.IYariObject"> </adapt> </iterate> </and> </with> </definition> <definition id="net.sf.yari.howto.expressions.definitions.dummyalwaystrue"> <with variable="activeWorkbenchWindow.isCoolbarVisible"> <equals value="true"> </equals> </with> </definition> </extension>
The menu contribution is not visible although you’re pretty sure that the expression is valid and correct? Open the Expression evaluator and check the definitions or part of the expressions. Paste the following snippet to the evaluation textfield and press “Evaluate”:
snippet to the evaluation textfield and press “Evaluate”: <with variable="selection"> <and> <count value="+"> </count> <iterate operator="and"> <adapt type="net.sf.yari.howto.pblic.types.IYariObject"> </adapt> </iterate> </and> </with>
If the Result is “true” there is another problem or the problem appears in another part of the expression.
Pay attention that you should not try to evaluate this expression:
<visibleWhen> <reference definitionId=" net.sf.yari.howto.expressions.definitions. AdaptableToIYariObject"> </reference> </visibleWhen>
This will result in an java.lang.NullPointerException?: Evaluation error null.
Use instead the expression without <visibleWhen>:
<reference definitionId=" net.sf.yari.howto.expressions.definitions. AdaptableToIYariObject"> </reference>
If this evaluates to “true”, the menu contribution should be visible
Description comming soon...
Open ExpressionEvaluator? -> switch to the "Evaluate sourceProvider variables" -> select selection -> press “inspect result”.
Take care of the difference of the selection variable provided by the sourceProvider and the selection object from the workbench selection service:
the source provider variable is an array -> therefore use iterate in eclipse expressions.