예제 #1
0
파일: UmlClass.cpp 프로젝트: DoUML/douml
void UmlClass::gen_python_decl(QByteArray s, bool descr)
{
    QByteArray st = PythonSettings::classStereotype(stereotype());

    if (st == "ignored")
        return;

    const char * p = bypass_comment(s);

    while (*p != 0) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${docstring}", 12))
            p += 12;
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(name());
        }
        else if (!strncmp(p, "${inherit}", 10)) {
            p += 10;

            const QVector<UmlItem*> ch = children();
            bool inh = FALSE;

            for (int 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->pythonDecl().isEmpty()) {
                        if (inh)
                            fw.write(", ");
                        else  {
                            inh = TRUE;
                            fw.write('(');
                        }

                        rel->roleType()->write();
                    }
                }
            }

            if (inh)
                fw.write(')');
            else if (isPython_2_2())
                fw.write("(object)");

            break;
        }
        else if (!descr && ((*p == '\r') || (*p == '\n') || (*p == ':')))
            break;
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #2
0
void UmlRelation::generate_implements(const char *& sep, QTextOStream & f,
                                      const Q3ValueList<UmlActualParameter> & actuals,
                                      const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (javaDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->java_stereotype();

        if ((other_stereotype == "interface") || (other_stereotype == "@interface")) {
            if ((cl_stereotype == "union") || (cl_stereotype == "enum_pattern")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot inherits</b></font><br>");
                incr_warning();
            }
            else {
                f << sep;
                sep = ", ";

                const char * p = javaDecl();

                while (*p) {
                    if (!strncmp(p, "${type}", 7)) {
                        role_type->write(f);
                        p += 7;

                        if (!actuals.isEmpty()) {
                            Q3ValueList<UmlActualParameter>::ConstIterator ita;
                            bool used = FALSE;

                            for (ita = actuals.begin(); ita != actuals.end(); ++ita) {
                                if ((*ita).superClass() == role_type) {
                                    used = TRUE;
                                    (*ita).generate(f);
                                }
                            }

                            if (used) {
                                f << ">";
                            }
                        }
                    }
                    else if (*p == '@')
                        manage_alias(p, f);
                    else
                        f << *p++;
                }
            }
        }
    }
}
예제 #3
0
void UmlRelation::generate_implements(const char *& sep, QTextStream & f,
                                      const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (phpDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->php_stereotype();

        if (other_stereotype == "interface") {
            if (cl_stereotype == "union") {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot inherits</b></font><br>");
                incr_warning();
            }
            else {
                f << sep;
                sep = ", ";

                const char * p = phpDecl();

                while (*p) {
                    if (!strncmp(p, "${type}", 7)) {
                        role_type->write(f);
                        p += 7;
                    }
                    else if (*p == '@')
                        manage_alias(p, f);
                    else
                        f << *p++;
                }
            }
        }
    }
}
예제 #4
0
void UmlRelation::gen_python_decl(QByteArray s)
{
    QByteArray st = PythonSettings::classStereotype(stereotype());
    const char * p = bypass_comment(s);

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(roleName());
        }
        else if (!strncmp(p, "${value}", 8)) {
            p += 8;
            writeq((defaultValue().isEmpty()) ? "None" : defaultValue());
        }
        else if (!strncmp(p, "${self}", 7)) {
            p += 7;

            if (!isClassMember())
                fw.write("self.");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            roleType()->write();
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            writeq(st);
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #5
0
void UmlRelation::generate_inherit(const char *& sep, QTextStream & f,
                                   const WrapperStr & cl_stereotype,
                                   BooL & already)
{
    if ((relationKind() == aGeneralisation) || (relationKind() == aRealization)) {
        UmlClass * role_type = roleType();
        WrapperStr other_stereotype = role_type->idl_stereotype();

        if (other_stereotype == "ignored")
            return;

        if ((cl_stereotype == "union") || (cl_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                          + cl_stereotype + "</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }

        if ((other_stereotype == "union") ||
                (other_stereotype == "struct") ||
                (other_stereotype == "enum") ||
                (other_stereotype == "typedef")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot inherits an <i>")
                          + other_stereotype + "</i></b></font><br>");
            incr_warning();
            return;
        }

        if (cl_stereotype == "valuetype") {
            if (other_stereotype == "valuetype") {
                if (isIdlTruncatableInheritance())
                    f << sep << "truncatable ";
                else
                    f << sep;
            }
            else {
                // other_stereotype == "interface"
                if (!already) {
                    already = TRUE;
                    f << " supports ";
                }
                else
                    f << sep;
            }
        }
        else
            f << sep;

        const char * p = idlDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else
                f << *p++;
        }

        sep = ", ";
    }
}
예제 #6
0
void UmlRelation::generate_decl(QTextStream & f,
                                const WrapperStr & cl_stereotype,
                                WrapperStr indent, bool)
{
    if ((relationKind() != aGeneralisation) &&
            (relationKind() != aRealization) &&
            (relationKind() != aDependency)) {
        if (cl_stereotype == "enum") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum</i> cannot have relation</b></font><br>");
            incr_warning();
            return;
        }

        if (cl_stereotype == "typedef") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have relation</b></font><br>");
            incr_warning();
            return;
        }

        if (!idlDecl().isEmpty()) {
            const char * p = idlDecl();
            const char * pp = 0;
            WrapperStr s;

            while ((*p == ' ') || (*p == '\t'))
                indent += *p++;

            if (*p != '#')
                f << indent;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;

                    if (*p != '#')
                        f << indent;
                }

                if (*p == '\n') {
                    f << *p++;

                    if (*p && (*p != '#'))
                        f << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f);
                else if (*p != '$')
                    f << *p++;
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp);
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${readonly}", 11)) {
                    p += 11;

                    if (isReadOnly())
                        f << "readonly ";
                }
                else if (!strncmp(p, "${attribut}", 11)) {
                    // old version
                    p += 11;

                    if (cl_stereotype == "interface")
                        f << "attribute ";
                }
                else if (!strncmp(p, "${attribute}", 12)) {
                    p += 12;

                    if (cl_stereotype == "interface")
                        f << "attribute ";
                }
                else if (!strncmp(p, "${visibility}", 13)) {
                    p += 13;

                    if (cl_stereotype == "valuetype") {
                        switch (visibility()) {
                        case PublicVisibility:
                        case PackageVisibility:
                            f << "public ";
                            break;

                        default:
                            f << "private ";
                        }
                    }
                }
                else if (!strncmp(p, "${case}", 7)) {
                    p += 7;

                    WrapperStr idl_case = idlCase();

                    if (idl_case.isEmpty()) {
                        write_trace_header();
                        UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>unspecified <i>case</i> for <i>")
                                      + name() + "</b></font><br>");
                        incr_error();
                    }
                    else
                        f << idlCase();
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;

                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f << side(side(TRUE) != this)->roleName();

                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f << IdlSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;
                    f << multiplicity();
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    f << IdlSettings::type(association().toString());
                }
                else
                    // strange
                    f << *p++;
            }

            f << '\n';
        }
    }
}
예제 #7
0
void UmlAttribute::generate_decl(aVisibility & current_visibility, QTextOStream & f_h,
				 const Q3CString & cl_stereotype, Q3CString indent,
				 BooL & first, bool last) {
  if (cl_stereotype == "typedef") {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have attribute</b></font><br>");
    incr_warning();
    return;
  }
  const char * p = cppDecl();
  const char * pp = 0;
  bool in_enum = (cl_stereotype == "enum");
  
  if (!in_enum)
    generate_visibility(current_visibility, f_h, first, indent);
  
  first = FALSE;
  
  while ((*p == ' ') || (*p == '\t'))
    indent += *p++;
  
  if (*p != '#')
    f_h << indent;
  
  for (;;) {
    if (*p == 0) {
      if (pp == 0)
	break;
      
      // comment management done
      p = pp;
      pp = 0;
      if (*p == 0)
	break;
      if (*p != '#')
	f_h << indent;
    }

    if (*p == '\n') {
      f_h << *p++;
      if (*p && (*p != '#'))
	f_h << indent;
    }
    else if (*p == '@')
      manage_alias(p, f_h);
    else if (*p != '$')
      f_h << *p++;
    else if (!strncmp(p, "${comment}", 10))
      manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
    else if (!strncmp(p, "${description}", 14))
      manage_description(p, pp);
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      f_h << name();
    }
    else if (!strncmp(p, "${multiplicity}", 15)) {
      p += 15;
      
      const Q3CString & m = multiplicity();
      
      if (!m.isEmpty() && (*((const char *) m) == '['))
	f_h << m;
      else
	f_h << '[' << m << ']';
    }
    else if (!strncmp(p, "${stereotype}", 13)) {
      p += 13;
      f_h << CppSettings::relationAttributeStereotype(stereotype());
    }
    else if (!strncmp(p, "${value}", 8) || !strncmp(p, "${h_value}", 10)) {
      const char * pb = p;

      p += (p[2] == 'h') ? 10 : 8;
      if (in_enum) {
	if (!defaultValue().isEmpty()) {
	  if (need_equal(pb, defaultValue()))
	    f_h << " = ";
          f_h << defaultValue();
	}
	if (last) {
	  if (*p == ',')
	    p += 1;
	}
	else if (*p != ',')
	  f_h << ',';
      }
      else if ((p[-8] == 'h') && isClassMember() && !defaultValue().isEmpty()) {
	if (need_equal(pb, defaultValue()))
	  f_h << " = ";
	f_h << defaultValue();
      }
    }
    else if (in_enum)
      // strange
      f_h << *p++;
    else if (!strncmp(p, "${static}", 9)) {
      p += 9;
      if (isClassMember())
	f_h << "static ";
    }
    else if (!strncmp(p, "${const}", 8)) {
      p += 8;
      if (isReadOnly())
	f_h << "const ";
    }
    else if (!strncmp(p, "${volatile}", 11)) {
      p += 11;
      if (isVolatile())
	f_h << "volatile ";
    }
    else if (!strncmp(p, "${mutable}", 10)) {
      p += 10;
      if (isCppMutable())
	f_h << "mutable ";
    }
    else if (!strncmp(p, "${type}", 7)) {
      p += 7;
      UmlClass::write(f_h, type());
      //f_h << CppSettings::Type(Type().Type());
    }
    else
      // strange
      f_h << *p++;
  }
  
  f_h << '\n';
}
예제 #8
0
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++;
  }
}
예제 #9
0
void UmlRelation::gen_java_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${visibility}", 13)) {
            p += 13;
            write(visibility(), javaLanguage);
            fw.write(' ');
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${transient}", 12)) {
            p += 12;

            if (isJavaTransient())
                fw.write("transient ");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write("volatile ");
        }
        else if (!strncmp(p, "${final}", 8)) {
            p += 8;

            if (isReadOnly())
                fw.write("final ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            roleType()->write();
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(roleName());
        }
        else if (!strncmp(p, "${multiplicity}", 15)) {
            p += 15;

            QByteArray m = multiplicity();

            if (! m.isEmpty()) {
                const char * s = m;

                if (*s != '[')
                    fw.write("[]");
                else {
                    while (*s) {
                        switch (*s++) {
                        case '[':
                            fw.write('[');
                            break;

                        case ']':
                            fw.write(']');

                        default:
                            break;
                        }
                    }
                }
            }
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            writeq(JavaSettings::relationAttributeStereotype(stereotype()));
        }
        else if (!strncmp(p, "${value}", 8)) {
            p += 8;
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            write(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 == ';') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #10
0
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;
        }
    }
}
예제 #11
0
void UmlOperation::gen_php_decl(QByteArray s, bool descr)
{
    QByteArray cl_stereotype =
        PhpSettings::classStereotype(parent()->stereotype());
    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 (isPhpFinal())
                fw.write("final ");
        }
        else if (!strncmp(p, "${visibility}", 13)) {
            p += 13;
            UmlItem::write(visibility(), phpLanguage);
            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() && (cl_stereotype != "interface"))
                fw.write("abstract ");
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(phpNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        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, phpLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                fw.write('$');
                writeq(pa[rank].name);
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= npa)
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        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++);
    }
}
예제 #12
0
파일: UmlClass.cpp 프로젝트: SciBoy/douml
void UmlClass::generate_decl(QTextOStream & f_h, Q3CString indent) {
  context.append(this);
  
  bool removed = FALSE;
  Q3PtrVector<UmlItem> ch = children();
  const unsigned sup = ch.size();
  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();  
  unsigned index;
  const char * p = cppDecl();
  const char * pp = 0;
  const char * sep;
  bool nestedp = parent()->kind() == aClass;
  
  if (nestedp)
    indent += "    ";
  
  while ((*p == ' ') || (*p == '\t'))
    indent += *p++;
  
  if (*p != '#')
    f_h << indent;
    
  for (;;) {
    if (*p == 0) {
      if (pp == 0)
	break;
      
      // comment management done
      p = pp;
      pp = 0;
      if (*p == 0)
	break;
      if (*p != '#')
	f_h << indent;
    }

    if (*p == '\n') {
      f_h << *p++;
      if (*p && (*p != '#') &&
	  strncmp(p, "${members}", 10) &&
	  strncmp(p, "${items}", 8))
	f_h << indent;
    }
    else if (*p == '@')
      manage_alias(p, f_h);
    else if (*p != '$')
      f_h << *p++;
    else if (!strncmp(p, "${comment}", 10))
      manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
    else if (!strncmp(p, "${description}", 14))
      manage_description(p, pp);
    else if (! strncmp(p, "${name}", 7)) {
      p += 7;
      f_h << name();
    }
    else if (a_typedef) {
      if (!strncmp(p, "${type}", 7)) {
	p += 7;
	UmlClass::write(f_h, baseType(), FALSE);
	
	UmlClass * cl = baseType().type;
	
	if ((cl != 0) && !actuals.isEmpty()) {
	  Q3ValueList<UmlActualParameter>::ConstIterator ita;
	  BooL need_space = FALSE;
    
	  for (ita = actuals.begin(); ita != actuals.end(); ++ita)
	    if ((*ita).superClass() == cl)
	      if (! (*ita).generate(f_h, need_space))
		// no specified value
		break;
	  
	  if (need_space)
	    f_h << " >";
	  else
	    f_h << '>';
	}
      }
      else
	// strange
	f_h << *p++;
    }
    else if (an_enum) {
      if (!strncmp(p, "${items}", 8)) {
	p += 8;
	
	// items declaration
	
	aVisibility current_visibility = DefaultVisibility;
	unsigned max = sup - 1;
	BooL first = TRUE;
	
	for (index = 0; index < sup; index += 1) {
	  UmlItem * it = ch[index];
	  
	  switch (it->kind()) {
	  case aClass:
	  case aNcRelation:
	    break;
	  default:
	    if (! ((UmlClassItem *) it)->cppDecl().isEmpty())
	      ((UmlClassItem *) it)->generate_decl(current_visibility,
						   f_h, stereotype, indent,
						   first, index == max);
	  }
	}
      
	if (*p == '}')
	  f_h << indent;
      }
      else
	// strange
	f_h << *p++;
    }
    else if (! strncmp(p, "${template}", 11)) {
      p += 11;
      
      // template
      
      if (!formals.isEmpty()) {
	sep = "template<";
	const char * sep2 = "<";
	BooL need_space = FALSE;
	
	Q3ValueList<UmlFormalParameter>::ConstIterator itf;
	
	for (itf = formals.begin(); itf != formals.end(); ++itf)
	  (*itf).generate(f_h, sep, sep2, need_space);
	
	f_h << ((need_space) ? " >\n" : ">\n");
	if (nestedp)
	  f_h << indent;
      }
      else if (name().find('<') != -1) {
	f_h << "template<>\n";
	if (nestedp)
	  f_h << indent;
      }
    }
    else if (! strncmp(p, "${inherit}", 10)) {
      p += 10;

      // inherit
  
      sep = " : ";
      
      for (index = 0; index != sup; index += 1) {
	UmlItem * x = ch[index];
	
	if ((x->kind() == aRelation) &&
	    !((UmlRelation *) ch[index])->cppDecl().isEmpty())
	  ((UmlRelation *) x)->generate_inherit(sep, f_h, actuals, stereotype);
      }
    }
    else if (! strncmp(p, "${members}", 10)) {
      p += 10;
  
      // members declaration
      
      aVisibility current_visibility;
      
      current_visibility = ((stereotype == "struct") || (stereotype == "union"))
	? PublicVisibility : DefaultVisibility;
      unsigned last = sup - 1;
      BooL first = TRUE;
      
      for (index = 0; index != sup; index += 1) {
	UmlItem * it = ch[index];
	  
	if ((it->kind() != aNcRelation) &&
	    ! ((UmlClassItem *) it)->cppDecl().isEmpty())
	  ((UmlClassItem *) it)->generate_decl(current_visibility,
					       f_h, stereotype, indent,
					       first, index == last);
      }
      
      if (*p == '}')
	f_h << indent;
    }
    else if (!strncmp(p, "${inlines}", 10)) {
      p += 10;
  
      context.removeLast();
      removed = TRUE;
      
      if (! nestedp) {
	// inline operations definition
	// template class members
	Q3CString templates;
	Q3CString cl_names;
	Q3CString templates_tmplop;
	Q3CString cl_names_tmplop;
	
	spec(templates, cl_names, templates_tmplop, cl_names_tmplop);
	
	for (index = 0; index != sup; index += 1)
	  if (ch[index]->kind() != aNcRelation)
	    ((UmlClassItem *) ch[index])
	      ->generate_def(f_h, indent, TRUE, templates, cl_names,
			     templates_tmplop, cl_names_tmplop);
      }
      
      if (*p == '\n')
	p += 1;
    }
    else
      // strange
      f_h << *p++;
  }
  
  if (! removed)
    context.removeLast();
}
예제 #13
0
void UmlOperation::generate(QTextStream & f, const WrapperStr & cl_stereotype,
                            WrapperStr indent, int &)
{
    if (!phpDecl().isEmpty()) {
        const char * p = phpDecl();
        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 (isAbstract() || (cl_stereotype == "interface")) {
                    f << ";";
                    break;
                }
                else {
                    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, PhpSettings::isGenerateJavadocStyleComment());
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${visibility}", 13)) {
                p += 13;
                generate_visibility(f);
            }
            else if (!strncmp(p, "${final}", 8)) {
                p += 8;

                if (isPhpFinal())
                    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"))
                    f << "abstract ";
            }
            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 (sscanf(p, "${v%u}", &rank) == 1) {
                if (!generate_init(params, rank, f))
                    param_error(parent()->name(), name(), rank);

                p = strchr(p, '}') + 1;
            }
            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, "${type}", 7)) {
                p += 7;
                UmlClass::write(f, returnType());
            }
            else
                f << *p++;
        }

        f << '\n';
    }
}
예제 #14
0
void UmlRelation::generate_extends(const char *& sep, QTextStream & f,
                                   const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (phpDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->php_stereotype();

        if ((cl_stereotype == "interface") || (cl_stereotype == "@interface")) {
            if ((other_stereotype != "interface") && (other_stereotype != "@interface")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot extends a <i>")
                              + other_stereotype + "</i></b></font><br>");
                incr_warning();
                return;
            }
        }
        else if ((other_stereotype != "interface") && (other_stereotype != "@interface")) {
            if (cl_stereotype == "union") {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot extends</b></font><br>");
                incr_warning();
                return;
            }
            else if ((other_stereotype == "union") ||
                     (other_stereotype == "enum")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot extends an <i>")
                              + other_stereotype + "</i></b></font><br>");
                incr_warning();
                return;
            }
            else if (*sep == ',') {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>extend several classes</b></font><br>");
                incr_warning();
                return;
            }
        }
        else
            return;

        // here the code is legal
        f << sep;
        sep = ", ";

        const char * p = phpDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else
                f << *p++;
        }
    }
}
예제 #15
0
void UmlRelation::generate(QTextStream & f, const Q3CString &,
                           Q3CString indent, int &) {
    switch (relationKind()) {
    case aDependency:
    case aGeneralisation:
    case aRealization:
        break;
    default:
        if (!phpDecl().isEmpty()) {
            const char * p = phpDecl();
            const char * pp = 0;
            Q3CString s;

            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)
                        f << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f);
                else if (*p != '$')
                    f << *p++;
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, PhpSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${visibility}", 13)) {
                    p += 13;
                    generate_visibility(f);
                }
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;
                    if (isClassMember())
                        f << "static ";
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    if (!isReadOnly())
                        f << "$";
                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;
                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                    {
                        UmlRelation * inverse = side(side(TRUE) != this);

                        if (!inverse->isReadOnly())
                            f << "$";
                        f << inverse->roleName();
                    }
                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${var}", 6)) {
                    p += 6;
                    if (!isReadOnly() &&
                            !isClassMember() &&
                            (visibility() == PackageVisibility))
                        f << "var ";
                }
                else if (!strncmp(p, "${value}", 8)) {
                    if (!defaultValue().isEmpty()) {
                        if (need_equal(p, defaultValue()))
                            f << " = ";
                        f << defaultValue();
                    }
                    p += 8;
                }
                else if (!strncmp(p, "${const}", 8)) {
                    p += 8;
                    if (isReadOnly())
                        f << "const ";
                }
                else
                    f << *p++;
            }

            f << '\n';
        }
    }
}
예제 #16
0
void UmlRelation::gen_php_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${visibility}", 13)) {
            p += 13;
            write(visibility(), phpLanguage);
            fw.write(' ');
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;

            if (!isReadOnly())
                fw.write("$");

            writeq(roleName());
        }
        else if (!strncmp(p, "${var}", 6)) {
            p += 6;

            if (!isReadOnly() &&
                    !isClassMember() &&
                    (visibility() == PackageVisibility))
                fw.write("var ");
        }
        else if (!strncmp(p, "${value}", 8)) {
            p += 8;
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isReadOnly())
                fw.write("const ");
        }
        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 == ';') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #17
