@Override public void renameAll(Set<OJPathName> match, String suffix) { getCatchParam().renameAll(match, suffix); getCatchPart().renameAll(match, suffix); }
public String toJavaString() { String result = ""; result = "try {\n"; result = result + JavaStringHelpers.indent(getTryPart().toJavaString(), 1); if (getCatchPart() != null) { result = result + "\n} catch (" + getCatchParam().toJavaString() + ") {\n"; result = result + JavaStringHelpers.indent(getCatchPart().toJavaString(), 1); result = result + "\n}"; } if (getFinallyPart() != null && !getFinallyPart().getStatements().isEmpty()) { if (getCatchPart() == null) { result = result + "\n} finally {\n"; } else { result = result + " finally {\n"; } result = result + JavaStringHelpers.indent(getFinallyPart().toJavaString(), 1); result = result + "\n}"; } return result; }
public void copyDeepInfoInto(OJTryStatement copy) { super.copyDeepInfoInto(copy); if (getTryPart() != null) { copy.setTryPart(getTryPart().getDeepCopy()); } if (getCatchPart() != null) { copy.setCatchPart(getCatchPart().getDeepCopy()); } if (getCatchParam() != null) { copy.setCatchParam(getCatchParam().getDeepCopy()); } if (getFinallyPart() != null) { copy.setFinallyPart(getFinallyPart().getDeepCopy()); } }
/** * 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(); } }
/** * 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 + ")"; } }
component.addToImports("java.net.URL"); ojTryStatement.setCatchParam(new OJParameter("e", new OJPathName("java.lang.Exception"))); ojTryStatement.getCatchPart().addToStatements("throw new RuntimeException(e)"); constructor.getBody().addToStatements(ojTryStatement); tryLoadClass.getTryPart().addToStatements("defaultDataCreator.createData()"); tryLoadClass.setCatchParam(new OJParameter("e", new OJPathName("java.lang.Exception"))); tryLoadClass.getCatchPart().addToStatements("throw new RuntimeException(e)"); constructor.getBody().addToStatements(ifCreateDefaultData); component.addToImports(UmlgRestletGenerationUtil.DefaultDataCreator);
protected void addImportsRecursively(OJBlock body) { if (body != null) { for (OJField ojField : body.getLocals()) { this.addToImports(ojField.getType()); } for (OJStatement s : body.getStatements()) { if (s instanceof OJIfStatement) { addImportsRecursively(((OJIfStatement) s).getThenPart()); addImportsRecursively(((OJIfStatement) s).getElsePart()); } else if (s instanceof OJBlock) { addImportsRecursively(((OJBlock) s)); } else if (s instanceof OJTryStatement) { addImportsRecursively(((OJTryStatement) s).getTryPart()); addImportsRecursively(((OJTryStatement) s).getCatchPart()); } else if (s instanceof OJWhileStatement) { addImportsRecursively(((OJWhileStatement) s).getBody()); } else if (s instanceof OJForStatement) { addImportsRecursively(((OJForStatement) s).getBody()); addToImports(((OJForStatement) s).getElemType()); } else if (s instanceof OJSwitchStatement) { for (OJSwitchCase ojSwitchCase : ((OJSwitchStatement) s).getCases()) { addImportsRecursively(ojSwitchCase.getBody()); } } } } }
ojTry.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); OJIfStatement ifRuntime = new OJIfStatement("e instanceof RuntimeException"); ifRuntime.addToThenPart("throw (RuntimeException)e"); ojTry.getCatchPart().addToStatements(ifRuntime); ojTry.getCatchPart().addToStatements("throw new RuntimeException(e)"); put.getBody().addToStatements(ojTry); ojTry.getFinallyPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()");
ojTry.setCatchParam(new OJParameter("e", new OJPathName("java.lang.Exception"))); ojTry.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); ojTry.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); annotatedClass.addToImports(UmlgRestletGenerationUtil.UmlgExceptionUtilFactory); delete.getBody().addToStatements(ojTry);
private void addFromJson(Class clazz) { OJAnnotatedClass annotatedClass = findOJClass(clazz); OJAnnotatedOperation fromJson = new OJAnnotatedOperation("fromJson"); fromJson.addParam("json", new OJPathName("String")); UmlgGenerationUtil.addOverrideAnnotation(fromJson); annotatedClass.addToOperations(fromJson); OJField objectMapper = new OJField("mapper", UmlgGenerationUtil.ObjectMapper); objectMapper.setInitExp(UmlgGenerationUtil.ObjectMapperFactory.getLast() + ".INSTANCE.getObjectMapper()"); annotatedClass.addToImports(UmlgGenerationUtil.ObjectMapperFactory); fromJson.getBody().addToLocals(objectMapper); OJTryStatement tryS = new OJTryStatement(); OJAnnotatedField propertyMap = new OJAnnotatedField("propertyMap", new OJPathName("java.util.Map").addToGenerics("String").addToGenerics("Object")); propertyMap.setInitExp("mapper.readValue(json, Map.class)"); propertyMap.addAnnotationIfNew(new OJAnnotationValue(new OJPathName("java.lang.SuppressWarnings"), "unchecked")); tryS.getTryPart().addToLocals(propertyMap); tryS.getTryPart().addToStatements("fromJson(propertyMap)"); tryS.setCatchParam(new OJParameter("e", new OJPathName("java.lang.Exception"))); tryS.getCatchPart().addToStatements("throw new RuntimeException(e)"); fromJson.getBody().addToStatements(tryS); }
ojTry.getCatchPart().addToStatements(ifRuntime); ojTry.getCatchPart().addToStatements("throw new RuntimeException(e)"); put.getBody().addToStatements(ojTry);
ojTryStatement.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); ojTryStatement.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); annotatedClass.addToImports(UmlgRestletGenerationUtil.UmlgExceptionUtilFactory);
tryInstantiate.getCatchPart().addToStatements("throw new RuntimeException(e)");
ojTryStatement.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); annotatedClass.addToImports(UmlgRestletGenerationUtil.UmlgExceptionUtilFactory);
ojTryStatement.getTryPart().addToStatements(pWrap.setter() + "(" + pWrap.fieldname() + ")"); ojTryStatement.setCatchParam(new OJParameter("e", "java.lang.Exception")); ojTryStatement.getCatchPart().addToStatements("throw new RuntimeException(e)"); ojTryStatement.getTryPart().addToStatements(pWrap.adder() + "(" + pWrap.fieldname() + ")"); ojTryStatement.setCatchParam(new OJParameter("e", "java.lang.Exception")); ojTryStatement.getCatchPart().addToStatements("throw new RuntimeException(e)");
ojTryStatement.getTryPart().addToStatements("return new " + UmlgRestletGenerationUtil.JsonRepresentation.getLast() + "(json.toString())"); ojTryStatement.setCatchParam(new OJParameter("e", new OJPathName("java.lang.Exception"))); ojTryStatement.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); ojTryStatement.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); ojTryStatement.getFinallyPart().addToStatements(UmlgGenerationUtil.UmlgTmpIdManager.getLast() + ".INSTANCE.remove()"); annotatedClass.addToImports(UmlgGenerationUtil.UmlgTmpIdManager);
tryInstantiate.getCatchPart().addToStatements("throw new RuntimeException(e)");
ojTryStatement.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); ojTryStatement.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); annotatedClass.addToImports(UmlgRestletGenerationUtil.UmlgExceptionUtilFactory);
ojTryStatement.getCatchPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); ojTryStatement.getCatchPart().addToStatements("throw " + UmlgRestletGenerationUtil.UmlgExceptionUtilFactory.getLast() + ".getTumlExceptionUtil().handle(e)"); annotatedClass.addToImports(UmlgRestletGenerationUtil.UmlgExceptionUtilFactory); post.getBody().addToStatements(ojTryStatement);
tryInstantiate.getCatchPart().addToStatements("throw new RuntimeException(e)");