blob: 14df35357dcbdc4a883ffc6c1cf59e6d9e8b82dc [file] [log] [blame]
Christopher Wiley3a9da172016-01-29 11:10:49 -08001/*
2 * Copyright (C) 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Adam Lesinskiffa16862014-01-23 18:17:42 -080017#include "generate_java.h"
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070018
Christopher Wileyf76b59a2016-01-29 11:32:11 -080019#include <memory>
Adam Lesinskiffa16862014-01-23 18:17:42 -080020#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
Christopher Wiley3a9da172016-01-29 11:10:49 -080024#include <android-base/stringprintf.h>
25
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070026#include "code_writer.h"
Christopher Wiley775fa1f2015-09-22 15:00:12 -070027#include "type_java.h"
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070028
Christopher Wileyf76b59a2016-01-29 11:32:11 -080029using std::unique_ptr;
Christopher Wileydb154a52015-09-28 16:32:25 -070030using ::android::aidl::java::Variable;
Christopher Wiley3a9da172016-01-29 11:10:49 -080031using std::string;
32using android::base::StringPrintf;
Christopher Wileydb154a52015-09-28 16:32:25 -070033
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070034namespace android {
35namespace aidl {
36
Adam Lesinskiffa16862014-01-23 18:17:42 -080037// =================================================
38VariableFactory::VariableFactory(const string& base)
Christopher Wiley3a9da172016-01-29 11:10:49 -080039 : base_(base),
40 index_(0) {
Adam Lesinskiffa16862014-01-23 18:17:42 -080041}
42
Christopher Wiley3a9da172016-01-29 11:10:49 -080043Variable* VariableFactory::Get(const Type* type) {
44 Variable* v = new Variable(
45 type, StringPrintf("%s%d", base_.c_str(), index_));
46 vars_.push_back(v);
47 index_++;
48 return v;
Adam Lesinskiffa16862014-01-23 18:17:42 -080049}
50
Christopher Wiley3a9da172016-01-29 11:10:49 -080051Variable* VariableFactory::Get(int index) {
52 return vars_[index];
Adam Lesinskiffa16862014-01-23 18:17:42 -080053}
54
Christopher Wileydb154a52015-09-28 16:32:25 -070055namespace java {
56
Christopher Wiley3a9da172016-01-29 11:10:49 -080057int generate_java(const string& filename, const string& originalSrc,
58 AidlInterface* iface, JavaTypeNamespace* types,
59 const IoDelegate& io_delegate) {
60 Class* cl = generate_binder_interface_class(iface, types);
Adam Lesinskiffa16862014-01-23 18:17:42 -080061
Christopher Wileyf76b59a2016-01-29 11:32:11 -080062 Document* document = new Document(
63 "" /* no comment */,
64 (!iface->GetPackage().empty()) ? iface->GetPackage() : "",
65 originalSrc,
66 unique_ptr<Class>(cl));
Adam Lesinskiffa16862014-01-23 18:17:42 -080067
Christopher Wiley3a9da172016-01-29 11:10:49 -080068 CodeWriterPtr code_writer = io_delegate.GetCodeWriter(filename);
69 document->Write(code_writer.get());
Adam Lesinskiffa16862014-01-23 18:17:42 -080070
Christopher Wiley3a9da172016-01-29 11:10:49 -080071 return 0;
Adam Lesinskiffa16862014-01-23 18:17:42 -080072}
73
Christopher Wileydb154a52015-09-28 16:32:25 -070074} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070075} // namespace android
76} // namespace aidl