void UmlClass::generate(QTextOStream & f, QCString indent) { QVector<UmlItem> ch = children(); const QValueList<UmlActualParameter> actuals = this->actuals(); const unsigned sup = ch.size(); const QCString & stereotype = java_stereotype(); bool an_enum_pattern = (stereotype == "enum_pattern"); bool an_enum = (stereotype == "enum"); unsigned index; const char * p = javaDecl(); const char * pp = 0; const char * sep; while ((*p == ' ') || (*p == '\t')) indent += *p++; f << indent; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; f << indent; } if (*p == '\n') { f << *p++; if (*p && strncmp(p, "${members}", 10) && strncmp(p, "${items}", 8) && strncmp(p, "${cases}", 8)) f << indent; } else if (*p == '@') manage_alias(p, f); else if (*p != '$') f << *p++; else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment()); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${public}", 9)) { p += 9; if (visibility() == PublicVisibility) f << "public "; } else if (!strncmp(p, "${visibility}", 13)) { p += 13; generate_visibility(f, ""); } else if (!strncmp(p, "${final}", 8)) { p += 8; if (isJavaFinal()) f << "final "; } else if (!strncmp(p, "${abstract}", 11)) { p += 11; if (isAbstract()) f << "abstract "; } else if (! strncmp(p, "${name}", 7)) { p += 7; f << name(); generate_formals(f); } else if (!strncmp(p, "${@}", 4)) { p += 4; if (pp != 0) f << "${@}"; else if (! javaAnnotations().isEmpty()) { pp = p; p = javaAnnotations(); } } else if (an_enum_pattern) { if (!strncmp(p, "${members}", 10)) { p += 10; int current_value = 0; QCString name = this->name(); for (index = 0; index != sup; index += 1) if ((ch[index]->kind() != aNcRelation) && !((UmlClassItem *) ch[index])->javaDecl().isEmpty()) ((UmlClassItem *) ch[index])-> generate_enum_pattern_item(f, current_value, name, indent); if (*p == '}') f << indent; } else if (!strncmp(p, "${cases}", 8)) { p += 8; for (index = 0; index != sup; index += 1) if ((ch[index]->kind() != aNcRelation) && !((UmlClassItem *) ch[index])->javaDecl().isEmpty()) ((UmlClassItem *) ch[index])->generate_enum_pattern_case(f, indent); } else // strange f << *p++; } else if (! strncmp(p, "${extends}", 10)) { p += 10; // extends sep = " extends "; for (index = 0; index != sup; index += 1) { UmlItem * x = ch[index]; if (x->kind() == aRelation) ((UmlRelation *) x)->generate_extends(sep, f, actuals, stereotype); } } else if (! strncmp(p, "${implements}", 13)) { p += 13; if (stereotype != "interface") { // implements sep = " implements "; for (index = 0; index != sup; index += 1) { UmlItem * x = ch[index]; if (x->kind() == aRelation) ((UmlRelation *) x)->generate_implements(sep, f, actuals, stereotype); } } } else if (! strncmp(p, "${members}", 10)) { p += 10; // members if (an_enum) { for (index = 0; index != sup; index += 1) { if (ch[index]->kind() != aNcRelation) { UmlClassItem * it = (UmlClassItem *)ch[index]; if (! it->javaDecl().isEmpty()) it->generate_enum_member(f, indent); } } } else { for (index = 0; index != sup; index += 1) { UmlItem * it = ch[index]; if (it->kind() == aClass) { if (! ((UmlClass *) it)->javaDecl().isEmpty()) { ((UmlClass *) it)->generate(f, indent + " "); f << '\n'; } } else if ((it->kind() != aNcRelation) && !((UmlClassItem *) it)->javaDecl().isEmpty()) ((UmlClassItem *) it)->generate(f, stereotype, indent); } } if (*p == '}') f << indent; } else if (an_enum && ! strncmp(p, "${items}", 8)) { p += 8; // enums items BooL first = TRUE; for (index = 0; index != sup; index += 1) { if (ch[index]->kind() != aNcRelation) { UmlClassItem * it = (UmlClassItem *)ch[index]; if (! it->javaDecl().isEmpty()) it->generate_enum_item(f, indent, first); } } if (*p == '}') f << indent; } else // strange f << *p++; } }
void UmlOperation::gen_java_decl(QByteArray s, bool descr) { const char * p = bypass_comment(s); const QList<UmlParameter> & pa = params(); unsigned npa = pa.count(); unsigned rank; while (*p) { if (!strncmp(p, "${comment}", 10)) p += 10; else if (!strncmp(p, "${description}", 14)) p += 14; else if (!strncmp(p, "${final}", 8)) { p += 8; if (isJavaFinal()) fw.write("final "); } else if (!strncmp(p, "${visibility}", 13)) { p += 13; UmlItem::write(visibility(), javaLanguage); fw.write(' '); } else if (!strncmp(p, "${static}", 9)) { p += 9; if (isClassMember()) fw.write("static "); } else if (!strncmp(p, "${abstract}", 11)) { p += 11; if (isAbstract()) fw.write("abstract "); } else if (!strncmp(p, "${synchronized}", 15)) { p += 15; if (isJavaSynchronized()) fw.write("synchronized "); } else if (!strncmp(p, "${type}", 7)) { p += 7; write(returnType(), javaLanguage); } else if (!strncmp(p, "${name}", 7)) { p += 7; writeq(compute_name(javaNameSpec())); } else if (!strncmp(p, "${(}", 4)) { p += 4; fw.write('('); } else if (!strncmp(p, "${)}", 4)) { p += 4; fw.write(')'); } else if (!strncmp(p, "${throws}", 9)) { p += 9; const char * sep = " throws "; const QList<UmlTypeSpec> e = exceptions(); unsigned n = e.count(); for (unsigned index2 = 0; index2 != n; index2 += 1) { fw.write(sep); sep = ", "; write(e[index2], javaLanguage); } } else if (!strncmp(p, "${staticnl}", 11)) break; else if (sscanf(p, "${t%u}", &rank) == 1) { p = strchr(p, '}') + 1; if (rank < npa) write(pa[rank].type, javaLanguage); else fw.write("???"); } else if (sscanf(p, "${p%u}", &rank) == 1) { p = strchr(p, '}') + 1; if (rank < npa) writeq(pa[rank].name); else fw.write("???"); } else if (!strncmp(p, "${stereotype}", 13)) { p += 13; // get/set relation with multiplicity > 1 UmlClassMember * m = getOf(); if ((m != 0) || ((m = setOf()) != 0)) writeq(JavaSettings::relationAttributeStereotype(m->stereotype())); } else if (!strncmp(p, "${association}", 14)) { p += 14; // get/set relation with multiplicity > 1 UmlClassMember * m = getOf(); if (((m != 0) || ((m = setOf()) != 0)) && (m->kind() == aRelation)) write(((UmlRelation *) m)->association(), javaLanguage); } else if (!strncmp(p, "${@}", 4)) p += 4; else if (*p == '\r') p += 1; else if (*p == '\n') { if (descr) { fw.write("<br />"); p += 1; } else { fw.write(' '); do p += 1; while ((*p != 0) && (*p <= ' ')); } } else if ((*p == '{') || (*p == ';')) { if (descr) fw.write(*p++); else break; } else if (*p == '@') manage_alias(p); else writeq(*p++); } }
void UmlOperation::generate(QTextStream & f, const WrapperStr & cl_stereotype, WrapperStr indent) { if (!javaDecl().isEmpty()) { const char * p = javaDecl(); const char * pp = 0; const char * afterparam = 0; const Q3ValueList<UmlParameter> & params = this->params(); unsigned rank; const char * body_indent = strstr(p, "${body}"); if (body_indent != 0) { while ((body_indent != p) && ((body_indent[-1] == ' ') || (body_indent[-1] == '\t'))) body_indent -= 1; } // manage old style indent while ((*p == ' ') || (*p == '\t')) indent += *p++; f << indent; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; f << indent; } if (*p == '\n') { f << *p++; if (p == body_indent) p = generate_body(f, indent, p); else if (*p) f << indent; } else if (*p == '{') { if (afterparam != 0) { if (cl_stereotype == "@interface") { if (strstr(afterparam, "default") != 0) afterparam = 0; else { f << ";"; p = bypass_body(p); continue; } } else if (isAbstract() || (cl_stereotype == "interface")) { f << ";"; p = bypass_body(p); continue; } } f << '{'; p += 1; } else if (*p == '@') manage_alias(p, f); else if (*p != '$') { if (p == body_indent) p = generate_body(f, indent, p); else f << *p++; } else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment()); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${visibility}", 13)) { p += 13; generate_visibility(f, cl_stereotype); } else if (!strncmp(p, "${final}", 8)) { p += 8; if (isJavaFinal()) f << "final "; } else if (!strncmp(p, "${static}", 9)) { p += 9; if (isClassMember()) f << "static "; } else if (!strncmp(p, "${abstract}", 11)) { p += 11; if (isAbstract() && (cl_stereotype != "interface") && (cl_stereotype != "@interface")) f << "abstract "; } else if (!strncmp(p, "${synchronized}", 15)) { p += 15; if (isJavaSynchronized()) f << "synchronized "; } else if (!strncmp(p, "${type}", 7)) { p += 7; UmlClass::write(f, returnType()); } else if (!strncmp(p, "${stereotype}", 13)) { p += 13; // get/set relation with multiplicity > 1 f << JavaSettings::relationAttributeStereotype(stereotype()); } else if (!strncmp(p, "${name}", 7)) { p += 7; f << compute_name(); } else if (!strncmp(p, "${(}", 4)) { p += 4; f << '('; } else if (!strncmp(p, "${)}", 4)) { p += 4; f << ')'; afterparam = p; } else if (sscanf(p, "${t%u}", &rank) == 1) { if (!generate_type(params, rank, f)) param_error(parent()->name(), name(), rank); p = strchr(p, '}') + 1; } else if (sscanf(p, "${p%u}", &rank) == 1) { if (!generate_var(params, rank, f)) param_error(parent()->name(), name(), rank); p = strchr(p, '}') + 1; } else if (!strncmp(p, "${throws}", 9)) { p += 9; const char * sep; const Q3ValueList<UmlTypeSpec> & exceptions = this->exceptions(); Q3ValueList<UmlTypeSpec>::ConstIterator it; for (it = exceptions.begin(), sep = " throws "; it != exceptions.end(); ++it, sep = ", ") { f << sep; UmlClass::write(f, *it); } } else if (!strncmp(p, "${staticnl}", 11)) { p += 11; if (isClassMember()) { f << '\n'; if (*p) f << indent; } else f << ' '; } else if (!strncmp(p, "${body}", 7) && (pp == 0)) // not in comment p = generate_body(f, indent, p); else if (!strncmp(p, "${association}", 14)) { p += 14; UmlClassMember * m; if (((m = getOf()) != 0) && (m->kind() == aRelation)) UmlClass::write(f, ((UmlRelation *) m)->association()); else if (((m = setOf()) != 0) && (m->kind() == aRelation)) UmlClass::write(f, ((UmlRelation *) m)->association()); } else if (!strncmp(p, "${@}", 4)) { p += 4; if (pp != 0) f << "${@}"; else if (! javaAnnotations().isEmpty()) { pp = p; p = javaAnnotations(); } } else f << *p++; } f << '\n'; } }
void UmlClass::gen_java_decl(QCString s, bool descr) { const char * p = bypass_comment(s); UmlRelation * extend = 0; while (*p != 0) { if (!strncmp(p, "${comment}", 10)) p += 10; else if (!strncmp(p, "${description}", 14)) p += 14; else if (!strncmp(p, "${public}", 9)) { p += 9; if (isJavaPublic()) fw.write("public "); } else if (!strncmp(p, "${visibility}", 13)) { p += 13; UmlItem::write(visibility(), javaLanguage); fw.write(' '); } else if (!strncmp(p, "${final}", 8)) { p += 8; if (isJavaFinal()) fw.write("final "); } else if (!strncmp(p, "${abstract}", 11)) { p += 11; if (isAbstract()) fw.write("abstract "); } else if (!strncmp(p, "${name}", 7)) { p += 7; writeq(name()); generics(); } else if (!strncmp(p, "${extends}", 10)) { p += 10; const QVector<UmlItem> ch = children(); for (unsigned i = 0; i != ch.size(); i += 1) { if (ch[i]->kind() == aRelation) { UmlRelation * rel = (UmlRelation *) ch[i]; aRelationKind k = rel->relationKind(); if (((k == aGeneralisation) || (k == aRealization)) && (!rel->javaDecl().isEmpty()) && ((JavaSettings::classStereotype(stereotype()) == "interface") || (JavaSettings::classStereotype(rel->roleType()->stereotype()) != "interface"))) { extend = rel; fw.write(" extends "); rel->roleType()->write(); generate(actuals(), rel->roleType(), FALSE); break; } } } } else if (!strncmp(p, "${implements}", 13)) { p += 13; const QVector<UmlItem> ch = children(); const char * sep = " implements "; for (unsigned i = 0; i != ch.size(); i += 1) { if (ch[i]->kind() == aRelation) { UmlRelation * rel = (UmlRelation *) ch[i]; aRelationKind k = rel->relationKind(); if ((rel != extend) && ((k == aGeneralisation) || (k == aRealization)) && (!rel->javaDecl().isEmpty())) { fw.write(sep); sep = ", "; rel->roleType()->write(); generate(actuals(), rel->roleType(), FALSE); } } } } else if (!strncmp(p, "${@}", 4)) p += 4; else if (*p == '\r') p += 1; else if (*p == '\n') { if (descr) { fw.write("<br />"); p += 1; } else { fw.write(' '); do p += 1; while ((*p != 0) && (*p <= ' ')); } } else if ((*p == '{') || (*p == ';')) { if (descr) fw.write(*p++); else break; } else if (*p == '@') manage_alias(p); else writeq(*p++); } }