/** * Bind an operation by copying the signature from the actual. * * @param copy the copier * @param actual the actual. If an operation, its signature is copied to the template * @param operation The operation template * @return */ public static Operation instantiateOperation( LazyCopier copy, Element actual, Operation operation) { try { Operation newOperation = copy.getCopy(operation); if (actual instanceof Operation) { for (Parameter parameter : ((Operation) actual).getOwnedParameters()) { Parameter newParam = EcoreUtil.copy(parameter); // copy parameter via EcoreUtil newParam.setType(copy.getCopy(parameter.getType())); newOperation.getOwnedParameters().add(newParam); } } TransformationContext.classifier = newOperation.getClass_(); if (actual instanceof Classifier) { bindOperation(newOperation, (Classifier) actual); } String newName = AcceleoDriverWrapper.evaluate(operation.getName(), actual, null); newOperation.setName(newName); return newOperation; } catch (TransformationException e) { // throw runtime exception throw new RuntimeException( String.format(Messages.TemplateInstantiationListener_TrafoException, e.getMessage())); } }
public static List<Parameter> filterParameters( List<Parameter> original, ParameterDirectionKind... direction) { List<ParameterDirectionKind> directionList = Arrays.asList(direction); List<Parameter> filtered = new ArrayList<Parameter>(original.size()); for (Parameter parameter : original) if (directionList.contains(parameter.getDirection())) filtered.add(parameter); return filtered; }
/** * Set correctly the invoked object, by creating it if needed. Then, notifies that the ok button * of this dialog has been pressed. * * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ @Override protected void okPressed() { // create element createdParameter = UMLFactory.eINSTANCE.createParameter(); createdParameter.setName(selectedName); createdParameter.setType((Type) selectedType); createdParameter.setDirection(selectedDirection); addParameter(createdParameter); super.okPressed(); }
/** * Gives the return parameter for this operation, or <code>null</code> if none exists. * * @return the return parameter of the operation or <code>null</code> */ private static Parameter getReturnParameter(Operation operation) { // Retrieve the return parameter (assume to be unique if defined) Parameter returnParameter = null; Iterator<Parameter> it = operation.getOwnedParameters().iterator(); while ((returnParameter == null) && (it.hasNext())) { Parameter parameter = it.next(); if (parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) { returnParameter = parameter; } } return returnParameter; }
/** * Returns operation modifiers as string, separated with comma. * * @return a string containing the modifiers */ private static String getModifiersAsString(Operation operation) { StringBuffer buffer = new StringBuffer(); boolean needsComma = false; // Return parameter modifiers Parameter returnParameter = OperationUtil.getReturnParameter(operation); if (returnParameter != null) { // non unique parameter if (!returnParameter.isUnique()) { buffer.append("nonunique"); needsComma = true; } // return parameter has ordered values if (returnParameter.isOrdered()) { if (needsComma) { buffer.append(", "); } buffer.append("ordered"); needsComma = true; } } // is the operation a query ? if (operation.isQuery()) { if (needsComma) { buffer.append(", "); } buffer.append("query"); needsComma = true; } // is the operation redefining another operation ? Iterator<Operation> it = operation.getRedefinedOperations().iterator(); while (it.hasNext()) { Operation currentOperation = it.next(); if (needsComma) { buffer.append(", "); } buffer.append("redefines "); buffer.append(currentOperation.getName()); needsComma = true; } // has the operation a constraint ? Iterator<Constraint> it2 = operation.getOwnedRules().iterator(); while (it2.hasNext()) { Constraint constraint = it2.next(); if (needsComma) { buffer.append(", "); } if (constraint.getSpecification() != null) { buffer.append(constraint.getSpecification().stringValue()); } needsComma = true; } return buffer.toString(); }
/** * {@inheritDoc} * * @see * org.eclipse.papyrus.uml.diagram.activity.edit.dialogs.CreateCallActionDialog#hasOutParameters(org.eclipse.emf.ecore.EObject) */ @Override protected boolean hasOutParameters(EObject invokedObject) { if (invokedObject instanceof Behavior) { for (Parameter param : ((Behavior) invokedObject).getOwnedParameters()) { if (ParameterDirectionKind.INOUT_LITERAL.equals(param.getDirection()) || ParameterDirectionKind.OUT_LITERAL.equals(param.getDirection())) { return true; } } } return false; }
/* * (non-Javadoc) * * @see com.cea.accordcpp.core.ui.panels.AccordAbstractPanel#checkModifications() */ @Override public boolean checkModifications() { String ptrValue = StereotypeUtil.isApplied(selectedParameter, Ptr.class) ? "*" : ""; if (!docPtr.get().equals(ptrValue)) { return true; } String refValue = StereotypeUtil.isApplied(selectedParameter, Ref.class) ? "&" : ""; if (!docRef.get().equals(refValue)) { return true; } String defaultValue = selectedParameter.getDefault(); if (defaultValue == null) { if (!docDefault.get().equals("")) { return true; } } else if (!docDefault.get().equals(defaultValue)) { return true; } String arrayValue = StereotypeUtil.isApplied(selectedParameter, Array.class) ? "[]" : ""; if (!docArray.get().equals(arrayValue)) { return true; } return false; }
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))"); }
/** * Returns the effect of the parameter as a String * * @param parameter the parameter * @return The effect of the parameter as a String */ public static String getEffectAsString(Parameter parameter) { StringBuffer buffer = new StringBuffer(); ParameterEffectKind effect = parameter.getEffect(); buffer.append(effect.toString()); if (!buffer.toString().equals("")) { // $NON-NLS-1$ buffer.insert(0, "{effect: "); // $NON-NLS-1$ buffer.append("}"); // $NON-NLS-1$ } return buffer.toString(); }
public static List<org.eclipse.uml2.uml.Property> getOnPort( org.eclipse.uml2.uml.Parameter param) { LinkedList<org.eclipse.uml2.uml.Property> result = new LinkedList<org.eclipse.uml2.uml.Property>(); for (Stereotype st : param.getAppliedStereotypes()) { if (st.getName().contains("OnPort")) { for (Property p : st.getAttributes()) { result.add(p); } } } return result; }
/** * Returns operation parameters as a string, the label is customized using a bit mask * * @param e * @return a string containing all parameters separated by commas */ private static String getParametersAsString( Message e, Operation operation, Collection<String> displayValue) { StringBuffer paramString = new StringBuffer(); Iterator<Parameter> paramIterator = operation.getOwnedParameters().iterator(); boolean firstParameter = true; int paramIndex = 0; while (paramIterator.hasNext()) { Parameter parameter = paramIterator.next(); // Do not include return parameters if (!parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) { // get the label for this parameter String parameterString = getCustomLabel(e, paramIndex, parameter, displayValue).trim(); paramIndex++; if (!parameterString.equals("")) { if (!firstParameter) { paramString.append(", "); } paramString.append(parameterString); firstParameter = false; } } } return paramString.toString(); }
/* * (non-Javadoc) * * @see com.cea.accordcpp.core.ui.panels.AccordAbstractPanel#refreshPanel() */ @Override protected void refreshPanel() { if (selectedParameter != null) { // Const isConst.setSelection(StereotypeUtil.isApplied(selectedParameter, Const.class)); // TODO: examine effect; // isConst.setSelection(selectedParameter.getEffect?); docPtr.set(StereotypeUtil.isApplied(selectedParameter, Ptr.class) ? "*" : ""); docRef.set(StereotypeUtil.isApplied(selectedParameter, Ref.class) ? "&" : ""); docDefault.set(selectedParameter.getDefault()); docArray.set(StereotypeUtil.isApplied(selectedParameter, Array.class) ? "[]" : ""); // need definition? } }
/** * Returns the string used to represent this parameter * * @param parameter a parameter * @return the string used to represent this parameter */ public static String getLabel(Parameter parameter) { StringBuffer buffer = new StringBuffer(); // visibility buffer.append(" "); // $NON-NLS-1$ buffer.append(NamedElementUtil.getVisibilityAsSign(parameter)); // direction buffer.append(" "); // $NON-NLS-1$ buffer.append(parameter.getDirection().getLiteral()); // name buffer.append(" "); // $NON-NLS-1$ if (parameter.getName() != null) { buffer.append(parameter.getName()); } // type if (parameter.getType() != null) { EList<Namespace> namespaces = parameter.allNamespaces(); buffer.append( " : " + getTypeLabel( parameter.getType(), namespaces.get(namespaces.size() - 1))); // $NON-NLS-1$ } else { buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME); // $NON-NLS-1$ } // multiplicity -> do not display [1] String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter); if (!multiplicity.trim().equals("[1]")) { // $NON-NLS-1$ buffer.append(multiplicity); } // default value if (parameter.getDefault() != null) { buffer.append(" = "); // $NON-NLS-1$ buffer.append(parameter.getDefault()); } // property modifiers buffer.append(ParameterUtil.getModifiersAsString(parameter, false)); buffer.append(getEffectAsString(parameter)); return buffer.toString(); }
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; }
/** * Returns the string representing the import block for a given classifier. * * @param aClassifier The classifier * @return The string representing the import block for a given classifier. */ public String reqImport(Classifier aClassifier) { Set<String> importedTypes = new LinkedHashSet<String>(); List<Property> attributes = aClassifier.getAttributes(); for (Property property : attributes) { String qualifiedName = this.qualifiedName(property.getType()); if (qualifiedName != null) { importedTypes.add(qualifiedName); } if (property.getUpper() != 1) { String collectionQualifiedName = this.collectionQualifiedName(aClassifier, property.isOrdered(), property.isUnique()); if (collectionQualifiedName != null) { importedTypes.add(collectionQualifiedName); } } } List<Operation> operations = aClassifier.getOperations(); for (Operation operation : operations) { String qualifiedName = this.qualifiedName(operation.getType()); if (qualifiedName != null) { importedTypes.add(qualifiedName); } if (operation.getUpper() != 1) { String collectionQualifiedName = this.collectionQualifiedName(aClassifier, operation.isOrdered(), operation.isUnique()); if (collectionQualifiedName != null) { importedTypes.add(collectionQualifiedName); } } List<Parameter> ownedParameters = operation.getOwnedParameters(); for (Parameter parameter : ownedParameters) { qualifiedName = this.qualifiedName(parameter.getType()); if (qualifiedName != null) { importedTypes.add(qualifiedName); } if (parameter.getUpper() != 1) { String collectionQualifiedName = this.collectionQualifiedName( aClassifier, parameter.isOrdered(), parameter.isUnique()); if (collectionQualifiedName != null) { importedTypes.add(collectionQualifiedName); } } } List<Type> raisedExceptions = operation.getRaisedExceptions(); for (Type type : raisedExceptions) { String exceptionQualifiedName = this.qualifiedName(type); if (exceptionQualifiedName != null) { importedTypes.add(exceptionQualifiedName); } } } List<String> sortedImportedTypes = new ArrayList<String>(importedTypes); Collections.sort(sortedImportedTypes); StringBuilder stringBuilder = new StringBuilder(); for (String importedType : sortedImportedTypes) { stringBuilder.append(IMPORT + importedType + END_IMPORT); } return stringBuilder.toString(); }
public static String getCustomLabel( Message e, int paramIndex, Parameter parameter, Collection<String> displayValue) { StringBuffer buffer = new StringBuffer(); // visibility buffer.append(" "); if (displayValue.contains(ICustomAppearance.DISP_VISIBILITY)) { buffer.append(NamedElementUtil.getVisibilityAsSign(parameter)); } // direction property if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_DIRECTION)) { buffer.append(" "); buffer.append(parameter.getDirection().getLiteral()); } boolean showEqualMark = false; // name if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_NAME)) { buffer.append(" "); String name = StringHelper.trimToEmpty(parameter.getName()); if (name.trim().length() > 0) { showEqualMark = true; } buffer.append(name); } if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_TYPE)) { // type if (parameter.getType() != null) { buffer.append(": " + StringHelper.trimToEmpty(parameter.getType().getName())); } else { buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME); } showEqualMark = true; } if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_MULTIPLICITY)) { // multiplicity -> do not display [1] String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter); buffer.append(multiplicity); } if (displayValue.contains(ICustomAppearance.DISP_DERIVE)) { String value = getValue(e, paramIndex, parameter); if (value != null) { if (showEqualMark) { buffer.append(" = "); } buffer.append(value); } } else if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_DEFAULT)) { // default value if (parameter.getDefault() != null) { if (showEqualMark) { buffer.append(" = "); } buffer.append(parameter.getDefault()); } } if (displayValue.contains(ICustomAppearance.DISP_MODIFIERS)) { boolean multiLine = displayValue.contains(ICustomAppearance.DISP_MULTI_LINE); // property modifiers String modifiers = ParameterUtil.getModifiersAsString(parameter, multiLine); if (!modifiers.equals("")) { if (multiLine) { buffer.append("\n"); } buffer.append(modifiers); } } return buffer.toString(); }