1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright (c) 2024. The RigelA open source project team and
* its contributors reserve all rights.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
use TokenStream;
/// 安卓平台的入口
///
/// 将此宏标记在`fn main()`函数上可以自动实现安卓应用的入口函数。
///
/// # 示例
///
/// ```
/// use droid_wrap_macros::android_main;
///
/// #[android_main]
/// fn main() {}
/// ```
/// 定义java class,将此属性标记在struct上,可以自动实现操作java对象的必要功能。
///
/// # Arguments
///
/// * `attrs`: 属性输入。
/// * `input`: struct输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use droid_wrap_macros::java_class;
/// #[java_class(name = "java/lang/System")]
/// struct System;
/// ```
/// 实现java类的方法,将此属性标记在fn函数上,可以自动实现调用java方法,可以自动识别静态方法(如果参数中没有“self”)。
///
/// # Arguments
///
/// * `attrs`: 属性输入。
/// * `input`: 函数输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use droid_wrap_macros::java_method;
/// struct System;
/// impl System {
/// #[java_method]
/// fn current_time_millis() -> i64 {}
/// }
/// ```
/// 实现java类的构造器,将此属性标记在fn函数上,可以自动实现调用java类的构造器。
///
/// # Arguments
///
/// * `_`: 未使用。
/// * `input`: 函数输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use droid_wrap_macros::java_constructor;
/// struct Integer;
/// impl Integer {
/// #[java_constructor]
/// fn new(value: i32) -> Self {}
/// }
/// ```
/// 定义java interface,将此属性标记在trait上,可以自动实现提供java对象与rust对象的互操作的功能。
///
/// # Arguments
///
/// * `attrs`: 属性。
/// * `input`: 特征输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use droid_wrap_macros::java_interface;
/// trait Runnable {
/// fn run(&self);
/// }
/// ```
/// 实现java interface,将此属性标记在impl上,可以自动实现java接口的动态代理,从而实现java层回调rust层。
/// 其中在接口中定义的每一个方法将自动实现并暴露给java层,但以下划线“_”开头的函数除外。
///
/// # Arguments
///
/// * `attrs`: 属性。
/// * `input`: impl输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use std::fmt::{Debug, Formatter};
/// use droid_wrap_macros::{java_interface,java_implement};
/// #[java_interface(name = "java/lang/Runnable")]
/// trait Runnable {
/// fn run(&self);
/// }
/// struct RunnableImpl;
/// impl PartialEq for RunnableImpl {
/// fn eq(&self, other: &Self) -> bool {
/// todo!()
/// }
/// }
/// impl Debug for RunnableImpl {
/// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
/// todo!()
/// }
/// }
/// #[java_implement]
/// impl Runnable for RunnableImpl {
/// fn run(&self) {
/// println!("Called from java.");
/// }
/// }
/// ```
/// 实现java类的字段,将此属性标记在带有get或set的fn函数上,可以自动实现访问java字段的能力,可以自动识别静态字段(如果参数中没有“self”)。
///
/// # Arguments
///
/// * `_`: 未使用。
/// * `input`: 函数输入。
///
/// returns: TokenStream
///
/// # Examples
///
/// ```
/// use droid_wrap_macros::java_field;
///
/// pub struct LayoutParams;
///
/// impl LayoutParams {
/// #[java_field]
/// pub fn get_width(&self) -> i32 {}
///
/// #[java_field]
/// pub fn set_width(&self, value: i32) {}
/// }
/// ```