void UmlItem::write_multiplicity(FileOut & out, WrapperStr s, UmlItem * who) { if (!s.isEmpty()) { WrapperStr min; WrapperStr max; int index = s.find(".."); if (index != -1) { min = s.left(index).stripWhiteSpace(); max = s.mid(index + 2).stripWhiteSpace(); } else min = max = s.stripWhiteSpace(); out.indent(); out << "<lowerValue xmi:type=\"uml:LiteralString\""; out.id_prefix(who, "MULTIPLICITY_L_"); out << " value=\"" << min.operator QString() << "\"/>\n"; out.indent(); out << "<upperValue xmi:type=\"uml:LiteralString\""; out.id_prefix(who, "MULTIPLICITY_U_"); out << " value=\"" << max.operator QString() << "\"/>\n"; } }
bool UmlAttribute::manage_enum_item(WrapperStr name, UmlClass * cl #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { WrapperStr comment = Lex::get_comments(); WrapperStr description = Lex::get_description(); UmlAttribute * item = 0; // initialize to avoid warning #ifdef ROUNDTRIP Class * container = 0; // initialize to avoid warning bool created = FALSE; // initialize to avoid warning #endif if (!Package::scanning()) { #ifdef ROUNDTRIP container = cl->get_class(); if (!roundtrip || ((item = search_attr(container, name)) == 0)) { #endif if ((item = UmlBaseAttribute::create(cl, name)) == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add enum item <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } item->set_Visibility(PublicVisibility); #ifdef ROUNDTRIP if (roundtrip) container->set_updated(); created = TRUE; } #endif } Lex::mark(); WrapperStr aux; WrapperStr s; if ((s = Lex::read_word()).isEmpty()) { if (! Package::scanning()) Lex::premature_eof(); return FALSE; } else if ((s == ";") || (s == "}")) { aux = Lex::region(); Lex::unread_word(s); } else if (s == ",") { aux = Lex::region(); Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); } else if ((s == "(") || (s == "{")) { char c = UmlOperation::skip_expr(1); // goes after opt init and body if (c == 0) { if (! Package::scanning()) Lex::premature_eof(); return FALSE; } // c is ',' or ';' if (c == ';') Lex::unread_word(";"); aux = Lex::region(); } else { if (! Package::scanning()) Lex::error_near(s); return FALSE; } if (!Package::scanning()) { // here aux = opt init and body + final character , ; or } WrapperStr decl = JavaSettings::enumItemDecl(); int index; if ((decl.find("${name}") == -1) || ((index = decl.find("${value}")) == -1)) { decl = " ${name}${value},${comment}"; index = decl.find("${value}"); } //aux.resize(aux.length()); // remove , ; or }, warning resize count \000 //warn_WrapperStr if (!aux.stripWhiteSpace().isEmpty()) decl.replace(index, 8, aux); #ifdef ROUNDTRIP if (roundtrip && !created) { if (decl.find("${description}") != -1) { if (nequal(item->description(), description)) { item->set_Description(description); container->set_updated(); } } else if (nequal(item->description(), Lex::simplify_comment(comment))) { item->set_Description(comment); // comment was changed container->set_updated(); } if (neq(item->javaDecl(), decl)) { item->set_JavaDecl(decl); container->set_updated(); } item->set_usefull(); expected_order.append(item); } else { #endif if (!comment.isEmpty()) item->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); item->set_JavaDecl(decl); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(item); } #endif } return TRUE; }
bool RelationData::tool_cmd(ToolCom * com, BrowserRelation * rel, const char * args) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!rel->is_writable() && !root_permission()) com->write_ack(FALSE); else { RoleData & r = (rel == start) ? a : b; switch ((unsigned char) args[-1]) { case setDescriptionCmd: r.comment = args; break; case setStereotypeCmd: set_stereotype(args); modified(); com->write_ack(TRUE); // send the other side to update it if (rel == start) { if (end != 0) end->write_id(com); else com->write_id(0); } else start->write_id(com); return TRUE; case setRelationAssocClassCmd: { AType t; com->get_type(t, args); set_association(t); modified(); com->write_ack(TRUE); // send the other side to update it if (rel == start) { if (end != 0) end->write_id(com); else com->write_id(0); } else start->write_id(com); } return TRUE; case setNameCmd: name = args; break; case setDefaultValueCmd: r.init_value = args; break; case setIsClassMemberCmd: r.isa_class_relation = (*args != 0); break; case setIsVolatileCmd: r.isa_volatile_relation = (*args != 0); break; case setVisibilityCmd: { UmlVisibility v; if (! com->get_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } r.uml_visibility = v; } break; case setConstraintCmd: r.constraint = args; break; case setCppDeclCmd: r.cpp_decl = args; break; case setJavaDeclCmd: r.java_decl = args; break; case setJavaAnnotationCmd: { WrapperStr s = args; s = s.stripWhiteSpace(); if (! s.isEmpty()) s += '\n'; r.java_annotation = s; } break; case setPhpDeclCmd: r.php_decl = args; break; case setPythonDeclCmd: r.python_decl = args; break; case setIdlDeclCmd: r.idl_decl = args; break; case setCppVisibilityCmd: { UmlVisibility v; if (! com->get_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } r.cpp_visibility = v; } break; case setIsReadOnlyCmd: r.isa_const_relation = (*args != 0); break; case setIsCppMutableCmd: r.cpp_mutable = (*args != 0); break; case setRoleNameCmd: if ((rel == start) ? wrong_role_a_name(args) : wrong_role_b_name(args)) { com->write_ack(FALSE); return TRUE; } r.role = args; break; case setMultiplicityCmd: r.multiplicity = args; break; case setCppVirtualInheritanceCmd: r.cpp_virtual_inheritance = (*args != 0); break; case setIsIdlTruncatableCmd: r.idl_truncatable_inheritance = (*args != 0);; break; case setIsJavaTransientCmd: r.java_transient = (*args != 0); break; case setIdlCaseCmd: { BrowserAttribute * at = (BrowserAttribute *) com->get_id(args); set_idlcase(r, at, args); } break; case setDerivedCmd: switch (*args) { case 0: r.is_derived = r.is_derivedunion = FALSE; break; case 1: r.is_derived = TRUE; r.is_derivedunion = FALSE; break; case 3: r.is_derived = r.is_derivedunion = TRUE; break; default: // derived union but non derived com->write_ack(FALSE); return TRUE; } break; case setOrderingCmd: r.is_ordered = (*args != 0); break; case setUniqueCmd: r.is_unique = (*args != 0); break; case setTypeCmd: // only inside associations { UmlCode c; if (!com->get_relation_kind(c, args)) { com->write_ack(FALSE); return TRUE; } else { type = c; if (end) end->package_modified(); if (check_end_visibility()) end->modified(); start->modified(); start->package_modified(); modified(); } } break; default: return FALSE; } // ok case if (rel == start) { start->modified(); start->package_modified(); } else { end->modified(); end->package_modified(); } modified(); com->write_ack(TRUE); } } else { switch ((unsigned char) args[-1]) { case getDefCmd: send_uml_def(com, rel); send_cpp_def(com, rel); send_java_def(com, rel); if (com->api_format() >= 34) { send_php_def(com, rel); if (com->api_format() >= 39) send_python_def(com, rel); } send_idl_def(com, rel); break; case getUmlDefCmd: send_uml_def(com, rel); break; case getCppDefCmd: send_uml_def(com, rel); send_cpp_def(com, rel); break; case getJavaDefCmd: send_uml_def(com, rel); send_java_def(com, rel); break; case getPhpDefCmd: send_uml_def(com, rel); send_php_def(com, rel); break; case getPythonDefCmd: send_uml_def(com, rel); send_python_def(com, rel); break; case getIdlDefCmd: send_uml_def(com, rel); send_idl_def(com, rel); break; case sideCmd: if (*args) start->write_id(com); else if (end != 0) end->write_id(com); else com->write_id(0); break; default: return FALSE; } } return TRUE; }
bool ClassData::tool_cmd(ToolCom * com, const char * args, BrowserNode * bn, const QString & comment) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!bn->is_writable() && !root_permission()) com->write_ack(FALSE); else { switch ((unsigned char) args[-1]) { case setIsAbstractCmd: if ((*args == 0) && strcmp(browser_node->get_stereotype(), "enum") && ((BrowserClass *) browser_node)->have_abstract_operation()) { com->write_ack(FALSE); return TRUE; } else is_abstract = (*args != 0); break; case setActiveCmd: is_active = (*args != 0); break; case setVisibilityCmd: { UmlVisibility v; if (! com->get_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } else uml_visibility = v; } break; case setBaseTypeCmd: if (stereotype != "typedef") { com->write_ack(FALSE); return TRUE; } else { AType t; com->get_type(t, args); set_base_type(t); } break; case setConstraintCmd: constraint = args; break; case setIsCppExternalCmd: cpp_external = (*args != 0); break; case setCppVisibilityCmd: { UmlVisibility v; if (! com->get_extended_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } else cpp_visibility = v; } break; case setCppDeclCmd: cpp_decl = args; break; case setIsJavaExternalCmd: java_external = (*args != 0); break; case setJavaDeclCmd: java_decl = args; break; case setJavaAnnotationCmd: { WrapperStr s = args; s = s.stripWhiteSpace(); if (! s.isEmpty()) s += '\n'; java_annotation = s; } break; case setIsJavaPublicCmd: { UmlVisibility v = (*args != 0) ? UmlPublic : UmlPackageVisibility; if ((cpp_visibility == UmlDefaultVisibility) && (uml_visibility != UmlPublic) && (uml_visibility != UmlPackageVisibility)) cpp_visibility = uml_visibility; uml_visibility = v; } break; case setIsJavaFinalCmd: java_final = (*args != 0); break; case setIsPhpExternalCmd: php_external = (*args != 0); break; case setPhpDeclCmd: php_decl = args; break; case setIsPhpFinalCmd: php_final = (*args != 0); break; case setIsPythonExternalCmd: python_external = (*args != 0); break; case setPythonDeclCmd: python_decl = args; break; case setIsPython2_2Cmd: python_2_2 = (*args != 0); break; case setIdlDeclCmd: idl_decl = args; break; case setSwitchTypeCmd: if (GenerationSettings::idl_class_stereotype(stereotype) != "union") { com->write_ack(FALSE); return TRUE; } else { AType t; com->get_type(t, args); set_switch_type(t); } break; case setIsIdlExternalCmd: idl_external = (*args != 0); break; case setIsIdlLocalCmd: idl_local = (*args != 0); break; case setIsIdlCustomCmd: idl_custom = (*args != 0); break; case setIsClassMemberCmd: case setIsVolatileCmd: com->write_ack(FALSE); return TRUE; case removeFormalCmd: { unsigned rank = com->get_unsigned(args); if (rank < nformals) { if (nformals == 1) { delete [] formals; formals = 0; } else while (++rank != nformals) formals[rank - 1] = formals[rank]; nformals -= 1; DontUpdateActuals = FALSE; } else { com->write_ack(FALSE); return TRUE; } } break; case addFormalCmd: { unsigned rank = com->get_unsigned(args); if (rank <= nformals) { FormalParamData * new_formals = new FormalParamData[++nformals]; unsigned index; for (index = 0; index != rank; index += 1) new_formals[index] = formals[index]; new_formals[index].read(com, args); while (++index != nformals) new_formals[index] = formals[index - 1]; delete [] formals; formals = new_formals; DontUpdateActuals = FALSE; } else { FormalParamData::skip(com, args); com->write_ack(FALSE); return TRUE; } } break; case replaceFormalCmd: { unsigned rank = com->get_unsigned(args); if (rank < nformals) { formals[rank].read(com, args); DontUpdateActuals = FALSE; } else { FormalParamData::skip(com, args); com->write_ack(FALSE); return TRUE; } } break; case replaceActualCmd: { unsigned rank = com->get_unsigned(args); if (rank < actuals.count()) { AType t; com->get_type(t, args); actuals.at(rank)->set_value(t); } else { com->write_ack(FALSE); return TRUE; } } break; default: return BasicData::tool_cmd(com, args, bn, comment); } // ok case bn->modified(); // call modified bn->package_modified(); com->write_ack(TRUE); } } else { // get only ! switch ((unsigned char) args[-1]) { case formalsCmd: { com->write_unsigned((unsigned) nformals); for (int index = 0; index != nformals; index += 1) formals[index].send_uml_def(com); } break; case actualsCmd: { com->write_unsigned((unsigned) actuals.count()); for (ActualParamData * a = actuals.first(); a != 0; a = actuals.next()) a->send_uml_def(com); } break; default: return BasicData::tool_cmd(com, args, bn, comment); } } return TRUE; }
void UmlClass::write(QTextStream & f, bool with_formals, BooL * is_template, const QList<UmlActualParameter> & actuals) { if (! context.contains(this)) { if (parent()->kind() == aClass) { if (! context.contains((UmlClass *) parent())) { // parent cannot have formals, but may have actuals ((UmlClass *) parent())->write(f, FALSE, 0, actuals); f << "::"; } } else { UmlArtifact * cp = associatedArtifact(); WrapperStr nasp = ((UmlPackage *) ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package()) ->cppNamespace(); if (CppSettings::isForceNamespacePrefixGeneration() || (nasp != UmlArtifact::generation_package()->cppNamespace())) f << nasp << "::"; } } WrapperStr s; if (isCppExternal()) { s = cppDecl(); int index = s.find('\n'); s = (index == -1) ? s.stripWhiteSpace() : s.left(index).stripWhiteSpace(); if ((index = s.find("${name}")) != -1) s.replace(index, 7, name()); else if ((index = s.find("${Name}")) != -1) s.replace(index, 7, capitalize(name())); else if ((index = s.find("${NAME}")) != -1) s.replace(index, 7, name().upper().toLatin1().constData()); else if ((index = s.find("${nAME}")) != -1) s.replace(index, 7, name().lower().toLatin1().constData()); } else s = name(); // true_name if (! s.isEmpty()) { f << s; if (is_template != 0) *is_template = (s.at(s.length() - 1) == QString('>')); } else if (is_template != 0) *is_template = FALSE; if (with_formals) { QList<UmlFormalParameter> formals = this->formals(); if (! formals.isEmpty()) { const char * sep = "<"; QList<UmlFormalParameter>::ConstIterator it; for (it = formals.begin(); it != formals.end(); ++it) { f << sep << (*it).name(); sep = ", "; } f << '>'; if (is_template != 0) *is_template = TRUE; } } else if (!actuals.isEmpty()) { QList<UmlActualParameter>::ConstIterator ita; BooL need_space = FALSE; bool used = FALSE; for (ita = actuals.begin(); ita != actuals.end(); ++ita) { if ((*ita).superClass() == this) { used = TRUE; (*ita).generate(f, need_space); } } if (used) { if (need_space) f << " >"; else f << '>'; if (is_template != 0) *is_template = TRUE; } } }
bool AttributeData::tool_cmd(ToolCom * com, const char * args, BrowserNode * bn, const QString & comment) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!bn->is_writable() && !root_permission()) com->write_ack(FALSE); else { switch ((unsigned char) args[-1]) { case setIsClassMemberCmd: isa_class_attribute = (*args != 0); break; case setIsVolatileCmd: isa_volatile_attribute = (*args != 0); break; case setVisibilityCmd: { UmlVisibility v; if (! com->get_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } else uml_visibility = v; } break; case setMultiplicityCmd: multiplicity = args; break; case setConstraintCmd: constraint = args; break; case setCppDeclCmd: cpp_decl = args; break; case setJavaDeclCmd: java_decl = args; break; case setJavaAnnotationCmd: { WrapperStr s = args; s = s.stripWhiteSpace(); if (! s.isEmpty()) s += '\n'; java_annotation = s; } break; case setPhpDeclCmd: php_decl = args; break; case setPythonDeclCmd: python_decl = args; break; case setIdlDeclCmd: idl_decl = args; break; case setCppVisibilityCmd: { UmlVisibility v; if (! com->get_extended_visibility(v, args)) { com->write_ack(FALSE); return TRUE; } else cpp_visibility = v; } break; case setIsReadOnlyCmd: isa_const_attribute = (*args != 0); break; case setDefaultValueCmd: init_value = args; break; case setTypeCmd: { AType t; com->get_type(t, args); set_type(t); } break; case setIsCppMutableCmd: cpp_mutable = (*args != 0); break; case setIsJavaTransientCmd: java_transient = (*args != 0); break; case setIdlCaseCmd: { BrowserAttribute * at = (BrowserAttribute *) com->get_id(args); set_idlcase(at, args); } break; case setDerivedCmd: switch (*args) { case 0: is_derived = is_derivedunion = FALSE; break; case 1: is_derived = TRUE; is_derivedunion = FALSE; break; case 3: is_derived = is_derivedunion = TRUE; break; default: // derived union but non derived com->write_ack(FALSE); return TRUE; } break; case setOrderingCmd: is_ordered = (*args != 0); break; case setUniqueCmd: is_unique = (*args != 0); break; default: return BasicData::tool_cmd(com, args, bn, comment); } // ok case bn->modified(); bn->package_modified(); modified(); com->write_ack(TRUE); } return TRUE; } else return BasicData::tool_cmd(com, args, bn, comment); }