Branch data 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 : 181 : rtl::OString translateUnoToJavaType(
43 : : codemaker::UnoType::Sort sort, RTTypeClass typeClass,
44 : : rtl::OString const & nucleus, bool referenceType)
45 : : {
46 : 181 : rtl::OStringBuffer buf;
47 [ + + ]: 181 : if (sort == codemaker::UnoType::SORT_COMPLEX) {
48 [ + + + + ]: 238 : if (typeClass == RT_TYPE_INTERFACE
[ + + ]
49 [ + + ][ + + ]: 123 : && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
50 : : {
51 [ + - ]: 2 : 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 [ + - ]: 113 : 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 : 2046 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")) } };
89 [ + + ][ # # ]: 2046 : buf.append(javaTypes[sort][referenceType]);
[ + - ]
90 : : }
91 : 181 : return buf.makeStringAndClear();
92 : : }
93 : :
94 : 528 : rtl::OString translateUnoToJavaIdentifier(
95 : : rtl::OString const & identifier, rtl::OString const & prefix)
96 : : {
97 [ + - + - : 26400 : if (identifier == "abstract"
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
+ ][ - + ]
98 : 528 : || identifier == "assert" // since Java 1.4
99 : 528 : || identifier == "boolean"
100 : 528 : || identifier == "break"
101 : 528 : || identifier == "byte"
102 : 528 : || identifier == "case"
103 : 528 : || identifier == "catch"
104 : 528 : || identifier == "char"
105 : 528 : || identifier == "class"
106 : 528 : || identifier == "const"
107 : 528 : || identifier == "continue"
108 : 528 : || identifier == "default"
109 : 528 : || identifier == "do"
110 : 528 : || identifier == "double"
111 : 528 : || identifier == "else"
112 : 528 : || identifier == "enum" // probable addition in Java 1.5
113 : 528 : || identifier == "extends"
114 : 528 : || identifier == "final"
115 : 528 : || identifier == "finally"
116 : 528 : || identifier == "float"
117 : 528 : || identifier == "for"
118 : 528 : || identifier == "goto"
119 : 528 : || identifier == "if"
120 : 528 : || identifier == "implements"
121 : 528 : || identifier == "import"
122 : 528 : || identifier == "instanceof"
123 : 528 : || identifier == "int"
124 : 528 : || identifier == "interface"
125 : 528 : || identifier == "long"
126 : 528 : || identifier == "native"
127 : 528 : || identifier == "new"
128 : 528 : || identifier == "package"
129 : 528 : || identifier == "private"
130 : 528 : || identifier == "protected"
131 : 528 : || identifier == "public"
132 : 528 : || identifier == "return"
133 : 528 : || identifier == "short"
134 : 528 : || identifier == "static"
135 : 528 : || identifier == "strictfp"
136 : 528 : || identifier == "super"
137 : 528 : || identifier == "switch"
138 : 528 : || identifier == "synchronized"
139 : 528 : || identifier == "this"
140 : 528 : || identifier == "throw"
141 : 528 : || identifier == "throws"
142 : 528 : || identifier == "transient"
143 : 528 : || identifier == "try"
144 : 528 : || identifier == "void"
145 : 528 : || identifier == "volatile"
146 : 528 : || 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 : 528 : return identifier;
154 : : }
155 : : }
156 : :
157 : : } }
158 : :
159 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|