Exemple #1
0
static WrapperStr root_relative_if_possible(WrapperStr p)
{
    unsigned rln = RootCDir.length();

    return ((p.length() >= rln) && (p.left(rln) == RootCDir))
           ? p.mid(rln)
           : p;
}
Exemple #2
0
static void manage_decorators(QTextStream & f, const WrapperStr & decorators,
                              QString indent, BooL & indent_needed)
{
    if (! decorators.isEmpty()) {
        int index = 0;
        int index2;

        while ((index2 = decorators.find("\n", index)) != -1) {
            if (indent_needed)
                f << indent;
            else
                indent_needed = TRUE;

            f << decorators.mid(index, index2 + 1 - index);
            index = index2 + 1;
        }

        if (index != (int) decorators.length()) {
            if (indent_needed) {
                f << indent;
                indent_needed = FALSE;
            }

            f << decorators.mid(index);
        }
    }
}
Exemple #3
0
void UmlItem::replace_alias(WrapperStr & s)
{
    int index = 0;

    while ((index = s.find("@{", index)) != -1) {
        int index2 = s.find('}', index + 2);

        if (index2 == -1)
            return;

        UmlBaseItem * obj = this;
        WrapperStr key = s.mid(index + 2, index2 - index - 2);
        WrapperStr value;

        for (;;) {
            if (obj->propertyValue(key, value)) {
                s.replace(index, index2 - index + 1, value);
                index += value.length();
                break;
            }
            else if ((obj = obj->parent()) == 0) {
                index = index2 + 1;
                break;
            }
        }
    }
}
Exemple #4
0
void UmlClass::need_artifact(const QStringList & imports,
                             bool remove_java_lang,
                             const QStringList & ,
                             const WrapperStr & path, UmlArtifact *& cp)
{
    if (parent()->kind() == aClassView) {
        if (cp != 0)
            cp->addAssociatedClass(this);
        else {
            UmlPackage * pack = (UmlPackage *) parent()->parent();

            if ((cp = associatedArtifact()) == 0) {
                // create associated artifact
                QFileInfo fi(path);
                WrapperStr artname = WrapperStr(fi.baseName().toAscii().constData());

                if ((cp = UmlBaseArtifact::create(pack->get_deploymentview(), artname)) == 0) {
                    UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ")
                                  + artname + "</i></b></font><br>");
                    return;
                }

                cp->addAssociatedClass(this);
            }

            cp->set_Stereotype("source");

            WrapperStr s = JavaSettings::sourceContent();
            int index = s.find("${definition}");

            if (index != -1) {


                for (QStringList::const_iterator it = imports.begin(); it != imports.end(); it++) {
                    WrapperStr import = WrapperStr((*it).toAscii().constData());

                    if (!remove_java_lang || (import != "java.lang.")) {
                        import += (((const char *) import)[import.length() - 1] == '.')
                                  ? "*;\n" : ";\n";

                        s.insert(index, (const char *)("import " + import));
                        index = s.find("${definition}", index);
                    }
                }

                for (QStringList::const_iterator it = imports.begin(); it != imports.end(); it++) {
                    s.insert(index, (const char *)("import static" + WrapperStr((*it).toAscii().constData()) + '\n'));
                    index = s.find("${definition}", index);
                }
            }

            cp->set_JavaSource(WrapperStr(s));
        }
    }
}
Exemple #5
0
static WrapperStr force_final_slash(WrapperStr p)
{
    int ln = p.length();

    if (ln < 2)
        return p;

    return (p[ln - 1] != '/')
           ? WrapperStr(p + '/')
           : p;
}
Exemple #6
0
void UmlItem::importExtension(FileIn & in, Token & token, UmlItem * where)
{
    if (! token.closed()) {
        WrapperStr s = token.valueOf("extender");

        if (s.isNull())
            s = token.valueOf("xmi:extender");

        if (s == "Bouml") {
            WrapperStr k = token.what();
            const char * kstr = k;

            while (in.read(), !token.close(kstr)) {
                s = token.what();

                if (s == "taggedvalue")
                    // is closed
                    where->set_PropertyValue(token.valueOf("tag"), token.valueOf("value"));
                else if (s == "stereotype")
                    where->set_Stereotype(token.valueOf("name"));

                if (! token.closed())
                    in.finish(token.what());
            }
        }
        else if (s == "Visual Paradigm for UML") {
            WrapperStr k = token.what();
            const char * kstr = k;

            while (in.read(), !token.close(kstr)) {
                s = token.what();

                if (s == "appliedstereotype") {
                    s = token.valueOf("xmi:value");

                    if (s.right(3) == "_id") {
                        s = s.mid(s.find("_") + 1);
                        s = s.left(s.length() - 3).lower();
                    }

                    where->set_Stereotype(s);
                }

                if (! token.closed())
                    in.finish(token.what());
            }
        }
        else
            in.finish(token.what());
    }
}
Exemple #7
0
void UmlClass::write(QTextStream & f, const UmlTypeSpec & t,
                     bool with_formals, BooL * is_template)
{
    if (t.type != 0)
        t.type->write(f, with_formals, is_template);
    else {
        WrapperStr s = CppSettings::type(t.explicit_type);

        f << s;

        if (is_template != 0)
            *is_template = (!s.isEmpty() && (s.at(s.length() - 1) == QString('>')));
    }

}
Exemple #8
0
WrapperStr UmlItem::legalName(WrapperStr s)
{
    unsigned index;
    unsigned n = s.length();

    for (index = 0; index != n; index += 1) {
        char c = s.operator QString().toLocal8Bit()[index];

        if (!(((c >= 'a') && (c <= 'z')) ||
              ((c >= 'A') && (c <= 'Z')) ||
              ((c >= '0') && (c <= '9')) ||
              (c == '_')))
            s.replace(index, 1, "_");
    }

    return s;
}
Exemple #9
0
WrapperStr UmlItem::legalName(WrapperStr s)
{
    unsigned index;
    unsigned n = s.length();

    for (index = 0; index != n; index += 1) {
        char c = s.at(index);

        if (!(((c >= 'a') && (c <= 'z')) ||
              ((c >= 'A') && (c <= 'Z')) ||
              ((c >= '0') && (c <= '9')) ||
              (c == '_')))
            s.replace(index, 1, "_");
    }

    return s;
}
Exemple #10
0
bool UmlClass::is_itself(WrapperStr t)
{
    // class is a template class and t is x<...> where x is the class,
    // t is normalized
    // return true if t is the class with its formals
    int index = t.find('<');

    t = t.mid(index + 1, t.length() - index - 2);

    QList<UmlFormalParameter> l = formals();
    QList<UmlFormalParameter>::ConstIterator it = l.begin();
    WrapperStr t2 = (*it).name();

    while ((++it) != l.end())
        t2 += ',' + (*it).name();

    return (t == t2);
}
Exemple #11
0
// Between template < and > I suppose that a type is not included
// because I cannot know how the type is used and I do not want to
// produce circular #include
bool UmlClassMember::compute_dependency(Q3PtrList<CppRefType> & dependencies,
                                        WrapperStr decl, const UmlTypeSpec & t,
                                        bool force_incl)
{
    remove_comments(decl);
    remove_preprocessor(decl);
    remove_arrays(decl);

    int template_level = 0;
    bool have_type = FALSE;
    const char * p = decl;
    const char * dontsubstituteuntil = 0;

    for (;;) {
        UmlTypeSpec ts;
        char c;
        bool dontsearchend = FALSE;

        // search word beginning
        while ((c = *p) != 0) {
            if ((c == '_') ||
                ((c >= 'a') && (c <= 'z')) ||
                ((c >= 'A') && (c <= 'Z')))
                break;
            else if (dontsubstituteuntil != 0) {
                if (p >= dontsubstituteuntil)
                    dontsubstituteuntil = 0;
                else
                    p += 1;
            }
            else if (c == '=')
                // init, all is done
                return have_type;
            else if (!strncmp(p, "${type}", 7)) {
                p += 7;
                ts = t;

                if (ts.type != 0) {
                    dontsearchend = TRUE;
                    break;
                }
                else {
                    decl = ts.explicit_type + p;
                    p = decl;
                }
            }
            else {
                switch (c) {
                case '<':
                    template_level += 1;
                    break;

                case '>':
                    template_level -= 1;
                }

                p += 1;
            }
        }

        if (c == 0)
            return have_type;

        if (!dontsearchend) {
            // search word end
            const char * p2 = p;

            ts.type = 0;
            ts.explicit_type = p2;
            p += 1;

            while ((c = *p) != 0) {
                if ((c == '_') ||
                    (c == ':') ||
                    ((c >= 'a') && (c <= 'z')) ||
                    ((c >= 'A') && (c <= 'Z')) ||
                    ((c >= '0') && (c <= '9')))
                    p += 1;
                else {
                    ts.explicit_type.truncate(p - p2);
                    break;
                }
            }

//#warning NAMESPACE

            if (dontsubstituteuntil == 0) {
                WrapperStr subst = CppSettings::type(ts.explicit_type);

                if (subst != ts.explicit_type) {
                    decl = subst + ' ' + p;
                    p = decl;
                    dontsubstituteuntil = p + subst.length();
                    continue;
                }
            }
        }

        // check manually added keyword
        if ((ts.explicit_type == "const") ||
            (ts.explicit_type == "static"))
            continue;

        // search for a * or & or < after the typename
        bool incl = (template_level == 0);

        while ((c = *p) != 0) {
            if ((c == '*') || (c == '&')) {
                incl = FALSE;
                p += 1;
                break;
            }

            if ((c == '<') ||
                (c == '>') ||
                (c == '(') ||
                (c == ')') ||
                (c == ',') ||
                (c == '_') ||
                (c == '$') ||
                ((c >= 'a') && (c <= 'z')) ||
                ((c >= 'A') && (c <= 'Z'))) {
                break;
            }

            p += 1;
        }

        if (CppRefType::add(ts, dependencies, force_incl || incl))
            have_type = TRUE;
    }

    return have_type;
}
Exemple #12
0
bool Class::manage_member(WrapperStr s)
{
    WrapperStr comment = Lex::get_comments();
    WrapperStr description = Lex::get_description();
    int index;
    WrapperStr access = value_of(description, "@access", index);
    aVisibility visibility;

    if (access == "public")
        visibility = PublicVisibility;
    else if (access == "protected")
        visibility = ProtectedVisibility;
    else if (access == "private")
        visibility = PrivateVisibility;
    else
        visibility = PackageVisibility;

    if (visibility != PackageVisibility) {
        description.replace(index, access.length(), "${visibility}");

        access = value_of(comment, "@access", index);
        comment.replace(index, access.length(), "${visibility}");
    }

    bool m_staticp = FALSE;
    bool m_constp = FALSE;
    bool m_abstractp = FALSE;
    bool m_finalp = FALSE;

#ifdef TRACE
    QLOG_INFO() << "Class::manage_member(" << s << ")\n";
#endif

    for (;;) {
        if (s == "public")
            visibility = PublicVisibility;
        else if (s == "protected")
            visibility = ProtectedVisibility;
        else if (s == "private")
            visibility = PrivateVisibility;
        else if (s == "static")
            m_staticp = TRUE;
        else if (s == "const")
            m_constp = TRUE;
        else if (s == "final")
            m_finalp = TRUE;
        else if (s == "abstract")
            m_abstractp = TRUE;
        else if (s != "var")
            break;

        s = Lex::read_word();
    }

    if (s == "function") {
        // an operation
        return UmlOperation::new_one(this, visibility, m_finalp, m_abstractp,
                                     m_staticp, comment, description);
    }

    for (;;) {
        WrapperStr name = s;
        WrapperStr value;

        s = Lex::read_word();

#ifdef TRACE
        QLOG_INFO() << "define var '" << ((const char *) name) << "' followed by '" << ((const char *) s) << "'\n";
#endif

        if (s == "=") {
            // initialized variable, by pass value
            Lex::mark();
            UmlOperation::skip_expr(0);

            value = Lex::region();

#ifdef TRACE
            QLOG_INFO() << "value form is '" << ((const char *) value) << "'\n";
#endif
            char c = ((const char *) value)[value.length() - 1];

            if ((c == ';') || (c == ',')) {
                value.truncate(value.length() - 1); // remove ';' or ','
                s = (c == ';') ? ";" : ",";
            }
            else
                s = Lex::read_word();
        }

        if ((s != ";") && (s != ",")) {
            Lex::error_near(s);
            return FALSE;
        }

        if (!UmlAttribute::new_one(this, name, visibility, m_constp, m_staticp,
                                   value, comment, description))
            return FALSE;

        if (s == ";")
            return TRUE;

        // var1, var2 ...;
        s = Lex::read_word();

        if (s.isEmpty()) {
            if (! Package::scanning())
                Lex::premature_eof();

            return FALSE;
        }
    }
}
Exemple #13
0
bool UmlAttribute::new_one(Class * container, const WrapperStr & name,
                           const WrapperStr & type, const WrapperStr & modifier,
                           const WrapperStr & pretype, const WrapperStr & array,
                           aVisibility visibility, bool staticp, bool constp,
                           bool typenamep, bool mutablep, bool volatilep,
                           const WrapperStr & bitfield, const WrapperStr & value,
                           WrapperStr comment, WrapperStr description
#ifdef ROUNDTRIP
                           , bool roundtrip, QList<UmlItem *> & expected_order
#endif
                          )
{
#ifdef DEBUG_DOUML
    QLOG_INFO() << "ATTRIBUTE '" << name << "' type '" << type << "' modifier '" << modifier << "' array '" << array << "'\n";
#endif

    if (
#ifdef REVERSE
        container->from_libp() &&
#endif
        (visibility == PrivateVisibility)) {
        Lex::finish_line();
        Lex::clear_comments();
        return TRUE;
    }

    UmlClass * cl = container->get_uml();
    UmlAttribute * at;

#ifdef ROUNDTRIP
    bool created;

    if (!roundtrip ||
        ((at = search_attr(cl, name)) == 0)) {
#endif
        at = UmlBaseAttribute::create(cl, name);

        if (at == 0) {
            UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>")
                          + name + "</i> in <i>" + WrapperStr(cl->name())
                          + "</i></b></font><br><hr>");
            return FALSE;
        }

#ifdef REVERSE
# ifndef ROUNDTRIP
        Statistic::one_attribute_more();
# else

        if (roundtrip)
            container->set_updated();

        created = TRUE;
    }
    else
        created = FALSE;

