/** * Build a returnparameter. Removes all current return parameters from the operation and adds the * supplied parameter. The directionkind of the parameter will be return. The name will be equal * to the name of the last found return parameter or the default value "return" if no return * parameter was present in the operation. * * @param operation * @param newReturnParameter */ public void setReturnParameter(MOperation operation, MParameter newReturnParameter) { Iterator params = operation.getParameters().iterator(); String name = "return"; while (params.hasNext()) { MParameter parameter = (MParameter) params.next(); if ((parameter.getKind()).equals(MParameterDirectionKind.RETURN)) { operation.removeParameter(parameter); if (parameter.getName() != null || parameter.getName() == "") { name = parameter.getName(); } } } newReturnParameter.setName(name); newReturnParameter.setKind(MParameterDirectionKind.RETURN); operation.addParameter(0, newReturnParameter); // we set the listeners to the figs here too // it would be better to do that in the figs themselves Project p = ProjectBrowser.TheInstance.getProject(); Iterator it = p.findFigsForMember(operation).iterator(); while (it.hasNext()) { MElementListener listener = (MElementListener) it.next(); // UmlModelEventPump.getPump().removeModelEventListener(listener, newReturnParameter); UmlModelEventPump.getPump().addModelEventListener(listener, newReturnParameter); } }
/** * Returns all return parameters for an operation. * * @param operation * @return Collection */ public Collection getReturnParameters(MOperation operation) { Vector returnParams = new Vector(); MParameter firstReturnParameter = null; Iterator params = operation.getParameters().iterator(); while (params.hasNext()) { MParameter parameter = (MParameter) params.next(); if ((parameter.getKind()).equals(MParameterDirectionKind.RETURN)) { returnParams.add(parameter); } } return (Collection) returnParams; }
/** * this method finds all paramters of the given operation which have the MParamterDirectionType * RETURN. If it is only one, it is returned. In case there are no return parameters, null is * returned. If there is more than one return paramter, first of them is returned, but a message * is written to System.out * * @param operation the operation you want to find the return parameter for * @return If this operation has only one paramter with Kind: RETURN, this is it, otherwise null */ public MParameter getReturnParameter(MOperation operation) { Vector returnParams = new Vector(); MParameter firstReturnParameter = null; Iterator params = operation.getParameters().iterator(); while (params.hasNext()) { MParameter parameter = (MParameter) params.next(); if ((parameter.getKind()).equals(MParameterDirectionKind.RETURN)) { returnParams.add(parameter); } } switch (returnParams.size()) { case 1: return (MParameter) returnParams.elementAt(0); case 0: cat.debug("No ReturnParameter found!"); return null; default: cat.debug("More than one ReturnParameter found, returning first!"); return (MParameter) returnParams.elementAt(0); } }