/**
  * Checks body and languages list of an opaque expression.
  *
  * <p>It returns <code>true</code> if both lists have the same size. It returns <code>false</code>
  * if one of the list was bigger than the other one. In this latter case, one of the list was
  * corrected, ie enough elements where added in the list
  *
  * @param opaqueExpression the opaque expression to check
  * @return <code>true</code> if both lists already had the same size, <code>false</code> in other
  *     cases.
  */
 public static boolean checkAndCorrectLists(
     org.eclipse.uml2.uml.OpaqueExpression opaqueExpression) {
   // both lists, languages and bodies, should have the same size
   final int bodySize = opaqueExpression.getBodies().size();
   final int languageSize = opaqueExpression.getLanguages().size();
   // check both size
   // if equals, lists are supposed synchronized, it is ok
   // if less body than languages, add bodies
   // if more body, add enough languages
   if (bodySize == languageSize) {
     return true;
   } else {
     final int difference = languageSize - bodySize;
     if (difference > 0) {
       // more languages strings than body strings, add enough bodies
       for (int i = 0; i < difference; i++) {
         opaqueExpression.getBodies().add("");
       }
     } else {
       // more body strings than language strings, add enough languages
       for (int i = 0; i < (-difference); i++) {
         opaqueExpression.getLanguages().add("");
       }
     }
     // lists had to be modified, return false...
     return false;
   }
 }
  /** @generated */
  public void init_Constraint_2008(Constraint instance) {
    try {
      OpaqueExpression newInstance_0_0 = UMLFactory.eINSTANCE.createOpaqueExpression();
      instance.setSpecification(newInstance_0_0);
      Object value_0_0_0 =
          UMLOCLFactory.getExpression(13, UMLPackage.eINSTANCE.getOpaqueExpression(), null)
              .evaluate(newInstance_0_0);
      if (value_0_0_0 instanceof Collection) {
        newInstance_0_0.getLanguages().clear();
        newInstance_0_0.getLanguages().addAll(((Collection) value_0_0_0));
      } else {
        newInstance_0_0.getLanguages().add((String) value_0_0_0);
      }
      Object value_0_0_1 =
          UMLOCLFactory.getExpression(14, UMLPackage.eINSTANCE.getOpaqueExpression(), null)
              .evaluate(newInstance_0_0);
      if (value_0_0_1 instanceof Collection) {
        newInstance_0_0.getBodies().clear();
        newInstance_0_0.getBodies().addAll(((Collection) value_0_0_1));
      } else {
        newInstance_0_0.getBodies().add((String) value_0_0_1);
      }

    } catch (RuntimeException e) {
      UMLDiagramEditorPlugin.getInstance()
          .logError("Element initialization failed", e); // $NON-NLS-1$				
    }
  }
 /**
  * sets the body for an OpaqueExpression for the given language.
  *
  * <p>If the language was already defined, it replaces the corresponding body. If the language was
  * not already defined, it adds it to the list of languages and adds the corresponding body.
  *
  * <p>A utility method, {@link
  * OpaqueExpression#checkAndCorrectLists(org.eclipse.uml2.uml.OpaqueExpression)} is used to
  * correct the language and body lists.
  *
  * @param opaqueExpression the opaque expression to edit.
  * @param language the language in which the body is written
  * @param body the body to save
  */
 public static void setBodyForLanguage(
     org.eclipse.uml2.uml.OpaqueExpression opaqueExpression, String language, String body) {
   // checks both lists by size
   checkAndCorrectLists(opaqueExpression);
   // checks if language exists, if not, creates one
   if (!opaqueExpression.getLanguages().contains(language)) {
     opaqueExpression.getLanguages().add(language);
     opaqueExpression.getBodies().add(body);
   } else {
     // retrieve the index of the given language in the opaque Expression
     int index = opaqueExpression.getLanguages().indexOf(language);
     // sets the body at the given index in the list of bodies.
     opaqueExpression.getBodies().set(index, body);
   }
 }
  /**
   * @see
   *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   * @param event
   * @return null
   * @throws ExecutionException
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    EObject selectedObject = getSelectedElement();

    // test if this is a constraint
    if (selectedObject instanceof Constraint) {
      Constraint constraint = (Constraint) selectedObject;

      // test if this is an opaqueExpression
      if (constraint.getSpecification() instanceof OpaqueExpression) {
        OpaqueExpression opaqueExpression = ((OpaqueExpression) constraint.getSpecification());

        // look for the good body named OCL
        int indexOfOCLBody = -1;
        for (int i = 0; i < opaqueExpression.getLanguages().size() && indexOfOCLBody == -1; i++) {
          if (opaqueExpression.getLanguages().get(i).equals("OCL")) {
            indexOfOCLBody = i;
          }
        }
        if (indexOfOCLBody != -1) {
          try {
            OCLEvaluationView view =
                (OCLEvaluationView)
                    HandlerUtil.getActiveWorkbenchWindow(event)
                        .getActivePage()
                        .showView(OCLEvaluationView.ID);
            view.compute(constraint.getContext(), opaqueExpression.getBodies().get(indexOfOCLBody));
          } catch (PartInitException e) {
            e.printStackTrace();
          }
        }
      }
    }

    return null;
  }
 public OpaqueExpression createExpression(String language, String body) {
   // TODO: We can choose between something which matches UML 1.4 in name
   // or something that matches in functionality.  We've chosen
   // functionality for now, but this will create a name conflict during
   // the migration process. - tfm
   OpaqueExpression expression = UMLFactory.eINSTANCE.createOpaqueExpression();
   expression.getLanguages().add(language);
   expression.getBodies().add(body);
   return expression;
 }
 /**
  * Returns the body for an OpaqueExpression for the given language
  *
  * @param opaqueExpression the opaque expression to edit.
  * @param language the language in which the body is written
  * @return the body for the given language or the empty string if the language was not found
  */
 public static String getBodyForLanguage(
     org.eclipse.uml2.uml.OpaqueExpression opaqueExpression, String language) {
   String body = "";
   if (language == null) {
     if (!opaqueExpression.getBodies().isEmpty()) {
       body = opaqueExpression.getBodies().get(0);
     }
   } else {
     // retrieve the index of the given language in the opaque Expression
     int index = opaqueExpression.getLanguages().indexOf(language);
     if (index != -1) {
       // language found. return the corresponding body in the bodies list.
       // List should be synchronized, ie having the same size, but be sure...
       if (index < opaqueExpression.getBodies().size()) {
         body = opaqueExpression.getBodies().get(index);
       }
     }
   }
   return body;
 }
