1
|
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 "qdocgenerator.h"
|
|
43
|
|
44 #include "reporthandler.h"
|
|
45 #include "typesystem.h"
|
|
46
|
|
47 #include <QtCore/QDir>
|
|
48
|
|
49 QDocGenerator::QDocGenerator() { }
|
|
50
|
|
51 QString QDocGenerator::subDirectoryForClass(const AbstractMetaClass *) const
|
|
52 {
|
|
53 return "doc/japi";
|
|
54 }
|
|
55
|
|
56 QString QDocGenerator::fileNameForClass(const AbstractMetaClass *) const
|
|
57 {
|
|
58 return "qdoc.japi";
|
|
59 }
|
|
60
|
|
61 void QDocGenerator::generate()
|
|
62 {
|
|
63 QDir dir(outputDirectory() + "/" + subDirectoryForClass(0));
|
|
64 dir.mkpath(dir.absolutePath());
|
|
65
|
|
66 QFile f(dir.absoluteFilePath(fileNameForClass(0)));
|
|
67 if (!f.open(QIODevice::WriteOnly)) {
|
|
68 ReportHandler::warning(QString("failed to open file '%1' for writing")
|
|
69 .arg(f.fileName()));
|
|
70 return;
|
|
71 }
|
|
72
|
|
73 {
|
|
74 QTextStream s(&f);
|
|
75 s << "<japi>" << endl;
|
|
76
|
|
77 AbstractMetaClassList clazzes = classes();
|
|
78 foreach (AbstractMetaClass *cls, clazzes) {
|
|
79 if (shouldGenerate(cls)) {
|
|
80 write(s, cls);
|
|
81 }
|
|
82 }
|
|
83
|
|
84 s << "</japi>" << endl;
|
|
85 }
|
|
86 }
|
|
87
|
|
88 // copy-paste from linguist/shared/metatranslator.cpp
|
|
89 static QString numericEntity( int ch )
|
|
90 {
|
|
91 return QString( ch <= 0x20 ? "<byte value=\"x%1\"/>" : "&#x%1;" )
|
|
92 .arg( ch, 0, 16 );
|
|
93 }
|
|
94
|
|
95 static QString protect( const QByteArray& str )
|
|
96 {
|
|
97 QString result;
|
|
98 int len = (int) str.length();
|
|
99 for ( int k = 0; k < len; k++ ) {
|
|
100 switch( str[k] ) {
|
|
101 case '\"':
|
|
102 result += QString( """ );
|
|
103 break;
|
|
104 case '&':
|
|
105 result += QString( "&" );
|
|
106 break;
|
|
107 case '>':
|
|
108 result += QString( ">" );
|
|
109 break;
|
|
110 case '<':
|
|
111 result += QString( "<" );
|
|
112 break;
|
|
113 case '\'':
|
|
114 result += QString( "'" );
|
|
115 break;
|
|
116 default:
|
|
117 if ( (uchar) str[k] < 0x20 && str[k] != '\n' )
|
|
118 result += numericEntity( (uchar) str[k] );
|
|
119 else
|
|
120 result += str[k];
|
|
121 }
|
|
122 }
|
|
123 return result;
|
|
124 }
|
|
125
|
|
126
|
|
127 void QDocGenerator::write(QTextStream &s, const AbstractMetaFunction *java_function)
|
|
128 {
|
|
129 AbstractMetaArgumentList arguments = java_function->arguments();
|
|
130 int argument_count = arguments.size();
|
|
131
|
|
132 int overload_count = 0;
|
|
133
|
|
134 for (int i=0; i<argument_count; ++i) {
|
|
135 if (!arguments.at(i)->defaultValueExpression().isEmpty())
|
|
136 ++overload_count;
|
|
137 }
|
|
138
|
|
139 for (int i=0; i<=overload_count; ++i) {
|
|
140 writeOverload(s, java_function, argument_count - i);
|
|
141 }
|
|
142 }
|
|
143
|
|
144 void QDocGenerator::writeOverload(QTextStream &s,
|
|
145 const AbstractMetaFunction *java_function,
|
|
146 int arg_count)
|
|
147 {
|
|
148 if (java_function->isModifiedRemoved(TypeSystem::TargetLangCode))
|
|
149 return;
|
|
150
|
|
151 uint included_attributes = NoBlockedSlot;
|
|
152 uint excluded_attributes = 0;
|
|
153 setupForFunction(java_function, &included_attributes, &excluded_attributes);
|
|
154
|
|
155 if (arg_count < java_function->arguments().size()) {
|
|
156 // see DGenerator::writeFunctionOverloads()
|
|
157 if (!java_function->isConstructor())
|
|
158 included_attributes |= AbstractMetaAttributes::Final;
|
|
159 excluded_attributes |= AbstractMetaAttributes::Abstract | AbstractMetaAttributes::Native;
|
|
160 }
|
|
161
|
|
162 QString signature = functionSignature(java_function,
|
|
163 included_attributes,
|
|
164 excluded_attributes,
|
|
165 NoOption,
|
|
166 arg_count);
|
|
167
|
|
168 s << "<method java=\"" << protect(signature.toUtf8()) << "\"" << endl
|
|
169 << " cpp=\"" << protect(java_function->signature().toUtf8()) << "\"" << endl;
|
|
170
|
|
171 FunctionModificationList mods = java_function->modifications(java_function->implementingClass());
|
|
172 QList<ArgumentModification> argumentMods;
|
|
173 foreach (const FunctionModification &m, mods) {
|
|
174 if (!m.association.isEmpty())
|
|
175 s << " association=\"" << m.association << "\"" << endl;
|
|
176 if (m.modifiers & Modification::AccessModifierMask)
|
|
177 s << " access-change=\"" << m.accessModifierString() << "\"" << endl;
|
|
178 if (m.modifiers & Modification::Rename)
|
|
179 s << " renamed=\"" << m.renamedToName << "\"" << endl;
|
|
180 if (m.modifiers & (Modification::FinalMask)) {
|
|
181 s << " final=\"" << ((m.modifiers & Modification::Final) ? "final" : "non-final")
|
|
182 << "\"" << endl;
|
|
183 }
|
|
184 if (m.modifiers & Modification::Deprecated)
|
|
185 s << " deprecated=\"yes\"" << endl;
|
|
186 if (m.removal)
|
|
187 s << " removal=\"" << m.removal << "\"" << endl;
|
|
188
|
|
189 argumentMods << m.argument_mods;
|
|
190 }
|
|
191
|
|
192 AbstractMetaArgumentList arguments = java_function->arguments();
|
|
193 bool wroteOwnershipStolen = false;
|
|
194 foreach (AbstractMetaArgument *argument, arguments) {
|
|
195 if (java_function->disabledGarbageCollection(java_function->implementingClass(),
|
|
196 argument->argumentIndex() + 1)) {
|
|
197 if (!wroteOwnershipStolen) {
|
|
198 s << endl << " steals-ownership-of=\"";
|
|
199 wroteOwnershipStolen = true;
|
|
200 } else {
|
|
201 s << ",";
|
|
202 }
|
|
203 s << protect(argument->argumentName().toUtf8());
|
|
204 }
|
|
205 }
|
|
206 if (wroteOwnershipStolen)
|
|
207 s << "\"";
|
|
208
|
|
209 s << ">" << endl;
|
|
210
|
|
211 if (argumentMods.size()) {
|
|
212
|
|
213 foreach (const ArgumentModification &m, argumentMods) {
|
|
214 s << " <argument index=\"" << m.index << "\"" << endl;
|
|
215 if (m.removed_default_expression)
|
|
216 s << " remove-default-expression=\"yes\"" << endl;
|
|
217 if (m.removed)
|
|
218 s << " removed=\"yes\"" << endl;
|
|
219 if (m.no_null_pointers)
|
|
220 s << " no-null=\"yes\"" << endl;
|
|
221 if (!m.modified_type.isEmpty())
|
|
222 s << " modified-type=\"" << protect(m.modified_type.toLatin1()) << "\"" << endl;
|
|
223 if (!m.replaced_default_expression.isEmpty()) {
|
|
224 s << " default-expression=\"" << m.replaced_default_expression
|
|
225 << "\"" << endl;
|
|
226 }
|
|
227 if (!m.referenceCounts.isEmpty())
|
|
228 s << " reference-counted=\"...\"" << endl;
|
|
229 s << "/>" << endl;
|
|
230 }
|
|
231 }
|
|
232
|
|
233 s << "</method>" << endl;
|
|
234 }
|
|
235
|
|
236 void QDocGenerator::write(QTextStream &s, const AbstractMetaEnumValue *java_enum_value)
|
|
237 {
|
|
238 s << "<enum-value java=\"" << protect(java_enum_value->name().toUtf8()) << "\"" << endl
|
|
239 << " cpp=\"" << protect(java_enum_value->name().toUtf8()) << "\"" << endl
|
|
240 << " value=\"" << java_enum_value->value() << "\"/>" << endl;
|
|
241 }
|
|
242
|
|
243 void QDocGenerator::write(QTextStream &s, const AbstractMetaEnum *java_enum)
|
|
244 {
|
|
245 s << "<enum java=\"" << protect(java_enum->name().toUtf8()) << "\"" << endl
|
|
246 << " cpp=\"" << protect(java_enum->name().toUtf8()) << "\"" << endl;
|
|
247
|
|
248 if (java_enum->typeEntry()->flags()) {
|
|
249 s << " flags=\"" << protect(java_enum->typeEntry()->flags()->targetLangName().toUtf8())
|
|
250 << "\"" << endl;
|
|
251 }
|
|
252
|
|
253 s << " >" << endl;
|
|
254 AbstractMetaEnumValueList values = java_enum->values();
|
|
255 foreach (AbstractMetaEnumValue *value, values) {
|
|
256 write(s, value);
|
|
257 }
|
|
258 s << "</enum>" << endl;
|
|
259 }
|
|
260
|
|
261 void QDocGenerator::writeSignal(QTextStream &s, const AbstractMetaFunction *java_function)
|
|
262 {
|
|
263 s << "<signal java=\""
|
|
264 << protect(java_function->targetLangSignature().toUtf8()) << "\" cpp=\""
|
|
265 << protect(java_function->signature().toUtf8()) << "\"/>" << endl;
|
|
266 }
|
|
267
|
|
268 void QDocGenerator::write(QTextStream &s, const AbstractMetaField *java_field)
|
|
269 {
|
|
270 uint included_attributes = NoBlockedSlot;
|
|
271 uint excluded_attributes = 0;
|
|
272 setupForFunction(java_field->getter(), &included_attributes, &excluded_attributes);
|
|
273 s << "<variablegetter java=\"" << protect(functionSignature(java_field->getter(), included_attributes, excluded_attributes).toUtf8())
|
|
274 << "\"" << endl
|
|
275 << " cpp=\"" << protect(java_field->name().toUtf8()) << "\" />" << endl;
|
|
276
|
|
277 included_attributes = NoBlockedSlot;
|
|
278 excluded_attributes = 0;
|
|
279 setupForFunction(java_field->setter(), &included_attributes, &excluded_attributes);
|
|
280 s << "<variablesetter java=\"" << protect(functionSignature(java_field->setter(), included_attributes, excluded_attributes).toUtf8())
|
|
281 << "\"" << endl
|
|
282 << " cpp=\"" << protect(java_field->name().toUtf8()) << "\" />" << endl;
|
|
283 }
|
|
284
|
|
285 void QDocGenerator::write(QTextStream &s, const AbstractMetaClass *java_class)
|
|
286 {
|
|
287 s << "<class" << endl
|
|
288 << " java=\"" << protect(java_class->name().toUtf8()) << "\"" << endl
|
|
289 << " cpp=\"" << protect(java_class->typeEntry()->qualifiedCppName().toUtf8()) << "\"" << endl
|
|
290 << " java-extends=\"" << protect(java_class->baseClass() ? java_class->baseClass()->name().toUtf8() : "") << "\"" << endl
|
|
291 << " package=\"" << protect(java_class->package().toUtf8()) << "\"" << endl;
|
|
292
|
|
293 AbstractMetaClassList interfaces = java_class->interfaces();
|
|
294 if (interfaces.count() > 0) {
|
|
295 s << " javaimplements=\"";
|
|
296 for (int i=0; i<interfaces.count(); ++i) {
|
|
297 const AbstractMetaClass *interfaze = interfaces.at(i);
|
|
298 if (i > 0)
|
|
299 s << ",";
|
|
300 s << protect(interfaze->name().toUtf8());
|
|
301 }
|
|
302 s << "\"" << endl;
|
|
303 }
|
|
304
|
|
305 s << " type=\"";
|
|
306 if (java_class->isInterface())
|
|
307 s << "interface";
|
|
308 else if (java_class->typeEntry()->isValue())
|
|
309 s << "value";
|
|
310 else
|
|
311 s << "object";
|
|
312 s << "\">" << endl;
|
|
313
|
|
314 // Write signals
|
|
315 AbstractMetaFunctionList sigs = java_class->queryFunctions(AbstractMetaClass::Signals);
|
|
316 foreach (AbstractMetaFunction *f, sigs)
|
|
317 writeSignal(s, f);
|
|
318
|
|
319 // Write functions
|
|
320 AbstractMetaFunctionList functions = java_class->functionsInTargetLang();
|
|
321 foreach (AbstractMetaFunction *f, functions) {
|
|
322 write(s, f);
|
|
323 }
|
|
324
|
|
325 // Write enums
|
|
326 AbstractMetaEnumList enums = java_class->enums();
|
|
327 foreach (AbstractMetaEnum *e, enums) {
|
|
328 write(s, e);
|
|
329 }
|
|
330
|
|
331 // Write setters and getters
|
|
332 AbstractMetaFieldList fields = java_class->fields();
|
|
333 foreach (AbstractMetaField *f, fields) {
|
|
334 write(s, f);
|
|
335 }
|
|
336
|
|
337 s << "</class>" << endl;
|
|
338 }
|