blob: b6054c80ac07ed3a9e45ff49fab17ce8f815f9dd [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,
Christopher Wileya30a45e2015-10-17 10:56:59 -070052 AidlInterface* iface, JavaTypeNamespace* types,
53 const IoDelegate& io_delegate)
Adam Lesinskiffa16862014-01-23 18:17:42 -080054{
Casey Dahlinc1f39b42015-11-24 10:34:34 -080055 Class* cl = generate_binder_interface_class(iface, types);
Adam Lesinskiffa16862014-01-23 18:17:42 -080056
57 Document* document = new Document;
58 document->comment = "";
Casey Dahlinfb7da2e2015-10-08 17:26:09 -070059 if (!iface->GetPackage().empty())
60 document->package = iface->GetPackage();
Adam Lesinskiffa16862014-01-23 18:17:42 -080061 document->originalSrc = originalSrc;
62 document->classes.push_back(cl);
63
Christopher Wileya30a45e2015-10-17 10:56:59 -070064 CodeWriterPtr code_writer = io_delegate.GetCodeWriter(filename);
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070065 document->Write(code_writer.get());
Adam Lesinskiffa16862014-01-23 18:17:42 -080066
Adam Lesinskiffa16862014-01-23 18:17:42 -080067 return 0;
68}
69
Christopher Wileydb154a52015-09-28 16:32:25 -070070} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070071} // namespace android
72} // namespace aidl