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