public OJForStatement getDeepCopy() { OJForStatement copy = new OJForStatement(); copyDeepInfoInto(copy); return copy; }
public void copyDeepInfoInto(OJForStatement copy) { super.copyDeepInfoInto(copy); copy.setElemName(getElemName()); copy.setCollection(getCollection()); if (getElemType() != null) { copy.setElemType(getElemType().getDeepCopy()); } if (getBody() != null) { copy.setBody(getBody().getDeepCopy()); } }
public void renameAll(Set<OJPathName> renamePathNames, String suffix) { if (getElemType() != null) { getElemType().renameAll(renamePathNames, suffix); } setCollection(replaceAll(getCollection(), renamePathNames, suffix)); if (getBody() != null) { getBody().renameAll(renamePathNames, suffix); } } }
private void addCreateEdgeSchemas(OJAnnotatedClass globalMap) { OJAnnotatedOperation createEdgeSchemas = new OJAnnotatedOperation("createEdgeSchemas"); UmlgGenerationUtil.addOverrideAnnotation(createEdgeSchemas); createEdgeSchemas.addParam("edgeSchemaCreator", UmlgGenerationUtil.EdgeSchemaCreator); OJForStatement ojForStatement = new OJForStatement("label", new OJPathName("String"), UmlgGenerationUtil.QualifiedNameEdgeSchemaSet); ojForStatement.getBody().addToStatements("edgeSchemaCreator.create(label)"); createEdgeSchemas.getBody().addToStatements(ojForStatement); globalMap.addToOperations(createEdgeSchemas); }
if (pWrap.isDataType()) { if (pWrap.isEnumeration()) { ojForStatement = new OJForStatement("s", new OJPathName("String"), "(String[])umlgNode"); } else if (pWrap.isPrimitive()) { ojForStatement = new OJForStatement("s", new OJPathName(pWrap.asJavaPrimiteType()), "(" + pWrap.asJavaPrimiteType() + "[])umlgNode"); } else { ojForStatement = new OJForStatement("s", new OJPathName(pWrap.getDataTypeEnum().getPersistentType()), "(" + pWrap.getDataTypeEnum().getPersistentType() + "[])umlgNode"); ojForStatement = new OJForStatement("s", pWrap.javaBaseTypePath(), "(" + pWrap.javaBaseTypePath().getLast() + "[])umlgNode"); ojForStatement.setBody(new OJBlock()); OJSimpleStatement forStatement; if (pWrap.isDataType()) { forStatement = new OJSimpleStatement("this." + pWrap.fieldname() + ".z_internalAdder(s)"); ojForStatement.getBody().addToStatements(forStatement); statement = ojForStatement; } else {
public String toJavaString() { String result = "for ( " + getElemType().getCollectionTypeName() + " " + getElemName() + " : " + getCollection() + " ) {\n"; result = result + JavaStringHelpers.indent(getBody().toJavaString(), 1) + "\n}"; return result; }
/** Copies all attributes and associations of this instance into 'copy'. True parts, i.e. associations marked 'aggregate' or 'composite', and attributes, are copied as well. References to other objects, i.e. associations not marked 'aggregate' or 'composite', will not be copied. The 'copy' will refer to the same objects as the original (this) instance. * * @param copy */ public void copyInfoInto(OJForStatement copy) { super.copyInfoInto(copy); copy.setElemName(getElemName()); copy.setCollection(getCollection()); if ( getElemType() != null ) { copy.setElemType(getElemType()); } if ( getBody() != null ) { copy.setBody(getBody()); } }
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()); } } } } }
public OJForStatement(String elementName, OJPathName type, String collection) { this(null, null, elementName, collection); setElemType(type); setBody(new OJBlock()); }
/** Returns a copy of this instance. True parts, i.e. associations marked 'aggregate' or 'composite', and attributes, are copied as well. References to other objects, i.e. associations not marked 'aggregate' or 'composite', will not be copied. The returned copy will refer to the same objects as the original (this) instance. */ public OJElement getCopy() { OJForStatement result = new OJForStatement(); this.copyInfoInto(result); return result; }
public OJStatement findStatementRecursive(String name){ for(OJStatement statement:getStatements()){ if(statement.getName() != null && statement.getName().equals(name)){ return statement; } if(statement instanceof OJIfStatement){ OJIfStatement ifs = (OJIfStatement) statement; OJStatement s = ifs.getThenPart().findStatementRecursive(name); if(s == null && ifs.getElsePart()!=null){ s = ifs.getElsePart().findStatementRecursive(name); } if(s != null){ return s; } }else if(statement instanceof OJForStatement){ OJForStatement ifs = (OJForStatement) statement; OJStatement s = ifs.getBody().findStatementRecursive(name); if(s != null){ return s; } }else{ // TODO } } return null; } public OJField findLocal(String name){
/** * Constructor for OJForStatement * * @param name * @param comment * @param elemName * @param collection */ public OJForStatement(String name, String comment, String elemName, String collection) { super(name, comment, elemName, collection); setBody(new OJBlock()); }
private void addCreateVertexSchemas(OJAnnotatedClass globalMap) { OJAnnotatedOperation createVertexSchemas = new OJAnnotatedOperation("createVertexSchemas"); UmlgGenerationUtil.addOverrideAnnotation(createVertexSchemas); createVertexSchemas.addParam("vertexSchemaCreator", UmlgGenerationUtil.VertexSchemaCreator); OJForStatement ojForStatement = new OJForStatement("hierarchy", new OJPathName("List").addToGenerics("String"), UmlgGenerationUtil.QualifiedNameVertexSchemaSet); ojForStatement.getBody().addToStatements("vertexSchemaCreator.create(hierarchy)"); createVertexSchemas.getBody().addToStatements(ojForStatement); globalMap.addToOperations(createVertexSchemas); }
ojForStatement = new OJForStatement("s", pWrap.javaBaseTypePath(), "(" + pWrap.javaBaseTypePath().getLast() + "[])umlgNode"); ojForStatement.setBody(new OJBlock()); OJSimpleStatement forStatement = new OJSimpleStatement("this." + pWrap.fieldname() + ".z_internalAdder(s)"); ojForStatement.getBody().addToStatements(forStatement); statement = ojForStatement; } else {
/** * Constructor for OJForStatement */ public OJForStatement() { super(); setBody(new OJBlock()); }
private static void buildGetAssociationClassForPropertyInstance(OJAnnotatedClass owner, PropertyWrapper propertyWrapper) { OJAnnotatedOperation getAC = new OJAnnotatedOperation(propertyWrapper.associationClassGetterForProperty(), propertyWrapper.getAssociationClassPathName()); getAC.addParam(propertyWrapper.fieldname(), propertyWrapper.javaBaseTypePath()); OJForStatement forAC = new OJForStatement("ac", propertyWrapper.getAssociationClassPathName(), "this." + propertyWrapper.getAssociationClassFakePropertyName()); OJIfStatement ifStatement = new OJIfStatement("ac." + propertyWrapper.getter() + "().equals(" + propertyWrapper.fieldname() + ")", "return ac"); forAC.getBody().addToStatements(ifStatement); getAC.getBody().addToStatements(forAC); getAC.getBody().addToStatements("return null"); owner.addToOperations(getAC); }
public static void buildDeleteNotification(OJAnnotatedClass owner, OJAnnotatedOperation delete, PropertyWrapper propertyWrapper) { OJIfStatement ifChanged = new OJIfStatement(); ifChanged.setCondition("true"); PropertyWrapper otherEnd = PropertyWrapper.from(propertyWrapper.getOtherEnd()); if (otherEnd.isMany()) { OJForStatement forStatement = new OJForStatement(otherEnd.getName(), otherEnd.javaBaseTypePath(), "this." + otherEnd.getter() + "()"); forStatement.getBody().addToStatements(constructNotifierForOtherEndMany(propertyWrapper, otherEnd)); delete.getBody().addToStatements(0, forStatement); } else { ifChanged.addToThenPart( constructNotifier(propertyWrapper) ); delete.getBody().addToStatements(0, ifChanged); } owner.addToImports(UmlgClassOperations.getPathName(propertyWrapper.getOwningType()).append(UmlgClassOperations.propertyEnumName(propertyWrapper.getOwningType()))); owner.addToImports(UmlgGenerationUtil.UmlgNotificationManager); owner.addToImports(UmlgGenerationUtil.ChangeHolder); owner.addToImports(UmlgGenerationUtil.ChangeHolder); owner.addToImports("java.util.Optional"); }
OJForStatement ojForStatement = new OJForStatement("row", new OJPathName("Map<String,Integer>"), pWrap.fieldname() + "Map"); ifNotNull.addToThenPart(ojForStatement); OJSimpleStatement ojSimpleStatementConstructor = new OJSimpleStatement(pWrap.javaBaseTypePath().getLast() + " " + pWrap.fieldname() + " = " + UmlgGenerationUtil.UMLGAccess + "." + UmlgGenerationUtil.getEntity + "(row.get(\"id\"))"); ojForStatement.getBody().addToStatements(ojSimpleStatementConstructor); OJSimpleStatement ojSimpleStatementFromJson = new OJSimpleStatement(pWrap.adder() + "(" + pWrap.fieldname() + ")"); ojForStatement.getBody().addToStatements(ojSimpleStatementFromJson);
if (!pWrap.isDataType()) { if (pWrap.isMany()) { OJForStatement forChildToDelete = new OJForStatement("child", pWrap.javaBaseTypePath(), pWrap.getter() + "()"); forChildToDelete.getBody().addToStatements("child.delete()"); delete.getBody().addToStatements(forChildToDelete); } else {
OJForStatement forArray = new OJForStatement("overloadedJsonMap", new OJPathName("java.util.Map").addToGenerics(new OJPathName("String")).addToGenerics( new OJPathName("Object")), "array"); ifArrayForInsert.addToThenPart(forArray); forArray.getBody().addToStatements("add(resultMap, parentResource, overloadedJsonMap)"); ifDelete.addToThenPart(ifArrayForDelete); ojTryStatement.getTryPart().addToStatements(ifDelete); forArray = new OJForStatement("map", new OJPathName("java.util.Map").addToGenerics(new OJPathName("String")).addToGenerics( new OJPathName("Object")), "array"); ifArrayForDelete.addToThenPart(forArray); if (pWrap.isComposite()) { forArray.getBody().addToStatements("delete(map)"); } else { forArray.getBody().addToStatements("delete(parentResource, map)"); forArray = new OJForStatement("overloadedJsonMap", new OJPathName("java.util.Map").addToGenerics(new OJPathName("String")).addToGenerics( new OJPathName("Object")), "array"); ifArrayForUpdate.addToThenPart(forArray); if (pWrap.isOrdered()) { forArray.getBody().addToStatements("put(resultMap, parentResource, overloadedJsonMap)"); } else { forArray.getBody().addToStatements("put(resultMap, overloadedJsonMap)"); OJForStatement forConcreteClassifiers = new OJForStatement("baseClass", new OJPathName("Class").addToGenerics("? extends " + pWrap.javaBaseTypePath().getLast()), "resultMap.keySet()"); jsonResultBlock.addToStatements(forConcreteClassifiers); if (pWrap.isOne()) { forConcreteClassifiers.getBody().addToStatements("result.append(\"{\\\"data\\\": \")"); } else { forConcreteClassifiers.getBody().addToStatements("result.append(\"{\\\"data\\\": [\")");