0
void UmlOperation::gen_cpp_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);

    if (! descr) {
        write((cppVisibility() == DefaultVisibility)
              ? visibility() : cppVisibility(),
              cppLanguage);
        fw.write(": ");
        p = bypass_comment(s);
    }
    else
        p = 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, "${friend}", 9)) {
            p += 9;

            if (isCppFriend())
                fw.write("friend ");
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${inline}", 9)) {
            p += 9;

            if (isCppInline())
                fw.write("inline ");
        }
        else if (!strncmp(p, "${virtual}", 10)) {
            p += 10;

            if (isCppVirtual())
                fw.write("virtual ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            write(returnType(), cppLanguage);
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(cppNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isCppConst())
                fw.write(" const");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write(" volatile");
        }
        else if (!strncmp(p, "${throw}", 8)) {
            p += 8;

            const char * sep = " throw (";
            QList<UmlTypeSpec> e = exceptions();
            unsigned n = e.count();
            unsigned index2;

            for (index2 = 0; index2 != n; index2 += 1) {
                fw.write(sep);
                sep = ", ";
                write(e[index2], cppLanguage);
            }

            if (index2 != 0)
                fw.write(')');
            else if (CppSettings::operationForceThrow())
                fw.write(" throw ()");
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                write(pa[rank].type, cppLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < pa.count())
                writeq(pa[rank].name);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= pa.count())
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            if (isAbstract())
                fw.write("= 0 ");

            break;
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if ((m != 0) || ((m = setOf()) != 0))
                writeq(CppSettings::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(), cppLanguage);
        }
        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++);
    }
}
예제 #18
0
void UmlClass::gen_cpp_decl(QCString s, bool descr) {
  const char * p = (descr)
    ? (const char *) s
    : (const char *) bypass_comment(s);

  while (*p) {
    if (!strncmp(p, "${comment}", 10))
      p += 10;
    else if (!strncmp(p, "${description}", 14))
      p += 14;
    else if (!strncmp(p, "${type}", 7)) {
      p += 7;
      bool find = FALSE;

      if (baseType().type != 0) {
	UmlClass * mother = baseType().type;
	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->roleType() == mother)) {
	      rel->roleType()->write();
	      generate(actuals(), mother, TRUE);
	      find = TRUE;
	      break;
	    }
	  }
	}
      }
      if (! find)
	UmlItem::write(baseType(), cppLanguage);
    }
    else if (!strncmp(p, "${template}", 11)) {
      p += 11;
      generate(formals());
    }
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      writeq(name());
    }
    else if (!strncmp(p, "${inherit}", 10)) {
      p += 10;

      const QVector<UmlItem> ch = children();
      const char * sep = " : ";

      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->cppDecl().isEmpty()) {
	    fw.write(sep);
	    // UmlItem::write else G++ call UmlClass::write(QCString) !
	    UmlItem::write((rel->cppVisibility() == DefaultVisibility)
		           ? rel->visibility() : rel->cppVisibility(),
			   cppLanguage);
	    fw.write((rel->cppVirtualInheritance()) ? " virtual " : " ");
	    rel->roleType()->write();
	    generate(actuals(), rel->roleType(), TRUE);
	    sep = ", ";
	  }
	}
      }
    }
    else if (*p == '{') {
      if (descr)
	fw.write(*p++);
      else
	break;
    }
    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 == '@')
      manage_alias(p);
    else
      writeq(*p++);
  }

}
예제 #19
0
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++);
    }
}
예제 #20
0
void UmlRelation::generate(QTextOStream & f, const Q3CString & cl_stereotype,
                           Q3CString indent) {
    switch (relationKind()) {
    case aDependency:
    case aGeneralisation:
    case aRealization:
        break;
    default:
        if (!javaDecl().isEmpty()) {
            if (cl_stereotype == "enum_pattern") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum_pattern</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            const char * p = javaDecl();
            const char * pp = 0;
            Q3CString s;

            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)
                        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, "${visibility}", 13)) {
                    p += 13;
                    generate_visibility(f, cl_stereotype);
                }
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;
                    if (isClassMember())
                        f << "static ";
                }
                else if (!strncmp(p, "${final}", 8)) {
                    p += 8;
                    if (isReadOnly())
                        f << "final ";
                }
                else if (!strncmp(p, "${transient}", 12)) {
                    p += 12;
                    if (isJavaTransient())
                        f << "transient ";
                }
                else if (!strncmp(p, "${volatile}", 11)) {
                    p += 11;
                    if (isVolatile())
                        f << "volatile ";
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f << JavaSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;
                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f << side(side(TRUE) != this)->roleName();
                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;

                    Q3CString m = multiplicity();

                    if (*m != '[')
                        f << "[]";
                    else {
                        for (unsigned index = 0; index != m.length(); index += 1) {
                            switch (m.at(index)) {
                            case '[':
                                f << '[';
                                break;
                            case ']':
                                f << ']';
                            default:
                                break;
                            }
                        }
                    }
                }
                else if (!strncmp(p, "${value}", 8)) {
                    if (!defaultValue().isEmpty()) {
                        if (need_equal(p, defaultValue()))
                            f << " = ";
                        f << defaultValue();
                    }
                    p += 8;
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    UmlClass::write(f, association());
                }
                else if (!strncmp(p, "${@}", 4)) {
                    p += 4;
                    if (pp != 0)
                        f << "${@}";
                    else if (! javaAnnotations().isEmpty()) {
                        pp =p;
                        p = javaAnnotations();
                    }
                }
                else
                    // strange
                    f << *p++;
            }

            f << '\n';
        }
    }
}
예제 #21
0
void UmlOperation::gen_python_decl(QByteArray s, bool descr)
{
    QByteArray cl_stereotype =
        PythonSettings::classStereotype(parent()->stereotype());
    const char * p = bypass_comment(s);
    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    bool in_params = FALSE;
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${docstring}", 12))
            p += 12;
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("@staticmethod<br />");
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract())
                fw.write("@abstractmethod<br />");
        }
        else if (!strncmp(p, "${@}", 4)) {
            p += 4;
            writeq(pythonDecorators());
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(pythonNameSpec()));
        }
        else if (!strncmp(p, "${class}", 8)) {
            p += 8;
            parent()->write();
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
            in_params = TRUE;
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
            in_params = FALSE;
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                const UmlTypeSpec & t = pa[rank].type;

                if (! t.toString().isEmpty()) {
                    if (in_params)
                        fw.write(": ");

                    write(t, pythonLanguage);
                }
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                fw.write('$');
                writeq(pa[rank].name);
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= npa)
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;

            const UmlTypeSpec & t = returnType();

            if (! t.toString().isEmpty()) {
                fw.write(" -> ");
                write(t, pythonLanguage);
            }
        }
        else if (*p == ':') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #22