# endif
#endif

        Lex::finish_line();

        comment = Lex::get_comments(comment);
        description = Lex::get_description(description);

        bool pfunc = (type.find('$') != -1);
        UmlTypeSpec typespec;
        WrapperStr typeform;
        WrapperStr stereotype;

        if (! pfunc) {
            typeform = (pretype.isEmpty())
                       ? WrapperStr("${type}")
                       : pretype + " ${type}";

            container->compute_type(type, typespec, typeform);
        }
        else {
            typespec.explicit_type = type.simplifyWhiteSpace();

            int index = typespec.explicit_type.find("${name}");

            if (index != -1)
                typespec.explicit_type.remove(index, 7);
        }

        WrapperStr decl = CppSettings::attributeDecl("");
        int index = decl.find("${type}");

        if ((index == -1) ||
            (decl.find("${const}") == -1) ||
            (decl.find("${name}") == -1) ||
            (decl.find("${mutable}") == -1) ||
            (decl.find("${volatile}") == -1) ||
            (decl.find(';') == -1)) {
            decl = "    ${comment}${static}${mutable}${volatile}${const}${type} ${name}${value};";
            index = decl.find("${type}");
        }

        if (pfunc)
            decl.replace(index, decl.find("${name}") + 7 - index, type);
        else {
            if (!modifier.isEmpty())
                decl.insert(index + 7, (const char *)(WrapperStr(" ") + modifier));

            if (typeform != "${type}")
                decl.replace(index, 7, typeform);
            else if (typespec.type == 0) {
                WrapperStr t = typespec.explicit_type;
                int index2 = 0;

                if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0))
                {
                    stereotype = t.left(index2);
                    typespec.explicit_type =
                        // may be a,b ...
                        t.mid(index2 + 1, t.length() - 2 - index2);
                    decl.replace(index, 7, "${stereotype}<${type}>");
                }
            }

            if (!array.isEmpty())
                decl.insert(decl.find("${name}") + 7, "${multiplicity}");

            if (!bitfield.isEmpty())
                decl.insert(decl.find(';'), (const char *)(WrapperStr(" : ") + bitfield));
        }

        if (typenamep) {
            int index = decl.find("${const}") + 8; // find cannot return -1
            int index2 = decl.find("${mutable}") + 10; // find cannot return -1
            int index3 = decl.find("${volatile}") + 11; // find cannot return -1

            if (index2 > index) index = index2;

            if (index3 > index) index = index3;

            decl.insert(index, "typename ");
        }

        if (!value.isEmpty() && ((index = decl.find("${value}")) != -1))
            decl.insert(index + 2,  "h_");

