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 UmlArtifact::roundtrip_java() { if (! managed) { managed = TRUE; if (stereotype() != "source") return; const WrapperStr srcdef = javaSource(); if (srcdef.isEmpty()) return; const WrapperStr & name = UmlArtifact::name(); UmlPackage * pack = package(); WrapperStr src_path = pack->java_path(name); { WrapperStr s = " <i> " + src_path + "</i>"; UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>roundtrip body from") + s + "</font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>roundtrip body from") + s + "</font><br>"); } UmlOperation::roundtrip(src_path, javaLanguage); } }
bool UmlArtifact::is_imported(Q3CString path, Q3CString class_name) { if (imports == 0) { imports = new Q3AsciiDict<UmlArtifact>(17); Q3CString 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)) { Q3CString p = s.mid(index2, index - index2); imports->insert(p, this); } else index = index2; } else index += 6; } } return ((imports->find(path + '.' + class_name) != 0) || (imports->find(path + ".*") != 0)); }
void UmlArtifact::generate_text() { const WrapperStr srcdef = javaSource(); if (srcdef.isEmpty()) { if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>artifact <i>") + name() + "</i> has an empty Java definition</font><br>"); return; } UmlPackage * pack = package(); const WrapperStr & name = UmlArtifact::name(); WrapperStr src_path = pack->text_path(name); WrapperStr s = " in <i> " + src_path + "</i>"; UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ") + name + "</i>" + s + "</font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ") + name + "</i>" + s + "</font><br>"); if (must_be_saved(src_path, (const char *) srcdef)) { write_trace_header(); FILE * fp_src; if ((fp_src = fopen((const char *) src_path, "wb")) == 0) { write_trace_header(); UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + " : </i> cannot open <i> " + src_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + pack->name() + "</i> Java directory specification</b></font><br>"); incr_error(); } else { fputs((const char *) srcdef, fp_src); fclose(fp_src); } } else if (get_trace_header().isEmpty()) UmlCom::trace(WrapperStr("<font face=helvetica><i> ") + src_path + "</i> not modified</font><br>"); }
void UmlArtifact::generate() { if (! managed) { managed = TRUE; if (stereotype() == "text") { generate_text(); return; } else if (stereotype() != "source") return; package_of_generated_artifact = package(); current = this; const WrapperStr filedef = javaSource(); if (filedef.isEmpty()) return; const WrapperStr & name = this->name(); WrapperStr path = package_of_generated_artifact->file_path(name); UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); // get bodies if preserve const QVector<UmlClass*> & cls = associatedClasses(); if (preserve()) UmlOperation::read_bodies(path); // generate file unsigned n = cls.count(); unsigned index; WrapperStr incl; QSharedPointer<QByteArray> headerFile(new QByteArray()); QTextStream f(headerFile.data(), QIODevice::WriteOnly); const char * p = filedef; const char * pp = 0; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; } 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, "${name}", 7)) { p += 7; f << name; } else if (!strncmp(p, "${Name}", 7)) { p += 7; f << capitalize(name); } else if (!strncmp(p, "${NAME}", 7)) { p += 7; f << name.upper(); } else if (!strncmp(p, "${nAME}", 7)) { p += 7; f << name.lower(); } else if (!strncmp(p, "${imports}", 10)) { WrapperStr indent = current_indent(p, filedef); for (index = 0; index != n; index += 1) cls[index]->generate_import(f, indent); p += 10; if (*p == '\n') p += 1; } else if (!strncmp(p, "${package}", 10)) { p += 10; const WrapperStr & package = package_of_generated_artifact->javaPackage(); if (!package.isEmpty()) f << "package " << package << ";\n\n"; if (*p == '\n') p += 1; } else if (!strncmp(p, "${definition}", 13)) { WrapperStr indent = current_indent(p, filedef); for (index = 0; index != n; index += 1) cls[index]->generate(f, indent); p += 13; if (*p == '\n') p += 1; } else // strange f << *p++; } f << '\000'; f.flush(); if (must_be_saved(path, headerFile->data())) { write_trace_header(); FILE * fp; if ((fp = fopen((const char *) path, "wb")) == 0) { write_trace_header(); UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + "</i> : cannot open <i> " + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + package_of_generated_artifact->name() + "</i> Java directory specification</b></font><br>"); incr_error(); } else { fputs((const char *) headerFile->data(), fp); fclose(fp); } } else if (get_trace_header().isEmpty()) UmlCom::trace(WrapperStr("<font face=helvetica><i> ") + path + "</i> not modified</font><br>"); if (imports != 0) { delete imports; imports = 0; } } }
void UmlArtifact::add_import(const char * i) { Q3CString s = javaSource(); s.insert(s.find("${definition}"), i); set_JavaSource(s); }