Ejemplo n.º 1
0
void UmlClass::add_inherited_opers(Vector * ops)
{
    if (inherited_opers == 0) {
        const QVector<UmlItem*> ch = children();

        inherited_opers = new Vector;

        for (int i = 0; i != ch.size(); i += 1) {
            switch (ch[i]->kind()) {
            case aRelation: {
                UmlRelation * rel = (UmlRelation *) ch[i];
                aRelationKind k = rel->relationKind();

                if ((k == aGeneralisation) || (k == aRealization))
                    rel->roleType()->add_inherited_opers(inherited_opers);
            }
            break;

            case anOperation: {
                UmlOperation * op = (UmlOperation *) ch[i];

                if ((op->visibility() == PublicVisibility) &&
                    (op->name()[0] != '~') &&
                    (op->name() != name()))
                    inherited_opers->addElement(op);
            }

            default:
                break;
            }
        }
    }

    if (ops != 0)
        for (unsigned i = 0; i != inherited_opers->size(); i += 1)
            if (! ops->contains(inherited_opers->elementAt(i)))
                ops->addElement(inherited_opers->elementAt(i));

    unload(TRUE, FALSE);
}
Ejemplo n.º 2
0
void UmlOperation::roundtrip(const char * path, aLanguage who)
{
    char * s = read_file(path);

    if (s != 0) {
        char * p1 = s;
        char * p2;
        WrapperStr(UmlOperation::*get_body)();
        bool (UmlOperation::*set_body)(const char * s);
        bool (UmlOperation::*set_contextualbodyindent)(bool v);
        const char * prefix;
        const char * postfix;

        switch (who) {
        case cppLanguage:
            get_body = &UmlOperation::cppBody;
            set_body = &UmlOperation::set_CppBody;
            set_contextualbodyindent = &UmlOperation::set_CppContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        case javaLanguage:
            get_body = &UmlOperation::javaBody;
            set_body = &UmlOperation::set_JavaBody;
            set_contextualbodyindent = &UmlOperation::set_JavaContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        case phpLanguage:
            get_body = &UmlOperation::phpBody;
            set_body = &UmlOperation::set_PhpBody;
            set_contextualbodyindent = &UmlOperation::set_PhpContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        default:
            // python
            get_body = &UmlOperation::pythonBody;
            set_body = &UmlOperation::set_PythonBody;
            set_contextualbodyindent = &UmlOperation::set_PythonContextualBodyIndent;
            prefix = BodyPythonPrefix;
            postfix = BodyPythonPostfix;
        }

        while ((p2 = strstr(p1, prefix)) != 0) {
            p2 += BodyPrefixLength;

            char * body;
            long id = strtol(p2, &body, 16);

            if (body != (p2 + 8)) {
                UmlCom::trace(WrapperStr("<font color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body identifier</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 1");
            }

            if (*body == '\r')
                body += 1;

            if (*body == '\n')
                body += 1;
            else {
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body block, end of line expected</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 2");
            }

            UmlOperation * op = (UmlOperation *)
                                UmlBaseItem::from_id((unsigned) id, anOperation);

            if (op == 0) {
                QString n("%1");
                n.arg(QString::number((unsigned) id));
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid operation id " + n + "</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 3");
                return;
            }

            if (((p1 = strstr(body, postfix)) == 0) ||
                (strncmp(p1 + BodyPostfixLength, p2, 8) != 0)) {
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body block, wrong balanced</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 4");
            }

            p2 = p1;

            while ((p2 != body) && (p2[-1] != '\n'))
                p2 -= 1;

            char c = *p2;

            *p2 = 0;

            WrapperStr previous = (op->*get_body)();

            if (!op->isBodyGenerationForced() && (body != previous)) {
                if (!(op->*set_body)(body)) {
                    write_trace_header();
                    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot update body of <i>"
                                  + op->name() +
                                  ((op->isWritable()) ? "</i>, it is probably deleted</b></font><br>"
                                   : "</i>, it is read-only</b></font><br>"));
                    incr_error();
                }
                else {
                    (op->*set_contextualbodyindent)(FALSE);

                    write_trace_header();
                    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;update body of <i>"
                                  + op->name() + "</i><br>");
                }
            }
            else if (verbose()) {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;body of <i>"
                              + op->name() + "</i> unchanged<br>");
            }

            *p2 = c;
            p1 += BodyPostfixLength + 8;
        }

        delete [] s;
    }
}