void UmlItem::replace_alias(WrapperStr & s) { int index = 0; while ((index = s.find("@{", index)) != -1) { int index2 = s.find('}', index + 2); if (index2 == -1) return; UmlBaseItem * obj = this; WrapperStr key = s.mid(index + 2, index2 - index - 2); WrapperStr value; for (;;) { if (obj->propertyValue(key, value)) { s.replace(index, index2 - index + 1, value); index += value.length(); break; } else if ((obj = obj->parent()) == 0) { index = index2 + 1; break; } } } }
void UmlOperation::write_cpp_returntype(FileOut & out, WrapperStr decl) { // doesn't manage function pointer // manage keywords int index; if ((index = decl.find("${static}")) != -1) decl.remove(index, 9); if ((index = decl.find("${friend}")) != -1) decl.remove(index, 9); if ((index = decl.find("${virtual}")) != -1) decl.remove(index, 10); if ((index = decl.find("${inline}")) != -1) decl.remove(index, 9); if ((index = decl.find("${(}")) == -1) decl = "${type} ${name}"; else decl.truncate(index); UmlTypeSpec t = returnType(); if ((t.type != 0) || !(t.explicit_type = CppSettings::type(t.explicit_type)).isEmpty()) write_type(out, t, decl, "${name}", "${type}"); }
static void create_directory(WrapperStr s) { int index = 0; QChar sep = QDir::separator(); //[lgfreitas] QChar does not if (sep != '/') { while ((index = s.find(sep, index)) != -1) s.replace(index++, 1, "/"); } s = QDir::cleanPath(s) + "/"; index = s.find("/"); int index2; while ((index2 = s.find("/", index + 1)) != -1) { WrapperStr s2 = s.left(index2); QDir sd(s2); if (!sd.exists()) { if (!sd.mkdir(s2)) { UmlCom::trace(WrapperStr("<font color=\"red\"><b> cannot create directory <i>") + s2 + "</i></b></font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("UmlPackage::file_path"); } } index = index2; } }
bool UmlArtifact::is_imported(WrapperStr path, WrapperStr class_name) { if (imports == 0) { imports = new QHash<WrapperStr, UmlArtifact*>; WrapperStr s = javaSource(); int index = 0; while ((index = s.find("import", index)) != -1) { if ((index == 0) || (s[index - 1] < ' ')) { int index2 = index + 6; while ((s[index2] == ' ') || (s[index2] == '\t')) index2 += 1; if ((index2 != (index + 6)) && ((index = s.find(';', index2)) != -1) && (index != index2)) { WrapperStr p = s.mid(index2, index - index2); imports->insert(p, this); } else index = index2; } else index += 6; } } return ((imports->value(path + '.' + class_name) != 0) || (imports->value(path + ".*") != 0)); }
void UmlClassMember::remove_comments(WrapperStr & s) { int index1 = 0; if ((index1 = s.find("${comment}")) != -1) s.remove((unsigned) index1, 10); else if ((index1 = s.find("${description}")) != -1) s.remove((unsigned) index1, 14); while ((index1 = s.find('/', index1)) != -1) { int index2; switch (((const char *) s)[index1 + 1]) { case '/': if ((index2 = s.find('\n', index1 + 2)) != -1) s.remove(index1, index2 - index1 + 1); else s.truncate(index1); break; case '*': if ((index2 = s.find("*/", index1 + 2)) != -1) s.replace(index1, index2 - index1 + 1, " "); else s.truncate(index1); break; default: index1 += 1; } } }
WrapperStr UmlOperation::compute_name() { WrapperStr get_set_spec = javaNameSpec(); if (! get_set_spec.isEmpty()) { UmlClassMember * it; if ((it = getOf()) == 0) it = setOf(); int index; WrapperStr s = (it->kind() == aRelation) ? ((UmlRelation *) it)->roleName() : it->name(); if ((index = get_set_spec.find("${name}")) != -1) get_set_spec.replace(index, 7, s); else if ((index = get_set_spec.find("${Name}")) != -1) get_set_spec.replace(index, 7, capitalize(s)); else if ((index = s.find("${NAME}")) != -1) get_set_spec.replace(index, 7, s.upper()); else if ((index = s.find("${nAME}")) != -1) get_set_spec.replace(index, 7, s.lower()); return get_set_spec; } else return name(); }
void UmlClass::need_artifact(const QStringList & imports, bool remove_java_lang, const QStringList & , const WrapperStr & path, UmlArtifact *& cp) { if (parent()->kind() == aClassView) { if (cp != 0) cp->addAssociatedClass(this); else { UmlPackage * pack = (UmlPackage *) parent()->parent(); if ((cp = associatedArtifact()) == 0) { // create associated artifact QFileInfo fi(path); WrapperStr artname = WrapperStr(fi.baseName().toAscii().constData()); if ((cp = UmlBaseArtifact::create(pack->get_deploymentview(), artname)) == 0) { UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ") + artname + "</i></b></font><br>"); return; } cp->addAssociatedClass(this); } cp->set_Stereotype("source"); WrapperStr s = JavaSettings::sourceContent(); int index = s.find("${definition}"); if (index != -1) { for (QStringList::const_iterator it = imports.begin(); it != imports.end(); it++) { WrapperStr import = WrapperStr((*it).toAscii().constData()); if (!remove_java_lang || (import != "java.lang.")) { import += (((const char *) import)[import.length() - 1] == '.') ? "*;\n" : ";\n"; s.insert(index, (const char *)("import " + import)); index = s.find("${definition}", index); } } for (QStringList::const_iterator it = imports.begin(); it != imports.end(); it++) { s.insert(index, (const char *)("import static" + WrapperStr((*it).toAscii().constData()) + '\n')); index = s.find("${definition}", index); } } cp->set_JavaSource(WrapperStr(s)); } } }
void remove_python_comments(WrapperStr & s) { int index1 = 0; while ((index1 = s.find('#', index1)) != -1) { int index2; if ((index2 = s.find('\n', index1 + 1)) != -1) s.remove(index1, index2 - index1 + 1); else s.truncate(index1); } }
void UmlClassMember::remove_arrays(WrapperStr & s) { int index1 = 0; while ((index1 = s.find('[', index1)) != -1) { int index2 = index1 = s.find(']', index1 + 1); if (index2 == -1) { s.truncate(index1); return; } else s.replace(index1, index2 - index1 + 1, " "); } }
static void manage_decorators(QTextStream & f, const WrapperStr & decorators, QString indent, BooL & indent_needed) { if (! decorators.isEmpty()) { int index = 0; int index2; while ((index2 = decorators.find("\n", index)) != -1) { if (indent_needed) f << indent; else indent_needed = TRUE; f << decorators.mid(index, index2 + 1 - index); index = index2 + 1; } if (index != (int) decorators.length()) { if (indent_needed) { f << indent; indent_needed = FALSE; } f << decorators.mid(index); } } }
void UmlClass::manage_generic(WrapperStr & form, UmlTypeSpec & typespec, WrapperStr str_actuals, const char * k) { if (typespec.type != 0) { int index; if (!typespec.explicit_type.isEmpty()) { if ((index = form.find(k)) != -1) form.replace(index, strlen(k), typespec.explicit_type); } else if (! str_actuals.isEmpty()) { if ((index = form.find(k)) != -1) form.insert(index + strlen(k), (const char *)str_actuals); } } }
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 UmlClass::isPrimitiveType(Token & token, UmlTypeSpec & ts) { if (token.xmiType() != "uml:PrimitiveType") return FALSE; WrapperStr href = token.valueOf("href"); int index; if (href.isEmpty() || ((index = href.find('#')) == -1)) return FALSE; ts.explicit_type = href.mid(index + 1); if ((CppSettings::type(ts.explicit_type) == ts.explicit_type) && CppSettings::umlType(ts.explicit_type).isEmpty()) { // not defined href = ts.explicit_type.lower(); if (href == "integer") ts.explicit_type = "int"; else if (href == "boolean") ts.explicit_type = "bool"; else if (href == "string") ts.explicit_type = "string"; else if (href == "unlimitednatural") ts.explicit_type = "long"; } return TRUE; }
void UmlClass::extend(WrapperStr mcl) { if (parent()->parent()->kind() != aPackage) return; int index = mcl.find('#'); if (index == -1) return; WrapperStr path = mcl.left(index); const char * defltpath0 = "http://schema.omg.org/spec/UML/2.0/uml.xml"; const char * defltpath1 = "http://schema.omg.org/spec/UML/2.1/uml.xml"; bool dflt = ((path == defltpath0) || (path == defltpath1)); mcl = mcl.mid(index + 1); static Q3PtrList<UmlClass> metaclasses; Q3PtrListIterator<UmlClass> it(metaclasses); UmlClass * metacl = UmlClass::get(mcl, 0); WrapperStr s; if ((metacl == 0) || (metacl->stereotype() != "metaclass") || !((dflt) ? (!metacl->propertyValue("metaclassPath", s) || (s == defltpath0) || (s == defltpath1)) : (metacl->propertyValue("metaclassPath", s) && (path == s)))) { metacl = 0; if (dflt) { for (; (metacl = it.current()) != 0; ++it) { if (!strcmp(mcl, metacl->name()) && (!metacl->propertyValue("metaclassPath", s) || (s == defltpath0) || (s == defltpath1))) break; } } else { for (; (metacl = it.current()) != 0; ++it) { if (!strcmp(mcl, metacl->name()) && metacl->propertyValue("metaclassPath", s) && (path == s)) break; } } if (metacl == 0) { metacl = addMetaclass(mcl, (dflt) ? 0 : (const char *)path); //[rageek] different types for ? : metaclasses.append(metacl); } } UmlRelation::create(aDirectionalAssociation, this, metacl); }
void UmlOperation::write_java_returntype(FileOut & out, WrapperStr decl) { // manage keywords int index; if ((index = decl.find("${visibility}")) != -1) decl.remove(index, 13); if ((index = decl.find("${final}")) != -1) decl.remove(index, 8); if ((index = decl.find("${static}")) != -1) decl.remove(index, 9); if ((index = decl.find("${abstract}")) != -1) decl.remove(index, 11); if ((index = decl.find("${synchronized}")) != -1) decl.remove(index, 15); if ((index = decl.find("${@}")) != -1) decl.remove(index, 4); if ((index = decl.find("${(}")) == -1) decl = "${type} ${name}"; else decl.truncate(index); UmlTypeSpec t = returnType(); if ((t.type != 0) || !(t.explicit_type = JavaSettings::type(t.explicit_type)).isEmpty()) write_type(out, t, decl, "${name}", "${type}"); }
unsigned UmlSettings::multiplicity_column(const WrapperStr & mult) { if (mult.isEmpty() || (mult == "1")) return 0; if ((mult == "*") || (mult.find("..") != -1)) return 1; return 2; }
void UmlOperation::generate_imports(QTextStream & f, WrapperStr & made) { WrapperStr s = pythonDecl(); if (!s.isEmpty()) { UmlArtifact * art = ((UmlClass *) parent())->assocArtifact(); returnType().generate_import(f, art, FALSE, made); int index1 = s.find("${(}"); if (index1 == -1) return; index1 += 4; int index2 = s.find("${)}", index1); if (index2 == -1) return; s = s.mid((unsigned) index1, (unsigned)(index2 - index1)); const QList<UmlParameter> & params = this->params(); QList<UmlParameter>::ConstIterator it; unsigned rank; char ti[16]; strcpy(ti, "${p"); for (it = params.begin(), rank = 0; it != params.end(); ++it, rank += 1) { sprintf(ti + 3, "%u}", rank); if (s.find(ti) != -1) (*it).type.generate_import(f, art, FALSE, made); } } }
void UmlItem::importExtension(FileIn & in, Token & token, UmlItem * where) { if (! token.closed()) { WrapperStr s = token.valueOf("extender"); if (s.isNull()) s = token.valueOf("xmi:extender"); if (s == "Bouml") { WrapperStr k = token.what(); const char * kstr = k; while (in.read(), !token.close(kstr)) { s = token.what(); if (s == "taggedvalue") // is closed where->set_PropertyValue(token.valueOf("tag"), token.valueOf("value")); else if (s == "stereotype") where->set_Stereotype(token.valueOf("name")); if (! token.closed()) in.finish(token.what()); } } else if (s == "Visual Paradigm for UML") { WrapperStr k = token.what(); const char * kstr = k; while (in.read(), !token.close(kstr)) { s = token.what(); if (s == "appliedstereotype") { s = token.valueOf("xmi:value"); if (s.right(3) == "_id") { s = s.mid(s.find("_") + 1); s = s.left(s.length() - 3).lower(); } where->set_Stereotype(s); } if (! token.closed()) in.finish(token.what()); } } else in.finish(token.what()); } }
void FileOut::define_datatypes(bool uml_20, bool primitive_type, bool gen_extension) { const char * pfix = (primitive_type) ? ((uml_20) ? "<ownedMember xmi:type=\"uml:PrimitiveType\"" : "<packagedElement xmi:type=\"uml:PrimitiveType\"") : ((uml_20) ? "<ownedMember xmi:type=\"uml:DataType\"" : "<packagedElement xmi:type=\"uml:DataType\""); QMap<QString, int>::ConstIterator it; for (it = _datatypes.begin(); it != _datatypes.end(); ++it) { indent(); (*this) << pfix << " xmi:id=\"BOUML_datatype_" << it.value() << "\" name=\""; quote(it.key()); //[jasa] ambiguous call (*this) << "\"/>\n"; } const char * postfix = (uml_20) ? "</ownedMember>\n" : "</packagedElement>\n"; for (it = _modifiedtypes.begin(); it != _modifiedtypes.end(); ++it) { WrapperStr k = it.key(); int index = k.find('_'); indent(); (*this) << pfix << " xmi:id=\"BOUML_basedontype_" << it.value() << "\" name = \""; quote((const char *)k.mid(index + 1)); (*this) << '"'; if (gen_extension) { (*this) << ">\n"; indent(); (*this) << "\t<xmi:Extension extender=\"Bouml\">\n"; indent(); (*this) << "\t\t<basedOn \"BOUML_" << k.left(index).operator QString() << "\"/>\n"; indent(); (*this) << "\t</xmi:Extension>\n"; indent(); (*this) << postfix; } else (*this) << "/>\n"; } }
bool UmlClass::isAppliedStereotype(Token & tk, WrapperStr & prof_st, Q3ValueList<WrapperStr> & base_v) { static Q3Dict<WrapperStr> stereotypes; static Q3Dict<Q3ValueList<WrapperStr> > bases; WrapperStr s = tk.what(); WrapperStr * st = stereotypes[s]; if (st != 0) { prof_st = *st; base_v = *bases[s]; return TRUE; } base_v.clear(); if (tk.xmiType().isEmpty() && (getFct(tk) == 0)) { int index = s.find(':'); if ((index != -1) && ((index != 3) || ((s.left(3) != "uml") && (s.left(3) != "xmi")))) { UmlClass * cl = findStereotype(s, FALSE); if (cl != 0) { const Q3PtrVector<UmlItem> ch = cl->children(); unsigned n = ch.size(); for (unsigned i = 0; i != n; i += 1) { UmlItem * x = ch[i]; if ((x->kind() == aRelation) && (((UmlRelation *) x)->relationKind() == aDirectionalAssociation) && (((UmlRelation *) x)->roleType()->stereotype() == "metaclass")) base_v.append("base_" + ((UmlRelation *) x)->roleType()->name().lower()); } if (base_v.isEmpty()) base_v.append("base_element"); prof_st = cl->parent()->parent()->name() + ":" + cl->name(); stereotypes.insert(s, new WrapperStr(prof_st)); bases.insert(s, new Q3ValueList<WrapperStr>(base_v)); return TRUE; } } } return FALSE; }
void UmlClassMember::remove_preprocessor(WrapperStr & s) { int index = 0; while ((index = s.find('#', index)) != -1) { // remove all up to the end of line int index2 = index + 1; int index3; while ((index3 = s.find('\n', index2)) != -1) { // manage multi lines #define if (((const char *) s)[index3 - 1] != '\\') break; else index2 = index3 + 1; } // the \n is still here to have a separator if (index3 == -1) s.truncate(index); else s.remove(index, index3 - index); } }
bool UmlClass::is_itself(WrapperStr t) { // class is a template class and t is x<...> where x is the class, // t is normalized // return true if t is the class with its formals int index = t.find('<'); t = t.mid(index + 1, t.length() - index - 2); QList<UmlFormalParameter> l = formals(); QList<UmlFormalParameter>::ConstIterator it = l.begin(); WrapperStr t2 = (*it).name(); while ((++it) != l.end()) t2 += ',' + (*it).name(); return (t == t2); }
void UmlItem::importGeneralization(FileIn & in, Token & token, UmlItem * where) { WrapperStr id = token.valueOf("general"); WrapperStr constraint; if (! token.closed()) { WrapperStr k = token.what(); const char * kstr = k; while (in.read(), !token.close(kstr)) { WrapperStr s = token.what(); if (s == "general") { id = token.xmiIdref(); if (id.isEmpty() && !(id = token.valueOf("href")).isEmpty()) { int index = id.find('#'); if (index != -1) id = id.mid(index + 1); } } else if (s == "ownedrule") { constraint = UmlItem::readConstraint(in, token); continue; } if (! token.closed()) in.finish(s); } } if (!id.isEmpty()) { QMap<QString, UmlItem *>::ConstIterator iter = All.find(id); if (iter != All.end()) where->generalizeDependRealize(*iter, in, 0, "", constraint); else Unresolved::addGeneralization(where, id, constraint); } else in.warning("'general' is missing"); }
WrapperStr UmlClass::decl() { WrapperStr result; WrapperStr close_template; UmlArtifact * cp = associatedArtifact(); WrapperStr nasp = ((UmlPackage *) ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package()) ->cppNamespace(); if (!nasp.isEmpty()) { int index = // bypass :: allowing ::a... ((nasp.at(0) == ":") && (nasp != QString("::"))) ? 2 : 0; int index2 = 0; while ((index2 = nasp.find("::", index)) != -1) { result += "namespace " + nasp.mid(index, index2 - index) + " { "; close_template += " } "; index = index2 + 2; } result += "namespace " + nasp.mid(index) + " { "; close_template += " } "; } WrapperStr template1; WrapperStr template2; get_template_prefixes(template1, template2); if (!template1.isEmpty()) result += template1.left(template1.length() - 1) + ' '; result += cpp_stereotype() + ' '; return result + name() + ';' + close_template + '\n'; }
void UmlArtifact::generate_imports(QTextStream & f, WrapperStr & made) { QVector<UmlItem*> ch = children(); unsigned index; const unsigned sup = ch.size(); for (index = 0; index != sup; index += 1) { UmlNcRelation * r = dynamic_cast<UmlNcRelation *>(ch[index]); if ((r != 0) && (r->relationKind() == aDependency) && (r->target()->kind() == anArtifact)) { UmlArtifact * other_art = (UmlArtifact *) r->target(); WrapperStr s_art = ((UmlPackage *) other_art->parent()->parent())->pythonPackage(); if (! s_art.isEmpty()) s_art += "." + other_art->name(); else s_art = other_art->name(); WrapperStr s = r->stereotype(); if (s == "import") s = "import " + s_art; else if (s == "from") s = "from " + s_art + " import *"; else return; if (made.find(s) == -1) { made += s + "\n"; f << s << '\n'; } } } }
void UmlPackage::packageImport(FileIn & in, Token & tk) { if (! tk.closed()) { WrapperStr id = tk.xmiId(); WrapperStr k = tk.what(); const char * kstr = k; while (in.read(), !tk.close(kstr)) { if (tk.what() == "importedpackage") { if (tk.xmiType() == "uml:Model") { WrapperStr v; if (propertyValue("metamodelReference", v) && (v == id)) { WrapperStr href = tk.valueOf("href"); int index = href.find('#'); set_PropertyValue("metamodelReference", (index == -1) ? href : href.left(index)); } } else if (tk.xmiType() == "uml:Profile") { WrapperStr s = tk.xmiIdref(); UmlPackage * pf = 0; if (!s.isEmpty()) { QMap<WrapperStr, UmlItem *>::Iterator it = All.find(s); if (it == All.end()) UnresolvedRelation::add(4, this->id(), s, "", ""); else if ((*it)->kind() == aPackage) pf = (UmlPackage *) *it; } else pf = importProfile(in, tk.valueOf("href")); if (pf != 0) { UmlNcRelation * ncr = UmlNcRelation::create(aDependency, this, pf); if (ncr != 0) ncr->set_Stereotype("import"); } } } else if (tk.what() == "importedelement") { WrapperStr v; if (propertyValue("metaclassReference", v) && (v == id)) { WrapperStr href = tk.valueOf("href"); int index = href.find('#'); set_PropertyValue("metaclassReference", (index == -1) ? href : href.left(index)); } } if (! tk.closed()) in.finish(tk.what()); } } }
// not from a form 'generic<...C...> var' where C is a class bool UmlRelation::new_one(Class * container, const WrapperStr & name, UmlTypeSpec & dest, WrapperStr str_actuals, aVisibility visibility, bool staticp, bool constp, bool transientp, bool volatilep, const WrapperStr & array, const WrapperStr & value, WrapperStr comment, WrapperStr description, WrapperStr annotation #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { #ifdef TRACE QLOG_INFO() << "RELATION '" << name << "' from '" << cl->Name() << "' to '" << dest.type->Name() << "' array '" << array << "'\n"; #endif if ( #ifdef REVERSE container->from_libp() && #endif (visibility == PrivateVisibility)) { Lex::finish_line(); Lex::clear_comments(); return TRUE; } UmlClass * cl = container->get_uml(); UmlRelation * rel; #ifdef ROUNDTRIP bool created; if (!roundtrip || ((rel = search_rel(container, name, dest.type, "")) == 0)) { #endif rel = UmlBaseRelation::create(aDirectionalAssociation, cl, dest.type); if (rel == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add relation <i>") + name + "</i> in <i>" + cl->name() + "</i> to <i>" + dest.type->name() + "</i></b></font><br>"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP Statistic::one_relation_more(); # else if (roundtrip) container->set_updated(); created = TRUE; } else created = FALSE; # endif #endif WrapperStr decl = JavaSettings::relationDecl(array); UmlClass::manage_generic(decl, dest, str_actuals, "${type}"); Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); #ifdef ROUNDTRIP if (roundtrip && !created) { if (rel->visibility() != visibility) { rel->set_Visibility(visibility); container->set_updated(); } if (decl.find("${description}") != -1) { if (nequal(rel->description(), description)) { rel->set_Description(description); container->set_updated(); } } else if (nequal(rel->description(), Lex::simplify_comment(comment))) { rel->set_Description(comment); // comment was set container->set_updated(); } if (rel->isReadOnly() != constp) { rel->set_isReadOnly(constp); container->set_updated(); } if (rel->isJavaTransient() != transientp) { rel->set_isJavaTransient(transientp); container->set_updated(); } if (rel->isVolatile() != volatilep) { rel->set_isVolatile(volatilep); container->set_updated(); } if (rel->isClassMember() != staticp) { rel->set_isClassMember(staticp); container->set_updated(); } if (neq(rel->multiplicity(), array)) { rel->set_Multiplicity(array); container->set_updated(); } WrapperStr v = rel->defaultValue(); if (!v.isEmpty() && (((const char *) v)[0] == '=')) v = v.mid(1); if (nequal(v, value)) { rel->set_DefaultValue(value); container->set_updated(); } if (nequal(rel->javaAnnotations(), annotation)) { rel->set_JavaAnnotations(annotation); container->set_updated(); } if (neq(rel->javaDecl(), decl)) { rel->set_JavaDecl(decl); container->set_updated(); } rel->set_usefull(); expected_order.append(rel); } else { #endif rel->set_Visibility(visibility); if (!comment.isEmpty()) rel->set_Description((decl.find("${description}") != -1) ? description : comment); if (constp) rel->set_isReadOnly(TRUE); if (transientp) rel->set_isJavaTransient(TRUE); if (volatilep) rel->set_isVolatile(TRUE); if (staticp) rel->set_isClassMember(TRUE); if (!array.isEmpty()) rel->set_Multiplicity(array); if (! value.isEmpty()) rel->set_DefaultValue(value); if (! annotation.isEmpty()) rel->set_JavaAnnotations(annotation); rel->set_JavaDecl(decl); rel->set_RoleName(name); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(rel); } #endif return TRUE; }
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; }
void CppRefType::compute(Q3PtrList<CppRefType> & dependencies, const WrapperStr & hdef, const WrapperStr & srcdef, WrapperStr & h_incl, WrapperStr & decl, WrapperStr & src_incl, UmlArtifact * who) { UmlPackage * pack = who->package(); WrapperStr hdir; WrapperStr srcdir; if (CppSettings::isRelativePath()) { WrapperStr empty; hdir = pack->header_path(empty); srcdir = pack->source_path(empty); } else if (CppSettings::isRootRelativePath()) hdir = srcdir = UmlPackage::rootDir(); // aze.cpp includes aze.h src_incl += "#include \""; if (CppSettings::includeWithPath()) src_incl += pack->header_path(who->name(), srcdir); else { src_incl += who->name(); src_incl += '.'; src_incl += CppSettings::headerExtension(); } src_incl += "\"\n"; h_incl = ""; // to not be WrapperStr::null decl = ""; // to not be WrapperStr::null CppRefType * ref; for (ref = dependencies.first(); ref != 0; ref = dependencies.next()) { UmlClass * cl = (ref->type.type) ? ref->type.type : UmlBaseClass::get(ref->type.explicit_type, 0); bool included = ref->included; WrapperStr hform; // form in header WrapperStr srcform; // form in source if (cl == 0) { WrapperStr in = CppSettings::include(ref->type.explicit_type); if (!in.isEmpty()) hform = srcform = in + '\n'; else // doesn't know what it is continue; } else if (cl->isCppExternal()) { QString className = cl->name(); hform = cl->cppDecl(); int index; if ((index = hform.find('\n')) == -1) // wrong form continue; hform = hform.mid(index + 1) + '\n'; for (;;) { if ((index = hform.find("${name}")) != -1) hform.replace(index, 7, cl->name()); else if ((index = hform.find("${Name}")) != -1) hform.replace(index, 7, capitalize(cl->name())); else if ((index = hform.find("${NAME}")) != -1) hform.replace(index, 7, cl->name().upper()); else if ((index = hform.find("${nAME}")) != -1) hform.replace(index, 7, cl->name().lower()); else break; } srcform = hform; } else { QString className = cl->name(); WrapperStr st = cl->cpp_stereotype(); if ((st == "enum") || (st == "typedef")) included = TRUE; UmlArtifact * art = cl->associatedArtifact(); if (art != 0) { if (art == who) // don't include itself continue; if (CppSettings::includeWithPath()) { UmlPackage * p = art->package(); hform = "#include \"" + p->header_path(art->name(), hdir) + "\"\n"; srcform = "#include \"" + p->header_path(art->name(), srcdir) + "\"\n"; } else srcform = hform = "#include \"" + art->name() + '.' + CppSettings::headerExtension() + "\"\n"; } else if (cl->parent()->kind() != aClass) { write_trace_header(); UmlCom::trace(WrapperStr(" <font color=\"red\"><b> class<i> ") + cl->name() + "</i> referenced but does not have associated <i>artifact</i></b></font><br>"); incr_warning(); continue; } } if (included) { // #include must be placed in the header file if ((h_incl.find(hform) == -1) && (hdef.find(hform) == -1)) h_incl += hform; } else if ((cl != 0) && (cl->parent()->kind() != aClass)) { // else too complicated // #include useless in header file, place it in the source file if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) && (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1)) src_incl += srcform; if (!cl->isCppExternal()) { // header file must contains the declaration hform = cl->decl(); if (decl.find(hform) == -1) decl += hform; if ((cl->associatedArtifact() == 0) && (cl->parent()->kind() != aClass)) { write_trace_header(); UmlCom::trace(WrapperStr(" <font color=\"red\"><b> class<i> ") + cl->name() + "</i> referenced but does not have associated <i>artifact</i></b></font><br>"); incr_warning(); } } } else if (!hform.isEmpty()) { // have the #include form but does not know if it is a class or other, // generate the #include in the header file EXCEPT if the #include is // already in the header/source file to allow to optimize the generated // code if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) && (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1)) h_incl += hform; } } }
bool UmlAttribute::new_one(Class * container, const WrapperStr & name, UmlTypeSpec typespec, aVisibility visibility, bool staticp, bool finalp, bool transientp, bool volatilep, const WrapperStr & array, const WrapperStr & value, WrapperStr comment, WrapperStr description, WrapperStr annotation #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { #ifdef TRACE QLOG_INFO() << "ATTRIBUTE '" << name << "'\n"; #endif if ( #ifdef REVERSE container->from_libp() && ( #endif visibility == PrivateVisibility #ifdef REVERSE ) #endif ) { Lex::finish_line(); Lex::clear_comments(); return TRUE; } UmlClass * cl = container->get_uml(); UmlAttribute * at; #ifdef ROUNDTRIP bool created; if (!roundtrip || ((at = search_attr(container, name)) == 0)) { #endif at = UmlBaseAttribute::create(cl, name); if (at == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP Statistic::one_attribute_more(); # else if (roundtrip) container->set_updated(); created = TRUE; } else created = FALSE; # endif #endif Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); WrapperStr decl = JavaSettings::attributeDecl(""); int index = decl.find("${type}"); if ((index == -1) || (decl.find("${name}") == -1)) { decl = " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type} ${name}${value};"; index = decl.find("${type}"); } #ifdef ROUNDTRIP if (roundtrip && !created) { if (decl.find("${description}") != -1) { if (nequal(at->description(), description)) { at->set_Description(description); container->set_updated(); } } else if (nequal(at->description(), Lex::simplify_comment(comment))) { at->set_Description(comment); // comment was set container->set_updated(); } if (at->isReadOnly() != finalp) { at->set_isReadOnly(finalp); container->set_updated(); } if (at->isJavaTransient() != transientp) { at->set_isJavaTransient(transientp); container->set_updated(); } if (at->isVolatile() != volatilep) { at->set_isVolatile(volatilep); container->set_updated(); } if (at->isClassMember() != staticp) { at->set_isClassMember(staticp); container->set_updated(); } if (!array.isEmpty()) decl.insert(index + 7, "${multiplicity}"); if (neq(at->multiplicity(), array)) { at->set_Multiplicity(array); container->set_updated(); } WrapperStr v = at->defaultValue(); if (!v.isEmpty() && (((const char *) v)[0] == '=')) v = v.mid(1); if (nequal(v, value)) { at->set_DefaultValue(value); container->set_updated(); } if (nequal(at->javaAnnotations(), annotation)) { at->set_JavaAnnotations(annotation); container->set_updated(); } WrapperStr stereotype; bool force_ste = FALSE; if (cl->stereotype() == "enum") { stereotype = "attribute"; force_ste = TRUE; } else if (typespec.type == 0) { WrapperStr t = typespec.explicit_type; int index2; if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0)) { stereotype = t.left(index2); typespec.explicit_type = // may be a,b ... t.mid(index2 + 1, t.length() - 2 - index2); decl.replace(index, 7, "${stereotype}<${type}>"); force_ste = TRUE; } } if (at->visibility() != visibility) { at->set_Visibility(visibility); container->set_updated(); } if (neq(at->stereotype(), stereotype)) { WrapperStr jst; if (! at->stereotype().isEmpty()) jst = JavaSettings::relationAttributeStereotype(at->stereotype()); if ((force_ste) ? (jst != stereotype) : (jst == "attribute")) { at->set_Stereotype(stereotype); container->set_updated(); } } if (neq(at->javaDecl(), decl)) { at->set_JavaDecl(decl); container->set_updated(); } if (!at->type().equal(typespec)) { at->set_Type(typespec); container->set_updated(); } at->set_usefull(); expected_order.append(at); } else { #endif if (!comment.isEmpty()) at->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); if (finalp) at->set_isReadOnly(TRUE); if (transientp) at->set_isJavaTransient(TRUE); if (volatilep) at->set_isVolatile(TRUE); if (staticp) at->set_isClassMember(TRUE); if (!array.isEmpty()) { decl.insert(index + 7, "${multiplicity}"); at->set_Multiplicity(array); } if (! value.isEmpty()) at->set_DefaultValue(value); if (! annotation.isEmpty()) at->set_JavaAnnotations(annotation); if ((typespec.type == 0) && (cl->stereotype() != "enum")) { WrapperStr t = typespec.explicit_type; int index2 = 0; if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0)) { at->set_Stereotype(t.left(index2)); typespec.explicit_type = // may be a,b ... t.mid(index2 + 1, t.length() - 2 - index2); decl.replace(index, 7, "${stereotype}<${type}>"); } } at->set_Visibility(visibility); if (cl->stereotype() == "enum") { at->set_JavaDecl(decl); at->set_Stereotype("attribute"); } else if (decl != JavaSettings::attributeDecl("")) at->set_JavaDecl(decl); at->set_Type(typespec); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(at); } #endif return TRUE; }