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 "rtl/strbuf.h"
31 : #include "rtl/string.h"
32 : #include "rtl/string.hxx"
33 : #include "rtl/ustring.hxx"
34 : #include "sal/types.h"
35 :
36 : #include <vector>
37 :
38 : namespace codemaker { namespace java {
39 :
40 94 : OString translateUnoToJavaType(
41 : codemaker::UnoType::Sort sort, OString const & nucleus, bool referenceType)
42 : {
43 94 : OStringBuffer buf;
44 94 : if (sort <= codemaker::UnoType::SORT_ANY) {
45 : OString const javaTypes[codemaker::UnoType::SORT_ANY + 1][2] = {
46 : { "void", "java/lang/Void" },
47 : { "boolean", "java/lang/Boolean" },
48 : { "byte", "java/lang/Byte" },
49 : { "short", "java/lang/Short" },
50 : { "short", "java/lang/Short" },
51 : { "int", "java/lang/Integer" },
52 : { "int", "java/lang/Integer" },
53 : { "long", "java/lang/Long" },
54 : { "long", "java/lang/Long" },
55 : { "float", "java/lang/Float" },
56 : { "double", "java/lang/Double" },
57 : { "char", "java/lang/Character" },
58 : { "java/lang/String", "java/lang/String" },
59 : { "com/sun/star/uno/Type", "com/sun/star/uno/Type" },
60 1271 : { "java/lang/Object", "java/lang/Object" } };
61 1271 : buf.append(javaTypes[sort][referenceType]);
62 : } else {
63 53 : if (nucleus == "com/sun/star/uno/XInterface") {
64 1 : buf.append("java/lang/Object");
65 : } else {
66 : //TODO: check that nucleus is a valid (Java-modified UTF-8)
67 : // identifier
68 52 : buf.append(nucleus);
69 : }
70 : }
71 94 : return buf.makeStringAndClear();
72 : }
73 :
74 736 : OString translateUnoToJavaIdentifier(
75 : OString const & identifier, OString const & prefix)
76 : {
77 1472 : if (identifier == "abstract"
78 736 : || identifier == "assert" // since Java 1.4
79 736 : || identifier == "boolean"
80 736 : || identifier == "break"
81 736 : || identifier == "byte"
82 736 : || identifier == "case"
83 736 : || identifier == "catch"
84 736 : || identifier == "char"
85 736 : || identifier == "class"
86 736 : || identifier == "const"
87 736 : || identifier == "continue"
88 736 : || identifier == "default"
89 736 : || identifier == "do"
90 736 : || identifier == "double"
91 736 : || identifier == "else"
92 736 : || identifier == "enum" // probable addition in Java 1.5
93 736 : || identifier == "extends"
94 736 : || identifier == "final"
95 736 : || identifier == "finally"
96 736 : || identifier == "float"
97 736 : || identifier == "for"
98 736 : || identifier == "goto"
99 736 : || identifier == "if"
100 736 : || identifier == "implements"
101 736 : || identifier == "import"
102 736 : || identifier == "instanceof"
103 736 : || identifier == "int"
104 736 : || identifier == "interface"
105 736 : || identifier == "long"
106 736 : || identifier == "native"
107 736 : || identifier == "new"
108 736 : || identifier == "package"
109 736 : || identifier == "private"
110 736 : || identifier == "protected"
111 736 : || identifier == "public"
112 736 : || identifier == "return"
113 736 : || identifier == "short"
114 736 : || identifier == "static"
115 736 : || identifier == "strictfp"
116 736 : || identifier == "super"
117 736 : || identifier == "switch"
118 736 : || identifier == "synchronized"
119 736 : || identifier == "this"
120 736 : || identifier == "throw"
121 736 : || identifier == "throws"
122 736 : || identifier == "transient"
123 736 : || identifier == "try"
124 736 : || identifier == "void"
125 736 : || identifier == "volatile"
126 1472 : || identifier == "while")
127 : {
128 0 : return prefix + "_" + identifier;
129 : } else {
130 736 : return identifier;
131 : }
132 : }
133 :
134 : } }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|