LCOV - code coverage report
Current view: top level - libreoffice/codemaker/source/commonjava - commonjava.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 66 93.9 %
Date: 2012-12-27 Functions: 2 2 100.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             : 
      21             : #include "sal/config.h"
      22             : 
      23             : #include "codemaker/commonjava.hxx"
      24             : 
      25             : #include "codemaker/options.hxx"
      26             : #include "codemaker/typemanager.hxx"
      27             : #include "codemaker/unotype.hxx"
      28             : 
      29             : #include "osl/diagnose.h"
      30             : #include "registry/reader.hxx"
      31             : #include "registry/types.h"
      32             : #include "rtl/strbuf.h"
      33             : #include "rtl/string.h"
      34             : #include "rtl/string.hxx"
      35             : #include "rtl/ustring.hxx"
      36             : #include "sal/types.h"
      37             : 
      38             : #include <vector>
      39             : 
      40             : namespace codemaker { namespace java {
      41             : 
      42          73 : rtl::OString translateUnoToJavaType(
      43             :     codemaker::UnoType::Sort sort, RTTypeClass typeClass,
      44             :     rtl::OString const & nucleus, bool referenceType)
      45             : {
      46          73 :     rtl::OStringBuffer buf;
      47          73 :     if (sort == codemaker::UnoType::SORT_COMPLEX) {
      48         100 :         if (typeClass == RT_TYPE_INTERFACE
      49          54 :             && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
      50             :         {
      51           1 :             buf.append(RTL_CONSTASCII_STRINGPARAM("java/lang/Object"));
      52             :         } else {
      53             :             //TODO: check that nucleus is a valid (Java-modified UTF-8)
      54             :             // identifier
      55          45 :             buf.append(nucleus);
      56             :         }
      57             :     } else {
      58             :         rtl::OString const javaTypes[codemaker::UnoType::SORT_ANY + 1][2] = {
      59             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")),
      60             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Void")) },
      61             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("boolean")),
      62             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")) },
      63             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("byte")),
      64             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")) },
      65             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
      66             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
      67             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
      68             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
      69             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
      70             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
      71             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
      72             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
      73             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
      74             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
      75             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
      76             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
      77             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("float")),
      78             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Float")) },
      79             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("double")),
      80             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Double")) },
      81             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("char")),
      82             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Character")) },
      83             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")),
      84             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")) },
      85             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
      86             :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")) },
      87             :             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
      88         837 :               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")) } };
      89         837 :         buf.append(javaTypes[sort][referenceType]);
      90             :     }
      91          73 :     return buf.makeStringAndClear();
      92             : }
      93             : 
      94         331 : rtl::OString translateUnoToJavaIdentifier(
      95             :     rtl::OString const & identifier, rtl::OString const & prefix)
      96             : {
      97       16550 :     if (identifier == "abstract"
      98         331 :         || identifier == "assert" // since Java 1.4
      99         331 :         || identifier == "boolean"
     100         331 :         || identifier == "break"
     101         331 :         || identifier == "byte"
     102         331 :         || identifier == "case"
     103         331 :         || identifier == "catch"
     104         331 :         || identifier == "char"
     105         331 :         || identifier == "class"
     106         331 :         || identifier == "const"
     107         331 :         || identifier == "continue"
     108         331 :         || identifier == "default"
     109         331 :         || identifier == "do"
     110         331 :         || identifier == "double"
     111         331 :         || identifier == "else"
     112         331 :         || identifier == "enum" // probable addition in Java 1.5
     113         331 :         || identifier == "extends"
     114         331 :         || identifier == "final"
     115         331 :         || identifier == "finally"
     116         331 :         || identifier == "float"
     117         331 :         || identifier == "for"
     118         331 :         || identifier == "goto"
     119         331 :         || identifier == "if"
     120         331 :         || identifier == "implements"
     121         331 :         || identifier == "import"
     122         331 :         || identifier == "instanceof"
     123         331 :         || identifier == "int"
     124         331 :         || identifier == "interface"
     125         331 :         || identifier == "long"
     126         331 :         || identifier == "native"
     127         331 :         || identifier == "new"
     128         331 :         || identifier == "package"
     129         331 :         || identifier == "private"
     130         331 :         || identifier == "protected"
     131         331 :         || identifier == "public"
     132         331 :         || identifier == "return"
     133         331 :         || identifier == "short"
     134         331 :         || identifier == "static"
     135         331 :         || identifier == "strictfp"
     136         331 :         || identifier == "super"
     137         331 :         || identifier == "switch"
     138         331 :         || identifier == "synchronized"
     139         331 :         || identifier == "this"
     140         331 :         || identifier == "throw"
     141         331 :         || identifier == "throws"
     142         331 :         || identifier == "transient"
     143         331 :         || identifier == "try"
     144         331 :         || identifier == "void"
     145         331 :         || identifier == "volatile"
     146         331 :         || identifier == "while")
     147             :     {
     148           0 :         rtl::OStringBuffer buf(prefix);
     149           0 :         buf.append('_');
     150           0 :         buf.append(identifier);
     151           0 :         return buf.makeStringAndClear();
     152             :     } else {
     153         331 :         return identifier;
     154             :     }
     155             : }
     156             : 
     157             : } }
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10