1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/config.h>
23 #include <codemaker/commonjava.hxx>
25 #include <codemaker/options.hxx>
26 #include <codemaker/typemanager.hxx>
27 #include <codemaker/unotype.hxx>
29 #include <rtl/strbuf.h>
30 #include <rtl/string.h>
31 #include <rtl/string.hxx>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
37 namespace codemaker::java
{
39 OString
translateUnoToJavaType(
40 codemaker::UnoType::Sort sort
, std::string_view nucleus
, bool referenceType
)
42 OStringBuffer
buf(128);
43 if (sort
<= codemaker::UnoType::Sort::Any
) {
44 OString
const javaTypes
[static_cast<int>(codemaker::UnoType::Sort::Any
) + 1][2] = {
45 { "void"_ostr
, "java/lang/Void"_ostr
},
46 { "boolean"_ostr
, "java/lang/Boolean"_ostr
},
47 { "byte"_ostr
, "java/lang/Byte"_ostr
},
48 { "short"_ostr
, "java/lang/Short"_ostr
},
49 { "short"_ostr
, "java/lang/Short"_ostr
},
50 { "int"_ostr
, "java/lang/Integer"_ostr
},
51 { "int"_ostr
, "java/lang/Integer"_ostr
},
52 { "long"_ostr
, "java/lang/Long"_ostr
},
53 { "long"_ostr
, "java/lang/Long"_ostr
},
54 { "float"_ostr
, "java/lang/Float"_ostr
},
55 { "double"_ostr
, "java/lang/Double"_ostr
},
56 { "char"_ostr
, "java/lang/Character"_ostr
},
57 { "java/lang/String"_ostr
, "java/lang/String"_ostr
},
58 { "com/sun/star/uno/Type"_ostr
, "com/sun/star/uno/Type"_ostr
},
59 { "java/lang/Object"_ostr
, "java/lang/Object"_ostr
} };
60 buf
.append(javaTypes
[static_cast<int>(sort
)][referenceType
]);
62 if (nucleus
== "com/sun/star/uno/XInterface") {
63 buf
.append("java/lang/Object");
65 //TODO: check that nucleus is a valid (Java-modified UTF-8)
70 return buf
.makeStringAndClear();
73 OString
translateUnoToJavaIdentifier(
74 OString
const & identifier
, std::string_view prefix
)
76 if (identifier
== "abstract"
77 || identifier
== "assert" // since Java 1.4
78 || identifier
== "boolean"
79 || identifier
== "break"
80 || identifier
== "byte"
81 || identifier
== "case"
82 || identifier
== "catch"
83 || identifier
== "char"
84 || identifier
== "class"
85 || identifier
== "const"
86 || identifier
== "continue"
87 || identifier
== "default"
89 || identifier
== "double"
90 || identifier
== "else"
91 || identifier
== "enum" // probable addition in Java 1.5
92 || identifier
== "extends"
93 || identifier
== "final"
94 || identifier
== "finally"
95 || identifier
== "float"
96 || identifier
== "for"
97 || identifier
== "goto"
99 || identifier
== "implements"
100 || identifier
== "import"
101 || identifier
== "instanceof"
102 || identifier
== "int"
103 || identifier
== "interface"
104 || identifier
== "long"
105 || identifier
== "native"
106 || identifier
== "new"
107 || identifier
== "package"
108 || identifier
== "private"
109 || identifier
== "protected"
110 || identifier
== "public"
111 || identifier
== "return"
112 || identifier
== "short"
113 || identifier
== "static"
114 || identifier
== "strictfp"
115 || identifier
== "super"
116 || identifier
== "switch"
117 || identifier
== "synchronized"
118 || identifier
== "this"
119 || identifier
== "throw"
120 || identifier
== "throws"
121 || identifier
== "transient"
122 || identifier
== "try"
123 || identifier
== "void"
124 || identifier
== "volatile"
125 || identifier
== "while")
127 return OString::Concat(prefix
) + "_" + identifier
;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */