1*ff7655f0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ff7655f0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ff7655f0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ff7655f0SAndrew Rist  * distributed with this work for additional information
6*ff7655f0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ff7655f0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ff7655f0SAndrew Rist  * "License"); you may not use this file except in compliance
9*ff7655f0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ff7655f0SAndrew Rist  *
11*ff7655f0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ff7655f0SAndrew Rist  *
13*ff7655f0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ff7655f0SAndrew Rist  * software distributed under the License is distributed on an
15*ff7655f0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ff7655f0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ff7655f0SAndrew Rist  * specific language governing permissions and limitations
18*ff7655f0SAndrew Rist  * under the License.
19*ff7655f0SAndrew Rist  *
20*ff7655f0SAndrew Rist  *************************************************************/
21*ff7655f0SAndrew Rist 
22*ff7655f0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "sal/config.h"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "codemaker/commonjava.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "codemaker/options.hxx"
32cdf0e10cSrcweir #include "codemaker/typemanager.hxx"
33cdf0e10cSrcweir #include "codemaker/unotype.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "osl/diagnose.h"
36cdf0e10cSrcweir #include "registry/reader.hxx"
37cdf0e10cSrcweir #include "registry/types.h"
38cdf0e10cSrcweir #include "rtl/strbuf.h"
39cdf0e10cSrcweir #include "rtl/string.h"
40cdf0e10cSrcweir #include "rtl/string.hxx"
41cdf0e10cSrcweir #include "rtl/ustring.hxx"
42cdf0e10cSrcweir #include "sal/types.h"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <vector>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace codemaker { namespace java {
47cdf0e10cSrcweir 
translateUnoToJavaType(codemaker::UnoType::Sort sort,RTTypeClass typeClass,rtl::OString const & nucleus,bool referenceType)48cdf0e10cSrcweir rtl::OString translateUnoToJavaType(
49cdf0e10cSrcweir     codemaker::UnoType::Sort sort, RTTypeClass typeClass,
50cdf0e10cSrcweir     rtl::OString const & nucleus, bool referenceType)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     rtl::OStringBuffer buf;
53cdf0e10cSrcweir     if (sort == codemaker::UnoType::SORT_COMPLEX) {
54cdf0e10cSrcweir         if (typeClass == RT_TYPE_INTERFACE
55cdf0e10cSrcweir             && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
56cdf0e10cSrcweir         {
57cdf0e10cSrcweir             buf.append(RTL_CONSTASCII_STRINGPARAM("java/lang/Object"));
58cdf0e10cSrcweir         } else {
59cdf0e10cSrcweir             //TODO: check that nucleus is a valid (Java-modified UTF-8)
60cdf0e10cSrcweir             // identifier
61cdf0e10cSrcweir             buf.append(nucleus);
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir     } else {
64cdf0e10cSrcweir         rtl::OString const javaTypes[codemaker::UnoType::SORT_ANY + 1][2] = {
65cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")),
66cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Void")) },
67cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("boolean")),
68cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")) },
69cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("byte")),
70cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")) },
71cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
72cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
73cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("short")),
74cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Short")) },
75cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
76cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
77cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("int")),
78cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")) },
79cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
80cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
81cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("long")),
82cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Long")) },
83cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("float")),
84cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Float")) },
85cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("double")),
86cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Double")) },
87cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("char")),
88cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Character")) },
89cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")),
90cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")) },
91cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
92cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")) },
93cdf0e10cSrcweir             { rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
94cdf0e10cSrcweir               rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")) } };
95cdf0e10cSrcweir         buf.append(javaTypes[sort][referenceType]);
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir     return buf.makeStringAndClear();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
translateUnoToJavaIdentifier(rtl::OString const & identifier,rtl::OString const & prefix)100cdf0e10cSrcweir rtl::OString translateUnoToJavaIdentifier(
101cdf0e10cSrcweir     rtl::OString const & identifier, rtl::OString const & prefix)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     if (identifier == "abstract"
104cdf0e10cSrcweir         || identifier == "assert" // since Java 1.4
105cdf0e10cSrcweir         || identifier == "boolean"
106cdf0e10cSrcweir         || identifier == "break"
107cdf0e10cSrcweir         || identifier == "byte"
108cdf0e10cSrcweir         || identifier == "case"
109cdf0e10cSrcweir         || identifier == "catch"
110cdf0e10cSrcweir         || identifier == "char"
111cdf0e10cSrcweir         || identifier == "class"
112cdf0e10cSrcweir         || identifier == "const"
113cdf0e10cSrcweir         || identifier == "continue"
114cdf0e10cSrcweir         || identifier == "default"
115cdf0e10cSrcweir         || identifier == "do"
116cdf0e10cSrcweir         || identifier == "double"
117cdf0e10cSrcweir         || identifier == "else"
118cdf0e10cSrcweir         || identifier == "enum" // probable addition in Java 1.5
119cdf0e10cSrcweir         || identifier == "extends"
120cdf0e10cSrcweir         || identifier == "final"
121cdf0e10cSrcweir         || identifier == "finally"
122cdf0e10cSrcweir         || identifier == "float"
123cdf0e10cSrcweir         || identifier == "for"
124cdf0e10cSrcweir         || identifier == "goto"
125cdf0e10cSrcweir         || identifier == "if"
126cdf0e10cSrcweir         || identifier == "implements"
127cdf0e10cSrcweir         || identifier == "import"
128cdf0e10cSrcweir         || identifier == "instanceof"
129cdf0e10cSrcweir         || identifier == "int"
130cdf0e10cSrcweir         || identifier == "interface"
131cdf0e10cSrcweir         || identifier == "long"
132cdf0e10cSrcweir         || identifier == "native"
133cdf0e10cSrcweir         || identifier == "new"
134cdf0e10cSrcweir         || identifier == "package"
135cdf0e10cSrcweir         || identifier == "private"
136cdf0e10cSrcweir         || identifier == "protected"
137cdf0e10cSrcweir         || identifier == "public"
138cdf0e10cSrcweir         || identifier == "return"
139cdf0e10cSrcweir         || identifier == "short"
140cdf0e10cSrcweir         || identifier == "static"
141cdf0e10cSrcweir         || identifier == "strictfp"
142cdf0e10cSrcweir         || identifier == "super"
143cdf0e10cSrcweir         || identifier == "switch"
144cdf0e10cSrcweir         || identifier == "synchronized"
145cdf0e10cSrcweir         || identifier == "this"
146cdf0e10cSrcweir         || identifier == "throw"
147cdf0e10cSrcweir         || identifier == "throws"
148cdf0e10cSrcweir         || identifier == "transient"
149cdf0e10cSrcweir         || identifier == "try"
150cdf0e10cSrcweir         || identifier == "void"
151cdf0e10cSrcweir         || identifier == "volatile"
152cdf0e10cSrcweir         || identifier == "while")
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         rtl::OStringBuffer buf(prefix);
155cdf0e10cSrcweir         buf.append('_');
156cdf0e10cSrcweir         buf.append(identifier);
157cdf0e10cSrcweir         return buf.makeStringAndClear();
158cdf0e10cSrcweir     } else {
159cdf0e10cSrcweir         return identifier;
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir } }
164