blob: 09a4410cd661a7cef475dc56c2a6ad5110c04da3 [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
10namespace android {
11namespace aidl {
12
Adam Lesinskiffa16862014-01-23 18:17:42 -080013// =================================================
14VariableFactory::VariableFactory(const string& base)
15 :m_base(base),
16 m_index(0)
17{
18}
19
20Variable*
Christopher Wiley8f6816e2015-09-22 17:03:47 -070021VariableFactory::Get(const Type* type)
Adam Lesinskiffa16862014-01-23 18:17:42 -080022{
23 char name[100];
24 sprintf(name, "%s%d", m_base.c_str(), m_index);
25 m_index++;
26 Variable* v = new Variable(type, name);
27 m_vars.push_back(v);
28 return v;
29}
30
31Variable*
32VariableFactory::Get(int index)
33{
34 return m_vars[index];
35}
36
37// =================================================
38string
39gather_comments(extra_text_type* extra)
40{
41 string s;
42 while (extra) {
43 if (extra->which == SHORT_COMMENT) {
44 s += extra->data;
45 }
46 else if (extra->which == LONG_COMMENT) {
47 s += "/*";
48 s += extra->data;
49 s += "*/";
50 }
51 extra = extra->next;
52 }
53 return s;
54}
55
56string
57append(const char* a, const char* b)
58{
59 string s = a;
60 s += b;
61 return s;
62}
63
64// =================================================
65int
66generate_java(const string& filename, const string& originalSrc,
67 interface_type* iface)
68{
69 Class* cl;
70
71 if (iface->document_item.item_type == INTERFACE_TYPE_BINDER) {
72 cl = generate_binder_interface_class(iface);
73 }
Adam Lesinskiffa16862014-01-23 18:17:42 -080074
75 Document* document = new Document;
76 document->comment = "";
77 if (iface->package) document->package = iface->package;
78 document->originalSrc = originalSrc;
79 document->classes.push_back(cl);
80
Christopher Wiley413e0422015-09-18 10:54:51 -070081 CodeWriterPtr code_writer = GetFileWriter(filename);
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070082 document->Write(code_writer.get());
Adam Lesinskiffa16862014-01-23 18:17:42 -080083
Adam Lesinskiffa16862014-01-23 18:17:42 -080084 return 0;
85}
86
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070087} // namespace android
88} // namespace aidl