use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testForcePluginActivation.
public void testForcePluginActivation() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement enable = findExtension(ces, "test2").getChildren("enablement")[0];
EnablementExpression exp = (EnablementExpression) ExpressionConverter.getDefault().perform(enable);
Expression[] children = exp.getChildren();
assertTrue(children.length == 3);
TestExpression test = (TestExpression) children[0];
assertTrue(test.testGetForcePluginActivation());
test = (TestExpression) children[1];
assertTrue(!test.testGetForcePluginActivation());
test = (TestExpression) children[2];
assertTrue(!test.testGetForcePluginActivation());
}
use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionAndTrue.
public void testIterateExpressionAndTrue() throws Exception {
final List<Object> result = new ArrayList<>();
Expression myExpression = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
result.add(context.getDefaultVariable());
return EvaluationResult.TRUE;
}
};
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("and");
exp.add(myExpression);
List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
// $NON-NLS-1$
input.add("two");
EvaluationContext context = new EvaluationContext(null, input);
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
assertTrue(result.equals(input));
}
use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testReadDOMExpression.
public void testReadDOMExpression() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
URL url = FrameworkUtil.getBundle(ExpressionTests.class).getEntry("plugin.xml");
Document document = builder.parse(url.openStream());
NodeList testParticipants = document.getElementsByTagName("testParticipant");
for (int i = 0; i < testParticipants.getLength(); i++) {
Element elem = (Element) testParticipants.item(i);
String id = elem.getAttribute("id");
Element enable1 = (Element) elem.getElementsByTagName("enablement").item(0);
// $NON-NLS-1$
IConfigurationElement enable2 = findExtension(ces, id).getChildren("enablement")[0];
Expression exp1 = ExpressionConverter.getDefault().perform(enable1);
Expression exp2 = ExpressionConverter.getDefault().perform(enable2);
assertEquals(exp1, exp2);
}
}
use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.
the class DefinitionRegistry method getExpression.
/**
* Get the expression with the id defined by an extension. This class will
* cache the expressions when appropriate, so it's OK to always ask the
* registry.
*
* @param id The unique ID of the expression definition
* @return the expression
* @throws CoreException If the expression cannot be found.
*/
public Expression getExpression(String id) throws CoreException {
Expression cachedExpression = getCache().get(id);
if (cachedExpression != null) {
return cachedExpression;
}
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions", "definitions");
Expression foundExpression = null;
for (IConfigurationElement ce : ces) {
// $NON-NLS-1$
String cid = ce.getAttribute("id");
if (cid != null && cid.equals(id)) {
try {
foundExpression = getExpression(id, ce);
break;
} catch (InvalidRegistryObjectException e) {
throw new CoreException(new ExpressionStatus(ExpressionStatus.MISSING_EXPRESSION, Messages.format(ExpressionMessages.Missing_Expression, id)));
}
}
}
if (foundExpression == null) {
throw new CoreException(new ExpressionStatus(ExpressionStatus.MISSING_EXPRESSION, Messages.format(ExpressionMessages.Missing_Expression, id)));
}
return foundExpression;
}
use of org.eclipse.core.expressions.Expression in project dbeaver by dbeaver.
the class DebugUIInternals method createShortcutActions.
public static Map<IAction, String> createShortcutActions(Object[] selected, String mode, int accelerator) {
Map<IAction, String> result = new LinkedHashMap<IAction, String>();
if (selected == null) {
return result;
}
List<Object> selection = Arrays.asList(selected);
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(selection);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("selection", selection);
List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
List<LaunchShortcutExtension> filteredShortCuts = new ArrayList<LaunchShortcutExtension>();
Iterator<LaunchShortcutExtension> iter = allShortCuts.iterator();
while (iter.hasNext()) {
LaunchShortcutExtension ext = iter.next();
if (WorkbenchActivityHelper.filterItem(ext)) {
continue;
}
try {
Expression expr = ext.getContextualLaunchEnablementExpression();
if (ext.evalEnablementExpression(context, expr)) {
filteredShortCuts.add(ext);
}
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), // $NON-NLS-1$
"Launch shortcut '" + ext.getId() + "' enablement expression caused exception. Shortcut was removed.", // $NON-NLS-1$
e);
DebugUIPlugin.log(status);
iter.remove();
}
}
for (LaunchShortcutExtension ext : filteredShortCuts) {
for (String supported : ext.getModes()) {
if (supported.equals(mode)) {
LaunchShortcutAction action = new LaunchShortcutAction(supported, ext);
// $NON-NLS-1$
action.setActionDefinitionId(ext.getId() + "." + supported);
String helpContextId = ext.getHelpContextId();
if (helpContextId != null) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);
}
StringBuffer label = new StringBuffer();
if (accelerator >= 0 && accelerator < 10) {
// add the numerical accelerator
label.append('&');
label.append(accelerator);
label.append(' ');
}
String contextLabel = ext.getContextLabel(supported);
// replace default action label with context label if
// specified.
label.append((contextLabel != null) ? contextLabel : action.getText());
action.setText(label.toString());
String category = ext.getCategory();
result.put(action, category);
accelerator++;
}
}
}
return result;
}
Aggregations