~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/doxydoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
*   Copyright (C) 2003 by Jonas B. Jacobi                                 *
 
3
*   j.jacobi@gmx.de                                                       *
 
4
*                                                                         *
 
5
*   This program is free software; you can redistribute it and/or modify  *
 
6
*   it under the terms of the GNU General Public License as published by  *
 
7
*   the Free Software Foundation; either version 2 of the License, or     *
 
8
*   (at your option) any later version.                                   *
 
9
***************************************************************************/
 
10
#include "doxydoc.h"
 
11
 
 
12
#include <list>
 
13
 
 
14
#include <qstring.h>
 
15
#include <qstringlist.h>
 
16
#include <qdom.h>
 
17
#include <qdir.h>
 
18
#include <qfile.h>
 
19
#include <qregexp.h>
 
20
 
 
21
void DoxyDoc::formatType( QString& str )
 
22
{
 
23
        str.replace( QRegExp( " " ), "" );
 
24
}
 
25
 
 
26
DoxyDoc::DoxyDoc( const QStringList& dir )
 
27
{
 
28
        for ( uint i = 0; i < dir.count(); ++i )
 
29
                m_dirs.push_back( QDir( *( dir.at( i ) ) ) );
 
30
}
 
31
 
 
32
//crappy implementation, change later
 
33
QString DoxyDoc::functionDescription( const QString& tmpscope, const QString& name,
 
34
                                      const QString& tmptype, const QString& tmparguments )
 
35
{
 
36
        QString scope = tmpscope;
 
37
        bool foundfile = false;
 
38
        //produce doxygen conform filenames
 
39
        QString filename = "/class" + scope.replace( QRegExp( "_" ), "__" ).replace( QRegExp( "::" ), "_1_1" ) + ".xml";
 
40
        
 
41
        //search for file in all directories
 
42
        for ( std::list<QDir>::const_iterator ci = m_dirs.begin(); !foundfile && ci != m_dirs.end(); ++ci )
 
43
        {
 
44
                if ( QFile::exists( ci->path() + filename ) )
 
45
                {
 
46
                        if ( m_file.name() != ci->path() + filename )
 
47
                        {
 
48
                                m_file.close();
 
49
                                m_file.setName( ci->path() + filename );
 
50
                                if ( !m_file.open( IO_ReadOnly ) )
 
51
                                {
 
52
                                        m_file.setName( "" );
 
53
                                        return "";
 
54
                                }
 
55
                                QDomDocument m_doc;
 
56
                                m_doc.setContent( m_file.readAll() );
 
57
                                m_file.close();
 
58
                                m_list = m_doc.elementsByTagName( "memberdef" );
 
59
                                foundfile = true;
 
60
                                
 
61
                        }
 
62
                        else //file is already opened
 
63
                                foundfile = true;
 
64
                }
 
65
        }
 
66
        if ( !foundfile )
 
67
                return QString::null;
 
68
        
 
69
        QString type = tmptype;
 
70
        formatType( type );
 
71
        
 
72
        for ( uint i = 0; i < m_list.count(); ++i )
 
73
        {
 
74
                QDomElement elem = m_list.item( i ).toElement();
 
75
                if ( elem.elementsByTagName( "name" ).item( 0 ).toElement().text() == name && 
 
76
                     elem.elementsByTagName( "type" ).item( 0 ).toElement().text() == tmptype )
 
77
                {
 
78
                        QDomNodeList paramnodes = elem.elementsByTagName( "param" );
 
79
                        QString nodearguments = "", arguments = tmparguments;
 
80
                        for ( unsigned int j = 0; j < paramnodes.count(); ++j )
 
81
                                nodearguments += paramnodes.item( j ).childNodes().item( 0 ).toElement().text() + ",";
 
82
                        if ( nodearguments != "" )
 
83
                        {
 
84
                                nodearguments = nodearguments.left( nodearguments.length() - 1 );
 
85
                                formatType( nodearguments );
 
86
                        }
 
87
                        formatType( arguments );
 
88
                        if ( arguments == nodearguments )
 
89
                        {
 
90
                                QString brief = "";
 
91
                                QDomNode briefnode = elem.elementsByTagName( "briefdescription" ).item( 0 );
 
92
                                if ( briefnode.hasChildNodes() )
 
93
                                        brief = briefnode.firstChild().toElement().text();
 
94
                                
 
95
                                QString detailstr = "", paramstr = "";
 
96
                                QDomNode detail = elem.elementsByTagName( "detaileddescription" ).item( 0 );
 
97
                                if ( detail.hasChildNodes() )
 
98
                                        detail = detail.firstChild();
 
99
                                
 
100
                                QDomNode descnode = detail.firstChild();
 
101
                                while ( !descnode.isNull() )
 
102
                                {
 
103
                                        if ( descnode.nodeName() == "parameterlist" )
 
104
                                        {
 
105
                                                int tmpcount = descnode.childNodes().count();
 
106
                                                for ( int k = 0; k < tmpcount; ++k )
 
107
                                                {
 
108
                                                        //add parametername
 
109
                                                        paramstr += "<li><i>" + descnode.childNodes().item( k++ ).toElement().text() + "</i>\t";
 
110
                                                        //add parameterdescription
 
111
                                                        paramstr += descnode.childNodes().item( k ).toElement().text() + "</li>";
 
112
                                                }
 
113
                                        }
 
114
                                        else
 
115
                                                if ( descnode.nodeName() == "simplesect" )
 
116
                                                {}
 
117
                                        else
 
118
                                        {
 
119
                                                if ( descnode.isText() )
 
120
                                                        detailstr += descnode.toText().data();
 
121
                                                else
 
122
                                                        detailstr += descnode.toElement().text();
 
123
                                        }
 
124
                                        descnode = descnode.nextSibling();
 
125
                                }
 
126
                                
 
127
                                
 
128
                                QString description = "";
 
129
                                if ( brief != "" )
 
130
                                        description += brief + "<p>";
 
131
                                if ( detailstr != "" )
 
132
                                        description += detailstr + "<p>";
 
133
                                if ( paramstr != "" )
 
134
                                        description += "<b>Parameterlist:</b><p>" + paramstr;
 
135
                                
 
136
                                if ( description == "" )
 
137
                                        return QString::null;
 
138
                                else
 
139
                                        return description;
 
140
                        }
 
141
                }
 
142
                
 
143
        }
 
144
        
 
145
        return QString::null;
 
146
}
 
147
 
 
148
//kate: indent-mode csands; tab-width 4; space-indent off;