@Override public String getName() { return this.operation.getName(); }
result = operation.getName();
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; } }
redefinedOperationLoop : for (Operation redefinedOperation : getRedefinedOperations()) { if (name != null && !(ignoreCase ? name.equalsIgnoreCase(redefinedOperation.getName()) : name.equals(redefinedOperation.getName()))) continue redefinedOperationLoop; EList<Parameter> ownedParameterList = redefinedOperation
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; } }
/** * Callback for an OperationCallExp visit. * <p/> * Look at the source to determine operator ( -> or . ) * * @param oc the operation call expression * @return string */ @Override protected String handleOperationCallExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { String name = oc.getReferredOperation().getName(); return OclOperationExpEnum.from(name).setOJClass(this.ojClass).handleOperationExp(oc, sourceResult, argumentResults); }
sb.append(oper.getName()); sb.append("("); List<Parameter> parametersExceptReturn = getParametersExceptReturn(oper);
@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()); } }
/** * Wraps the source expression in a try catch block. If * OclIsInvalidException is caught return true else false */ @Override public String handleOperationExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { if (argumentResults.size() != 1) { throw new IllegalStateException("oclAsType operation must have one argument!"); } List<OCLExpression<Classifier>> arguments = oc.getArgument(); Type argumentType = arguments.get(0).getType(); String operationName = oc.getReferredOperation().getName(); OJAnnotatedOperation oper = new OJAnnotatedOperation(operationName + this.ojClass.countOperationsStartingWith(operationName), UmlgClassOperations.getPathName(argumentType)); oper.addParam("sourceResult", "Object"); this.ojClass.addToOperations(oper); oper.setVisibility(OJVisibilityKind.PRIVATE); if (sourceResult.equals("self")) { sourceResult = "this"; } oper.getBody().addToStatements("return ((" + argumentResults.get(0) + ")" + "sourceResult)"); if (sourceResult.equals("self")) { sourceResult = "this"; } return oper.getName() + "(" + sourceResult + ")"; } }
private OJAnnotatedOperation addOperSignature(OJAnnotatedClass ojClass, Operation oper) { OperationWrapper operWrapper = new OperationWrapper(oper); OJAnnotatedOperation ojOper = new OJAnnotatedOperation(oper.getName(), operWrapper.getReturnParamPathName()); ojOper.addToParameters(operWrapper.getOJParametersExceptReturn()); ojClass.addToOperations(ojOper); return ojOper; }
/** * Generaate the Java methods from UML. * * @param clazz * the UML class * @param ast * the JDT Java AST * @param td * TypeDeclaration JDT */ public void generateMethods(Classifier clazz, AST ast, TypeDeclaration td) { // Get all methods for this clazz // Only for this class without inheritance EList<Operation> operations = clazz.getOperations(); for (Operation operation : operations) { logger.log(Level.FINE, "Operation: " + operation.getName()); MethodDeclaration md = ast.newMethodDeclaration(); md.setName(ast.newSimpleName(operation.getName())); // Parameters, exclude the return parameter generateMethodParams(ast, td, operation, md); // Return type generateMethodReturnType(ast, td, operation, md); // Throws Exception generateMethodThrowException(ast, operation, md); // Generate Javadoc generateMethodJavadoc(ast, operation, md); // Generate Method template params generateMethodTemplateParams(ast, operation, md); } }
/** * Wraps the source expression in a try catch block. If * OclIsInvalidException is caught return true else false */ @Override public String handleOperationExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { if (argumentResults.size() != 1) { throw new IllegalStateException("oclIsTypeOf operation must have one argument!"); } Type sourceType = oc.getSource().getType(); String operationName = oc.getReferredOperation().getName(); OJAnnotatedOperation oper = new OJAnnotatedOperation(operationName + this.ojClass.countOperationsStartingWith(operationName), new OJPathName("Boolean")); oper.addParam(sourceResult, UmlgClassOperations.getPathName(sourceType)); this.ojClass.addToOperations(oper); oper.setVisibility(OJVisibilityKind.PRIVATE); oper.getBody().addToStatements("return " + sourceResult + " instanceof " + argumentResults.get(0)); if (sourceResult.equals("self")) { sourceResult = "this"; } return oper.getName() + "(" + sourceResult + ")"; } }
/** * Wraps the source expression in a try catch block. If * OclIsInvalidException is caught return true else false */ @Override public String handleOperationExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { if (argumentResults.size() != 1) { throw new IllegalStateException("oclIsKindOf operation must have one argument!"); } Type sourceType = oc.getSource().getType(); String operationName = oc.getReferredOperation().getName(); OJAnnotatedOperation oper = new OJAnnotatedOperation(operationName + this.ojClass.countOperationsStartingWith(operationName), new OJPathName("Boolean")); oper.addParam(sourceResult, UmlgClassOperations.getPathName(sourceType)); this.ojClass.addToOperations(oper); oper.setVisibility(OJVisibilityKind.PRIVATE); oper.getBody().addToStatements("return " + argumentResults.get(0) + ".class.isAssignableFrom(" + sourceResult + ".getClass())"); if (sourceResult.equals("self")) { sourceResult = "this"; } return oper.getName() + "(" + sourceResult + ")"; } }
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);
/** * Wraps the source expression in a try catch block. If * OclIsInvalidException is caught return true else false */ @Override public String handleOperationExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { if (!argumentResults.isEmpty()) { throw new IllegalStateException("oclIsInvalid operation can not have arguments!"); } String operationName = oc.getReferredOperation().getName(); OJAnnotatedOperation oper = new OJAnnotatedOperation(operationName + this.ojClass.countOperationsStartingWith(operationName), new OJPathName("Boolean")); this.ojClass.addToOperations(oper); oper.setVisibility(OJVisibilityKind.PRIVATE); OJTryStatement ojTryStatement = new OJTryStatement(); ojTryStatement.getTryPart().addToStatements("return " + sourceResult + " == null"); // ojTryStatement.getTryPart().addToStatements("return false"); ojTryStatement.setCatchParam(new OJParameter("e", UmlgGenerationUtil.umlgOclIsInvalidException.getCopy())); this.ojClass.addToImports(UmlgGenerationUtil.umlgOclIsInvalidException.getCopy()); ojTryStatement.getCatchPart().addToStatements("return true"); oper.getBody().addToStatements(ojTryStatement); return oper.getName() + "()"; // return ojTryStatement.toJavaString(); } }
String operName = getReferredOperation().getName();
/** * Wraps the source expression in a try catch block. If * OclIsInvalidException is caught return true else false */ @Override public String handleOperationExp(OperationCallExp<Classifier, Operation> oc, String sourceResult, List<String> argumentResults) { if (!argumentResults.isEmpty()) { throw new IllegalStateException("oclIsUndefined operation can not have arguments!"); } String operationName = oc.getReferredOperation().getName(); Type sourceType = oc.getSource().getType(); OJAnnotatedOperation oper = new OJAnnotatedOperation(operationName + this.ojClass.countOperationsStartingWith(operationName), new OJPathName("Boolean")); if (!(sourceType instanceof PrimitiveType) && !(sourceType instanceof Enumeration) && sourceType instanceof DataType) { oper.addParam(StringUtils.uncapitalize(sourceType.getName()), DataTypeEnum.getPathNameFromDataType((DataType) sourceType)); } else if (sourceType instanceof PrimitiveType) { oper.addParam(StringUtils.uncapitalize(sourceType.getName()), UmlgPropertyOperations.umlPrimitiveTypeToJava(sourceType)); } else { oper.addParam(StringUtils.uncapitalize(sourceType.getName()), UmlgClassOperations.getPathName(sourceType)); } this.ojClass.addToOperations(oper); oper.setVisibility(OJVisibilityKind.PRIVATE); OJTryStatement ojTryStatement = new OJTryStatement(); ojTryStatement.getTryPart().addToStatements("return " + StringUtils.uncapitalize(sourceType.getName()) + " == null"); ojTryStatement.setCatchParam(new OJParameter("e", UmlgGenerationUtil.umlgOclIsInvalidException.getCopy())); this.ojClass.addToImports(UmlgGenerationUtil.umlgOclIsInvalidException.getCopy()); ojTryStatement.getCatchPart().addToStatements("return true"); oper.getBody().addToStatements(ojTryStatement); return oper.getName() + "(" + sourceResult + ")"; } }