public OJSwitchCase getDeepCopy() { OJSwitchCase copy = new OJSwitchCase(); copyDeepInfoInto(copy); return copy; }
public void copyDeepInfoInto(OJSwitchStatement copy) { super.copyDeepInfoInto(copy); copy.setCondition(getCondition()); Iterator casesIt = new ArrayList<OJSwitchCase>(getCases()).iterator(); while (casesIt.hasNext()) { OJSwitchCase elem = (OJSwitchCase) casesIt.next(); copy.addToCases(elem.getDeepCopy()); } if (getDefCase() != null) { copy.setDefCase(getDefCase().getDeepCopy()); } }
public String toJavaString() { StringBuilder sb = new StringBuilder(); sb.append("case "); sb.append(getLabel()); sb.append(":\n"); sb.append(JavaStringHelpers.indent(getBody().toJavaString(), 1)); sb.append("\n"); if (this.breakInCase) { sb.append(JavaStringHelpers.indent("break;", 1)); sb.append("\n"); } return sb.toString(); }
if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !pWrap.isRefined()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("this." + pWrap.fieldname() + ".setLoaded(loaded)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.getAssociationClassFakePropertyName()); statement = new OJSimpleStatement("this." + pWrap.fieldname() + ".setLoaded(loaded)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); PropertyWrapper pWrap = new PropertyWrapper(memberEnd); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); ojSwitchStatement.addToCases(ojSwitchCase); annotatedClass.addToImports(UmlgPropertyOperations.getDefaultTinkerCollection(memberEnd, true));
private void addGetMetaClassForQualifiedName(OJAnnotatedClass root) { OJAnnotatedOperation getMetaClassForQualifiedName = new OJAnnotatedOperation("getMetaClassForQualifiedName", UmlgGenerationUtil.UmlgMetaNode.getLast()); getMetaClassForQualifiedName.addToParameters(new OJParameter("qualifiedName", "String")); getMetaClassForQualifiedName.addAnnotationIfNew(new OJAnnotationValue(new OJPathName("java.lang.Override"))); root.addToOperations(getMetaClassForQualifiedName); root.addToImports(UmlgGenerationUtil.UmlgMetaNode); OJSwitchStatement ojSwitchStatement = new OJSwitchStatement(); ojSwitchStatement.setCondition("qualifiedName"); for (Class clazz : ModelLoader.INSTANCE.getAllConcreteClasses()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel("\"" + clazz.getQualifiedName() + "\""); ojSwitchCase.getBody().addToStatements("return get" + UmlgClassOperations.getMetaClassPathName(clazz).getLast() + "()"); ojSwitchCase.setBreakInCase(false); ojSwitchStatement.addToCases(ojSwitchCase); } OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.getBody().addToStatements("throw new IllegalArgumentException(\"Unknown qualified name: \" + qualifiedName + \"!\")"); ojSwitchStatement.setDefCase(ojSwitchCase); getMetaClassForQualifiedName.getBody().addToStatements(ojSwitchStatement); }
public String toJavaString() { String result = "switch ( " + getCondition() + " ) {\n"; Iterator cases = getCases().iterator(); while (cases.hasNext()) { OJSwitchCase c = (OJSwitchCase) cases.next(); result = result + JavaStringHelpers.indent(c.toJavaString(), 1) + "\n"; } OJSwitchCase c = getDefCase(); if (c != null) { result = result + JavaStringHelpers.indent("default", 1) + c.getLabel() + ":\n" + JavaStringHelpers.indent(c.getBody().toJavaString(), 2) + "\n" ; } result = result + "}\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(OJSwitchCase copy) { super.copyInfoInto(copy); copy.setLabel(getLabel()); if ( getBody() != null ) { copy.setBody(getBody()); } }
/** 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() { OJSwitchCase result = new OJSwitchCase(); this.copyInfoInto(result); return result; }
/********************************************************************* * The constructor ********************************************************************/ public OJSwitchCase() { super(); this.setBody(new OJBlock()); }
public void renameAll(Set<OJPathName> renamePathNames, String newName) { Iterator casesIt = new ArrayList<OJSwitchCase>(getCases()).iterator(); while (casesIt.hasNext()) { OJSwitchCase elem = (OJSwitchCase) casesIt.next(); elem.renameAll(renamePathNames, newName); } if (getDefCase() != null) { getDefCase().renameAll(renamePathNames, newName); } }
OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("this." + pWrap.fieldname() + " = " + pWrap.javaDefaultInitialisation(classifier)); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); ojSwitchCase.getBody().addToStatements(statement); PropertyWrapper pWrap = new PropertyWrapper(memberEnd); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); ojSwitchStatement.addToCases(ojSwitchCase); annotatedClass.addToImports(UmlgPropertyOperations.getDefaultTinkerCollection(memberEnd, true));
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()); } } } } }
PropertyWrapper pWrap = new PropertyWrapper(p); if (!pWrap.isDerived() && !pWrap.isRefined()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("result = " + pWrap.fieldname() + ".size()"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.getBody().addToStatements("result = 0"); ojSwitchStatement.setDefCase(ojSwitchCase);
PropertyWrapper pWrap = new PropertyWrapper(p); if (pWrap.isQualified()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("result = " + pWrap.getQualifiedGetterName() + "((" + pWrap.getType().getName() + ")node)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.getBody().addToStatements("result = Collections.emptyList()"); ojSwitchStatement.setDefCase(ojSwitchCase);
if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !pWrap.isRefined()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJStatement statement; if (pWrap.isDataType() && pWrap.isMany()) { ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.getAssociationClassFakePropertyName()); statement = new OJSimpleStatement("this." + pWrap.getAssociationClassFakePropertyName() + ".z_internalAdder((" + pWrap.getAssociationClassPathName().getLast() + ")umlgNode)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); PropertyWrapper pWrap = new PropertyWrapper(memberEnd); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); ojSwitchStatement.addToCases(ojSwitchCase); annotatedClass.addToImports(UmlgPropertyOperations.getDefaultTinkerCollection(memberEnd, true));
PropertyWrapper pWrap = new PropertyWrapper(p); if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && pWrap.getOtherEnd() != null && !pWrap.isEnumeration() && !pWrap.isRefined()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJSimpleStatement statement = new OJSimpleStatement("this." + pWrap.fieldname() + ".inverseAdder((" + pWrap.javaBaseTypePath().getLast() + ")umlgNode)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.getAssociationClassFakePropertyName()); statement = new OJSimpleStatement("this." + pWrap.getAssociationClassFakePropertyName() + ".inverseAdder((" + pWrap.getAssociationClassPathName().getLast() + ")umlgNode)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase);
OJAnnotatedOperation getter = definingFeatureGetterMap.get(definingFeature); OJSwitchStatement ojSwitchStatement = (OJSwitchStatement) getter.getBody().getStatements().get(0); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(literal.getName()); ojSwitchStatement.addToCases(ojSwitchCase); InstanceValue instanceValue = (InstanceValue) slot.getValues().get(0); if (instanceValue.getInstance().equals(literal)) { ojSwitchCase.getBody().addToStatements( "result.add(" + slot.getOwningInstance().getClassifiers().get(0).getName() +
if (!(pWrap.isDerived() || pWrap.isDerivedUnion()) && !pWrap.isRefined()) { OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); OJStatement statement; if (pWrap.isDataType() && pWrap.isMany()) { ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); annotatedClass.addToImports(UmlgGenerationUtil.umlgFormatter); ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.getAssociationClassFakePropertyName()); statement = new OJSimpleStatement("this." + pWrap.getAssociationClassFakePropertyName() + ".z_internalAdder((" + pWrap.getAssociationClassPathName().getLast() + ")umlgNode)"); statement.setName(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); annotatedClass.addToImports(pWrap.javaImplTypePath()); ojSwitchStatement.addToCases(ojSwitchCase); PropertyWrapper pWrap = new PropertyWrapper(memberEnd); OJSwitchCase ojSwitchCase = new OJSwitchCase(); ojSwitchCase.setLabel(pWrap.fieldname()); ojSwitchCase.getBody().addToStatements(statement); ojSwitchStatement.addToCases(ojSwitchCase); annotatedClass.addToImports(UmlgPropertyOperations.getDefaultTinkerCollection(memberEnd, true));