0
void UmlAttribute::generate(QTextStream & f, const WrapperStr & st,
                            WrapperStr indent, int & enum_item_rank)
{
    if (!phpDecl().isEmpty()) {
        const char * p = phpDecl();
        const char * pp = 0;

        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)
                    f << indent;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else if (*p != '$')
                f << *p++;
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp, PhpSettings::isGenerateJavadocStyleComment());
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${visibility}", 13)) {
                p += 13;
                generate_visibility(f);
            }
            else if (!strncmp(p, "${static}", 9)) {
                p += 9;

                if (isClassMember())
                    f << "static ";
            }
            else if (!strncmp(p, "${type}", 7)) {
                p += 7;
                UmlClass::write(f, type());
            }
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;

                if ((st != "enum") && !isReadOnly())
                    f << "$";

                f << name();
            }
            else if (!strncmp(p, "${var}", 6)) {
                p += 6;

                if ((st != "enum") &&
                    !isReadOnly() &&
                    !isClassMember() &&
                    (visibility() == PackageVisibility))
                    f << "var ";
            }
            else if (!strncmp(p, "${value}", 8)) {
                if (!defaultValue().isEmpty()) {
                    if (need_equal(p, defaultValue()))
                        f << " = ";

                    f << defaultValue();
                }
                else if (st == "enum")
                    f << " = " << enum_item_rank;

                p += 8;
            }
            else if (!strncmp(p, "${const}", 8)) {
                p += 8;

                if (isReadOnly())
                    f << "const ";
            }
            else
                f << *p++;
        }

        f << '\n';
    }

    enum_item_rank += 1;
}
예제 #23
0
void UmlClass::gen_php_decl(QCString s, bool descr) {
  QCString st = PhpSettings::classStereotype(stereotype());
  
  if (st == "ignored")
    return;
    
  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, "${visibility}", 13)) {
      p += 13;
      UmlItem::write(visibility(), phpLanguage);
      fw.write(' ');
    }
    else if (!strncmp(p, "${final}", 8)) {
      p += 8;
      if (isPhpFinal())
	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->phpDecl().isEmpty()) &&
	      ((st == "interface") ||
	       (PhpSettings::classStereotype(rel->roleType()->stereotype()) != "interface"))) {
	    extend = rel;
	    fw.write(" extends ");
	    rel->roleType()->write();
	    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->phpDecl().isEmpty())) {
	    fw.write(sep);
	    sep = ", ";
	    rel->roleType()->write();
	  }
	}
      }
    }
    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++);
  }
}
예제 #24
0
void UmlRelation::gen_cpp_decl(QByteArray s, bool descr)
{
    const char * p;

    if (! descr) {
        write((cppVisibility() == DefaultVisibility)
              ? visibility() : cppVisibility(),
              cppLanguage);
        fw.write(": ");
        p = bypass_comment(s);
    }
    else
        p = s;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isReadOnly())
                fw.write("const ");
        }
        else if (!strncmp(p, "${mutable}", 10)) {
            p += 10;

            if (isCppMutable())
                fw.write("mutable ");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write("volatile ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            roleType()->write();
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(roleName());
        }
        else if (!strncmp(p, "${multiplicity}", 15)) {
            p += 15;

            QByteArray m = multiplicity();

            if (m.isEmpty() || (((const char *) m)[0] != '[')) {
                fw.write("[");
                writeq(m);
                fw.write("]");
            }
            else
                writeq(m);
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            writeq(CppSettings::relationAttributeStereotype(stereotype()));
        }
        else if (!strncmp(p, "${value}", 8) || !strncmp(p, "${h_value}", 10)) {
            break;
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            write(association(), cppLanguage);
        }
        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 == ';') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
