LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - skeletoncommon.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 327 0.0 %
Date: 2014-04-11 Functions: 0 17 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 "osl/thread.hxx"
      21             : 
      22             : #include "codemaker/commonjava.hxx"
      23             : #include "codemaker/commoncpp.hxx"
      24             : #include "codemaker/generatedtypeset.hxx"
      25             : #include "codemaker/global.hxx"
      26             : #include "unoidl/unoidl.hxx"
      27             : 
      28             : #include "skeletoncommon.hxx"
      29             : 
      30             : #include <cassert>
      31             : #include <iostream>
      32             : 
      33             : using namespace ::rtl;
      34             : using namespace ::codemaker::cpp;
      35             : 
      36             : namespace skeletonmaker {
      37             : 
      38           0 : void printLicenseHeader(std::ostream& o, rtl::OString const & filename)
      39             : {
      40           0 :     sal_Int32 index = -1;
      41             : #ifdef SAL_UNX
      42           0 :     index = filename.lastIndexOf('/');
      43             : #else
      44             :     index = filename.lastIndexOf('\\');
      45             : #endif
      46           0 :     OString shortfilename(filename);
      47           0 :     if ( index != -1 )
      48           0 :         shortfilename = filename.copy(index+1);
      49             : 
      50             :     o << "/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */\n"
      51             :          "/*\n"
      52             :          " * This file is part of the LibreOffice project.\n"
      53             :          " *\n"
      54             :          " * This Source Code Form is subject to the terms of the Mozilla Public\n"
      55             :          " * License, v. 2.0. If a copy of the MPL was not distributed with this\n"
      56             :          " * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"
      57           0 :          " */\n\n";
      58           0 : }
      59             : 
      60           0 : bool getOutputStream(ProgramOptions const & options,
      61             :                      OString const & extension,
      62             :                      std::ostream** ppOutputStream,
      63             :                      OString & targetSourceFileName,
      64             :                      OString & tmpSourceFileName)
      65             : {
      66           0 :     bool bStandardout = false;
      67           0 :     if ( options.outputpath.equals("stdout") )
      68             :     {
      69           0 :         bStandardout = true;
      70           0 :         *ppOutputStream = &std::cout;
      71           0 :         return bStandardout;
      72             :     }
      73             : 
      74           0 :     targetSourceFileName = createFileNameFromType(
      75           0 :         options.outputpath, options.implname.replace('.','/'), extension);
      76             : 
      77           0 :     OString tmpDir = getTempDir(targetSourceFileName);
      78           0 :     FileStream file;
      79           0 :     file.createTempFile(tmpDir);
      80             : 
      81           0 :     if( !file.isValid() )
      82             :     {
      83             :         throw CannotDumpException(
      84           0 :             "cannot open " + b2u(targetSourceFileName) + " for writing");
      85             :     } else {
      86           0 :         tmpSourceFileName = file.getName();
      87             :     }
      88           0 :     file.close();
      89             :     *ppOutputStream = new std::ofstream(tmpSourceFileName.getStr(),
      90           0 :                                         std::ios_base::binary);
      91             : 
      92           0 :     return bStandardout;
      93             : }
      94             : 
      95           0 : bool containsAttribute(AttributeInfo& attributes, OUString const & attrname)
      96             : {
      97           0 :     for ( AttributeInfo::const_iterator i(attributes.begin());
      98           0 :           i != attributes.end(); ++i ) {
      99           0 :         if ( (*i).name == attrname ) {
     100           0 :             return true;
     101             :         }
     102             :     }
     103           0 :     return false;
     104             : }
     105             : 
     106             : // collect attributes including inherited attributes
     107           0 : void checkAttributes(rtl::Reference< TypeManager > const & manager,
     108             :                      OUString const & name,
     109             :                      AttributeInfo& attributes,
     110             :                      std::set< OUString >& propinterfaces)
     111             : {
     112           0 :     if ( name == "com.sun.star.beans.XPropertySet" ||
     113           0 :          name == "com.sun.star.beans.XFastPropertySet" ||
     114           0 :          name == "com.sun.star.beans.XPropertyAccess" )
     115             :     {
     116           0 :         propinterfaces.insert(name);
     117             :     }
     118           0 :     rtl::Reference< unoidl::Entity > ent;
     119           0 :     switch (manager->getSort(name, &ent)) {
     120             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     121             :         {
     122             :             rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
     123           0 :                 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
     124             :             assert(ent2.is());
     125           0 :             for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     126           0 :                      ent2->getDirectMandatoryBases().begin());
     127           0 :                  i != ent2->getDirectMandatoryBases().end(); ++i)
     128             :             {
     129           0 :                 checkAttributes(manager, i->name, attributes, propinterfaces);
     130             :             }
     131           0 :             for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
     132           0 :                      const_iterator i(ent2->getDirectAttributes().begin());
     133           0 :                  i != ent2->getDirectAttributes().end(); ++i)
     134             :             {
     135           0 :                 if (!containsAttribute(attributes, i->name)) {
     136             :                     attributes.push_back(
     137             :                         unoidl::AccumulationBasedServiceEntity::Property(
     138           0 :                             i->name,
     139           0 :                             i->type,
     140             :                             (unoidl::AccumulationBasedServiceEntity::Property::
     141             :                              Attributes(
     142           0 :                                  ((i->bound
     143             :                                    ? (unoidl::AccumulationBasedServiceEntity::
     144             :                                       Property::ATTRIBUTE_BOUND)
     145             :                                    : 0)
     146           0 :                                   | (i->readOnly
     147             :                                      ? (unoidl::AccumulationBasedServiceEntity::
     148             :                                         Property::ATTRIBUTE_READ_ONLY)
     149             :                                      : 0)))),
     150           0 :                             std::vector< OUString >()));
     151             :                 }
     152             :             }
     153           0 :             break;
     154             :         }
     155             :     case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     156             :         {
     157             :             rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2(
     158             :                 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
     159           0 :                     ent.get()));
     160             :             assert(ent2.is());
     161           0 :             for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     162           0 :                      ent2->getDirectMandatoryBaseServices().begin());
     163           0 :                  i != ent2->getDirectMandatoryBaseServices().end(); ++i)
     164             :             {
     165           0 :                 checkAttributes(manager, i->name, attributes, propinterfaces);
     166             :             }
     167           0 :             for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     168           0 :                      ent2->getDirectMandatoryBaseInterfaces().begin());
     169           0 :                  i != ent2->getDirectMandatoryBaseInterfaces().end(); ++i)
     170             :             {
     171           0 :                 checkAttributes(manager, i->name, attributes, propinterfaces);
     172             :             }
     173           0 :             for (std::vector<
     174             :                      unoidl::AccumulationBasedServiceEntity::Property >::
     175           0 :                      const_iterator i(ent2->getDirectProperties().begin());
     176           0 :                  i != ent2->getDirectProperties().end(); ++i)
     177             :             {
     178           0 :                 if (!containsAttribute(attributes, i->name)) {
     179           0 :                     attributes.push_back(*i);
     180             :                 }
     181             :             }
     182           0 :             break;
     183             :         }
     184             :     default:
     185             :         throw CannotDumpException(
     186           0 :             "unexpected entity \"" + name
     187           0 :             + "\" in call to skeletonmaker::checkAttributes");
     188           0 :     }
     189           0 : }
     190             : 
     191           0 : void checkType(rtl::Reference< TypeManager > const & manager,
     192             :                OUString const & name,
     193             :                std::set< OUString >& interfaceTypes,
     194             :                std::set< OUString >& serviceTypes,
     195             :                AttributeInfo& properties)
     196             : {
     197           0 :     rtl::Reference< unoidl::Entity > ent;
     198           0 :     switch (manager->getSort(name, &ent)) {
     199             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     200             :         // com.sun.star.lang.XComponent should be also not in the list
     201             :         // but it will be used for checking the impl helper and will be
     202             :         // removed later if necessary.
     203           0 :         if ( name == "com.sun.star.lang.XTypeProvider" ||
     204           0 :              name == "com.sun.star.uno.XWeak" )
     205           0 :             return;
     206           0 :         if (interfaceTypes.find(name) == interfaceTypes.end()) {
     207           0 :             interfaceTypes.insert(name);
     208             :         }
     209           0 :         break;
     210             :     case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
     211           0 :         if (serviceTypes.find(name) == serviceTypes.end()) {
     212           0 :             serviceTypes.insert(name);
     213             :             rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
     214             :                 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
     215           0 :                     ent.get()));
     216             :             assert(ent2.is());
     217           0 :             if (interfaceTypes.find(ent2->getBase()) == interfaceTypes.end()) {
     218           0 :                 interfaceTypes.insert(ent2->getBase());
     219             :                 // check if constructors are specified, if yes automatically
     220             :                 // support of XInitialization. We will take care of the default
     221             :                 // constructor because in this case XInitialization is not
     222             :                 // called.
     223           0 :                 if (ent2->getConstructors().size() > 1 ||
     224           0 :                     (ent2->getConstructors().size() == 1 &&
     225           0 :                      !ent2->getConstructors()[0].defaultConstructor))
     226             :                 {
     227           0 :                     OUString s("com.sun.star.lang.XInitialization");
     228           0 :                     if (interfaceTypes.find(s) == interfaceTypes.end())
     229           0 :                         interfaceTypes.insert(s);
     230             :                 }
     231           0 :             }
     232             :         }
     233           0 :         break;
     234             :     case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     235           0 :         if ( serviceTypes.find(name) == serviceTypes.end() ) {
     236           0 :             serviceTypes.insert(name);
     237             :             rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2(
     238             :                 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
     239           0 :                     ent.get()));
     240             :             assert(ent2.is());
     241           0 :             for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     242           0 :                      ent2->getDirectMandatoryBaseServices().begin());
     243           0 :                  i != ent2->getDirectMandatoryBaseServices().end(); ++i)
     244             :             {
     245             :                 checkType(
     246           0 :                     manager, i->name, interfaceTypes, serviceTypes, properties);
     247             :             }
     248           0 :             for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     249           0 :                      ent2->getDirectMandatoryBaseInterfaces().begin());
     250           0 :                  i != ent2->getDirectMandatoryBaseInterfaces().end(); ++i)
     251             :             {
     252             :                 checkType(
     253           0 :                     manager, i->name, interfaceTypes, serviceTypes, properties);
     254             :             }
     255           0 :             for (std::vector<
     256             :                      unoidl::AccumulationBasedServiceEntity::Property >::
     257           0 :                      const_iterator i(ent2->getDirectProperties().begin());
     258           0 :                  i != ent2->getDirectProperties().end(); ++i)
     259             :             {
     260           0 :                 properties.push_back(*i);
     261           0 :             }
     262             :         }
     263           0 :         break;
     264             :     default:
     265             :         throw CannotDumpException(
     266           0 :             "unexpected entity \"" + name
     267           0 :             + "\" in call to skeletonmaker::checkType");
     268           0 :     }
     269             : }
     270             : 
     271           0 : void checkDefaultInterfaces(
     272             :     std::set< OUString >& interfaces,
     273             :     const std::set< OUString >& services,
     274             :     const OUString & propertyhelper)
     275             : {
     276           0 :     if ( services.empty() ) {
     277           0 :         if (interfaces.find("com.sun.star.lang.XServiceInfo") != interfaces.end())
     278           0 :             interfaces.erase("com.sun.star.lang.XServiceInfo");
     279             :     } else {
     280           0 :         if (interfaces.find("com.sun.star.lang.XServiceInfo") == interfaces.end())
     281           0 :             interfaces.insert("com.sun.star.lang.XServiceInfo");
     282             :     }
     283             : 
     284           0 :     if ( propertyhelper.equals("_") ) {
     285           0 :         if (interfaces.find("com.sun.star.beans.XPropertySet")
     286           0 :             != interfaces.end())
     287           0 :             interfaces.erase("com.sun.star.beans.XPropertySet");
     288           0 :         if (interfaces.find("com.sun.star.beans.XFastPropertySet")
     289           0 :             != interfaces.end())
     290           0 :             interfaces.erase("com.sun.star.beans.XFastPropertySet");
     291           0 :         if (interfaces.find("com.sun.star.beans.XPropertyAccess")
     292           0 :             != interfaces.end())
     293           0 :             interfaces.erase("com.sun.star.beans.XPropertyAccess");
     294             :     }
     295           0 : }
     296             : 
     297           0 : bool checkServiceProperties(rtl::Reference< TypeManager > const & manager,
     298             :                             OUString const & name)
     299             : {
     300           0 :     rtl::Reference< unoidl::Entity > ent;
     301           0 :     if (manager->getSort(name, &ent)
     302             :         == codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE)
     303             :     {
     304             :         rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2(
     305             :             dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
     306           0 :                 ent.get()));
     307             :         assert(ent2.is());
     308           0 :         if (!ent2->getDirectProperties().empty()) {
     309           0 :             return true;
     310             :         }
     311           0 :         for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     312           0 :                  ent2->getDirectMandatoryBaseServices().begin());
     313           0 :              i != ent2->getDirectMandatoryBaseServices().end(); ++i)
     314             :         {
     315           0 :             if (checkServiceProperties(manager, i->name)) {
     316           0 :                 return true;
     317             :             }
     318           0 :         }
     319             :     }
     320           0 :     return false;
     321             : }
     322             : 
     323             : 
     324           0 : OUString checkPropertyHelper(
     325             :     ProgramOptions const & options,
     326             :     rtl::Reference< TypeManager > const & manager,
     327             :     const std::set< OUString >& services,
     328             :     const std::set< OUString >& interfaces,
     329             :     AttributeInfo& attributes,
     330             :     std::set< OUString >& propinterfaces)
     331             : {
     332           0 :     std::set< OUString >::const_iterator iter;
     333           0 :     std::set< OUString >::const_iterator end;
     334             : 
     335           0 :     if ( !services.empty() ) {
     336           0 :         iter = services.begin();
     337           0 :         end = services.end();
     338             :     } else {
     339           0 :         iter = interfaces.begin();
     340           0 :         end = interfaces.end();
     341             :     }
     342             : 
     343           0 :     bool oldStyleWithProperties = false;
     344           0 :     while ( iter != end ) {
     345           0 :         rtl::Reference< unoidl::Entity > ent;
     346           0 :         codemaker::UnoType::Sort sort = manager->getSort(*iter, &ent);
     347           0 :         if ( !services.empty() ) {
     348           0 :             if (options.supportpropertysetmixin
     349           0 :                 && (sort
     350             :                     == codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE))
     351             :             {
     352             :                 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity >
     353             :                     ent2(
     354             :                         dynamic_cast<
     355             :                         unoidl::SingleInterfaceBasedServiceEntity * >(
     356           0 :                             ent.get()));
     357             :                 assert(ent2.is());
     358             :                 checkAttributes(
     359           0 :                     manager, ent2->getBase(), attributes, propinterfaces);
     360           0 :                 if (!(attributes.empty() || propinterfaces.empty())) {
     361           0 :                     return ent2->getBase();
     362           0 :                 }
     363             :             } else {
     364           0 :                 oldStyleWithProperties = checkServiceProperties(manager, *iter);
     365             :             }
     366             :         } else {
     367           0 :             checkAttributes(manager, *iter, attributes, propinterfaces);
     368           0 :             if (!(attributes.empty() || propinterfaces.empty())) {
     369           0 :                 return *iter;
     370             :             }
     371             :         }
     372           0 :         ++iter;
     373           0 :     }
     374             : 
     375           0 :     return oldStyleWithProperties ? OUString("_") : OUString();
     376             : }
     377             : 
     378           0 : bool checkXComponentSupport(
     379             :     rtl::Reference< TypeManager > const & manager, OUString const & name)
     380             : {
     381             :     assert(manager.is());
     382           0 :     if (name == "com.sun.star.lang.XComponent") {
     383           0 :         return true;
     384             :     }
     385           0 :     rtl::Reference< unoidl::Entity > ent;
     386           0 :     codemaker::UnoType::Sort sort = manager->getSort(name, &ent);
     387           0 :     if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) {
     388             :         throw CannotDumpException(
     389           0 :             "unexpected entity \"" + name
     390           0 :             + "\" in call to skeletonmaker::checkXComponentSupport");
     391             :     }
     392             :     rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
     393           0 :         dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
     394             :     assert(ent2.is());
     395           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     396           0 :              ent2->getDirectMandatoryBases().begin());
     397           0 :          i != ent2->getDirectMandatoryBases().end(); ++i)
     398             :     {
     399           0 :         if (checkXComponentSupport(manager, i->name)) {
     400           0 :             return true;
     401             :         }
     402             :     }
     403           0 :     return false;
     404             : }
     405             : 
     406             : 
     407             : // if XComponent is directly specified, return true and remove it from the
     408             : // supported interfaces list
     409           0 : bool checkXComponentSupport(rtl::Reference< TypeManager > const & manager,
     410             :                             std::set< OUString >& interfaces)
     411             : {
     412           0 :     if ( interfaces.empty() )
     413           0 :         return false;
     414             : 
     415           0 :     std::set< OUString >::const_iterator iter = interfaces.begin();
     416           0 :     while ( iter != interfaces.end() ) {
     417           0 :         if ( (*iter).equals("com.sun.star.lang.XComponent") ) {
     418           0 :             interfaces.erase("com.sun.star.lang.XComponent");
     419           0 :             return true;
     420             :         }
     421           0 :         if ( checkXComponentSupport(manager, *iter) )
     422           0 :             return true;
     423           0 :         ++iter;
     424             :     }
     425             : 
     426           0 :     return false;
     427             : }
     428             : 
     429             : unoidl::AccumulationBasedServiceEntity::Property::Attributes
     430           0 : checkAdditionalPropertyFlags(
     431             :     unoidl::InterfaceTypeEntity::Attribute const & attribute)
     432             : {
     433           0 :     int flags = 0;
     434           0 :     bool getterSupportsUnknown = false;
     435           0 :     for (std::vector< OUString >::const_iterator i(
     436           0 :              attribute.getExceptions.begin());
     437           0 :          i != attribute.getExceptions.end(); ++i)
     438             :     {
     439           0 :         if (*i == "com.sun.star.beans.UnknownPropertyException") {
     440           0 :             getterSupportsUnknown = true;
     441             :         }
     442             :     }
     443           0 :     for (std::vector< OUString >::const_iterator i(
     444           0 :              attribute.setExceptions.begin());
     445           0 :          i != attribute.setExceptions.end(); ++i)
     446             :     {
     447           0 :         if (*i == "com.sun.star.beans.PropertyVetoException") {
     448             :             flags |= unoidl::AccumulationBasedServiceEntity::Property::
     449           0 :                 ATTRIBUTE_CONSTRAINED;
     450           0 :         } else if (getterSupportsUnknown
     451           0 :                    && *i == "com.sun.star.beans.UnknownPropertyException")
     452             :         {
     453             :             flags |= unoidl::AccumulationBasedServiceEntity::Property::
     454           0 :                 ATTRIBUTE_OPTIONAL;
     455             :         }
     456             :     }
     457           0 :     return unoidl::AccumulationBasedServiceEntity::Property::Attributes(flags);
     458             : }
     459             : 
     460             : // This function checks if the specified types for parameters and return
     461             : // types are allowed add-in types, for more info see the com.sun.star.sheet.AddIn
     462             : // service description
     463           0 : bool checkAddinType(rtl::Reference< TypeManager > const & manager,
     464             :                     OUString const & type, bool & bLastAny,
     465             :                     bool & bHasXPropertySet, bool bIsReturn)
     466             : {
     467             :     assert(manager.is());
     468             :     sal_Int32 rank;
     469             :     codemaker::UnoType::Sort sort = manager->decompose(
     470           0 :         type, true, 0, &rank, 0, 0);
     471             : 
     472           0 :     if ( sort == codemaker::UnoType::SORT_LONG ||
     473           0 :          sort == codemaker::UnoType::SORT_DOUBLE ||
     474             :          sort == codemaker::UnoType::SORT_STRING )
     475             :     {
     476           0 :         if ( rank == 0 || rank ==2 )
     477           0 :             return true;
     478             :     }
     479           0 :     if ( sort == codemaker::UnoType::SORT_ANY )
     480             :     {
     481           0 :         if ( rank <= 2 ) {
     482           0 :             if ( rank ==1 ) {
     483           0 :                 if ( bIsReturn )
     484           0 :                     return false;
     485           0 :                 bLastAny = true;
     486             :             }
     487             : 
     488           0 :             return true;
     489             :         }
     490             :     }
     491           0 :     if ( sort == codemaker::UnoType::SORT_INTERFACE_TYPE )
     492             :     {
     493           0 :         if ( bIsReturn && type == "com.sun.star.sheet.XVolatileResult" )
     494           0 :             return true;
     495           0 :         if ( !bIsReturn && type == "com.sun.star.table.XCellRange" )
     496           0 :             return true;
     497           0 :         if ( !bIsReturn && type == "com.sun.star.beans.XPropertySet" )
     498             :         {
     499           0 :             if ( bHasXPropertySet ) {
     500           0 :                 return false;
     501             :             } else {
     502           0 :                 bHasXPropertySet = true;
     503           0 :                 return true;
     504             :             }
     505             :         }
     506             :     }
     507           0 :     return false;
     508             : }
     509             : 
     510           0 : void checkAddInTypes(
     511             :     rtl::Reference< TypeManager > const & manager, OUString const & name,
     512             :     rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
     513             : {
     514             :     assert(entity.is());
     515           0 :     bool bLastAny = false;
     516           0 :     bool bHasXPropertySet = false;
     517           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
     518           0 :              entity->getDirectMethods().begin());
     519           0 :          i != entity->getDirectMethods().end(); ++i)
     520             :     {
     521           0 :         if ( !checkAddinType(
     522           0 :                  manager, i->returnType, bLastAny, bHasXPropertySet, true) )
     523             :         {
     524             :             throw CannotDumpException(
     525           0 :                 "the return type of the calc add-in function '" + name
     526           0 :                 + ":" + i->name
     527           0 :                 + "' is invalid. Please check your IDL defintion.");
     528             :         }
     529             : 
     530           0 :         bHasXPropertySet = false;
     531           0 :         for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
     532           0 :                  const_iterator j(i->parameters.begin());
     533           0 :              j != i->parameters.end(); ++j)
     534             :         {
     535           0 :             bLastAny = false;
     536           0 :             if ( !checkAddinType(manager, j->type,
     537           0 :                                 bLastAny, bHasXPropertySet, false) ||
     538             :                  bLastAny )
     539             :             {
     540             :                 throw CannotDumpException(
     541           0 :                     "the type of the " + j->name
     542           0 :                     + " parameter of the calc add-in function '" + name
     543           0 :                     + ":" + i->name + "' is invalid."
     544           0 :                     + (bLastAny
     545             :                        ? OUString(
     546             :                            " The type 'sequence<any>' is allowed as last"
     547             :                            " parameter only.")
     548           0 :                        : OUString())
     549           0 :                     + (bHasXPropertySet
     550             :                        ? OUString(
     551             :                            " The type 'XPropertySet' is allowed only once.")
     552           0 :                        : OUString())
     553           0 :                     + " Please check your IDL definition.");
     554             :             }
     555             :         }
     556             :     }
     557           0 : }
     558             : 
     559           0 : void generateFunctionParameterMap(std::ostream& o,
     560             :                                  ProgramOptions const & options,
     561             :                                  rtl::Reference< TypeManager > const & manager,
     562             :                                  OUString const & name,
     563             :                                  ::codemaker::GeneratedTypeSet & generated,
     564             :                                  bool bFirst)
     565             : {
     566           0 :     if ( name == "com.sun.star.uno.XInterface" ||
     567           0 :          name == "com.sun.star.lang.XLocalizable" ||
     568           0 :          name == "com.sun.star.lang.XServiceInfo" ||
     569             :          // the next three checks becomes obsolete when configuration is used
     570           0 :          name == "com.sun.star.sheet.XAddIn" ||
     571           0 :          name == "com.sun.star.sheet.XCompatibilityNames" ||
     572           0 :          name == "com.sun.star.lang.XServiceName" )
     573             :     {
     574           0 :         return;
     575             :     }
     576             : 
     577           0 :     rtl::Reference< unoidl::Entity > ent;
     578           0 :     codemaker::UnoType::Sort sort = manager->getSort(name, &ent);
     579           0 :     if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) {
     580             :         throw CannotDumpException(
     581           0 :             "unexpected entity \"" + name
     582           0 :             + "\" in call to skeletonmaker::generateFunctionParameterMap");
     583             :     }
     584             :     rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
     585           0 :         dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
     586             :     assert(ent2.is());
     587             : 
     588             :     // check if the specified add-in functions supports valid types
     589           0 :     checkAddInTypes(manager, name, ent2);
     590             : 
     591           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     592           0 :              ent2->getDirectMandatoryBases().begin());
     593           0 :          i != ent2->getDirectMandatoryBases().end(); ++i)
     594             :     {
     595             :         generateFunctionParameterMap(
     596           0 :             o, options, manager, i->name, generated, bFirst);
     597             :     }
     598             : 
     599           0 :     if ( generated.contains(u2b(name)) )
     600           0 :         return;
     601             :     else
     602           0 :         generated.add(u2b(name));
     603             : 
     604           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
     605           0 :              ent2->getDirectMethods().begin());
     606           0 :          i != ent2->getDirectMethods().end(); ++i)
     607             :     {
     608           0 :         if ( bFirst ) {
     609           0 :             if (options.language == 2) {
     610           0 :                 o << "        ParamMap fpm;\n";
     611             :             }
     612             :             else {
     613             :                 o << "        java.util.Hashtable< Integer, String > fpm = "
     614           0 :                     "new java.util.Hashtable< Integer, String >();\n";
     615             :             }
     616           0 :             bFirst = false;
     617             :         } else
     618           0 :             if ( options.language == 2 ) {
     619           0 :                 o << "        fpm = ParamMap();\n";
     620             :             }
     621             :             else {
     622             :                 o << "        fpm = new java.util.Hashtable< "
     623           0 :                     "Integer, String >();\n";
     624             :             }
     625             : 
     626             :         std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::size_type
     627           0 :             n = 0;
     628           0 :         for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
     629           0 :                  const_iterator j(i->parameters.begin());
     630           0 :              j != i->parameters.end(); ++j)
     631             :         {
     632           0 :             if ( options.language == 2 ) {
     633           0 :                 o << "        fpm[" << n
     634           0 :                   << "] = ::rtl::OUString(\""
     635           0 :                   << j->name
     636           0 :                   << "\");\n";
     637             :             }
     638             :             else {
     639           0 :                 o << "        fpm.put(" << n << ", \""
     640           0 :                   << j->name
     641           0 :                   << "\");\n";
     642             :             }
     643           0 :             ++n;
     644             :         }
     645             : 
     646           0 :         if ( options.language == 2 ) {
     647           0 :             o << "        m_functionMap[::rtl::OUString(\""
     648           0 :               << i->name << "\")] = fpm;\n\n";
     649             :         }
     650             :         else {
     651           0 :             o << "        m_functionMap.put(\"" << i->name << "\", fpm);\n\n";
     652             :         }
     653           0 :     }
     654             : }
     655             : 
     656           0 : void generateFunctionParameterMap(std::ostream& o,
     657             :          ProgramOptions const & options,
     658             :          rtl::Reference< TypeManager > const & manager,
     659             :          const std::set< OUString >& interfaces)
     660             : {
     661           0 :     ::codemaker::GeneratedTypeSet generated;
     662           0 :     bool bFirst = true;
     663           0 :     std::set< OUString >::const_iterator iter = interfaces.begin();
     664           0 :     while ( iter != interfaces.end() ) {
     665           0 :         generateFunctionParameterMap(o, options, manager, *iter, generated, bFirst);
     666           0 :         ++iter;
     667           0 :     }
     668           0 : }
     669             : 
     670           0 : }
     671             : 
     672             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10