1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sal/config.h"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "codemaker/commonjava.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "codemaker/options.hxx"
36*cdf0e10cSrcweir #include "codemaker/typemanager.hxx"
37*cdf0e10cSrcweir #include "codemaker/unotype.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "osl/diagnose.h"
40*cdf0e10cSrcweir #include "registry/reader.hxx"
41*cdf0e10cSrcweir #include "registry/types.h"
42*cdf0e10cSrcweir #include "rtl/strbuf.h"
43*cdf0e10cSrcweir #include "rtl/string.h"
44*cdf0e10cSrcweir #include "rtl/string.hxx"
45*cdf0e10cSrcweir #include "rtl/ustring.hxx"
46*cdf0e10cSrcweir #include "sal/types.h"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <vector>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace codemaker { namespace java {
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir rtl::OString translateUnoToJavaType(
53*cdf0e10cSrcweir     codemaker::UnoType::Sort sort, RTTypeClass typeClass,
54*cdf0e10cSrcweir     rtl::OString const & nucleus, bool referenceType)
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir     rtl::OStringBuffer buf;
57*cdf0e10cSrcweir     if (sort == codemaker::UnoType::SORT_COMPLEX) {
58*cdf0e10cSrcweir         if (typeClass == RT_TYPE_INTERFACE
59*cdf0e10cSrcweir             && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
60*cdf0e10cSrcweir         {
61*cdf0e10cSrcweir             buf.append(RTL_CONSTASCII_STRINGPARAM("java/lang/Object"));
62*cdf0e10cSrcweir         } else {
63*cdf0e10cSrcweir             //TODO: check that nucleus is a valid (Java-modified UTF-8)
64*cdf0e10cSrcweir             // identifier
65*cdf0e10cSrcweir             buf.append(nucleus);
66*cdf0e10cSrcweir         }
67*cdf0e10cSrcweir     } else {
68*cdf0e10cSrcweir         rtl::OString const javaTypes[codemaker::UnoType::SORT_ANY + 1][2] = {
69*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")),
70*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Void")) },
71*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("boolean")),
72*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")) },
73*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("byte")),
74*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")) },
75*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
76*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
77*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
78*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
79*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
80*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
81*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
82*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
83*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
84*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
85*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
86*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
87*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("float")),
88*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Float")) },
89*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("double")),
90*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Double")) },
91*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("char")),
92*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Character")) },
93*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")),
94*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")) },
95*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
96*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")) },
97*cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
98*cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")) } };
99*cdf0e10cSrcweir         buf.append(javaTypes[sort][referenceType]);
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir     return buf.makeStringAndClear();
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir rtl::OString translateUnoToJavaIdentifier(
105*cdf0e10cSrcweir     rtl::OString const & identifier, rtl::OString const & prefix)
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     if (identifier == "abstract"
108*cdf0e10cSrcweir         || identifier == "assert" // since Java 1.4
109*cdf0e10cSrcweir         || identifier == "boolean"
110*cdf0e10cSrcweir         || identifier == "break"
111*cdf0e10cSrcweir         || identifier == "byte"
112*cdf0e10cSrcweir         || identifier == "case"
113*cdf0e10cSrcweir         || identifier == "catch"
114*cdf0e10cSrcweir         || identifier == "char"
115*cdf0e10cSrcweir         || identifier == "class"
116*cdf0e10cSrcweir         || identifier == "const"
117*cdf0e10cSrcweir         || identifier == "continue"
118*cdf0e10cSrcweir         || identifier == "default"
119*cdf0e10cSrcweir         || identifier == "do"
120*cdf0e10cSrcweir         || identifier == "double"
121*cdf0e10cSrcweir         || identifier == "else"
122*cdf0e10cSrcweir         || identifier == "enum" // probable addition in Java 1.5
123*cdf0e10cSrcweir         || identifier == "extends"
124*cdf0e10cSrcweir         || identifier == "final"
125*cdf0e10cSrcweir         || identifier == "finally"
126*cdf0e10cSrcweir         || identifier == "float"
127*cdf0e10cSrcweir         || identifier == "for"
128*cdf0e10cSrcweir         || identifier == "goto"
129*cdf0e10cSrcweir         || identifier == "if"
130*cdf0e10cSrcweir         || identifier == "implements"
131*cdf0e10cSrcweir         || identifier == "import"
132*cdf0e10cSrcweir         || identifier == "instanceof"
133*cdf0e10cSrcweir         || identifier == "int"
134*cdf0e10cSrcweir         || identifier == "interface"
135*cdf0e10cSrcweir         || identifier == "long"
136*cdf0e10cSrcweir         || identifier == "native"
137*cdf0e10cSrcweir         || identifier == "new"
138*cdf0e10cSrcweir         || identifier == "package"
139*cdf0e10cSrcweir         || identifier == "private"
140*cdf0e10cSrcweir         || identifier == "protected"
141*cdf0e10cSrcweir         || identifier == "public"
142*cdf0e10cSrcweir         || identifier == "return"
143*cdf0e10cSrcweir         || identifier == "short"
144*cdf0e10cSrcweir         || identifier == "static"
145*cdf0e10cSrcweir         || identifier == "strictfp"
146*cdf0e10cSrcweir         || identifier == "super"
147*cdf0e10cSrcweir         || identifier == "switch"
148*cdf0e10cSrcweir         || identifier == "synchronized"
149*cdf0e10cSrcweir         || identifier == "this"
150*cdf0e10cSrcweir         || identifier == "throw"
151*cdf0e10cSrcweir         || identifier == "throws"
152*cdf0e10cSrcweir         || identifier == "transient"
153*cdf0e10cSrcweir         || identifier == "try"
154*cdf0e10cSrcweir         || identifier == "void"
155*cdf0e10cSrcweir         || identifier == "volatile"
156*cdf0e10cSrcweir         || identifier == "while")
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         rtl::OStringBuffer buf(prefix);
159*cdf0e10cSrcweir         buf.append('_');
160*cdf0e10cSrcweir         buf.append(identifier);
161*cdf0e10cSrcweir         return buf.makeStringAndClear();
162*cdf0e10cSrcweir     } else {
163*cdf0e10cSrcweir         return identifier;
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir } }
168