#ifdef ROUNDTRIP

        if (roundtrip && !created) {
            if (decl.find("${description}") != -1) {
                if (nequal(at->description(), description)) {
                    at->set_Description(description);
                    container->set_updated();
                }
            }
            else if (nequal(at->description(), Lex::simplify_comment(comment))) {
                at->set_Description(comment); // comment was set
                container->set_updated();
            }

            if (at->isReadOnly() != constp) {
                at->set_isReadOnly(constp);
                container->set_updated();
            }

            if (at->isCppMutable() != mutablep) {
                at->set_isCppMutable(mutablep);
                container->set_updated();
            }

            if (at->isVolatile() != volatilep) {
                at->set_isVolatile(volatilep);
                container->set_updated();
            }

            if (at->isClassMember() != staticp) {
                at->set_isClassMember(staticp);
                container->set_updated();
            }

            if (neq(at->multiplicity(), array)) {
                at->set_Multiplicity(array);
                container->set_updated();
            }

            if (!staticp) {
                WrapperStr v = at->defaultValue();

                if (!v.isEmpty() && (((const char *) v)[0] == '='))
                    v = v.mid(1);

                if (nequal(v, value)) {
                    at->set_DefaultValue(value);
                    container->set_updated();
                }
            }

            if (at->visibility() != visibility) {
                at->set_Visibility(visibility);
                container->set_updated();
            }

            if (!stereotype.isEmpty()) {
                WrapperStr cppst;

                if (!at->stereotype().isEmpty())
                    cppst = CppSettings::relationAttributeStereotype(at->stereotype());

                if (cppst != stereotype) {
                    at->set_Stereotype(stereotype);
                    container->set_updated();
                }
            }

            if (!at->type().equal(typespec)) {
                at->set_Type(typespec);
                container->set_updated();
            }

            if (neq(at->cppDecl(), decl)) {
                at->set_CppDecl(decl);
                container->set_updated();
            }

            at->set_usefull();

            expected_order.append(at);
        }
        else {
#endif

            if (!comment.isEmpty())
                at->set_Description((decl.find("${description}") != -1)
                                    ? description : Lex::simplify_comment(comment));

            if (constp)
                at->set_isReadOnly(TRUE);

            if (mutablep)
                at->set_isCppMutable(TRUE);

            if (volatilep)
                at->set_isVolatile(TRUE);

            if (staticp)
                at->set_isClassMember(TRUE);

            if (!array.isEmpty())
                at->set_Multiplicity(array);

            if (! value.isEmpty())
                at->set_DefaultValue(value);

            at->set_Visibility(visibility);

            if (! stereotype.isEmpty())
                at->set_Stereotype(stereotype);

            at->set_Type(typespec);

            at->set_CppDecl(decl);

#ifdef ROUNDTRIP

            if (roundtrip)
                expected_order.append(at);
        }

#endif

        return TRUE;
    }
Exemple #14
0
// from a form 'generic<...C...> var' where C is a class
    bool UmlRelation::new_one(Class * container, const WrapperStr & name,
                              UmlClass * type, WrapperStr type_def,
                              WrapperStr genericname,
                              aVisibility visibility, bool staticp,
                              bool constp, bool transientp, bool volatilep,
                              const WrapperStr & array, const WrapperStr & value,
                              WrapperStr comment, WrapperStr description,
                              WrapperStr annotation
#ifdef ROUNDTRIP
                              , bool roundtrip, QList<UmlItem *> & expected_order
#endif
                             )
    {
#ifdef TRACE
        QLOG_INFO() << "RELATION '" << name << "' from '" << cl->Name() << "' to '" << type->Name()
                    << "' array '" << array << "'\n";
#endif

        if (
#ifdef REVERSE
            container->from_libp() &&
#endif
            (visibility == PrivateVisibility)) {
            Lex::finish_line();
            Lex::clear_comments();
            return TRUE;
        }

        WrapperStr st = JavaSettings::umlType(genericname);

        if (st.isEmpty())
            st = genericname;

        UmlClass * cl = container->get_uml();
        UmlRelation * rel;

#ifdef ROUNDTRIP
        bool created;

        if (!roundtrip ||
            ((rel = search_rel(container, name, type, st)) == 0)) {
#endif
            rel = UmlBaseRelation::create(aDirectionalAssociation, cl, type);

            if (rel == 0) {
                JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add relation <i>")
                                     + name + "</i> in <i>" + cl->name() + "</i> to <i>"
                                     + type->name() + "</i></b></font><br>");
                return FALSE;
            }

#ifdef REVERSE
# ifndef ROUNDTRIP
            Statistic::one_relation_more();
# else

            if (roundtrip)
                container->set_updated();

            created = TRUE;
        }
        else
            created = FALSE;

