/**
   * If the specified configuration element is activated under the current input.
   *
   * @param input The input object.
   * @param configuration The configuration element that defines the activation element.
   * @return true if it is activated.
   */
  private boolean isElementActivated(Object input, final IConfigurationElement configuration) {
    IConfigurationElement[] children = configuration.getChildren("activation"); // $NON-NLS-1$
    if (children == null || children.length == 0) return true;
    children = children[0].getChildren();
    if (children == null || children.length == 0) return true;
    final IConfigurationElement config = children[0];
    final EvaluationContext context = new EvaluationContext(null, input);
    context.addVariable("input", input); // $NON-NLS-1$
    context.setAllowPluginActivation(true);
    final boolean[] result = new boolean[1];
    SafeRunner.run(
        new SafeRunnable() {
          @Override
          public void handleException(Throwable e) {
            // Ignore exception
          }

          @Override
          public void run() throws Exception {
            Expression expression = ExpressionConverter.getDefault().perform(config);
            EvaluationResult evaluate = expression.evaluate(context);
            if (evaluate == EvaluationResult.TRUE) {
              result[0] = true;
            }
          }
        });
    return result[0];
  }
  protected void renameFooToFooBar(final XtextEditor contextEditor) throws Exception {
    contextEditor.getEditorSite().getPage().activate(contextEditor);
    waitForDisplay();
    IXtextDocument document = contextEditor.getDocument();
    final int offset = document.get().indexOf("foo");
    contextEditor.selectAndReveal(offset, 3);

    EvaluationContext evaluationContext = new EvaluationContext(null, new Object());
    evaluationContext.addVariable(ISources.ACTIVE_EDITOR_NAME, contextEditor);
    ExecutionEvent executionEvent = new ExecutionEvent(null, newHashMap(), null, evaluationContext);
    renameElementHandler.execute(executionEvent);
    //		syncUtil.totalSync(refactoringPreferences.isSaveAllBeforeRefactoring());
    //		IRenameElementContext context = document.readOnly(new IUnitOfWork<IRenameElementContext,
    // XtextResource>() {
    //			public IRenameElementContext exec(XtextResource state) throws Exception {
    //				EObject target = eObjectAtOffsetHelper.resolveElementAt(state, offset);
    //				return renameContextFactory.createRenameElementContext(target, contextEditor, new
    // TextSelection(offset,
    //						3), state);
    //			}
    //		});
    //		controller.initialize(context);
    //		waitForDisplay();
    //		controller.startRefactoring(RefactoringType.LINKED_EDITING);
    //		waitForDisplay();
    pressKeys(contextEditor, "fooBar\n");
    waitForDisplay();
    waitForReconciler(fooEditor);
    waitForReconciler(barEditor);
    waitForDisplay();
  }
  public boolean matches(IJavaProject javaProject) {
    if (fStatus != null) {
      return fStatus.booleanValue();
    }

    IConfigurationElement[] children =
        fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
    if (children.length == 1) {
      try {
        ExpressionConverter parser = ExpressionConverter.getDefault();
        Expression expression = parser.perform(children[0]);
        EvaluationContext evalContext = new EvaluationContext(null, javaProject);
        evalContext.addVariable("project", javaProject); // $NON-NLS-1$
        evalContext.addVariable(
            "sourceLevel", javaProject.getOption(JavaCore.COMPILER_SOURCE, true)); // $NON-NLS-1$
        return expression.evaluate(evalContext) == EvaluationResult.TRUE;
      } catch (CoreException e) {
        JavaPlugin.log(e);
      }
      return false;
    }
    fStatus = Boolean.FALSE;
    return false;
  }
Exemple #4
0
 private void mockSelection(ISelection selection) {
   EvaluationContext context = new EvaluationContext(null, new Object());
   context.addVariable(ISources.ACTIVE_MENU_SELECTION_NAME, selection);
   when(handlerService.getCurrentState()).thenReturn(context);
 }