LibreOffice Module codemaker (master) 1
commonjava.cxx
Go to the documentation of this file.
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
24
25#include <codemaker/options.hxx>
27#include <codemaker/unotype.hxx>
28
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>
34
35#include <vector>
36
37namespace codemaker::java {
38
40 codemaker::UnoType::Sort sort, std::string_view nucleus, bool referenceType)
41{
42 OStringBuffer buf(128);
44 OString const javaTypes[static_cast<int>(codemaker::UnoType::Sort::Any) + 1][2] = {
45 { "void", "java/lang/Void" },
46 { "boolean", "java/lang/Boolean" },
47 { "byte", "java/lang/Byte" },
48 { "short", "java/lang/Short" },
49 { "short", "java/lang/Short" },
50 { "int", "java/lang/Integer" },
51 { "int", "java/lang/Integer" },
52 { "long", "java/lang/Long" },
53 { "long", "java/lang/Long" },
54 { "float", "java/lang/Float" },
55 { "double", "java/lang/Double" },
56 { "char", "java/lang/Character" },
57 { "java/lang/String", "java/lang/String" },
58 { "com/sun/star/uno/Type", "com/sun/star/uno/Type" },
59 { "java/lang/Object", "java/lang/Object" } };
60 buf.append(javaTypes[static_cast<int>(sort)][referenceType]);
61 } else {
62 if (nucleus == "com/sun/star/uno/XInterface") {
63 buf.append("java/lang/Object");
64 } else {
65 //TODO: check that nucleus is a valid (Java-modified UTF-8)
66 // identifier
67 buf.append(nucleus);
68 }
69 }
70 return buf.makeStringAndClear();
71}
72
74 OString const & identifier, std::string_view prefix)
75{
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"
88 || identifier == "do"
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"
98 || identifier == "if"
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")
126 {
127 return OString::Concat(prefix) + "_" + identifier;
128 } else {
129 return identifier;
130 }
131}
132
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Sort
An enumeration of all the sorts of relevant UNOIDL entities.
Definition: unotype.hxx:33
OString translateUnoToJavaType(codemaker::UnoType::Sort sort, std::string_view nucleus, bool referenceType)
Definition: commonjava.cxx:39
OString translateUnoToJavaIdentifier(OString const &identifier, std::string_view prefix)
Definition: commonjava.cxx:73
::boost::spirit::classic::rule< ScannerT > identifier