# endif
#endif

            Lex::finish_line();

            comment = Lex::get_comments(comment);
            description = Lex::get_description(description);

            WrapperStr decl = JavaSettings::relationDecl(array);

            type_def.replace(0, genericname.length(), "${stereotype}");
            decl.replace(decl.find("${type}"), 7, type_def);


#ifdef ROUNDTRIP

            if (roundtrip && !created) {
                if (rel->visibility() != visibility) {
                    rel->set_Visibility(visibility);
                    container->set_updated();
                }

                if (decl.find("${description}") != -1) {
                    if (nequal(rel->description(), description)) {
                        rel->set_Description(description);
                        container->set_updated();
                    }
                }
                else if (nequal(rel->description(), Lex::simplify_comment(comment))) {
                    rel->set_Description(comment); // comment was set
                    container->set_updated();
                }

                if (rel->isReadOnly() != constp) {
                    rel->set_isReadOnly(constp);
                    container->set_updated();
                }

                if (rel->isJavaTransient() != transientp) {
                    rel->set_isJavaTransient(transientp);
                    container->set_updated();
                }

                if (rel->isVolatile() != volatilep) {
                    rel->set_isVolatile(volatilep);
                    container->set_updated();
                }

                if (rel->isClassMember() != staticp) {
                    rel->set_isClassMember(staticp);
                    container->set_updated();
                }

                if (neq(rel->multiplicity(), array)) {
                    rel->set_Multiplicity(array);
                    container->set_updated();
                }

                if (neq(rel->defaultValue(), value)) {
                    rel->set_DefaultValue(value);
                    container->set_updated();
                }

                if (nequal(rel->javaAnnotations(), annotation)) {
                    rel->set_JavaAnnotations(annotation);
                    container->set_updated();
                }

                if (neq(rel->stereotype(), st) &&
                    (rel->stereotype().isEmpty() ||
                     (JavaSettings::relationAttributeStereotype(rel->stereotype()) != st))) {
                    rel->set_Stereotype(st);
                    container->set_updated();
                }

                if (neq(rel->javaDecl(), decl)) {
                    rel->set_JavaDecl(decl);
                    container->set_updated();
                }

                // role name is the right one

                rel->set_usefull();
                expected_order.append(rel);
            }
            else {
#endif
                rel->set_Visibility(visibility);

                if (!comment.isEmpty())
                    rel->set_Description((decl.find("${description}") != -1)
                                         ? description : Lex::simplify_comment(comment));

                if (constp)
                    rel->set_isReadOnly(TRUE);

                if (transientp)
                    rel->set_isJavaTransient(TRUE);

                if (volatilep)
                    rel->set_isVolatile(TRUE);

                if (staticp)
                    rel->set_isClassMember(TRUE);

                if (!array.isEmpty())
                    rel->set_Multiplicity(array);

                if (! value.isEmpty())
                    rel->set_DefaultValue(value);

                if (! annotation.isEmpty())
                    rel->set_JavaAnnotations(annotation);

                rel->set_Stereotype(st);

                rel->set_JavaDecl(decl);

                rel->set_RoleName(name);

#ifdef ROUNDTRIP

                if (roundtrip)
                    expected_order.append(rel);
            }

