ReflectiveAtInjectBinding.java
8.91 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package dagger.internal.loaders;
import dagger.internal.Binding;
import dagger.internal.Binding.InvalidBindingException;
import dagger.internal.Keys;
import dagger.internal.Linker;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
public final class ReflectiveAtInjectBinding<T>
extends Binding<T>
{
private final Constructor<T> constructor;
private final Binding<?>[] fieldBindings;
private final Field[] fields;
private final String[] keys;
private final ClassLoader loader;
private final Binding<?>[] parameterBindings;
private final Class<?> supertype;
private Binding<? super T> supertypeBinding;
private ReflectiveAtInjectBinding(String paramString1, String paramString2, boolean paramBoolean, Class<?> paramClass1, Field[] paramArrayOfField, Constructor<T> paramConstructor, int paramInt, Class<?> paramClass2, String[] paramArrayOfString)
{
super(paramString1, paramString2, paramBoolean, paramClass1);
this.constructor = paramConstructor;
this.fields = paramArrayOfField;
this.supertype = paramClass2;
this.keys = paramArrayOfString;
this.parameterBindings = new Binding[paramInt];
this.fieldBindings = new Binding[paramArrayOfField.length];
this.loader = paramClass1.getClassLoader();
}
public static <T> Binding<T> create(Class<T> paramClass, boolean paramBoolean)
{
boolean bool = paramClass.isAnnotationPresent(Singleton.class);
ArrayList localArrayList1 = new ArrayList();
ArrayList localArrayList2 = new ArrayList();
Object localObject2;
for (Object localObject1 = paramClass; localObject1 != Object.class; localObject1 = ((Class)localObject1).getSuperclass())
{
localObject2 = ((Class)localObject1).getDeclaredFields();
j = localObject2.length;
i = 0;
while (i < j)
{
localObject4 = localObject2[i];
if ((((Field)localObject4).isAnnotationPresent(Inject.class)) && (!Modifier.isStatic(((Field)localObject4).getModifiers())))
{
if ((((Field)localObject4).getModifiers() & 0x2) != 0) {
throw new IllegalStateException("Can't inject private field: " + localObject4);
}
((Field)localObject4).setAccessible(true);
localArrayList2.add(localObject4);
localArrayList1.add(Keys.get(((Field)localObject4).getGenericType(), ((Field)localObject4).getAnnotations(), localObject4));
}
i += 1;
}
}
Object localObject4 = getConstructorsForType(paramClass);
int j = localObject4.length;
int i = 0;
for (localObject1 = null; i < j; localObject1 = localObject2)
{
localObject2 = localObject4[i];
if (((Constructor)localObject2).isAnnotationPresent(Inject.class))
{
if (localObject1 != null) {
throw new Binding.InvalidBindingException(paramClass.getName(), "has too many injectable constructors");
}
}
else {
localObject2 = localObject1;
}
i += 1;
}
if (localObject1 == null) {
if (localArrayList2.isEmpty()) {}
}
label549:
label569:
for (;;)
{
try
{
localObject2 = paramClass.getDeclaredConstructor(new Class[0]);
localObject1 = localObject2;
}
catch (NoSuchMethodException localNoSuchMethodException)
{
continue;
}
Object localObject3;
if (localObject1 != null)
{
if ((((Constructor)localObject1).getModifiers() & 0x2) != 0)
{
throw new IllegalStateException("Can't inject private constructor: " + localObject1);
if (!paramBoolean) {
break label569;
}
throw new Binding.InvalidBindingException(paramClass.getName(), "has no injectable members. Do you want to add an injectable constructor?");
}
localObject4 = Keys.get(paramClass);
((Constructor)localObject1).setAccessible(true);
localObject5 = ((Constructor)localObject1).getGenericParameterTypes();
int k = localObject5.length;
localObject3 = localObject4;
j = k;
if (k != 0)
{
Annotation[][] arrayOfAnnotation = ((Constructor)localObject1).getParameterAnnotations();
i = 0;
for (;;)
{
localObject3 = localObject4;
j = k;
if (i >= localObject5.length) {
break;
}
localArrayList1.add(Keys.get(localObject5[i], arrayOfAnnotation[i], localObject1));
i += 1;
}
}
}
else
{
if (bool) {
throw new IllegalArgumentException("No injectable constructor on @Singleton " + paramClass.getName());
}
localObject3 = null;
j = 0;
}
Object localObject5 = paramClass.getSuperclass();
localObject4 = localObject5;
if (localObject5 != null) {
if (!Keys.isPlatformType(((Class)localObject5).getName())) {
break label549;
}
}
for (localObject4 = null;; localObject4 = localObject5)
{
return new ReflectiveAtInjectBinding((String)localObject3, Keys.getMembersKey(paramClass), bool, paramClass, (Field[])localArrayList2.toArray(new Field[localArrayList2.size()]), (Constructor)localObject1, j, (Class)localObject4, (String[])localArrayList1.toArray(new String[localArrayList1.size()]));
localArrayList1.add(Keys.getMembersKey((Class)localObject5));
}
}
}
private static <T> Constructor<T>[] getConstructorsForType(Class<T> paramClass)
{
return (Constructor[])paramClass.getDeclaredConstructors();
}
public final void attach(Linker paramLinker)
{
int j = 0;
int i = 0;
while (j < this.fields.length)
{
if (this.fieldBindings[j] == null) {
this.fieldBindings[j] = paramLinker.requestBinding(this.keys[i], this.fields[j], this.loader);
}
i += 1;
j += 1;
}
int k = i;
if (this.constructor != null)
{
j = 0;
for (;;)
{
k = i;
if (j >= this.parameterBindings.length) {
break;
}
if (this.parameterBindings[j] == null) {
this.parameterBindings[j] = paramLinker.requestBinding(this.keys[i], this.constructor, this.loader);
}
i += 1;
j += 1;
}
}
if ((this.supertype != null) && (this.supertypeBinding == null)) {
this.supertypeBinding = paramLinker.requestBinding(this.keys[k], this.membersKey, this.loader, false, true);
}
}
public final T get()
{
if (this.constructor == null) {
throw new UnsupportedOperationException();
}
Object localObject1 = new Object[this.parameterBindings.length];
int i = 0;
while (i < this.parameterBindings.length)
{
localObject1[i] = this.parameterBindings[i].get();
i += 1;
}
try
{
localObject1 = this.constructor.newInstance((Object[])localObject1);
injectMembers(localObject1);
return (T)localObject1;
}
catch (InvocationTargetException localInvocationTargetException)
{
Object localObject2 = localInvocationTargetException.getCause();
if ((localObject2 instanceof RuntimeException)) {}
for (localObject2 = (RuntimeException)localObject2;; localObject2 = new RuntimeException((Throwable)localObject2)) {
throw ((Throwable)localObject2);
}
}
catch (IllegalAccessException localIllegalAccessException)
{
throw new AssertionError(localIllegalAccessException);
}
catch (InstantiationException localInstantiationException)
{
throw new RuntimeException(localInstantiationException);
}
}
public final void getDependencies(Set<Binding<?>> paramSet1, Set<Binding<?>> paramSet2)
{
if (this.parameterBindings != null) {
Collections.addAll(paramSet1, this.parameterBindings);
}
Collections.addAll(paramSet2, this.fieldBindings);
if (this.supertypeBinding != null) {
paramSet2.add(this.supertypeBinding);
}
}
public final void injectMembers(T paramT)
{
int i = 0;
try
{
while (i < this.fields.length)
{
this.fields[i].set(paramT, this.fieldBindings[i].get());
i += 1;
}
if (this.supertypeBinding != null) {
this.supertypeBinding.injectMembers(paramT);
}
return;
}
catch (IllegalAccessException paramT)
{
throw new AssertionError(paramT);
}
}
public final String toString()
{
if (this.provideKey != null) {
return this.provideKey;
}
return this.membersKey;
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/dagger/internal/loaders/ReflectiveAtInjectBinding.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/