示例#7
0
 protected static void addOcl() {
   Operation find =
       example
           .getConstructionCase()
           .createOwnedOperation(
               "findRoomPlan", list("nameToFind"), list((Type) example.getType("String")));
   Parameter result = find.createOwnedParameter("result", example.getRoomPlans());
   result.setDirection(ParameterDirectionKind.RETURN_LITERAL);
   result.setUpper(-1);
   result.setIsUnique(false);
   OpaqueExpression ocl =
       (OpaqueExpression)
           find.createBodyCondition("body")
               .createSpecification(
                   "spec", example.getRoomPlans(), UMLPackage.eINSTANCE.getOpaqueExpression());
   ocl.getLanguages().add("ocl");
   ocl.getBodies().add("housePlan.wallPlans->collect(roomPlans->any(rp|rp.name=nameToFind))");
 }
示例#8
0
  public static TransitionDetails transitionDetails(Transition trans) {
    String condition = "";
    TransitionDetails transition = new TransitionDetails();

    /// ****** guard condition ***********************
    EList<Constraint> ownedRules = trans.getOwnedRules();
    com.mbe.umlce.dataobjects.stateMachine.Guard guard =
        new com.mbe.umlce.dataobjects.stateMachine.Guard();
    for (Constraint Rule : ownedRules) {

      ValueSpecification Specifications = Rule.getSpecification();
      guard.setName(Rule.getLabel());
      OpaqueExpression expr = (OpaqueExpression) Specifications;

      condition += expr.getBodies().toString();
      guard.setBody(removeSquareBrackets(condition));
      // condition = expr.getLanguages();
      //	System.out.println("Condition : "+condition);
    }
    transition.setGuard(guard);

    Effect effect = new Effect();
    String methodBody = null;
    if ((OpaqueBehavior) trans.getEffect() != null) {
      methodBody = "";
      effect.setName(trans.getEffect().getLabel());
      // methodBody += ("\nif ( "+removeSquareBrackets(condition)+" ){\n");
      methodBody +=
          removeSquareBrackets(((OpaqueBehavior) trans.getEffect()).getBodies().toString());
      // System.out.println("Effect : "+methodBody);
      effect.setBody(methodBody);
    }

    // Trigger yet to read//

    //
    transition.setEffect(effect);
    /*		TimeEvent timeEvent=null;
    		ChangeEvent changeEvent = null;
    */
    // Triggers reading
    CallEvent callEvent = null;
    Operation operation = null;
    EList<Trigger> trigger = trans.getTriggers();
    com.mbe.umlce.dataobjects.stateMachine.Trigger trig =
        new com.mbe.umlce.dataobjects.stateMachine.Trigger();
    for (Trigger triger : trigger) {
      // System.out.println("Triger : "+triger.getQualifiedName());
      // if(triger.getEvent().getName().contains("CallEvent")){
      callEvent = (CallEvent) (triger.getEvent());
      operation = callEvent.getOperation();

      if (operation != null) {

        // System.out.println("Operation : "+operation.getLabel());
        EList<Parameter> parameters = operation.getOwnedParameters();
        ArrayList<String> param = new ArrayList<>();
        ArrayList<String> paramClass = new ArrayList<>();

        for (Parameter pm : parameters) {
          param.add(pm.getLabel());
          paramClass.add(pm.getClass().getName());
          // System.out.println("Parameters : "+pm.getLabel());
        }
        trig.setOpName(operation.getLabel());
        trig.setOpParameters(param);
        trig.setParametersClass(paramClass);
      }
    }
    transition.setTrigger(trig);
    // }
    return transition;
  }