/**
  * Analyze the expression and provide a validation result. This method will dynamically
  * re-configure the required interpreter based on the given context.
  *
  * @param context the {@link IInterpreterContext} to use for validating this expression
  * @param expression the expression to analyze
  * @return the validation result.
  */
 public ValidationResult validateExpression(IInterpreterContext context, String expression) {
   IInterpreter interpreter = provide(context, expression);
   ValidationResult result = new ValidationResult();
   if (interpreter instanceof TypedValidation) {
     result = ((TypedValidation) interpreter).analyzeExpression(context, expression);
   } else if (interpreter != null && interpreter.supportsValidation()) {
     result.addAllStatus(interpreter.validateExpression(context, expression));
   }
   return result;
 }
  /**
   * {@inheritDoc}
   *
   * <p>Overridden to have END_BEFORE_VARIABLE in tool precondition expression.
   */
  @Override
  protected boolean evaluatePrecondition(
      IInterpreter interpreter, EObject semanticContainer, String precondition) {
    interpreter.setVariable(END_BEFORE_VARIABLE, endBefore);

    boolean result = super.evaluatePrecondition(interpreter, semanticContainer, precondition);

    interpreter.unSetVariable(END_BEFORE_VARIABLE);
    return result;
  }
 /**
  * @param semantic The semantic root of the diagram
  * @return The new diagram name
  * @throws InterruptedException If the user pressed cancel
  */
 private String askDiagramName(final EObject semantic) throws InterruptedException {
   final IInterpreter interpreter = InterpreterUtil.getInterpreter(semantic);
   String theName = new IdentifiedElementQuery(this.description).getLabel();
   if (!StringUtil.isEmpty(this.description.getTitleExpression())) {
     try {
       theName = interpreter.evaluateString(semantic, this.description.getTitleExpression());
     } catch (final EvaluationException e) {
       RuntimeLoggerManager.INSTANCE.error(
           this.description,
           DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression(),
           e);
     }
   }
   if (uiCallBack != null) {
     theName = uiCallBack.askForDetailName(theName, this.description.getEndUserDocumentation());
   }
   return theName;
 }
  private IInterpreter provide(IInterpreterContext context, String expression) {
    if (currentContext == null) {
      createNewInterpreter(context, expression);
    } else {
      if (!IInterpreterContextUtils.haveSameScopeDefinition(context, currentContext)) {
        if (currentInterpreter != null) {
          currentInterpreter.dispose();
        }
        createNewInterpreter(context, expression);
      }
    }

    return currentInterpreter;
  }
 @Override
 public boolean canExecute() {
   boolean canExecute = true;
   if (getCreationTool() != null) {
     if (getCreationTool().getFirstModelOperation() == null) {
       canExecute = false;
     } else {
       if (getCreationTool().getPrecondition() != null
           && !StringUtil.isEmpty(getCreationTool().getPrecondition().trim())) {
         IInterpreter interpreter = null;
         try {
           if (getTreeItem() != null) {
             interpreter = InterpreterUtil.getInterpreter(getTreeItem().getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.ROOT, TreeHelper.getTree(getTreeItem()).getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.ELEMENT, getTreeItem().getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.CONTAINER,
                 ((DTreeItemContainer) getTreeItem().eContainer()).getTarget());
             canExecute =
                 interpreter.evaluateBoolean(
                     getTreeItem().getTarget(), getCreationTool().getPrecondition());
           } else {
             interpreter = InterpreterUtil.getInterpreter(getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.ROOT, getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.ELEMENT, getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.CONTAINER, null);
             canExecute =
                 interpreter.evaluateBoolean(
                     getTable().getTarget(), getCreationTool().getPrecondition());
           }
         } catch (final EvaluationException e) {
           RuntimeLoggerManager.INSTANCE.error(
               getCreationTool(),
               ToolPackage.eINSTANCE.getAbstractToolDescription_Precondition(),
               e);
         }
         interpreter.unSetVariable(IInterpreterSiriusVariables.ROOT);
         interpreter.unSetVariable(IInterpreterSiriusVariables.ELEMENT);
         interpreter.unSetVariable(IInterpreterSiriusVariables.CONTAINER);
       }
     }
   }
   return canExecute;
 }
 public EObject debugContext(EObject context) {
   IInterpreter interpreter = InterpreterUtil.getInterpreter(context);
   System.out.println(interpreter.getVariables().keySet());
   return context;
 }