blob: d71f8cc3e848018c751ea9fffbefe84182db9c35 [file] [log] [blame]
Adam Lesinskiffa16862014-01-23 18:17:42 -08001#include "generate_java.h"
Christopher Wileyfdeb0f42015-09-11 15:38:22 -07002
Adam Lesinskiffa16862014-01-23 18:17:42 -08003#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
Christopher Wileyfdeb0f42015-09-11 15:38:22 -07007#include "code_writer.h"
Christopher Wiley775fa1f2015-09-22 15:00:12 -07008#include "type_java.h"
Christopher Wileyfdeb0f42015-09-11 15:38:22 -07009
Christopher Wileydb154a52015-09-28 16:32:25 -070010using ::android::aidl::java::Variable;
11
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070012namespace android {
13namespace aidl {
14
Adam Lesinskiffa16862014-01-23 18:17:42 -080015// =================================================
16VariableFactory::VariableFactory(const string& base)
17 :m_base(base),
18 m_index(0)
19{
20}
21
22Variable*
Christopher Wiley8f6816e2015-09-22 17:03:47 -070023VariableFactory::Get(const Type* type)
Adam Lesinskiffa16862014-01-23 18:17:42 -080024{
25 char name[100];
26 sprintf(name, "%s%d", m_base.c_str(), m_index);
27 m_index++;
28 Variable* v = new Variable(type, name);
29 m_vars.push_back(v);
30 return v;
31}
32
33Variable*
34VariableFactory::Get(int index)
35{
36 return m_vars[index];
37}
38
39// =================================================
40string
Adam Lesinskiffa16862014-01-23 18:17:42 -080041append(const char* a, const char* b)
42{
43 string s = a;
44 s += b;
45 return s;
46}
47
Christopher Wileydb154a52015-09-28 16:32:25 -070048namespace java {
49
Adam Lesinskiffa16862014-01-23 18:17:42 -080050int
51generate_java(const string& filename, const string& originalSrc,
Casey Dahlin1ae2bc52015-10-07 18:49:10 -070052 AidlInterface* iface, JavaTypeNamespace* types)
Adam Lesinskiffa16862014-01-23 18:17:42 -080053{
54 Class* cl;
55
Casey Dahlin1ae2bc52015-10-07 18:49:10 -070056 if (iface->item_type == INTERFACE_TYPE_BINDER) {
Christopher Wiley84c1eac2015-09-23 13:29:28 -070057 cl = generate_binder_interface_class(iface, types);
Adam Lesinskiffa16862014-01-23 18:17:42 -080058 }
Adam Lesinskiffa16862014-01-23 18:17:42 -080059
60 Document* document = new Document;
61 document->comment = "";
62 if (iface->package) document->package = iface->package;
63 document->originalSrc = originalSrc;
64 document->classes.push_back(cl);
65
Christopher Wiley413e0422015-09-18 10:54:51 -070066 CodeWriterPtr code_writer = GetFileWriter(filename);
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070067 document->Write(code_writer.get());
Adam Lesinskiffa16862014-01-23 18:17:42 -080068
Adam Lesinskiffa16862014-01-23 18:17:42 -080069 return 0;
70}
71
Christopher Wileydb154a52015-09-28 16:32:25 -070072} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070073} // namespace android
74} // namespace aidl