예제 #25
0
void UmlOperation::generate(QTextStream & f, const WrapperStr &,
                            WrapperStr indent, BooL & indent_needed,
                            int &, const WrapperStr &)
{
    const char * p = pythonDecl();

    if ((p == 0) || (*p == 0))
        return;

    const char * pp = 0;
    WrapperStr saved_indent = indent;
    WrapperStr indent_step = PythonSettings::indentStep();
    const char * afterparam = 0;
    const QList<UmlParameter> & params = this->params();
    unsigned rank;
    bool isinline = TRUE;
    bool in_params = FALSE;

    for (;;) {
        if (*p == 0) {
            if (pp == 0)
                break;

            // comment management done
            p = pp;

            if (*p == 0)
                break;

            pp = 0;
            indent = saved_indent;
        }

        if (*p == '@')
            manage_alias(p, f, indent, indent_needed);
        else if (*p != '$') {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            switch (*p) {
            case ':':
                if (pp == 0) {
                    indent += indent_step;
                    saved_indent = indent;
                    indent_step = "";
                }

                break;

            case '\n':
                indent_needed = TRUE;
                break;
            }

            f << *p++;
        }
        else if (!strncmp(p, "${comment}", 10))
            manage_comment(p, pp);
        else if (!strncmp(p, "${description}", 14))
            manage_description(p, pp);
        else if (!strncmp(p, "${docstring}", 12))
            manage_docstring(p, pp, indent_needed, indent, saved_indent);
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember()) {
                if (indent_needed)
                    f << indent;
                else
                    indent_needed = TRUE;

                f << "@staticmethod\n";
            }
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract()) {
                if (indent_needed)
                    f << indent;
                else
                    indent_needed = TRUE;

                f << "@abstractmethod\n";
            }
        }
        else if (!strncmp(p, "${@}", 4)) {
            p += 4;
            manage_decorators(f, pythonDecorators(), indent, indent_needed);
        }
        else if (!strncmp(p, "${name}", 7)) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            p += 7;
            f << compute_name();
        }
        else if (!strncmp(p, "${class}", 8)) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            p += 8;
            f << parent()->name();
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            f << '(';
            in_params = TRUE;
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            f << ')';
            afterparam = p;
            in_params = FALSE;
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            if (!generate_type(params, rank, f, in_params))
                param_error(parent()->name(), name(), rank);

            p = strchr(p, '}') + 1;
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            if (!generate_var(params, rank, f))
                param_error(parent()->name(), name(), rank);

            p = strchr(p, '}') + 1;
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            if (!generate_init(params, rank, f))
                param_error(parent()->name(), name(), rank);

            p = strchr(p, '}') + 1;
        }
        else if (!strncmp(p, "${body}", 7) &&
                 (pp == 0))	{// not in comment
            isinline = FALSE;
            p = generate_body(f, indent, indent_needed, p);
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;

            UmlClassMember * m;

            if ((((m = getOf()) != 0) || ((m = setOf()) != 0)) &&
                (m->kind() == aRelation)) {
                if (indent_needed) {
                    indent_needed = FALSE;
                    f << indent;
                }

                UmlClass::write(f, ((UmlRelation *) m)->association());
            }
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;

            const UmlTypeSpec & t = returnType();

            if ((t.type != 0) || !t.explicit_type.isEmpty()) {
                f << " -> ";

                UmlClass::write(f, t);
            }
        }
        else {
            // strange
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            f << *p++;
        }
    }

    if (isinline) {
        if (indent_needed)
            f << indent << '\n';
        else
            f << '\n';

        indent_needed = TRUE;
    }
}
예제 #26
0
void UmlRelation::generate_inherit(const char *& sep, QTextStream & f_h,
                                   const Q3ValueList<UmlActualParameter> & actuals,
                                   const WrapperStr & cl_stereotype)
{
    switch (relationKind()) {
    default:
        break;

    case aGeneralisation:
    case aRealization:
        if ((cl_stereotype == "union") || (cl_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                          + cl_stereotype + "</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }
        else if (cl_stereotype == "typedef") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }

        UmlClass * role_type = roleType();
        const WrapperStr & other_stereotype = role_type->stereotype();

        if ((other_stereotype == "union") ||
            (other_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot inherits an <i>")
                          + other_stereotype + "</i></b></font><br>");
            incr_warning();
            return;
        }

        f_h << sep;
        sep = ", ";

        if (cppVirtualInheritance())
            f_h << "virtual ";

        aVisibility visibility = (cppVisibility() == DefaultVisibility)
                                 ? this->visibility() : cppVisibility();

        switch (visibility) {
        case PublicVisibility:
        case PackageVisibility:
            f_h << "public ";
            break;

        case ProtectedVisibility:
            f_h << "protected ";
            break;

        default:
            f_h  << "private ";
        }

        const char * p = cppDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f_h, FALSE, 0, actuals);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f_h);
            else
                f_h << toLocale(p);
        }
    }
}
예제 #27
0
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';
    }
}
예제 #28
0
void UmlRelation::generate_decl(aVisibility & current_visibility, QTextStream & f_h,
                                const WrapperStr & cl_stereotype, WrapperStr indent,
                                BooL & first, bool)
{
    switch (relationKind()) {
    case aDependency:
        if (stereotype() == "friend") {
            Q3ValueList<UmlFormalParameter> formals = roleType()->formals();

            if (! formals.isEmpty()) {
                const char * sep = "  template <";
                Q3ValueList<UmlFormalParameter>::ConstIterator it;

                for (it = formals.begin(); it != formals.end(); ++it) {
                    f_h << sep << (*it).type() << ' ' << (*it).name();
                    sep = ", ";
                }

                f_h << "> ";
            }
            else
                f_h << "  ";

            f_h << "friend " << roleType()->cpp_stereotype() << " ";
            roleType()->write(f_h, FALSE);
            f_h << ";\n";
            first = FALSE;
        }

        break;

    case aGeneralisation:
    case aRealization:
        break;

    default:
        if (!cppDecl().isEmpty()) {
            if (cl_stereotype == "enum") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            if (cl_stereotype == "typedef") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            generate_visibility(current_visibility, f_h, first, indent);
            first = FALSE;

            const char * p = cppDecl();
            const char * pp = 0;
            WrapperStr s;

            while ((*p == ' ') || (*p == '\t'))
                indent += toLocale(p);

            if (*p != '#')
                f_h << indent;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;

                    if (*p != '#')
                        f_h << indent;
                }

                if (*p == '\n') {
                    f_h << toLocale(p);

                    if (*p && (*p != '#'))
                        f_h << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f_h);
                else if (*p != '$')
                    f_h << toLocale(p);
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;

                    if (isClassMember())
                        f_h << "static ";
                }
                else if (!strncmp(p, "${const}", 8)) {
                    p += 8;

                    if (isReadOnly())
                        f_h << "const ";
                }
                else if (!strncmp(p, "${volatile}", 11)) {
                    p += 11;

                    if (isVolatile())
                        f_h << "volatile ";
                }
                else if (!strncmp(p, "${mutable}", 10)) {
                    p += 10;

                    if (isCppMutable())
                        f_h << "mutable ";
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f_h);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f_h << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;

                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f_h << side(side(TRUE) != this)->roleName();

                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;

                    const WrapperStr & m = multiplicity();

                    if (!m.isEmpty() && (*((const char *) m) == '['))
                        f_h << m;
                    else
                        f_h << '[' << m << ']';
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f_h << CppSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${value}", 8))
                    p += 8;
                else if (!strncmp(p, "${h_value}", 10)) {
                    if (!defaultValue().isEmpty() && isClassMember()) {
                        if (need_equal(p, defaultValue()))
                            f_h << " = ";

                        f_h << defaultValue();
                    }

                    p += 10;
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    UmlClass::write(f_h, association());
                }
                else
                    // strange
                    f_h << toLocale(p);
            }

            f_h << '\n';
        }
    }
}
예제 #29
0
void UmlArtifact::generate() {
  if (! managed) {
    managed = TRUE;
    
    if (stereotype() == "text") {
      generate_text();
      return;
    }
    else if (stereotype() != "source")
      return;
    
    package_of_generated_artifact = package();
    
    const Q3CString def = idlSource();
    
    if (def.isEmpty())
      return;
    
    const Q3CString & name = this->name();    
    UmlPackage * pack = package();
    Q3CString path = pack->path(name);
    Q3CString mod_start;
    Q3CString mod_end;
    Q3CString mod = pack->idlModule();
    
    if (! mod.isEmpty()) {
      int index = 0;
      int index2;
      Q3CString closed = "\n}; // module ";
      
      while ((index2 = mod.find(':', index)) != -1) {
	Q3CString mo = mod.mid(index, index2 - index);
	
	mod_start += Q3CString("module ") + mo + " {\n\n";
	closed += mo;
	mod_end = closed + "\n" + mod_end;
	closed += "::";
	mod.replace(index2, 2, "_");
	index = index2 + 1;
      }
      
      mod_start += Q3CString("module ") + mod.mid(index) + " {\n\n";
      closed += mod.mid(index);
      mod_end = closed + "\n" + mod_end;
    }
    
    UmlCom::message(name);
    if (verbose())
      UmlCom::trace(Q3CString("<hr><font face=helvetica>Generate code for <i> ")
		    + name + "</i> in <i>" + path + "</i></font><br>");
    else
      set_trace_header(Q3CString("<font face=helvetica>Generate code for <i> ")
		       + name + "</i> in <i>" + path + "</i></font><br>");
    
#if 0
    // compute dependencies
    
    Q3PtrList<CppRefType> dependencies;
#endif
    const Q3PtrVector<UmlClass> & cls = associatedClasses();
    unsigned n = cls.count();
    unsigned index;
    
#if 0
    for (index = 0; index != n; index += 1)
      cls[index]->compute_dependencies(dependencies);
#endif
    
    // generate source file
    
    QByteArray file;
    QTextOStream f(&file);
    const char * p = def;
    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);
      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, "${module}", 9)) {
	p += 9;
	f << mod;
      }
      else if (!strncmp(p, "${MODULE}", 9)) {
	p += 9;
	f << mod.upper();
      }
      else if (!strncmp(p, "${includes}", 11)) {
	p += 11;
	/*if (!incl_computed) {
	  incl_computed = TRUE;
	  CppRefType::compute(dependencies, hdef, srcdef, h_incl, decl, incl, this);
	}
	if (!incl.isEmpty()) {
	  f << incl;
	  if (*p != '\n')
	    f << '\n';
	}
	else*/ if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${definition}", 13)) {
	p += 13;
	for (index = 0; index != n; index += 1)
	  cls[index]->generate(f);
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_start}", 15)) {
	p += 15;
	if (!mod_start.isEmpty())
	  f << mod_start;
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_end}", 13)) {
	p += 13;
	if (!mod_end.isEmpty())
	  f << mod_end;
	if (*p == '\n')
	  p += 1;
      }
      else
	// strange
	f << *p++;
    }
    
    f << '\000';
    
    if (must_be_saved(path, file)) {
      write_trace_header();
	
      FILE * fp;
      
      if ((fp = fopen((const char *) path, "wb")) == 0) {
	write_trace_header();
	UmlCom::trace(Q3CString("<font color=\"red\"><b><i> ")
		      + name + " : </i> cannot open <i> " 
		      + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
		      + pack->name() + "</i> Idl directory specification</b></font><br>");
	incr_error();
      }
      else {
	fputs((const char *) file, fp);
	fclose(fp);
      }
    }
    else if (get_trace_header().isEmpty())
      UmlCom::trace(Q3CString("<font face=helvetica><i> ")
		    + path + "</i> not modified</font><br>");
  }
}
예제 #30
0
void UmlRelation::generate_def(QTextStream & f, WrapperStr indent, bool h,
                               WrapperStr templates, WrapperStr cl_names,
                               WrapperStr, WrapperStr)
{
    if (isClassMember() && !cppDecl().isEmpty()) {
        UmlClass * cl = (UmlClass *) parent();

        if ((!templates.isEmpty() || (cl->name().find('<') != -1))
            ? h : !h) {
            const char * p = cppDecl();
            const char * pp = 0;

            while ((*p == ' ') || (*p == '\t'))
                p += 1;

            bool re_template = !templates.isEmpty() &&
                               insert_template(p, f, indent, templates);

            if (*p != '#')
                f << indent;

            const char * pname = name_spec(p);

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (re_template)
                        f << templates;

                    if (*p == 0)
                        break;

                    if (*p != '#')
                        f << indent;
                }

                if (*p == '\n') {
                    f << toLocale(p);

                    if (*p && (*p != '#'))
                        f << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f);
                else if (*p != '$') {
                    if (p == pname)
                        f << cl_names << "::";

                    f << toLocale(p);
                }
                else if (!strncmp(p, "${comment}", 10)) {
                    if (!manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment())
                        && re_template)
                        f << templates;
                }
                else if (!strncmp(p, "${description}", 14)) {
                    if (!manage_description(p, pp) && re_template)
                        f << templates;
                }
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;
                }
                else if (!strncmp(p, "${const}", 8)) {
                    p += 8;

                    if (isReadOnly())
                        f << "const ";
                }
                else if (!strncmp(p, "${volatile}", 11)) {
                    p += 11;

                    if (isVolatile())
                        f << "volatile ";
                }
                else if (!strncmp(p, "${mutable}", 10)) {
                    p += 10;
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;

                    if (*pname == '$')
                        f << cl_names << "::";

                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;

                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f << side(side(TRUE) != this)->roleName();

                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;

                    const WrapperStr & m = multiplicity();

                    if (!m.isEmpty() && (*((const char *) m) == '['))
                        f << m;
                    else
                        f << '[' << m << ']';
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f << CppSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${value}", 8)) {
                    if (!defaultValue().isEmpty()) {
                        if (need_equal(p, defaultValue()))
                            f << " = ";

                        f << defaultValue();
                    }

                    p += 8;
                }
                else if (!strncmp(p, "${h_value}", 10))
                    p += 10;
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    UmlClass::write(f, association());
                }
                else
                    // strange
                    f << toLocale(p);
            }

            f << '\n';
        }
    }
}