LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - javatypemaker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 479 0.0 %
Date: 2014-11-03 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include <cstring>
      23             : 
      24             : #include "codemaker/codemaker.hxx"
      25             : #include "codemaker/commonjava.hxx"
      26             : #include "codemaker/global.hxx"
      27             : 
      28             : #include "skeletoncommon.hxx"
      29             : #include "skeletonjava.hxx"
      30             : 
      31             : namespace skeletonmaker { namespace java {
      32             : 
      33           0 : void printType(
      34             :     std::ostream & o, ProgramOptions const & options,
      35             :     rtl::Reference< TypeManager > const & manager,
      36             :     codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
      37             :     std::vector< OUString > const & arguments, bool referenceType,
      38             :     bool defaultvalue)
      39             : {
      40           0 :     if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
      41           0 :         switch (sort) {
      42             :         case codemaker::UnoType::SORT_BOOLEAN:
      43           0 :             o << "false";
      44           0 :             return;
      45             :         case codemaker::UnoType::SORT_CHAR:
      46             :         case codemaker::UnoType::SORT_BYTE:
      47             :         case codemaker::UnoType::SORT_SHORT:
      48             :         case codemaker::UnoType::SORT_UNSIGNED_SHORT:
      49             :         case codemaker::UnoType::SORT_LONG:
      50             :         case codemaker::UnoType::SORT_UNSIGNED_LONG:
      51             :         case codemaker::UnoType::SORT_HYPER:
      52             :         case codemaker::UnoType::SORT_UNSIGNED_HYPER:
      53             :         case codemaker::UnoType::SORT_FLOAT:
      54             :         case codemaker::UnoType::SORT_DOUBLE:
      55           0 :             o << "0";
      56           0 :             return;
      57             :         default:
      58           0 :             break;
      59             :         }
      60             :     }
      61             : 
      62           0 :     if (defaultvalue) {
      63           0 :         if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE) {
      64           0 :             o << "null";
      65           0 :             return;
      66           0 :         } else if (sort == codemaker::UnoType::SORT_ANY && rank == 0) {
      67           0 :             o << "com.sun.star.uno.Any.VOID";
      68           0 :             return;
      69           0 :         } else if (sort == codemaker::UnoType::SORT_TYPE && rank == 0) {
      70           0 :             o << "com.sun.star.uno.Type.VOID";
      71           0 :             return;
      72           0 :         } else if (sort != codemaker::UnoType::SORT_ENUM_TYPE || rank != 0) {
      73           0 :             o << "new ";
      74             :         }
      75             :     }
      76             : 
      77             :     OString sType(
      78             :         codemaker::java::translateUnoToJavaType(
      79           0 :             sort, u2b(nucleus), referenceType && rank == 0));
      80           0 :     if (sType.startsWith("java.lang.")) {
      81           0 :         sType = sType.copy(std::strlen("java.lang."));
      82             :     }
      83           0 :     o << sType;
      84           0 :     if (!arguments.empty()) {
      85           0 :         o << '<';
      86           0 :         for (std::vector< OUString >::const_iterator i(arguments.begin());
      87           0 :              i != arguments.end(); ++i)
      88             :         {
      89           0 :             if (i != arguments.begin()) {
      90           0 :                 o << ", ";
      91             :             }
      92           0 :             printType(o, options, manager, *i, true, false);
      93             :         }
      94           0 :         o << '>';
      95             :     }
      96           0 :     for (sal_Int32 i = 0; i != rank; ++i) {
      97           0 :         if (defaultvalue)
      98           0 :             o << "[0]";
      99             :         else
     100           0 :             o << "[]";
     101             :     }
     102             : 
     103           0 :     if (defaultvalue && sort > codemaker::UnoType::SORT_CHAR && rank == 0) {
     104           0 :         if (sort == codemaker::UnoType::SORT_ENUM_TYPE)
     105           0 :             o << ".getDefault()";
     106             :         else
     107           0 :             o << "()";
     108           0 :     }
     109             : }
     110             : 
     111           0 : void printType(
     112             :     std::ostream & o, ProgramOptions const & options,
     113             :     rtl::Reference< TypeManager > const & manager, OUString const & name,
     114             :     bool referenceType, bool defaultvalue)
     115             : {
     116           0 :     OUString nucleus;
     117             :     sal_Int32 rank;
     118           0 :     std::vector< OUString > arguments;
     119             :     codemaker::UnoType::Sort sort = manager->decompose(
     120           0 :         name, true, &nucleus, &rank, &arguments, 0);
     121             :     printType(
     122             :         o, options, manager, sort, nucleus, rank, arguments, referenceType,
     123           0 :         defaultvalue);
     124           0 : }
     125             : 
     126           0 : bool printConstructorParameters(
     127             :     std::ostream & o, ProgramOptions const & options,
     128             :     rtl::Reference< TypeManager > const & manager,
     129             :     codemaker::UnoType::Sort sort,
     130             :     rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
     131             :     std::vector< OUString > const & arguments)
     132             : {
     133           0 :     bool previous = false;
     134           0 :     switch (sort) {
     135             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     136             :         {
     137             :             rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
     138           0 :                 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
     139             :             assert(ent2.is());
     140           0 :             if (!ent2->getDirectBase().isEmpty()) {
     141           0 :                 rtl::Reference< unoidl::Entity > baseEnt;
     142             :                 codemaker::UnoType::Sort baseSort = manager->getSort(
     143           0 :                     ent2->getDirectBase(), &baseEnt);
     144             :                 previous = printConstructorParameters(
     145             :                     o, options, manager, baseSort, baseEnt,
     146           0 :                     ent2->getDirectBase(), std::vector< OUString >());
     147             :             }
     148           0 :             for (std::vector< unoidl::PlainStructTypeEntity::Member >::
     149           0 :                      const_iterator i(ent2->getDirectMembers().begin());
     150           0 :                  i != ent2->getDirectMembers().end(); ++i)
     151             :             {
     152           0 :                 if (previous) {
     153           0 :                     o << ", ";
     154             :                 }
     155           0 :                 previous = true;
     156           0 :                 printType(o, options, manager, i->type, false);
     157           0 :                 o << ' '
     158             :                   << codemaker::java::translateUnoToJavaIdentifier(
     159           0 :                       u2b(i->name), "param");
     160             :             }
     161           0 :             break;
     162             :         }
     163             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     164             :         {
     165             :             rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
     166             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
     167           0 :                     entity.get()));
     168             :             assert(ent2.is());
     169           0 :             for (std::vector<
     170             :                      unoidl::PolymorphicStructTypeTemplateEntity::Member >::
     171           0 :                      const_iterator i(ent2->getMembers().begin());
     172           0 :                  i != ent2->getMembers().end(); ++i)
     173             :             {
     174           0 :                 if (previous) {
     175           0 :                     o << ", ";
     176             :                 }
     177           0 :                 previous = true;
     178           0 :                 if (i->parameterized) {
     179           0 :                     o << i->type;
     180             :                 } else {
     181           0 :                     printType(o, options, manager, i->type, false);
     182             :                 }
     183           0 :                 o << ' '
     184             :                   << codemaker::java::translateUnoToJavaIdentifier(
     185           0 :                       u2b(i->name), "param");
     186             :             }
     187           0 :             break;
     188             :         }
     189             :     case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     190             :         {
     191             :             rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
     192             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
     193           0 :                     entity.get()));
     194             :             assert(ent2.is());
     195           0 :             for (std::vector<
     196             :                      unoidl::PolymorphicStructTypeTemplateEntity::Member >::
     197           0 :                      const_iterator i(ent2->getMembers().begin());
     198           0 :                  i != ent2->getMembers().end(); ++i)
     199             :             {
     200           0 :                 if (previous) {
     201           0 :                     o << ", ";
     202             :                 }
     203           0 :                 previous = true;
     204           0 :                 if (i->parameterized) {
     205           0 :                     for (std::vector< OUString >::const_iterator j(
     206           0 :                              ent2->getTypeParameters().begin());
     207           0 :                          j != ent2->getTypeParameters().end(); ++j)
     208             :                     {
     209           0 :                         if (i->type == *j) {
     210             :                             o << arguments[
     211           0 :                                 j - ent2->getTypeParameters().begin()];
     212           0 :                             break;
     213             :                         }
     214             :                     }
     215             :                 } else {
     216           0 :                     printType(o, options, manager, i->type, false);
     217             :                 }
     218           0 :                 o << ' '
     219             :                   << codemaker::java::translateUnoToJavaIdentifier(
     220           0 :                       u2b(i->name), "param");
     221             :             }
     222           0 :             break;
     223             :         }
     224             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     225             :         {
     226             :             rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
     227           0 :                 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
     228             :             assert(ent2.is());
     229           0 :             if (!ent2->getDirectBase().isEmpty()) {
     230           0 :                 rtl::Reference< unoidl::Entity > baseEnt;
     231             :                 codemaker::UnoType::Sort baseSort = manager->getSort(
     232           0 :                     ent2->getDirectBase(), &baseEnt);
     233             :                 previous = printConstructorParameters(
     234             :                     o, options, manager, baseSort, baseEnt,
     235           0 :                     ent2->getDirectBase(), std::vector< OUString >());
     236             :             }
     237           0 :             for (std::vector< unoidl::ExceptionTypeEntity::Member >::
     238           0 :                      const_iterator i(ent2->getDirectMembers().begin());
     239           0 :                  i != ent2->getDirectMembers().end(); ++i)
     240             :             {
     241           0 :                 if (previous) {
     242           0 :                     o << ", ";
     243             :                 }
     244           0 :                 previous = true;
     245           0 :                 printType(o, options, manager, i->type, false);
     246           0 :                 o << ' '
     247             :                   << codemaker::java::translateUnoToJavaIdentifier(
     248           0 :                       u2b(i->name), "param");
     249             :             }
     250           0 :             break;
     251             :         }
     252             :     default:
     253             :         throw CannotDumpException(
     254           0 :             "unexpected entity \"" + name
     255           0 :             + "\" in call to skeletonmaker::cpp::printConstructorParameters");
     256             :     }
     257           0 :     return previous;
     258             : }
     259             : 
     260           0 : void printConstructor(
     261             :     std::ostream & o, ProgramOptions const & options,
     262             :     rtl::Reference< TypeManager > const & manager,
     263             :     codemaker::UnoType::Sort sort,
     264             :     rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
     265             :     std::vector< OUString > const & arguments)
     266             : {
     267           0 :     o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
     268             :     printConstructorParameters(
     269           0 :         o, options, manager, sort, entity, name, arguments);
     270           0 :     o << ");\n";
     271           0 : }
     272             : 
     273           0 : void printMethodParameters(
     274             :     std::ostream & o, ProgramOptions const & options,
     275             :     rtl::Reference< TypeManager > const & manager,
     276             :     std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
     277             :         parameters,
     278             :     bool withType)
     279             : {
     280           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
     281           0 :              const_iterator i(parameters.begin());
     282           0 :          i != parameters.end(); ++i)
     283             :     {
     284           0 :         if (i != parameters.begin()) {
     285           0 :             o << ", ";
     286             :         }
     287           0 :         if (withType) {
     288           0 :             printType(o, options, manager, i->type, false);
     289           0 :             if (i->direction
     290           0 :                 != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
     291             :             {
     292           0 :                 o << "[]";
     293             :             }
     294           0 :             o << ' ';
     295             :         }
     296             :         o << codemaker::java::translateUnoToJavaIdentifier(
     297           0 :             u2b(i->name), "param");
     298             :     }
     299           0 : }
     300             : 
     301           0 : void printExceptionSpecification(
     302             :     std::ostream & o, ProgramOptions const & options,
     303             :     rtl::Reference< TypeManager > const & manager,
     304             :     std::vector< OUString > const & exceptions)
     305             : {
     306           0 :     if (!exceptions.empty()) {
     307           0 :         o << " throws ";
     308           0 :         for (std::vector< OUString >::const_iterator i(exceptions.begin());
     309           0 :              i != exceptions.end(); ++i)
     310             :         {
     311           0 :             if (i !=exceptions.begin() ) {
     312           0 :                 o << ", ";
     313             :             }
     314           0 :             printType(o, options, manager, *i, false);
     315             :         }
     316             :     }
     317           0 : }
     318             : 
     319             : 
     320           0 : void printSetPropertyMixinBody(
     321             :     std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute,
     322             :     OString const & indentation)
     323             : {
     324             :     unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
     325           0 :         = checkAdditionalPropertyFlags(attribute);
     326             : 
     327           0 :     o << "\n" << indentation << "{\n";
     328             : 
     329           0 :     if ( attribute.bound ) {
     330           0 :         o << indentation << "    PropertySetMixin.BoundListeners l = "
     331           0 :             "new PropertySetMixin.BoundListeners();\n\n";
     332             :     }
     333             : 
     334           0 :     o << indentation << "    m_prophlp.prepareSet(\""
     335           0 :       << attribute.name << "\", ";
     336           0 :     if ( propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED ) {
     337           0 :         OString fieldtype = codemaker::convertString(attribute.type);
     338             : 
     339           0 :         sal_Int32 index = fieldtype.lastIndexOf('<');
     340           0 :         sal_Int32 nPos=0;
     341           0 :         bool single = true;
     342           0 :         bool optional = false;
     343           0 :         OStringBuffer buffer1(64);
     344           0 :         OStringBuffer buffer2(64);
     345           0 :         do
     346             :         {
     347           0 :             OString s(fieldtype.getToken(0, '<', nPos));
     348           0 :             OStringBuffer buffer(16);
     349           0 :             buffer.append("((");
     350           0 :             buffer.append(s.copy(s.lastIndexOf('/')+1));
     351           0 :             buffer.append(')');
     352           0 :             OString t = buffer.makeStringAndClear();
     353             : 
     354           0 :             if ( t.equals("((Optional)") ) {
     355           0 :                 optional=true;
     356           0 :                 if (single) {
     357           0 :                     single=false;
     358           0 :                     buffer1.append("the_value.IsPresent");
     359           0 :                     buffer2.append("the_value.Value");
     360             :                 } else {
     361           0 :                     buffer1.insert(0, t);
     362           0 :                     buffer1.append(").IsPresent");
     363           0 :                     buffer2.insert(0, t);
     364           0 :                     buffer2.append(").Value");
     365             :                 }
     366             :             } else {
     367           0 :                 if ( single ) {
     368           0 :                     single=false;
     369           0 :                     if ( !optional ) {
     370           0 :                         buffer1.append("the_value.Value");
     371             :                     }
     372           0 :                     buffer2.append("the_value.Value");
     373             :                 } else {
     374           0 :                     if ( !optional ) {
     375           0 :                         buffer1.insert(0, t);
     376           0 :                         buffer1.append(").Value");
     377             :                     }
     378           0 :                     buffer2.insert(0, t);
     379           0 :                     buffer2.append(").Value");
     380             :                 }
     381           0 :             }
     382           0 :         } while( nPos <= index );
     383             : 
     384           0 :         o << "Any.VOID,\n" << indentation << "        ";
     385           0 :         if ( optional )
     386           0 :             o << "(";
     387           0 :         o << buffer1.makeStringAndClear();
     388           0 :         if ( optional )
     389           0 :             o << ") ? " << buffer2.makeStringAndClear() << " : Any.VOID,\n"
     390           0 :               << indentation << "        ";
     391             :         else
     392           0 :             o << ", ";
     393             :     }
     394             : 
     395           0 :     if ( attribute.bound )
     396           0 :         o << "l";
     397             :     else
     398           0 :         o << "null";
     399           0 :     o << ");\n";
     400             : 
     401           0 :     o << indentation << "    synchronized (this) {\n"
     402           0 :       << indentation << "        m_" << attribute.name
     403           0 :       << " = the_value;\n" << indentation << "    }\n";
     404             : 
     405           0 :     if ( attribute.bound ) {
     406           0 :         o << indentation << "    l.notifyListeners();\n";
     407             :     }
     408           0 :     o  << indentation << "}\n\n";
     409           0 : }
     410             : 
     411           0 : void printMethods(std::ostream & o,
     412             :     ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
     413             :     OUString const & name,
     414             :     codemaker::GeneratedTypeSet & generated,
     415             :     OString const & delegate, OString const & indentation,
     416             :     bool defaultvalue, bool usepropertymixin)
     417             : {
     418           0 :     if ( generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
     419           0 :          ( defaultvalue &&
     420           0 :            ( name == "com.sun.star.lang.XComponent" ||
     421           0 :              name == "com.sun.star.lang.XTypeProvider" ||
     422           0 :              name == "com.sun.star.uno.XWeak" ) ) ) {
     423           0 :         return;
     424             :     }
     425             : 
     426           0 :     if ( usepropertymixin ) {
     427           0 :         if (name == "com.sun.star.beans.XPropertySet") {
     428           0 :             generated.add(u2b(name));
     429           0 :             generateXPropertySetBodies(o);
     430           0 :             return;
     431           0 :         } else if (name == "com.sun.star.beans.XFastPropertySet") {
     432           0 :             generated.add(u2b(name));
     433           0 :             generateXFastPropertySetBodies(o);
     434           0 :             return;
     435           0 :         } else if (name == "com.sun.star.beans.XPropertyAccess") {
     436           0 :             generated.add(u2b(name));
     437           0 :             generateXPropertyAccessBodies(o);
     438           0 :             return;
     439             :         }
     440             :     }
     441             : 
     442           0 :     static OString sd("_");
     443           0 :     bool body = !delegate.isEmpty();
     444           0 :     bool defaultbody = delegate.equals(sd);
     445             : 
     446           0 :     generated.add(u2b(name));
     447           0 :     rtl::Reference< unoidl::Entity > ent;
     448           0 :     if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
     449             :     {
     450             :         throw CannotDumpException(
     451           0 :             "unexpected entity \"" + name
     452           0 :             + "\" in call to skeletonmaker::java::printMethods");
     453             :     }
     454             :     rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
     455           0 :         dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
     456             :     assert(ent2.is());
     457           0 :     if ( options.all || defaultvalue ) {
     458           0 :         for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     459           0 :                  ent2->getDirectMandatoryBases().begin());
     460           0 :              i != ent2->getDirectMandatoryBases().end(); ++i)
     461             :         {
     462             :             printMethods(
     463           0 :                 o, options, manager, i->name, generated, delegate, indentation,
     464           0 :                 defaultvalue, usepropertymixin);
     465             :         }
     466           0 :         if (!(ent2->getDirectAttributes().empty()
     467           0 :               && ent2->getDirectMethods().empty()))
     468             :         {
     469           0 :             o << indentation << "// ";
     470           0 :             printType(o, options, manager, name, false);
     471           0 :             o << ":\n";
     472             :         }
     473             :     }
     474           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
     475           0 :              i(ent2->getDirectAttributes().begin());
     476           0 :          i != ent2->getDirectAttributes().end(); ++i)
     477             :     {
     478           0 :         o << indentation << "public ";
     479           0 :         printType(o, options, manager, i->type, false);
     480           0 :         o << " get" << i->name << "()";
     481           0 :         printExceptionSpecification(o, options, manager, i->getExceptions);
     482           0 :         if ( body ) {
     483           0 :             if ( defaultbody ) {
     484           0 :                 if ( usepropertymixin ) {
     485           0 :                     o << "\n" << indentation << "{\n" << indentation
     486           0 :                       << "    return m_" << i->name << ";\n" << indentation
     487           0 :                       << "}\n\n";
     488             :                 } else {
     489           0 :                     o << "\n" << indentation << "{\n" << indentation
     490           0 :                       << "    return ";
     491           0 :                     printType(o, options, manager, i->type, false, true);
     492           0 :                     o << ";\n" << indentation << "}\n\n";
     493             :                 }
     494             :             } else {
     495           0 :                 o << "\n" << indentation << "{\n" << indentation
     496           0 :                   << "    return " << delegate.getStr() << "get" << i->name
     497           0 :                   << "();\n" << indentation << "}\n\n";
     498             :             }
     499             :         } else {
     500           0 :             o << ";\n";
     501             :         }
     502             : 
     503             :         // REMOVE next line
     504           0 :         if (!i->readOnly) {
     505           0 :             o << indentation << "public void set" << i->name << '(';
     506           0 :             printType(o, options, manager, i->type, false);
     507           0 :             o << " the_value)";
     508           0 :             printExceptionSpecification(o, options, manager, i->setExceptions);
     509           0 :             if ( body ) {
     510           0 :                 if ( defaultbody ) {
     511           0 :                     if ( usepropertymixin ) {
     512           0 :                         printSetPropertyMixinBody(o, *i, indentation);
     513             :                     } else {
     514           0 :                         o << "\n" << indentation << "{\n\n" << indentation
     515           0 :                           << "}\n\n";
     516             :                     }
     517             :                 } else {
     518           0 :                     o << "\n" << indentation << "{\n" << indentation
     519           0 :                       << "    " << delegate.getStr() << "set" << i->name
     520           0 :                       << "(the_value);\n" << indentation << "}\n\n";
     521             :                 }
     522             :             } else {
     523           0 :                 o << ";\n";
     524             :             }
     525             :         }
     526             :     }
     527           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
     528           0 :              ent2->getDirectMethods().begin());
     529           0 :          i != ent2->getDirectMethods().end(); ++i)
     530             :     {
     531           0 :         o << indentation << "public ";
     532           0 :         printType(o, options, manager, i->returnType, false);
     533           0 :         o << ' ' << i->name << '(';
     534           0 :         printMethodParameters(o, options, manager, i->parameters, true);
     535           0 :         o << ')';
     536           0 :         printExceptionSpecification(o, options, manager, i->exceptions);
     537           0 :         if ( body ) {
     538           0 :             if ( defaultbody ) {
     539           0 :                 o << "\n" << indentation << "{\n";
     540           0 :                 if (i->returnType != "void") {
     541           0 :                     o << indentation << "    // TODO: Exchange the default return implementation for \"" << i->name << "\" !!!\n";
     542           0 :                     o << indentation << "    // NOTE: "
     543             :                         "Default initialized polymorphic structs can cause problems"
     544           0 :                         "\n" << indentation << "    // because of missing default "
     545           0 :                         "initialization of primitive types of\n" << indentation
     546             :                       << "    // some C++ compilers or different Any initialization"
     547           0 :                         " in Java and C++\n" << indentation
     548           0 :                       << "    // polymorphic structs.\n" << indentation
     549           0 :                       << "    return ";
     550           0 :                     printType(o, options, manager, i->returnType, false, true);
     551           0 :                     o << ";";
     552             :                 } else {
     553           0 :                     o << indentation << "    // TODO: Insert your implementation for \""
     554           0 :                       << i->name << "\" here.";
     555             :                 }
     556           0 :                 o << "\n" << indentation << "}\n\n";
     557             :             } else {
     558           0 :                 o << "\n" << indentation << "{\n" << indentation << "    ";
     559           0 :                 if (i->returnType != "void") {
     560           0 :                     o << "return ";
     561             :                 }
     562           0 :                 o << delegate.getStr() << i->name << '(';
     563             :                 printMethodParameters(
     564           0 :                     o, options, manager, i->parameters, false);
     565           0 :                 o << ");\n" << indentation << "}\n\n";
     566             :             }
     567             :         } else {
     568           0 :             o << ";\n";
     569             :         }
     570           0 :     }
     571             : }
     572             : 
     573           0 : void printConstructors(
     574             :     std::ostream & o, ProgramOptions const & options,
     575             :     rtl::Reference< TypeManager > const & manager, OUString const & name)
     576             : {
     577           0 :     rtl::Reference< unoidl::Entity > ent;
     578           0 :     if (manager->getSort(name, &ent)
     579             :         != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
     580             :     {
     581             :         throw CannotDumpException(
     582           0 :             "unexpected entity \"" + name
     583           0 :             + "\" in call to skeletonmaker::java::printConstructors");
     584             :     }
     585             :     rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
     586           0 :         dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
     587             :     assert(ent2.is());
     588           0 :     for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
     589           0 :              const_iterator i(ent2->getConstructors().begin());
     590           0 :          i != ent2->getConstructors().end(); ++i)
     591             :     {
     592           0 :         o << "public static ";
     593           0 :         printType(o, options, manager, ent2->getBase(), false);
     594           0 :         o << ' ';
     595           0 :         if (i->defaultConstructor) {
     596           0 :             o << "create";
     597             :         } else {
     598             :             o << codemaker::java::translateUnoToJavaIdentifier(
     599           0 :                 u2b(i->name), "method");
     600             :         }
     601           0 :         o << "(com.sun.star.uno.XComponentContext the_context";
     602           0 :         for (std::vector<
     603             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor::
     604           0 :                  Parameter >::const_iterator j(i->parameters.begin());
     605           0 :              j != i->parameters.end(); ++i)
     606             :         {
     607           0 :             o << ", ";
     608           0 :             printType(o, options, manager, j->type, false);
     609           0 :             if (j->rest) {
     610           0 :                 o << "...";
     611             :             }
     612           0 :             o << ' '
     613             :               << codemaker::java::translateUnoToJavaIdentifier(
     614           0 :                   u2b(j->name), "param");
     615             :         }
     616           0 :         o << ')';
     617           0 :         printExceptionSpecification(o, options, manager, i->exceptions);
     618           0 :         o << ";\n";
     619           0 :     }
     620           0 : }
     621             : 
     622           0 : void printServiceMembers(
     623             :     std::ostream & o, ProgramOptions const & options,
     624             :     rtl::Reference< TypeManager > const & manager,
     625             :     OUString const & name,
     626             :     rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
     627             :     OString const & delegate)
     628             : {
     629             :     assert(entity.is());
     630           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     631           0 :              entity->getDirectMandatoryBaseServices().begin());
     632           0 :          i != entity->getDirectMandatoryBaseServices().end(); ++i)
     633             :     {
     634           0 :         o << "\n// exported service " << i->name << "\n";
     635           0 :         generateDocumentation(o, options, manager, u2b(i->name), delegate);
     636             :     }
     637           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     638           0 :              entity->getDirectMandatoryBaseInterfaces().begin());
     639           0 :          i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
     640             :     {
     641           0 :         o << "\n// supported interface " << i->name << "\n";
     642           0 :         generateDocumentation(o, options, manager, u2b(i->name), delegate);
     643             :     }
     644           0 :     o << "\n// properties of service \""<< name << "\"\n";
     645           0 :     for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
     646           0 :              const_iterator i(entity->getDirectProperties().begin());
     647           0 :          i != entity->getDirectProperties().end(); ++i)
     648             :     {
     649           0 :         o << "// private ";
     650           0 :         printType(o, options, manager, i->type, false);
     651           0 :         o << " "
     652             :           << codemaker::java::translateUnoToJavaIdentifier(
     653           0 :               u2b(i->name), "property")
     654           0 :           << ";\n";
     655             :     }
     656           0 : }
     657             : 
     658           0 : void printMapsToJavaType(
     659             :     std::ostream & o, ProgramOptions const & options,
     660             :     rtl::Reference< TypeManager > const & manager,
     661             :     codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
     662             :     std::vector< OUString > const & arguments, const char * javaTypeSort)
     663             : {
     664           0 :     o << "maps to Java 1.5 ";
     665           0 :     if (javaTypeSort != 0) {
     666           0 :         o << javaTypeSort << ' ';
     667             :     }
     668           0 :     o << "type \"";
     669           0 :     if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
     670           0 :         o << "com.sun.star.uno.XInterface";
     671             :     } else {
     672             :         printType(
     673           0 :             o, options, manager, sort, nucleus, rank, arguments, false, false);
     674             :     }
     675           0 :     o << '"';
     676           0 : }
     677             : 
     678           0 : void generateDocumentation(std::ostream & o,
     679             :     ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
     680             :     OString const & type, OString const & delegate)
     681             : {
     682           0 :     OUString nucleus;
     683             :     sal_Int32 rank;
     684             :     codemaker::UnoType::Sort sort = manager->decompose(
     685           0 :         b2u(type), false, &nucleus, &rank, 0, 0);
     686             : 
     687           0 :     bool comment = true;
     688           0 :     if (!delegate.isEmpty()) {
     689           0 :         if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
     690           0 :             sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
     691             :             sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
     692             :         {
     693           0 :             return;
     694             :         }
     695           0 :         comment = false;
     696             :     }
     697             : 
     698           0 :     if (comment) {
     699           0 :         o << "\n// UNO";
     700           0 :         if (rank != 0) {
     701           0 :             o << " sequence type";
     702           0 :         } else if (sort <= codemaker::UnoType::SORT_ANY) {
     703           0 :             o << " simple type";
     704             :         } else {
     705           0 :             switch (sort) {
     706             :             case codemaker::UnoType::SORT_INTERFACE_TYPE:
     707           0 :                 o << " interface type";
     708           0 :                 break;
     709             : 
     710             :             case codemaker::UnoType::SORT_MODULE:
     711           0 :                 o << "IDL module";
     712           0 :                 break;
     713             : 
     714             :             case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     715           0 :                 o << " simple struct type";
     716           0 :                 break;
     717             : 
     718             :             case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     719           0 :                 o << " polymorphic struct type template";
     720           0 :                 break;
     721             : 
     722             :             case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     723           0 :                 o << " instantiated polymorphic struct type";
     724           0 :                 break;
     725             : 
     726             :             case codemaker::UnoType::SORT_ENUM_TYPE:
     727           0 :                 o << " enum type";
     728           0 :                 break;
     729             : 
     730             :             case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     731           0 :                 o << " exception type";
     732           0 :                 break;
     733             : 
     734             :             case codemaker::UnoType::SORT_TYPEDEF:
     735           0 :                 o << "IDL typedef";
     736           0 :                 break;
     737             : 
     738             :             case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
     739           0 :                 o << " single-inheritance--based service";
     740           0 :                 break;
     741             : 
     742             :             case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     743           0 :                 o << "IDL accumulation-based service";
     744           0 :                 break;
     745             : 
     746             :             case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
     747           0 :                 o << " inheritance-based singleton";
     748           0 :                 break;
     749             : 
     750             :             case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
     751           0 :                 o << "IDL service-based singleton";
     752           0 :                 break;
     753             : 
     754             :             case codemaker::UnoType::SORT_CONSTANT_GROUP:
     755           0 :                 o << "IDL constant group";
     756           0 :                 break;
     757             : 
     758             :             default:
     759             :                 OSL_ASSERT(false);
     760           0 :                 break;
     761             :             }
     762             :         }
     763           0 :         o << " \"" << type << "\" ";
     764             :     }
     765           0 :     std::vector< OUString > arguments;
     766           0 :     rtl::Reference< unoidl::Entity > entity;
     767             :     sort = manager->decompose(
     768           0 :         b2u(type), true, &nucleus, &rank, &arguments, &entity);
     769           0 :     if (rank != 0) {
     770             :         printMapsToJavaType(
     771           0 :             o, options, manager, sort, nucleus, rank, arguments, "array");
     772           0 :         o << '\n';
     773           0 :     } else if (sort <= codemaker::UnoType::SORT_ANY) {
     774             :         printMapsToJavaType(
     775           0 :             o, options, manager, sort, nucleus, rank, arguments, 0);
     776           0 :         o << '\n';
     777             :     } else {
     778           0 :         switch (sort) {
     779             :         case codemaker::UnoType::SORT_INTERFACE_TYPE:
     780             :             printMapsToJavaType(
     781             :                 o, options, manager, sort, nucleus, rank, arguments,
     782           0 :                 "interface");
     783           0 :             if (nucleus == "com.sun.star.uno.XInterface") {
     784           0 :                 o << '\n';
     785             :             } else {
     786           0 :                 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
     787           0 :                 codemaker::GeneratedTypeSet generated;
     788             :                 printMethods(
     789           0 :                     o, options, manager, nucleus, generated, delegate, "");
     790             :             }
     791           0 :             break;
     792             : 
     793             :         case codemaker::UnoType::SORT_MODULE:
     794             :             printMapsToJavaType(
     795           0 :                 o, options, manager, sort, nucleus, rank, arguments, "package");
     796           0 :             o << '\n';
     797           0 :             break;
     798             : 
     799             :         case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     800             :             printMapsToJavaType(
     801           0 :                 o, options, manager, sort, nucleus, rank, arguments, "class");
     802           0 :             o << "; full constructor:\n";
     803             :             printConstructor(
     804             :                 o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
     805           0 :                 entity, nucleus, arguments);
     806           0 :             break;
     807             : 
     808             :         case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     809             :             printMapsToJavaType(
     810             :                 o, options, manager, sort, nucleus, rank, arguments,
     811           0 :                 "generic class");
     812           0 :             o << "; full constructor:\n";
     813             :             printConstructor(
     814             :                 o, options, manager,
     815             :                 codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
     816           0 :                 entity, nucleus, arguments);
     817           0 :             break;
     818             : 
     819             :         case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     820             :             printMapsToJavaType(
     821             :                 o, options, manager, sort, nucleus, rank, arguments,
     822           0 :                 "generic class instantiation");
     823           0 :             o << "; full constructor:\n";
     824             :             printConstructor(
     825             :                 o, options, manager,
     826             :                 codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
     827           0 :                 entity, nucleus, arguments);
     828           0 :             break;
     829             : 
     830             :         case codemaker::UnoType::SORT_ENUM_TYPE:
     831             :         case codemaker::UnoType::SORT_CONSTANT_GROUP:
     832             :             printMapsToJavaType(
     833           0 :                 o, options, manager, sort, nucleus, rank, arguments, "class");
     834           0 :             o << '\n';
     835           0 :             break;
     836             : 
     837             :         case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     838             :             printMapsToJavaType(
     839             :                 o, options, manager, sort, nucleus, rank, arguments,
     840           0 :                 "exception class");
     841           0 :             o << "; full constructor:\n";
     842             :             printConstructor(
     843             :                 o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
     844           0 :                 entity, nucleus, arguments);
     845           0 :             break;
     846             : 
     847             :         case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
     848             :             printMapsToJavaType(
     849           0 :                 o, options, manager, sort, nucleus, rank, arguments, "class");
     850           0 :             o << "; construction methods:\n";
     851           0 :             printConstructors(o, options, manager, nucleus);
     852             :             generateDocumentation(
     853             :                 o, options, manager,
     854             :                 u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
     855           0 :                         entity.get())->getBase()),
     856           0 :                 delegate);
     857           0 :             break;
     858             : 
     859             :         case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     860             :             o << ("does not map to Java\n"
     861           0 :                   "// the service members are generated instead\n");
     862             :             printServiceMembers(
     863             :                 o, options, manager, nucleus,
     864             :                 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
     865           0 :                     entity.get()),
     866           0 :                 delegate);
     867           0 :             break;
     868             : 
     869             :         case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
     870             :             printMapsToJavaType(
     871           0 :                 o, options, manager, sort, nucleus, rank, arguments, "class");
     872           0 :             o << "; get method:\npublic static ";
     873             :             printType(
     874             :                 o, options, manager,
     875             :                 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
     876           0 :                     entity.get())->getBase(),
     877           0 :                 false);
     878           0 :             o << " get(com.sun.star.uno.XComponentContext context);\n";
     879           0 :             break;
     880             : 
     881             :         case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
     882           0 :             o << "does not map to Java\n";
     883           0 :             break;
     884             : 
     885             :         default:
     886             :             OSL_ASSERT(false);
     887           0 :             break;
     888             :         }
     889           0 :     }
     890             : }
     891             : 
     892             : } }
     893             : 
     894             : 
     895             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10