#endif

            return TRUE;
        }
Exemple #15
0
WrapperStr UmlPackage::text_path(const WrapperStr & f)
{
    WrapperStr r = file_path(f);

    return r.left(r.length() - 1 - PythonSettings::sourceExtension().length());
}
bool UmlAttribute::new_one(Class * container, const WrapperStr & name,
                           UmlTypeSpec typespec, aVisibility visibility,
                           bool staticp, bool finalp, bool transientp,
                           bool volatilep, const WrapperStr & array,
                           const WrapperStr & value, WrapperStr comment,
                           WrapperStr description, WrapperStr annotation
#ifdef ROUNDTRIP
                           , bool roundtrip, QList<UmlItem *> & expected_order
#endif
                          )
{
#ifdef TRACE
    QLOG_INFO() << "ATTRIBUTE '" << name << "'\n";
#endif

    if (
#ifdef REVERSE
        container->from_libp() && (
#endif
                                   visibility == PrivateVisibility
#ifdef REVERSE
                                   )
#endif
        )
    {
        Lex::finish_line();
        Lex::clear_comments();
        return TRUE;
    }

    UmlClass * cl = container->get_uml();
    UmlAttribute * at;

#ifdef ROUNDTRIP
    bool created;

    if (!roundtrip ||
        ((at = search_attr(container, name)) == 0)) {
#endif
        at = UmlBaseAttribute::create(cl, name);

        if (at == 0) {
            JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>")
                                 + name + "</i> in <i>" + cl->name()
                                 + "</i></b></font><br>");
            return FALSE;
        }

#ifdef REVERSE
# ifndef ROUNDTRIP
        Statistic::one_attribute_more();
# else

        if (roundtrip)
            container->set_updated();

        created = TRUE;
    }
    else
        created = FALSE;

# endif
#endif

        Lex::finish_line();

        comment = Lex::get_comments(comment);
        description = Lex::get_description(description);

        WrapperStr decl = JavaSettings::attributeDecl("");
        int index = decl.find("${type}");

        if ((index == -1) || (decl.find("${name}") == -1)) {
            decl = "  ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type} ${name}${value};";
            index = decl.find("${type}");
        }

#ifdef ROUNDTRIP

        if (roundtrip && !created) {
            if (decl.find("${description}") != -1) {
                if (nequal(at->description(), description)) {
                    at->set_Description(description);
                    container->set_updated();
                }
            }
            else if (nequal(at->description(), Lex::simplify_comment(comment))) {
                at->set_Description(comment); // comment was set
                container->set_updated();
            }

            if (at->isReadOnly() != finalp) {
                at->set_isReadOnly(finalp);
                container->set_updated();
            }

            if (at->isJavaTransient() != transientp) {
                at->set_isJavaTransient(transientp);
                container->set_updated();
            }

            if (at->isVolatile() != volatilep) {
                at->set_isVolatile(volatilep);
                container->set_updated();
            }

            if (at->isClassMember() != staticp) {
                at->set_isClassMember(staticp);
                container->set_updated();
            }

            if (!array.isEmpty())
                decl.insert(index + 7, "${multiplicity}");

            if (neq(at->multiplicity(), array)) {
                at->set_Multiplicity(array);
                container->set_updated();
            }

            WrapperStr v = at->defaultValue();

            if (!v.isEmpty() && (((const char *) v)[0] == '='))
                v = v.mid(1);

            if (nequal(v, value)) {
                at->set_DefaultValue(value);
                container->set_updated();
            }

            if (nequal(at->javaAnnotations(), annotation)) {
                at->set_JavaAnnotations(annotation);
                container->set_updated();
            }

            WrapperStr stereotype;
            bool force_ste = FALSE;

            if (cl->stereotype() == "enum") {
                stereotype = "attribute";
                force_ste = TRUE;
            }
            else if (typespec.type == 0) {
                WrapperStr t = typespec.explicit_type;
                int index2;

                if (!t.isEmpty() &&
                    (t.at(t.length() - 1) == ">") &&
                    ((index2 = t.find('<')) > 0)) {
                    stereotype = t.left(index2);
                    typespec.explicit_type =
                        // may be a,b ...
                        t.mid(index2 + 1, t.length() - 2 - index2);
                    decl.replace(index, 7, "${stereotype}<${type}>");
                    force_ste = TRUE;
                }
            }

            if (at->visibility() != visibility) {
                at->set_Visibility(visibility);
                container->set_updated();
            }

            if (neq(at->stereotype(), stereotype)) {
                WrapperStr jst;

                if (! at->stereotype().isEmpty())
                    jst = JavaSettings::relationAttributeStereotype(at->stereotype());

                if ((force_ste) ? (jst != stereotype) : (jst == "attribute")) {
                    at->set_Stereotype(stereotype);
                    container->set_updated();
                }
            }

            if (neq(at->javaDecl(), decl)) {
                at->set_JavaDecl(decl);
                container->set_updated();
            }

            if (!at->type().equal(typespec)) {
                at->set_Type(typespec);
                container->set_updated();
            }

            at->set_usefull();

            expected_order.append(at);
        }
        else {
#endif

            if (!comment.isEmpty())
                at->set_Description((decl.find("${description}") != -1)
                                    ? description : Lex::simplify_comment(comment));

            if (finalp)
                at->set_isReadOnly(TRUE);

            if (transientp)
                at->set_isJavaTransient(TRUE);

            if (volatilep)
                at->set_isVolatile(TRUE);

            if (staticp)
                at->set_isClassMember(TRUE);

            if (!array.isEmpty()) {
                decl.insert(index + 7, "${multiplicity}");
                at->set_Multiplicity(array);
            }

            if (! value.isEmpty())
                at->set_DefaultValue(value);

            if (! annotation.isEmpty())
                at->set_JavaAnnotations(annotation);

            if ((typespec.type == 0) && (cl->stereotype() != "enum")) {
                WrapperStr t = typespec.explicit_type;
                int index2 = 0;

                if (!t.isEmpty() &&
                        (t.at(t.length() - 1) == ">") &&
                    ((index2 = t.find('<')) > 0))
                {
                    at->set_Stereotype(t.left(index2));
                    typespec.explicit_type =
                        // may be a,b ...
                        t.mid(index2 + 1, t.length() - 2 - index2);
                    decl.replace(index, 7, "${stereotype}<${type}>");
                }
            }

            at->set_Visibility(visibility);

            if (cl->stereotype() == "enum") {
                at->set_JavaDecl(decl);
                at->set_Stereotype("attribute");
            }
            else if (decl != JavaSettings::attributeDecl(""))
                at->set_JavaDecl(decl);

            at->set_Type(typespec);

#ifdef ROUNDTRIP

            if (roundtrip)
                expected_order.append(at);
        }

