Пример #1
0
void UmlClass::generate() {
  if (! managed) {
    managed = TRUE;
    
    if (!isJavaExternal() && !javaDecl().isEmpty()) {
      if (associatedArtifact() != 0)
	associatedArtifact()->generate();
      else if ((children().size() != 0) && verbose())
	UmlCom::trace(QCString("<hr><font face=helvetica><i> ") + name() +
		      " : </i> does not have associated <i>artifact</i></font><br>");
    }
  }
}
Пример #2
0
void UmlClass::import(QTextOStream & f, const QCString & indent) {
  QCString s;
  
  if (!isJavaExternal()) {
    UmlArtifact * cp = associatedArtifact();
    UmlPackage * pack = (UmlPackage *)
      ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package();
    
    if ((s = pack->javaPackage()).isEmpty())
      return;
    
    QCString s2 = name();
    UmlItem * p = this;
    
    while ((p = p->parent())->kind() == aClass)
      s2 = p->name() + dot + s2;
    
    s += dot + s2;
  }
  else if ((s = package()->javaPackage()).isEmpty())
    return;
  else
    s += dot + name();
  
  if (! UmlArtifact::generated_one()->is_imported(s)) {
    f << indent << "import " << s << ";\n";
    UmlArtifact::generated_one()->imported(s);
  }
}
Пример #3
0
Q3CString UmlClass::decl() {      
  Q3CString result;
  Q3CString close_template;
  UmlArtifact * cp = associatedArtifact();
  Q3CString nasp = ((UmlPackage *)
		   ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package())
    ->cppNamespace();
    
  if (! nasp.isEmpty()) {
    int index = 
      // bypass :: allowing ::a...
      ((nasp.at(0) == ':') && (nasp != "::")) ? 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 += " } ";
  }
  
  Q3CString template1;
  Q3CString template2;
  
  get_template_prefixes(template1, template2);
  
  if (!template1.isEmpty())
    result += template1.left(template1.length() - 1) + ' ';
  
  result += cpp_stereotype() + ' ';
  
  return result + name() + ';' + close_template + '\n';
}
Пример #4
0
bool UmlClass::set_roundtrip_expected()
{
    if (is_roundtrip_expected() ||
            ((parent()->kind() != aClass) &&
             ((associatedArtifact() == 0) ||
              !associatedArtifact()->set_roundtrip_expected_for_class())))
        return TRUE;

    const Q3PtrVector<UmlItem> & ch = UmlItem::children();
    UmlClassItem ** v = (UmlClassItem **) ch.data();
    UmlClassItem ** const vsup = v + ch.size();
    bool result = UmlClassItem::set_roundtrip_expected();

    for (; v != vsup; v += 1)
        result &= (*v)->set_roundtrip_expected();

    return result;

}
Пример #5
0
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));
        }
    }
}
Пример #6
0
void UmlClass::generate() {
  if (! managed) {
    managed = TRUE;
    
    if (!isCppExternal() && !cppDecl().isEmpty()) {
      if (associatedArtifact() == 0) {
	if (verbose())
	  UmlCom::trace(Q3CString("<hr><font face=helvetica><i> ") + name() +
			" : </i> does not have associated <i>artifact</i></font><br>");
      }
      else if (cppDecl().isEmpty()) {
	if (verbose())
	  UmlCom::trace(Q3CString("<hr><font face=helvetica>class <i>")
			+ name() + "</i> has an empty C++ definition</font><br>");
      }
      else
	associatedArtifact()->generate();
    }
  }
}
Пример #7
0
UmlArtifact * UmlClass::artifact() {
  // note : class is not nested
  UmlArtifact * art = associatedArtifact();
  
  if (art == 0) {
    UmlDeploymentView * depl =	((UmlClassView *) parent())->deploymentView();
    
    art = UmlArtifact::create(depl, name());
    
    if (art == 0) {
      UmlCom::trace("<b>cannot create artifact '" +
		    name() + "' in deployment view '" + depl->name() + "'</b><br>");
      throw 0;
    }
    
    art->set_Stereotype("source");
    art->addAssociatedClass(this);
  }

  return art;
}
Пример #8
0
void UmlClass::send_it(int n)
{
    if (is_roundtrip_expected())
        associatedArtifact()->send_it(n);
}
Пример #9
0
void UmlClass::gen_html(QCString pfix, unsigned int rank, unsigned int level) {
  UmlCom::message(name());
  
  QCString s;
 
  s = description();
  
  if (isActive())
    fw.write("<p>Active class</p>\n");
    
  if (!s.isEmpty()) {
    fw.write("<p>");
    if (! javaDecl().isEmpty())
      gen_java_decl(s, TRUE);
    else if (! phpDecl().isEmpty())
      gen_php_decl(s, TRUE);
    else if (! pythonDecl().isEmpty())
      gen_python_decl(s, TRUE);
    else
      gen_cpp_decl(s, TRUE);
    fw.write("<br /></p>\n");
  }

  if (!cppDecl().isEmpty() ||
      !javaDecl().isEmpty() ||
      !phpDecl().isEmpty() ||
      !pythonDecl().isEmpty()) {
    fw.write("<p>Declaration :</p><ul>\n");
    
    s = cppDecl();
    
    if (!s.isEmpty()) {
      fw.write("<li>C++ : ");
      gen_cpp_decl(s, FALSE);
      fw.write("</li>");
    }
    
    s = javaDecl();
    
    if (!s.isEmpty()) {
      fw.write("<li>Java : ");
      gen_java_decl(s, FALSE);
      fw.write("</li>");
    }
    
    s = phpDecl();
    
    if (!s.isEmpty()) {
      fw.write("<li>Php : ");
      gen_php_decl(s, FALSE);
      fw.write("</li>");
    }
    
    s = pythonDecl();
    
    if (!s.isEmpty()) {
      fw.write("<li>Python : ");
      gen_python_decl(s, FALSE);
      fw.write("</li>");
    }
    
    fw.write("</ul>");
  }
  
  if (subClasses.size() != 0) {
    sort(subClasses);
    fw.write("<p>Directly inherited by : ");
    
    for (unsigned i = 0; i != subClasses.size(); i += 1) {
      subClasses.elementAt(i)->write();
      fw.write(' ');
    }
    fw.write("</p>\n");    
  }
  
  write_dependencies();

  annotation_constraint();
  
  bool p = FALSE;
  UmlItem * x;
  
  if ((x = associatedArtifact()) != 0) {
    p = TRUE;
    fw.write("<p>Artifact : ");
    x->write();
  }

  const QVector<UmlComponent> comps = associatedComponents();
  
  if (comps.size() != 0) {
    if (p) 
      fw.write(", Component(s) :");
    else {
      p = TRUE;
      fw.write("<p>Component(s) :");
    }
    
    for (unsigned i = 0; i != comps.size(); i += 1) {
      fw.write(' ');
      comps[i]->write();
    }
  }

  if ((x = associatedDiagram()) != 0) {
    if (p) 
      fw.write(", Diagram : ");
    else {
      p = TRUE;
      fw.write("<p>Diagram : ");
    }
    x->write();
  }

  if (p)
    fw.write("</p>\n");
  
  if (parent()->kind() == aClass) {
    fw.write("<p>nested in ");
    parent()->write();
    fw.write("</p>\n");
  }

  write_properties();

  //

  const QVector<UmlItem> ch = children();
  
  if (ch.size() != 0) {
    if (stereotype() == "enum_pattern") {
      p = FALSE;
            
      for (unsigned i = 0; i != ch.size(); i += 1) {
	if (ch[i]->kind() == anAttribute) {
	  if (!p) {
	    p = TRUE;
	    fw.write("<div class=\"sub\">\n<p>Items :</p><ul>\n");
	  }
	  fw.write("<li>");
	  writeq(ch[i]->name());
	  fw.write("</li>\n");
	}
      }
      if (p)
	fw.write("</ul>\n</div>\n");
    }
    else {
      fw.write("<div class=\"sub\">\n");
      
      if (stereotype() == "enum") {
	unsigned i;
	
	p = FALSE;
	
	for (i = 0; i != ch.size(); i += 1) {
	  if ((ch[i]->kind() == anAttribute) &&
	      (ch[i]->stereotype() != "attribute")) {
	    if (!p) {
	      p = TRUE;
	      fw.write("<p>Items :</p><ul>\n");
	    }
	    fw.write("<li>");
	    writeq(ch[i]->name());
	    fw.write("</li>\n");
	  }
	}
	if (p)
	  fw.write("</ul>\n");
	
	s = "";
	for (i = 0; i != ch.size(); i += 1)
	  if ((ch[i]->kind() != anAttribute) ||
	      (ch[i]->stereotype() == "attribute"))
	    ch[i]->html(s, 0, 0);
      }
      else if (flat)
	write_children(pfix, rank, level);
      else {
	// non flat
	s = "";
	for (unsigned i = 0; i != ch.size(); i += 1)
	  ch[i]->html(s, 0, 0);
      }
      
      fw.write("</div>\n");
    }
  }

  sort(*inherited_opers);
  bool already = FALSE;
  
  for (unsigned i = 0; i != inherited_opers->size(); i += 1) {
    if (already)
      fw.write(", ");
    else {
      already = TRUE;
      fw.write("<p>All public operations : ");
    }
    inherited_opers->elementAt(i)->write();
    fw.write(' ');
  }
  if (already)
    fw.write("</p>\n");
}
Пример #10
0
void UmlClass::compute_dependency(Q3PtrList<CppRefType> & dependencies,
				  const Q3CString &, bool all_in_h) {
  Q3PtrVector<UmlItem> ch = children();
  const Q3CString stereotype = cpp_stereotype();
  bool a_typedef = (stereotype == "typedef");
  bool an_enum = (stereotype == "enum");
  const Q3ValueList<UmlFormalParameter> formals = this->formals();
  const Q3ValueList<UmlActualParameter> actuals = this->actuals();  
  
  if (!formals.isEmpty())
    // template class, force depend in h
    all_in_h = TRUE;
  
  for (unsigned index = 0; index != ch.size(); index += 1) {
    if (ch[index]->kind() != aNcRelation) {
      UmlClassItem * it = (UmlClassItem *) ch[index];
      
      if (! it->cppDecl().isEmpty())
	it->compute_dependency(dependencies, stereotype, all_in_h);
    }
  }
  
  if (an_enum && (!formals.isEmpty() || !actuals.isEmpty())) {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b><i>template enum</i></b></font><br>");
    incr_warning();
  }
  else if (a_typedef && !formals.isEmpty()) {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b><i>template typedef</i></b></font><br>");
    incr_warning();
  }
  else {
    Q3ValueList<UmlFormalParameter>::ConstIterator itf;
    
    for (itf = formals.begin(); itf != formals.end(); ++itf)
      CppRefType::remove((*itf).name(), dependencies);
  
    Q3ValueList<UmlActualParameter>::ConstIterator ita;
    
    for (ita = actuals.begin(); ita != actuals.end(); ++ita)
      UmlClassMember::compute_dependency(dependencies, "${type}",
					 (*ita).value(), all_in_h);
    
    if (a_typedef) {
      Q3CString decl = cppDecl();
      int index;
      
      remove_comments(decl);
      if ((index = decl.find("${name}")) != -1)
	decl.remove((unsigned) index, 7);
      replace_alias(decl);

      UmlClassMember::compute_dependency(dependencies, decl,
					 baseType(), all_in_h);
    }
  }
  
  if ((associatedArtifact() == 0) ||
      (associatedArtifact()->associatedClasses().count() == 1))
    CppRefType::remove(this, dependencies);
  else
    CppRefType::force_ref(this, dependencies);
}
Пример #11
0
void UmlClass::write(QTextOStream & f, bool with_formals, BooL * is_template,
		     const Q3ValueList<UmlActualParameter> & actuals) {
  if (context.findRef(this) == -1) {
    if (parent()->kind() == aClass) {
      if (context.findRef((UmlClass *) parent()) == -1) {
	// parent cannot have formals, but may have actuals
	((UmlClass *) parent())->write(f, FALSE, 0, actuals);
	f << "::";
      }
    }
    else {
      UmlArtifact * cp = associatedArtifact();
      Q3CString nasp = ((UmlPackage *)
		       ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package())
	->cppNamespace();
      
      if (CppSettings::isForceNamespacePrefixGeneration() ||
	  (nasp != UmlArtifact::generation_package()->cppNamespace()))
	f << nasp << "::";
    }
  }
  
  Q3CString 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());
    else if ((index = s.find("${nAME}")) != -1)
      s.replace(index, 7, name().lower());
  }
  else 
    s = name();	// true_name
  
  if (! s.isEmpty()){
    f << s;
    
    if (is_template != 0)
      *is_template = (s.at(s.length() - 1) == '>');
  }
  else if (is_template != 0)
    *is_template = FALSE;
    
  if (with_formals) {
    Q3ValueList<UmlFormalParameter> formals = this->formals();
    
    if (! formals.isEmpty()) {
      const char * sep = "<";
      Q3ValueList<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()) {
    Q3ValueList<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;
    }
  }
}