public int compare(final Operation operation1, final Operation operation2) { int rtn = operation1.getName().compareTo(operation2.getName()); if (rtn == 0) { rtn = operation1.getOwnedParameters().size() - operation1.getOwnedParameters().size(); if (rtn == 0) { int index = 0; for (Parameter parameter : operation1.getOwnedParameters()) { rtn = parameter.getName().compareTo(operation2.getOwnedParameters().get(index).getName()); if (rtn != 0) { break; } index++; } } } return rtn; } }
/** * @see org.andromda.metafacades.uml.OperationFacade#getReturnType() */ @Override protected Type handleGetReturnType() { return this.metaObject.getType(); }
/** * @see org.andromda.metafacades.uml.OperationFacade#getParameters() */ @Override protected Collection<Parameter> handleGetParameters() { final Collection<Parameter> params = new ArrayList<Parameter>(this.metaObject.getOwnedParameters()); params.add(this.metaObject.getReturnResult()); CollectionUtils.filter( params, new Predicate() { public boolean evaluate(final Object object) { return object != null && !((Parameter)object).isException(); } }); return params; }
/** * @see org.andromda.metafacades.uml.OperationFacade#getOwner() */ @Override protected Object handleGetOwner() { Object obj = null; // Fix from UML2, no longer calls getOwner to get the owning Class if (this.metaObject.getInterface()!=null) { obj = this.metaObject.getInterface(); } else if (this.metaObject.getDatatype()!=null) { obj = this.metaObject.getDatatype(); } else { obj = this.metaObject.getClass_(); } return obj; }
@Override public Object caseOperation(Operation operation) { Namespace namespace = operation.getNamespace(); .getEGenericExceptions(); for (Type raisedException : operation.getRaisedExceptions()) { EGenericType eGenericType = getEGenericType(raisedException); .setEGenericType(getEGenericType(operation.getType())); int upper = operation.getUpper(); int lower = operation.getLower(); eOperation.setOrdered(operation.isOrdered()); eOperation.setUnique(operation.isUnique());
@Override public EList<Parameter> getOwnedParameters() { return this.operation.getOwnedParameters(); }
@Override public void visitBefore(Operation oper) { Element operOwner = oper.getOwner(); if (oper.getBodyCondition() != null && !oper.isQuery()) { throw new IllegalStateException(String.format("Operation %s on %s has a bodyCondition but is not a query.", new Object[] { oper.getName(), ((NamedElement) operOwner).getName() })); } OJAnnotatedClass ojClass; if (operOwner instanceof Interface) { ojClass = findOJClass((Interface) operOwner); addOperSignature(ojClass, oper); } else if ((operOwner instanceof org.eclipse.uml2.uml.Class) || (operOwner instanceof Enumeration)) { ojClass = findOJClass((org.eclipse.uml2.uml.Classifier) operOwner); OJAnnotatedOperation ojOper = addOperSignature(ojClass, oper); if (oper.isQuery()) { addQueryBody(ojClass, ojOper, oper); } } else { throw new IllegalStateException("Operations are only supported on Interfaces and Classes, not on " + operOwner.toString()); } }
@Override public String getName() { return this.operation.getName(); }
public static String asOclSignature(Operation oper) { StringBuilder sb = new StringBuilder(); if (oper.getClass_() != null) { sb.append(oper.getClass_().getName()); } else if (oper.getDatatype() != null) { sb.append(oper.getDatatype().getName()); } else { throw new IllegalStateException("Operation only supported on Class and Datatype"); sb.append(oper.getName()); sb.append("("); List<Parameter> parametersExceptReturn = getParametersExceptReturn(oper); Parameter returnResult = oper.getReturnResult(); if (returnResult!=null) { sb.append(" : ");
getOwnedOperations(classifier).add(operation); operation.setName(eOperation.getName()); operation.createReturnResult(null, getType(eOperation, eGenericType)); EList<Type> raisedExceptions = operation.getRaisedExceptions(); operation.setVisibility(VisibilityKind.PUBLIC_LITERAL); && upperBound != operation.getUpper()) { operation.setUpper(upperBound); if (lowerBound != operation.getLower()) { operation.setLower(lowerBound); operation.setIsOrdered(eOperation.isOrdered()); operation.setIsUnique(eOperation.isUnique());
when(iteratorOperation.hasNext()).thenReturn(true, false); when(iteratorOperation.next()).thenReturn(operation); when(operation.getName()).thenReturn("calculateMe"); when(operation.getType()).thenReturn(operationType); when(operation.getRaisedExceptions()).thenReturn(raisedExceptions); when(raisedExceptions.iterator()).thenReturn(iteratorException); when(iteratorException.hasNext()).thenReturn(true, false);
@Override public Parameter getReturnResult() { return this.operation.getReturnResult(); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public static void setIsOrdered(Operation operation, boolean newIsOrdered) { Parameter returnResult = operation.getReturnResult(); if (returnResult == null) { returnResult = operation.createOwnedParameter(null, null); returnResult.setDirection(ParameterDirectionKind.RETURN_LITERAL); } returnResult.setIsOrdered(newIsOrdered); }
public Operation defineOperation(Classifier owner, String name, Classifier type, List<Variable<Classifier, Parameter>> params, Constraint constraint) { resetTypeCaches(); Operation result = UMLFactory.eINSTANCE.createOperation(); result.addKeyword(UMLReflection.OCL_HELPER); result.setName(name); result.setType(type == null ? getOCLStandardLibrary().getOclVoid() : type); result.setIsQuery(true); // OCL can only define queries for (Variable<Classifier, Parameter> next : params) { Parameter param = UMLFactory.eINSTANCE.createParameter(); param.setName(next.getName()); param.setType(next.getType() == null ? getOCLStandardLibrary() .getOclVoid() : next.getType()); param.setDirection(ParameterDirectionKind.IN_LITERAL); param.setEffect(ParameterEffectKind.READ_LITERAL); result.getOwnedParameters().add(param); } annotate(result, constraint); addHelperOperation(owner, result); return result; }
private void generateMethodReturnType(AST ast, TypeDeclaration td, Operation operation, MethodDeclaration md) { Type type = operation.getType(); String umlTypeName = type.getName(); String umlQualifiedTypeName = type.getQualifiedName(); logger.log(Level.FINE, "UmlQualifiedTypeName: " + umlQualifiedTypeName + " - " + "umlTypeName: " + umlTypeName); if (operation.getUpper() >= 0) { // Upper Cardinality 0..1 // Only for parameterized type if (dataTypeUtils.isParameterizedType(umlTypeName)) { Map<String, String> types = umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type); umlTypeName = types.get("umlTypeName"); umlQualifiedTypeName = types.get("umlQualifiedTypeName"); } jdtHelper.createReturnType(ast, td, md, umlTypeName, umlQualifiedTypeName, sourceDirectoryPackageName); } else { // Upper Cardinality 0..* generateAssociationEndUpperCardinalityMultiples(ast, td, operation, md, umlTypeName, umlQualifiedTypeName); } }
EList<Parameter> ownedParameters = operation.getOwnedParameters(); int ownedParametersSize = ownedParameters.size(); EList<Parameter> opOwnedParameters = op.getOwnedParameters(); EList<Parameter> returnResult = operation.returnResult(); int returnResultSize = returnResult.size(); EList<Parameter> opReturnResult = op.returnResult();
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * <!-- begin-model-doc --> * A bodyCondition can only be specified for a query operation. * bodyCondition->notEmpty() implies isQuery * @param operation The receiving '<em><b>Operation</b></em>' model object. * @param diagnostics The chain of diagnostics to which problems are to be appended. * @param context The cache of context-specific information. * <!-- end-model-doc --> * @generated NOT */ public static boolean validateOnlyBodyForQuery(Operation operation, DiagnosticChain diagnostics, Map<Object, Object> context) { boolean result = true; if (operation.getBodyCondition() != null && !operation.isQuery()) { result = false; if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING, UMLValidator.DIAGNOSTIC_SOURCE, UMLValidator.OPERATION__ONLY_BODY_FOR_QUERY, UMLPlugin.INSTANCE.getString( "_UI_Operation_OnlyBodyForQuery_diagnostic", //$NON-NLS-1$ getMessageSubstitutions(context, operation)), new Object[]{operation})); } } return result; }