#endif

        return TRUE;
    }
Exemple #17
0
void UmlClass::write(QTextStream & f, bool with_formals, BooL * is_template,
                     const QList<UmlActualParameter> & actuals)
{
    if (! context.contains(this)) {
        if (parent()->kind() == aClass) {
            if (! context.contains((UmlClass *) parent())) {
                // parent cannot have formals, but may have actuals
                ((UmlClass *) parent())->write(f, FALSE, 0, actuals);
                f << "::";
            }
        }
        else {
            UmlArtifact * cp = associatedArtifact();
            WrapperStr nasp = ((UmlPackage *)
                              ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package())
                             ->cppNamespace();

            if (CppSettings::isForceNamespacePrefixGeneration() ||
                (nasp != UmlArtifact::generation_package()->cppNamespace()))
                f << nasp << "::";
        }
    }

    WrapperStr s;

    if (isCppExternal()) {
        s = cppDecl();

        int index = s.find('\n');

        s = (index == -1) ? s.stripWhiteSpace()
            : s.left(index).stripWhiteSpace();

        if ((index = s.find("${name}")) != -1)
            s.replace(index, 7, name());
        else if ((index = s.find("${Name}")) != -1)
            s.replace(index, 7, capitalize(name()));
        else if ((index = s.find("${NAME}")) != -1)
            s.replace(index, 7, name().upper().toLatin1().constData());
        else if ((index = s.find("${nAME}")) != -1)
            s.replace(index, 7, name().lower().toLatin1().constData());
    }
    else
        s = name();	// true_name

    if (! s.isEmpty()) {
        f << s;

        if (is_template != 0)
            *is_template = (s.at(s.length() - 1) == QString('>'));
    }
    else if (is_template != 0)
        *is_template = FALSE;

    if (with_formals) {
        QList<UmlFormalParameter> formals = this->formals();

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

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

            f << '>';

            if (is_template != 0)
                *is_template = TRUE;
        }
    }
    else if (!actuals.isEmpty()) {
        QList<UmlActualParameter>::ConstIterator ita;
        BooL need_space = FALSE;
        bool used = FALSE;

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

        if (used) {
            if (need_space)
                f << " >";
            else
                f << '>';

            if (is_template != 0)
                *is_template = TRUE;
        }
    }
}
Exemple #18
0
WrapperStr UmlPackage::text_path(const WrapperStr & f, WrapperStr relto)
{
    WrapperStr r = source_path(f, relto);

    return r.left(r.length() - 1 - CppSettings::sourceExtension().length());
}
Exemple #19
0
bool UmlOperation::get_param(WrapperStr s, int & index, WrapperStr & r, WrapperStr & kname, WrapperStr & ktype, int & rank)
{
    int index0 = index;
    int level = 0;
//const char * p = (const char *) s;

    r = "";

    do {
        if (index >= (int) s.length()) {
            if (level != 0)
                return FALSE;

            r = s.mid(index0, index - index0).stripWhiteSpace();

            if (r.isEmpty())
                return FALSE;

            break;
        }

        switch (s[index]) {
        case ',':
            if (level == 0) {
                r = s.mid(index0, index - index0).stripWhiteSpace();
                index += 1;

                if (r.isEmpty())
                    return FALSE;
            }

            break;

        case '(':
        case '{':
        case '[':
            level += 1;
            break;

        case ')':
        case '}':
        case ']':
            if (--level < 0)
                return FALSE;

        default:
            break;
        }

        index += 1;
    }
    while (r.isEmpty());

    int index1;
    int index2;

    rank = -1;

    if (((index1 = r.find("${p")) != -1) &&
        ((index2 = r.find("}", index1 + 3)) != -1)) {
        kname = r.mid(index1, index2 - index1 + 1);
        rank = atoi(((const char *) r) + index1 + 3);
    }
    else
        kname = "";

    if (((index1 = r.find("${t")) != -1) &&
        ((index2 = r.find("}", index1 + 3)) != -1)) {
        ktype = r.mid(index1, index2 - index1 + 1);

        if (rank == -1)
            rank = atoi(((const char *) r) + index1 + 3);
    }
    else if (rank == -1)
        // too complicated;
        return FALSE;
    else
        ktype = "";

    return TRUE;
}