Mercurial > projects > qtd
comparison generator/docparser.cpp @ 1:e78566595089
initial import
author | mandel |
---|---|
date | Mon, 11 May 2009 16:01:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:36fb74dc547d | 1:e78566595089 |
---|---|
1 /**************************************************************************** | |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #include "docparser.h" | |
43 | |
44 #include "metajava.h" | |
45 #include "reporthandler.h" | |
46 | |
47 #include <QtCore/QFileInfo> | |
48 #include <QtCore/QFile> | |
49 | |
50 #include <QtXml> | |
51 | |
52 DocParser::DocParser(const QString &name) | |
53 : m_doc_file(name), | |
54 m_dom(0) | |
55 { | |
56 build(); | |
57 } | |
58 | |
59 DocParser::~DocParser() | |
60 { | |
61 delete m_dom; | |
62 } | |
63 | |
64 QString DocParser::documentation(const AbstractMetaClass *meta_class) const | |
65 { | |
66 if (!m_dom) | |
67 return QString(); | |
68 | |
69 QDomElement root_node = m_dom->documentElement(); | |
70 | |
71 QString class_name = root_node.attribute("name"); | |
72 QString doc = root_node.attribute("doc"); | |
73 | |
74 if (class_name != meta_class->name()) { | |
75 ReportHandler::warning("Documentelement file contains unexpected class: " + class_name + ", file=" + m_doc_file); | |
76 } | |
77 | |
78 return doc; | |
79 } | |
80 | |
81 QString DocParser::documentationForFunction(const QString &signature, const QString &tag) const | |
82 { | |
83 if (!m_dom) | |
84 return QString(); | |
85 | |
86 QDomElement root_node = m_dom->documentElement(); | |
87 QDomNodeList functions = root_node.elementsByTagName(tag); | |
88 | |
89 for (int i=0; i<functions.size(); ++i) { | |
90 QDomNode node = functions.item(i); | |
91 | |
92 QDomElement *e = (QDomElement *) &node; | |
93 | |
94 Q_ASSERT(e->isElement()); | |
95 | |
96 if (e->attribute("name") == signature) | |
97 return e->attribute("doc"); | |
98 } | |
99 | |
100 return QString(); | |
101 } | |
102 | |
103 | |
104 QString DocParser::documentationForSignal(const QString &signature) const | |
105 { | |
106 return documentationForFunction(signature, "signal"); | |
107 } | |
108 | |
109 QString DocParser::documentationForFunction(const QString &signature) const | |
110 { | |
111 return documentationForFunction(signature, "method"); | |
112 } | |
113 | |
114 QString DocParser::documentation(const AbstractMetaEnum *java_enum) const | |
115 { | |
116 if (!m_dom) | |
117 return QString(); | |
118 | |
119 QDomElement root_node = m_dom->documentElement(); | |
120 | |
121 QDomNodeList enums = root_node.elementsByTagName("enum"); | |
122 | |
123 for (int i=0; i<enums.size(); ++i) { | |
124 QDomNode node = enums.item(i); | |
125 QDomElement *e = (QDomElement *) &node; | |
126 | |
127 Q_ASSERT(e->isElement()); | |
128 | |
129 if (e->attribute("name") == java_enum->name()) { | |
130 return e->attribute("doc"); | |
131 } | |
132 } | |
133 | |
134 return QString(); | |
135 } | |
136 | |
137 | |
138 QString DocParser::documentation(const AbstractMetaEnumValue *java_enum_value) const | |
139 { | |
140 if (!m_dom) | |
141 return QString(); | |
142 | |
143 QDomElement root_node = m_dom->documentElement(); | |
144 | |
145 QDomNodeList enums = root_node.elementsByTagName("enum"); | |
146 | |
147 for (int i=0; i<enums.size(); ++i) { | |
148 QDomNode node = enums.item(i); | |
149 QDomElement *e = (QDomElement *) &node; | |
150 Q_ASSERT(e->isElement()); | |
151 | |
152 QDomNodeList enumValues = e->elementsByTagName("enum-value"); | |
153 for (int j=0; j<enumValues.size(); ++j) { | |
154 QDomNode node = enumValues.item(j); | |
155 QDomElement *ev = (QDomElement *) &node; | |
156 if (ev->attribute("name") == java_enum_value->name()) { | |
157 return ev->attribute("doc"); | |
158 } | |
159 } | |
160 } | |
161 | |
162 return QString(); | |
163 } | |
164 | |
165 | |
166 | |
167 void DocParser::build() | |
168 { | |
169 if (!QFileInfo(m_doc_file).exists()) { | |
170 ReportHandler::warning("Missing documentation file: " + m_doc_file); | |
171 return; | |
172 } | |
173 | |
174 QFile f(m_doc_file); | |
175 if (!f.open(QFile::ReadOnly | QFile::Text)) { | |
176 ReportHandler::warning("Failed to open documentation file: " + m_doc_file); | |
177 return; | |
178 } | |
179 | |
180 m_dom = new QDomDocument(); | |
181 | |
182 QString error; | |
183 int line, column; | |
184 | |
185 if (!m_dom->setContent(&f, &error, &line, &column)) { | |
186 ReportHandler::warning(QString("Failed to parse the documentation file:" | |
187 " '%1' %2 line=%3 column=%4") | |
188 .arg(m_doc_file) | |
189 .arg(error) | |
190 .arg(line) | |
191 .arg(column)); | |
192 | |
193 delete m_dom; | |
194 m_dom = 0; | |
195 | |
196 return; | |
197 } | |
198 | |
199 | |
200 } |