public OJSimpleStatement getDeepCopy() { OJSimpleStatement copy = new OJSimpleStatement(); copyDeepInfoInto(copy); return copy; }
/** 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() { OJSimpleStatement result = new OJSimpleStatement(); this.copyInfoInto(result); return result; }
public void addStatement(String ojStatement) { this.body.addToStatements(new OJSimpleStatement(ojStatement)); }
public void addToStatements(int indexOfRemoveVertex,String expression){ if(expression.length() == 0) return; OJSimpleStatement stat = new OJSimpleStatement(); stat.setExpression(expression); this.addToStatements(indexOfRemoveVertex, stat); } public String toJavaString(){
public void addToStatements(String str){ if(str.length() == 0) return; OJSimpleStatement stat = new OJSimpleStatement(); stat.setExpression(str); this.addToStatements(stat); } public void addToStatements(int index,OJStatement statement){
/********************************************************************* * The operations from the model ********************************************************************/ public OJSimpleStatement getCopy() { OJSimpleStatement result = new OJSimpleStatement(); result.setExpression(this.getExpression()); return result; } public String toJavaString() {
private void addUMLG(OJAnnotatedClass groovyImporter) { groovyImporter.addToStaticBlock( new OJSimpleStatement( "imports.add(\"" + UmlgGenerationUtil.UmlgAdaptorPackage.toJavaString() + ".*\")" ) ); }
public void addToStatements(String name, String str){ if(str.length() == 0) return; OJSimpleStatement stat = new OJSimpleStatement(); stat.setName(name); stat.setExpression(str); this.addToStatements(stat); }
private void addPrimitiveInitVariables(OJAnnotatedClass annotatedClass, Class clazz) { OJOperation initVariables = new OJAnnotatedOperation(INIT_DATE_TYPE_VARIABLES_WITH_DEFAULT_VALUES); if (UmlgClassOperations.hasSupertype(clazz)) { OJSimpleStatement simpleStatement = new OJSimpleStatement("super." + INIT_DATE_TYPE_VARIABLES_WITH_DEFAULT_VALUES + "()"); if (initVariables.getBody().getStatements().isEmpty()) { initVariables.getBody().addToStatements(simpleStatement); } else { initVariables.getBody().getStatements().set(0, simpleStatement); } } annotatedClass.addToOperations(initVariables); }
private void addEntry(OJAnnotatedClass groovyImporter, Class clazz) { groovyImporter.addToStaticBlock( new OJSimpleStatement( // "imports.add(\"" + Namer.name(clazz.getNearestPackage()) + "*\")" "imports.add(\"" + Namer.name(clazz.getNearestPackage()) + "." + Namer.name(clazz) + "\")" ) ); groovyImporter.addToStaticBlock( new OJSimpleStatement( "importStatic.add(\"" + Namer.name(clazz.getNearestPackage()) + "." + UmlgClassOperations.className(clazz) + "." + UmlgClassOperations.propertyEnumName(clazz) + "\")" ) ); }
private void addInitVariables(OJAnnotatedClass annotatedClass, Class clazz) { OJOperation initVariables = new OJAnnotatedOperation(INIT_VARIABLES); if (UmlgClassOperations.hasSupertype(clazz)) { OJSimpleStatement simpleStatement = new OJSimpleStatement("super.initVariables()"); if (initVariables.getBody().getStatements().isEmpty()) { initVariables.getBody().addToStatements(simpleStatement); } else { initVariables.getBody().getStatements().set(0, simpleStatement); } } annotatedClass.addToOperations(initVariables); }
private static OJSimpleStatement getDefaultTinkerCollectionInitalisation(Property p, Classifier propertyConcreteOwner, OJPathName collectionPathName) { OJSimpleStatement ojSimpleStatement = new OJSimpleStatement(" new " + collectionPathName.getCollectionTypeName() + "(this"); ojSimpleStatement.setExpression(ojSimpleStatement.getExpression() + ", " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).fieldname() + "), " + "loaded"); if (new PropertyWrapper(p).isMemberOfAssociationClass() && !(propertyConcreteOwner instanceof AssociationClass)) { //The constructor for an UmlgPropertyAssociationClassSet takes 2 runtime properties, one to the property end and one to the fake property end to the association class ojSimpleStatement.setExpression(ojSimpleStatement.getExpression() + ", " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).getAssociationClassFakePropertyName() + "), loaded"); } ojSimpleStatement.setExpression(ojSimpleStatement.getExpression() + ")"); return ojSimpleStatement; }
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);
!(classifier instanceof Enumeration && pWrap.getType() instanceof DataType)) { OJSimpleStatement statement = new OJSimpleStatement("this." + pWrap.fieldname() + " = " + pWrap.javaDefaultInitialisation(classifier)); statement = new OJSimpleStatement( "this." + pWrap.getAssociationClassFakePropertyName() + " = " + pWrap.javaDefaultInitialisationForAssociationClass(classifier, true)); for (Property memberEnd : memberEnds) { PropertyWrapper pWrap = new PropertyWrapper(memberEnd); OJSimpleStatement statement = new OJSimpleStatement("this." + pWrap.fieldname() + " = " + pWrap.javaDefaultInitialisation(classifier, true)); statement.setName(pWrap.fieldname()); initialiseProperties.getBody().addToStatements(statement);
public static void addGetDataTypeProperties(OJAnnotatedClass annotatedClass, Classifier classifier) { OJAnnotatedOperation primitiveProperties = new OJAnnotatedOperation(DATE_TYPE_PROPERTIES); primitiveProperties.setReturnType(new OJPathName("java.util.Set").addToGenerics(UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy())); annotatedClass.addToImports("java.util.HashSet"); UmlgGenerationUtil.addOverrideAnnotation(primitiveProperties); annotatedClass.addToOperations(primitiveProperties); OJAnnotatedField result = new OJAnnotatedField("result", primitiveProperties.getReturnType()); primitiveProperties.getBody().addToLocals(result); if (!classifier.getGeneralizations().isEmpty()) { result.setInitExp("super." + DATE_TYPE_PROPERTIES + "()"); } else { result.setInitExp("new HashSet<" + UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy() + ">()"); } for (Property p : UmlgClassOperations.getAllOwnedProperties(classifier)) { PropertyWrapper pWrap = new PropertyWrapper(p); if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !(pWrap.isRefined()) && pWrap.getType() instanceof DataType) { String propertyRuntimeEnumName = UmlgClassOperations.propertyEnumName(classifier) + "." + pWrap.fieldname(); OJSimpleStatement addPrimitiveDefaultValueStatement; addPrimitiveDefaultValueStatement = new OJSimpleStatement("result.add(" + propertyRuntimeEnumName + ")"); primitiveProperties.getBody().addToStatements(addPrimitiveDefaultValueStatement); } } primitiveProperties.getBody().addToStatements("return result"); }
public static void addGetBooleanProperties(OJAnnotatedClass annotatedClass, Classifier classifier) { OJAnnotatedOperation booleanProperties = new OJAnnotatedOperation(BOOLEAN_PROPERTIES); booleanProperties.setReturnType(new OJPathName("java.util.Set").addToGenerics(UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy())); annotatedClass.addToImports("java.util.HashSet"); UmlgGenerationUtil.addOverrideAnnotation(booleanProperties); annotatedClass.addToOperations(booleanProperties); OJAnnotatedField result = new OJAnnotatedField("result", booleanProperties.getReturnType()); booleanProperties.getBody().addToLocals(result); if (!classifier.getGeneralizations().isEmpty()) { result.setInitExp("super." + BOOLEAN_PROPERTIES + "()"); } else { result.setInitExp("new HashSet<" + UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy() + ">()"); } for (Property p : UmlgClassOperations.getAllOwnedProperties(classifier)) { PropertyWrapper pWrap = new PropertyWrapper(p); if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !(pWrap.isRefined()) && (!(classifier instanceof Enumeration && pWrap.getType() instanceof DataType)) && pWrap.isOne() && pWrap.isBoolean()) { String propertyRuntimeEnumName = UmlgClassOperations.propertyEnumName(classifier) + "." + pWrap.fieldname(); OJSimpleStatement addBooleanStatement = new OJSimpleStatement("result.add(" + propertyRuntimeEnumName + ")"); booleanProperties.getBody().addToStatements(addBooleanStatement); } } booleanProperties.getBody().addToStatements("return result"); }
private static OJSimpleStatement getDefaultTinkerCollectionInitalisationForAssociationClass(Property p, Classifier propertyConcreteOwner, OJPathName collectionPathName, boolean withLoaded) { OJSimpleStatement ojSimpleStatement = new OJSimpleStatement(" new " + collectionPathName.getCollectionTypeName() + "(this"); if (withLoaded) { ojSimpleStatement.setExpression( ojSimpleStatement.getExpression() + ", " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).fieldname() + "), " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).getAssociationClassFakePropertyName() + "), loaded" ); } else { ojSimpleStatement.setExpression( ojSimpleStatement.getExpression() + ", " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).fieldname() + "), " + UmlgGenerationUtil.PropertyTree.getLast() + ".from(" + UmlgClassOperations.propertyEnumName(propertyConcreteOwner) + "." + new PropertyWrapper(p).getAssociationClassFakePropertyName() + ")" ); } ojSimpleStatement.setExpression(ojSimpleStatement.getExpression() + ")"); return ojSimpleStatement; }
public static void addGetDataTypeWithDefaultValues(OJAnnotatedClass annotatedClass, Classifier classifier) { OJAnnotatedOperation primitiveProperties = new OJAnnotatedOperation(DATE_TYPE_PROPERTIES_WITH_DEFAULT_VALUES); primitiveProperties.setReturnType(new OJPathName("java.util.Map").addToGenerics(UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy()).addToGenerics("Object")); annotatedClass.addToImports("java.util.HashMap"); UmlgGenerationUtil.addOverrideAnnotation(primitiveProperties); annotatedClass.addToOperations(primitiveProperties); OJAnnotatedField result = new OJAnnotatedField("result", primitiveProperties.getReturnType()); primitiveProperties.getBody().addToLocals(result); if (!classifier.getGeneralizations().isEmpty()) { result.setInitExp("super." + DATE_TYPE_PROPERTIES_WITH_DEFAULT_VALUES + "()"); } else { result.setInitExp("new HashMap<" + UmlgGenerationUtil.umlgRuntimePropertyPathName.getCopy() + ", Object>()"); } for (Property p : UmlgClassOperations.getAllOwnedProperties(classifier)) { PropertyWrapper pWrap = new PropertyWrapper(p); if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !(pWrap.isRefined()) && pWrap.getType() instanceof DataType && // pWrap.isOne() && (pWrap.getDefaultValue() != null && !pWrap.hasOclDefaultValue())) { String propertyRuntimeEnumName = UmlgClassOperations.propertyEnumName(classifier) + "." + pWrap.fieldname(); OJSimpleStatement addPrimitiveDefaultValueStatement; addPrimitiveDefaultValueStatement = new OJSimpleStatement("result.put(" + propertyRuntimeEnumName + ", " + pWrap.getDefaultValueAsJava() + ")"); primitiveProperties.getBody().addToStatements(addPrimitiveDefaultValueStatement); } } primitiveProperties.getBody().addToStatements("return result"); }
OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("result = " + pWrap.fieldname() + ".size()"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement);
OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("result = this." + pWrap.fieldname()); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement);