generate_java.cpp revision 8f6816ea1fb532cff9ce0ecc1449926553b4e1da
1#include "generate_java.h"
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include "code_writer.h"
8#include "type_java.h"
9
10namespace android {
11namespace aidl {
12
13// =================================================
14VariableFactory::VariableFactory(const string& base)
15    :m_base(base),
16     m_index(0)
17{
18}
19
20Variable*
21VariableFactory::Get(const Type* type)
22{
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    }
74
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
81    CodeWriterPtr code_writer = GetFileWriter(filename);
82    document->Write(code_writer.get());
83
84    return 0;
85}
86
87}  // namespace android
88}  // namespace aidl
89