bump product version to 4.1.6.2
[LibreOffice.git] / unodevtools / source / skeletonmaker / javatypemaker.cxx
blobd6b29b00cf261d8ad6e666fe6728ca39839ce448
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
22 #include <cstring>
24 #include "codemaker/codemaker.hxx"
25 #include "codemaker/commonjava.hxx"
26 #include "codemaker/global.hxx"
28 #include "skeletoncommon.hxx"
29 #include "skeletonjava.hxx"
31 using namespace ::rtl;
33 namespace skeletonmaker { namespace java {
35 void printType(
36 std::ostream & o, ProgramOptions const & options,
37 rtl::Reference< TypeManager > const & manager,
38 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
39 std::vector< OUString > const & arguments, bool referenceType,
40 bool defaultvalue)
42 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
43 switch (sort) {
44 case codemaker::UnoType::SORT_BOOLEAN:
45 o << "false";
46 return;
47 case codemaker::UnoType::SORT_CHAR:
48 case codemaker::UnoType::SORT_BYTE:
49 case codemaker::UnoType::SORT_SHORT:
50 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
51 case codemaker::UnoType::SORT_LONG:
52 case codemaker::UnoType::SORT_UNSIGNED_LONG:
53 case codemaker::UnoType::SORT_HYPER:
54 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
55 case codemaker::UnoType::SORT_FLOAT:
56 case codemaker::UnoType::SORT_DOUBLE:
57 o << "0";
58 return;
59 default:
60 break;
64 if (defaultvalue) {
65 if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE) {
66 o << "null";
67 return;
68 } else if (sort == codemaker::UnoType::SORT_ANY && rank == 0) {
69 o << "com.sun.star.uno.Any.VOID";
70 return;
71 } else if (sort == codemaker::UnoType::SORT_TYPE && rank == 0) {
72 o << "com.sun.star.uno.Type.VOID";
73 return;
74 } else if (sort != codemaker::UnoType::SORT_ENUM_TYPE || rank != 0) {
75 o << "new ";
79 OString sType(
80 codemaker::java::translateUnoToJavaType(
81 sort, u2b(nucleus), referenceType && rank == 0));
82 if (sType.startsWith("java.lang.")) {
83 sType = sType.copy(std::strlen("java.lang."));
85 o << sType;
86 if (!arguments.empty() && options.java5) {
87 o << '<';
88 for (std::vector< OUString >::const_iterator i(arguments.begin());
89 i != arguments.end(); ++i)
91 if (i != arguments.begin()) {
92 o << ", ";
94 printType(o, options, manager, *i, true, false);
96 o << '>';
98 for (sal_Int32 i = 0; i != rank; ++i) {
99 if (defaultvalue)
100 o << "[0]";
101 else
102 o << "[]";
105 if (defaultvalue && sort > codemaker::UnoType::SORT_CHAR && rank == 0) {
106 if (sort == codemaker::UnoType::SORT_ENUM_TYPE)
107 o << ".getDefault()";
108 else
109 o << "()";
113 void printType(
114 std::ostream & o, ProgramOptions const & options,
115 rtl::Reference< TypeManager > const & manager, OUString const & name,
116 bool referenceType, bool defaultvalue)
118 OUString nucleus;
119 sal_Int32 rank;
120 std::vector< OUString > arguments;
121 codemaker::UnoType::Sort sort = manager->decompose(
122 name, true, &nucleus, &rank, &arguments, 0);
123 printType(
124 o, options, manager, sort, nucleus, rank, arguments, referenceType,
125 defaultvalue);
128 bool printConstructorParameters(
129 std::ostream & o, ProgramOptions const & options,
130 rtl::Reference< TypeManager > const & manager,
131 codemaker::UnoType::Sort sort,
132 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
133 std::vector< OUString > const & arguments)
135 bool previous = false;
136 switch (sort) {
137 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
139 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
140 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
141 assert(ent2.is());
142 if (!ent2->getDirectBase().isEmpty()) {
143 rtl::Reference< unoidl::Entity > baseEnt;
144 codemaker::UnoType::Sort baseSort = manager->getSort(
145 ent2->getDirectBase(), &baseEnt);
146 previous = printConstructorParameters(
147 o, options, manager, baseSort, baseEnt,
148 ent2->getDirectBase(), std::vector< OUString >());
150 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
151 const_iterator i(ent2->getDirectMembers().begin());
152 i != ent2->getDirectMembers().end(); ++i)
154 if (previous) {
155 o << ", ";
157 previous = true;
158 printType(o, options, manager, i->type, false);
159 o << ' '
160 << codemaker::java::translateUnoToJavaIdentifier(
161 u2b(i->name), "param");
163 break;
165 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
167 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
168 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
169 entity.get()));
170 assert(ent2.is());
171 for (std::vector<
172 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
173 const_iterator i(ent2->getMembers().begin());
174 i != ent2->getMembers().end(); ++i)
176 if (previous) {
177 o << ", ";
179 previous = true;
180 if (i->parameterized) {
181 o << i->type;
182 } else {
183 printType(o, options, manager, i->type, false);
185 o << ' '
186 << codemaker::java::translateUnoToJavaIdentifier(
187 u2b(i->name), "param");
189 break;
191 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
193 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
194 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
195 entity.get()));
196 assert(ent2.is());
197 for (std::vector<
198 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
199 const_iterator i(ent2->getMembers().begin());
200 i != ent2->getMembers().end(); ++i)
202 if (previous) {
203 o << ", ";
205 previous = true;
206 if (i->parameterized) {
207 for (std::vector< OUString >::const_iterator j(
208 ent2->getTypeParameters().begin());
209 j != ent2->getTypeParameters().end(); ++j)
211 if (i->type == *j) {
212 o << arguments[
213 j - ent2->getTypeParameters().begin()];
214 break;
217 } else {
218 printType(o, options, manager, i->type, false);
220 o << ' '
221 << codemaker::java::translateUnoToJavaIdentifier(
222 u2b(i->name), "param");
224 break;
226 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
228 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
229 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
230 assert(ent2.is());
231 if (!ent2->getDirectBase().isEmpty()) {
232 rtl::Reference< unoidl::Entity > baseEnt;
233 codemaker::UnoType::Sort baseSort = manager->getSort(
234 ent2->getDirectBase(), &baseEnt);
235 previous = printConstructorParameters(
236 o, options, manager, baseSort, baseEnt,
237 ent2->getDirectBase(), std::vector< OUString >());
239 for (std::vector< unoidl::ExceptionTypeEntity::Member >::
240 const_iterator i(ent2->getDirectMembers().begin());
241 i != ent2->getDirectMembers().end(); ++i)
243 if (previous) {
244 o << ", ";
246 previous = true;
247 printType(o, options, manager, i->type, false);
248 o << ' '
249 << codemaker::java::translateUnoToJavaIdentifier(
250 u2b(i->name), "param");
252 break;
254 default:
255 throw CannotDumpException(
256 "unexpected entity \"" + name
257 + "\" in call to skeletonmaker::cpp::printConstructorParameters");
259 return previous;
262 void printConstructor(
263 std::ostream & o, ProgramOptions const & options,
264 rtl::Reference< TypeManager > const & manager,
265 codemaker::UnoType::Sort sort,
266 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
267 std::vector< OUString > const & arguments)
269 o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
270 printConstructorParameters(
271 o, options, manager, sort, entity, name, arguments);
272 o << ");\n";
275 void printMethodParameters(
276 std::ostream & o, ProgramOptions const & options,
277 rtl::Reference< TypeManager > const & manager,
278 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
279 parameters,
280 bool withType)
282 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
283 const_iterator i(parameters.begin());
284 i != parameters.end(); ++i)
286 if (i != parameters.begin()) {
287 o << ", ";
289 if (withType) {
290 printType(o, options, manager, i->type, false);
291 if (i->direction
292 != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
294 o << "[]";
296 o << ' ';
298 o << codemaker::java::translateUnoToJavaIdentifier(
299 u2b(i->name), "param");
303 void printExceptionSpecification(
304 std::ostream & o, ProgramOptions const & options,
305 rtl::Reference< TypeManager > const & manager,
306 std::vector< OUString > const & exceptions)
308 if (!exceptions.empty()) {
309 o << " throws ";
310 for (std::vector< OUString >::const_iterator i(exceptions.begin());
311 i != exceptions.end(); ++i)
313 if (i !=exceptions.begin() ) {
314 o << ", ";
316 printType(o, options, manager, *i, false);
322 void printSetPropertyMixinBody(
323 std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute,
324 OString const & indentation)
326 unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
327 = checkAdditionalPropertyFlags(attribute);
329 o << "\n" << indentation << "{\n";
331 if ( attribute.bound ) {
332 o << indentation << " PropertySetMixin.BoundListeners l = "
333 "new PropertySetMixin.BoundListeners();\n\n";
336 o << indentation << " m_prophlp.prepareSet(\""
337 << attribute.name << "\", ";
338 if ( propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED ) {
339 OString fieldtype = codemaker::convertString(attribute.type);
341 sal_Int32 index = fieldtype.lastIndexOf('<');
342 sal_Int32 nPos=0;
343 bool single = true;
344 bool optional = false;
345 OStringBuffer buffer1(64);
346 OStringBuffer buffer2(64);
349 OString s(fieldtype.getToken(0, '<', nPos));
350 OStringBuffer buffer(16);
351 buffer.append("((");
352 buffer.append(s.copy(s.lastIndexOf('/')+1));
353 buffer.append(')');
354 OString t = buffer.makeStringAndClear();
356 if ( t.equals("((Optional)") ) {
357 optional=true;
358 if (single) {
359 single=false;
360 buffer1.append("the_value.IsPresent");
361 buffer2.append("the_value.Value");
362 } else {
363 buffer1.insert(0, t);
364 buffer1.append(").IsPresent");
365 buffer2.insert(0, t);
366 buffer2.append(").Value");
368 } else {
369 if ( single ) {
370 single=false;
371 if ( !optional ) {
372 buffer1.append("the_value.Value");
374 buffer2.append("the_value.Value");
375 } else {
376 if ( !optional ) {
377 buffer1.insert(0, t);
378 buffer1.append(").Value");
380 buffer2.insert(0, t);
381 buffer2.append(").Value");
384 } while( nPos <= index );
386 o << "Any.VOID,\n" << indentation << " ";
387 if ( optional )
388 o << "(";
389 o << buffer1.makeStringAndClear();
390 if ( optional )
391 o << ") ? " << buffer2.makeStringAndClear() << " : Any.VOID,\n"
392 << indentation << " ";
393 else
394 o << ", ";
397 if ( attribute.bound )
398 o << "l";
399 else
400 o << "null";
401 o << ");\n";
403 o << indentation << " synchronized (this) {\n"
404 << indentation << " m_" << attribute.name
405 << " = the_value;\n" << indentation << " }\n";
407 if ( attribute.bound ) {
408 o << indentation << " l.notifyListeners();\n";
410 o << indentation << "}\n\n";
413 void generateXPropertySetBodies(std::ostream& o);
414 void generateXFastPropertySetBodies(std::ostream& o);
415 void generateXPropertyAccessBodies(std::ostream& o);
417 void printMethods(std::ostream & o,
418 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
419 OUString const & name,
420 codemaker::GeneratedTypeSet & generated,
421 OString const & delegate, OString const & indentation,
422 bool defaultvalue, bool usepropertymixin)
424 if ( generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
425 ( defaultvalue &&
426 ( name == "com.sun.star.lang.XComponent" ||
427 name == "com.sun.star.lang.XTypeProvider" ||
428 name == "com.sun.star.uno.XWeak" ) ) ) {
429 return;
432 if ( usepropertymixin ) {
433 if (name == "com.sun.star.beans.XPropertySet") {
434 generated.add(u2b(name));
435 generateXPropertySetBodies(o);
436 return;
437 } else if (name == "com.sun.star.beans.XFastPropertySet") {
438 generated.add(u2b(name));
439 generateXFastPropertySetBodies(o);
440 return;
441 } else if (name == "com.sun.star.beans.XPropertyAccess") {
442 generated.add(u2b(name));
443 generateXPropertyAccessBodies(o);
444 return;
448 static OString sd("_");
449 bool body = !delegate.isEmpty();
450 bool defaultbody = ((delegate.equals(sd)) ? true : false);
452 generated.add(u2b(name));
453 rtl::Reference< unoidl::Entity > ent;
454 if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
456 throw CannotDumpException(
457 "unexpected entity \"" + name
458 + "\" in call to skeletonmaker::java::printMethods");
460 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
461 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
462 assert(ent2.is());
463 if ( options.all || defaultvalue ) {
464 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
465 ent2->getDirectMandatoryBases().begin());
466 i != ent2->getDirectMandatoryBases().end(); ++i)
468 printMethods(
469 o, options, manager, i->name, generated, delegate, indentation,
470 defaultvalue, usepropertymixin);
472 if (!(ent2->getDirectAttributes().empty()
473 && ent2->getDirectMethods().empty()))
475 o << indentation << "// ";
476 printType(o, options, manager, name, false);
477 o << ":\n";
480 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
481 i(ent2->getDirectAttributes().begin());
482 i != ent2->getDirectAttributes().end(); ++i)
484 o << indentation << "public ";
485 printType(o, options, manager, i->type, false);
486 o << " get" << i->name << "()";
487 printExceptionSpecification(o, options, manager, i->getExceptions);
488 if ( body ) {
489 if ( defaultbody ) {
490 if ( usepropertymixin ) {
491 o << "\n" << indentation << "{\n" << indentation
492 << " return m_" << i->name << ";\n" << indentation
493 << "}\n\n";
494 } else {
495 o << "\n" << indentation << "{\n" << indentation
496 << " return ";
497 printType(o, options, manager, i->type, false, true);
498 o << ";\n" << indentation << "}\n\n";
500 } else {
501 o << "\n" << indentation << "{\n" << indentation
502 << " return " << delegate.getStr() << "get" << i->name
503 << "();\n" << indentation << "}\n\n";
505 } else {
506 o << ";\n";
509 // REMOVE next line
510 if (!i->readOnly) {
511 o << indentation << "public void set" << i->name << '(';
512 printType(o, options, manager, i->type, false);
513 o << " the_value)";
514 printExceptionSpecification(o, options, manager, i->setExceptions);
515 if ( body ) {
516 if ( defaultbody ) {
517 if ( usepropertymixin ) {
518 printSetPropertyMixinBody(o, *i, indentation);
519 } else {
520 o << "\n" << indentation << "{\n\n" << indentation
521 << "}\n\n";
523 } else {
524 o << "\n" << indentation << "{\n" << indentation
525 << " " << delegate.getStr() << "set" << i->name
526 << "(the_value);\n" << indentation << "}\n\n";
528 } else {
529 o << ";\n";
533 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
534 ent2->getDirectMethods().begin());
535 i != ent2->getDirectMethods().end(); ++i)
537 o << indentation << "public ";
538 printType(o, options, manager, i->returnType, false);
539 o << ' ' << i->name << '(';
540 printMethodParameters(o, options, manager, i->parameters, true);
541 o << ')';
542 printExceptionSpecification(o, options, manager, i->exceptions);
543 if ( body ) {
544 if ( defaultbody ) {
545 o << "\n" << indentation << "{\n";
546 if (i->returnType != "void") {
547 o << indentation << " // TODO: Exchange the default return "
548 << "implementation for \"" << i->name << "\" !!!\n";
549 o << indentation << " // NOTE: "
550 "Default initialized polymorphic structs can cause problems"
551 "\n" << indentation << " // because of missing default "
552 "initialization of primitive types of\n" << indentation
553 << " // some C++ compilers or different Any initialization"
554 " in Java and C++\n" << indentation
555 << " // polymorphic structs.\n" << indentation
556 << " return ";
557 printType(o, options, manager, i->returnType, false, true);
558 o << ";";
559 } else {
560 o << indentation << " // TODO: Insert your implementation for \""
561 << i->name << "\" here.";
563 o << "\n" << indentation << "}\n\n";
564 } else {
565 o << "\n" << indentation << "{\n" << indentation << " ";
566 if (i->returnType != "void") {
567 o << "return ";
569 o << delegate.getStr() << i->name << '(';
570 printMethodParameters(
571 o, options, manager, i->parameters, false);
572 o << ");\n" << indentation << "}\n\n";
574 } else {
575 o << ";\n";
580 void printConstructors(
581 std::ostream & o, ProgramOptions const & options,
582 rtl::Reference< TypeManager > const & manager, OUString const & name)
584 rtl::Reference< unoidl::Entity > ent;
585 if (manager->getSort(name, &ent)
586 != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
588 throw CannotDumpException(
589 "unexpected entity \"" + name
590 + "\" in call to skeletonmaker::java::printConstructors");
592 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
593 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
594 assert(ent2.is());
595 for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
596 const_iterator i(ent2->getConstructors().begin());
597 i != ent2->getConstructors().end(); ++i)
599 o << "public static ";
600 printType(o, options, manager, ent2->getBase(), false);
601 o << ' ';
602 if (i->defaultConstructor) {
603 o << "create";
604 } else {
605 o << codemaker::java::translateUnoToJavaIdentifier(
606 u2b(i->name), "method");
608 o << "(com.sun.star.uno.XComponentContext the_context";
609 for (std::vector<
610 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
611 Parameter >::const_iterator j(i->parameters.begin());
612 j != i->parameters.end(); ++i)
614 o << ", ";
615 printType(o, options, manager, j->type, false);
616 if (j->rest) {
617 o << (options.java5 ? "..." : "[]");
619 o << ' '
620 << codemaker::java::translateUnoToJavaIdentifier(
621 u2b(j->name), "param");
623 o << ')';
624 printExceptionSpecification(o, options, manager, i->exceptions);
625 o << ";\n";
629 void generateDocumentation(std::ostream & o,
630 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
631 OString const & type);
633 void printServiceMembers(
634 std::ostream & o, ProgramOptions const & options,
635 rtl::Reference< TypeManager > const & manager,
636 OUString const & name,
637 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
638 OString const & delegate)
640 assert(entity.is());
641 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
642 entity->getDirectMandatoryBaseServices().begin());
643 i != entity->getDirectMandatoryBaseServices().end(); ++i)
645 o << "\n// exported service " << i->name << "\n";
646 generateDocumentation(o, options, manager, u2b(i->name), delegate);
648 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
649 entity->getDirectMandatoryBaseInterfaces().begin());
650 i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
652 o << "\n// supported interface " << i->name << "\n";
653 generateDocumentation(o, options, manager, u2b(i->name), delegate);
655 o << "\n// properties of service \""<< name << "\"\n";
656 for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
657 const_iterator i(entity->getDirectProperties().begin());
658 i != entity->getDirectProperties().end(); ++i)
660 o << "// private ";
661 printType(o, options, manager, i->type, false);
662 o << " "
663 << codemaker::java::translateUnoToJavaIdentifier(
664 u2b(i->name), "property")
665 << ";\n";
669 void printMapsToJavaType(
670 std::ostream & o, ProgramOptions const & options,
671 rtl::Reference< TypeManager > const & manager,
672 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
673 std::vector< OUString > const & arguments, const char * javaTypeSort)
675 o << "maps to Java " << (options.java5 ? "1.5" : "1.4") << " ";
676 if (javaTypeSort != 0) {
677 o << javaTypeSort << ' ';
679 o << "type \"";
680 if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
681 o << "com.sun.star.uno.XInterface";
682 } else {
683 printType(
684 o, options, manager, sort, nucleus, rank, arguments, false, false);
686 o << '"';
689 void generateDocumentation(std::ostream & o,
690 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
691 OString const & type, OString const & delegate)
693 OUString nucleus;
694 sal_Int32 rank;
695 codemaker::UnoType::Sort sort = manager->decompose(
696 b2u(type), false, &nucleus, &rank, 0, 0);
698 bool comment = true;
699 if (!delegate.isEmpty()) {
700 if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
701 sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
702 sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
704 return;
706 comment = false;
709 if (comment) {
710 o << "\n// UNO";
711 if (rank != 0) {
712 o << " sequence type";
713 } else if (sort <= codemaker::UnoType::SORT_ANY) {
714 o << " simple type";
715 } else {
716 switch (sort) {
717 case codemaker::UnoType::SORT_INTERFACE_TYPE:
718 o << " interface type";
719 break;
721 case codemaker::UnoType::SORT_MODULE:
722 o << "IDL module";
723 break;
725 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
726 o << " simple struct type";
727 break;
729 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
730 o << " polymorphic struct type template";
731 break;
733 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
734 o << " instantiated polymorphic struct type";
735 break;
737 case codemaker::UnoType::SORT_ENUM_TYPE:
738 o << " enum type";
739 break;
741 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
742 o << " exception type";
743 break;
745 case codemaker::UnoType::SORT_TYPEDEF:
746 o << "IDL typedef";
747 break;
749 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
750 o << " single-inheritance--based service";
751 break;
753 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
754 o << "IDL accumulation-based service";
755 break;
757 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
758 o << " inheritance-based singleton";
759 break;
761 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
762 o << "IDL service-based singleton";
763 break;
765 case codemaker::UnoType::SORT_CONSTANT_GROUP:
766 o << "IDL constant group";
767 break;
769 default:
770 OSL_ASSERT(false);
771 break;
774 o << " \"" << type << "\" ";
776 std::vector< OUString > arguments;
777 rtl::Reference< unoidl::Entity > entity;
778 sort = manager->decompose(
779 b2u(type), true, &nucleus, &rank, &arguments, &entity);
780 if (rank != 0) {
781 printMapsToJavaType(
782 o, options, manager, sort, nucleus, rank, arguments, "array");
783 o << '\n';
784 } else if (sort <= codemaker::UnoType::SORT_ANY) {
785 printMapsToJavaType(
786 o, options, manager, sort, nucleus, rank, arguments, 0);
787 o << '\n';
788 } else {
789 switch (sort) {
790 case codemaker::UnoType::SORT_INTERFACE_TYPE:
791 printMapsToJavaType(
792 o, options, manager, sort, nucleus, rank, arguments,
793 "interface");
794 if (nucleus == "com.sun.star.uno.XInterface") {
795 o << '\n';
796 } else {
797 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
798 codemaker::GeneratedTypeSet generated;
799 printMethods(
800 o, options, manager, nucleus, generated, delegate, "");
802 break;
804 case codemaker::UnoType::SORT_MODULE:
805 printMapsToJavaType(
806 o, options, manager, sort, nucleus, rank, arguments, "package");
807 o << '\n';
808 break;
810 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
811 printMapsToJavaType(
812 o, options, manager, sort, nucleus, rank, arguments, "class");
813 o << "; full constructor:\n";
814 printConstructor(
815 o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
816 entity, nucleus, arguments);
817 break;
819 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
820 printMapsToJavaType(
821 o, options, manager, sort, nucleus, rank, arguments,
822 options.java5 ? "generic class" : "class");
823 o << "; full constructor:\n";
824 printConstructor(
825 o, options, manager,
826 codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
827 entity, nucleus, arguments);
828 break;
830 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
831 printMapsToJavaType(
832 o, options, manager, sort, nucleus, rank, arguments,
833 options.java5 ? "generic class instantiation" : "class");
834 o << "; full constructor:\n";
835 printConstructor(
836 o, options, manager,
837 codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
838 entity, nucleus, arguments);
839 break;
841 case codemaker::UnoType::SORT_ENUM_TYPE:
842 case codemaker::UnoType::SORT_CONSTANT_GROUP:
843 printMapsToJavaType(
844 o, options, manager, sort, nucleus, rank, arguments, "class");
845 o << '\n';
846 break;
848 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
849 printMapsToJavaType(
850 o, options, manager, sort, nucleus, rank, arguments,
851 "exception class");
852 o << "; full constructor:\n";
853 printConstructor(
854 o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
855 entity, nucleus, arguments);
856 break;
858 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
859 printMapsToJavaType(
860 o, options, manager, sort, nucleus, rank, arguments, "class");
861 o << "; construction methods:\n";
862 printConstructors(o, options, manager, nucleus);
863 generateDocumentation(
864 o, options, manager,
865 u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
866 entity.get())->getBase()),
867 delegate);
868 break;
870 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
871 o << ("does not map to Java\n"
872 "// the service members are generated instead\n");
873 printServiceMembers(
874 o, options, manager, nucleus,
875 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
876 entity.get()),
877 delegate);
878 break;
880 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
881 printMapsToJavaType(
882 o, options, manager, sort, nucleus, rank, arguments, "class");
883 o << "; get method:\npublic static ";
884 printType(
885 o, options, manager,
886 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
887 entity.get())->getBase(),
888 false);
889 o << " get(com.sun.star.uno.XComponentContext context);\n";
890 break;
892 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
893 o << "does not map to Java\n";
894 break;
896 default:
897 OSL_ASSERT(false);
898 break;
906 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */