PageRenderTime 72ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/util/DeserializeBeanInfo.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 432 lines | 408 code | 20 blank | 4 comment | 115 complexity | 768f768b0cbfa340963f600746e9da01 MD5 | raw file
  1. package com.alibaba.fastjson.util;
  2. import com.alibaba.fastjson.JSONException;
  3. import com.alibaba.fastjson.annotation.JSONCreator;
  4. import com.alibaba.fastjson.annotation.JSONField;
  5. import java.beans.Introspector;
  6. import java.lang.reflect.Constructor;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.Method;
  9. import java.lang.reflect.Modifier;
  10. import java.lang.reflect.Type;
  11. import java.util.ArrayList;
  12. import java.util.Collection;
  13. import java.util.Collections;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.concurrent.atomic.AtomicBoolean;
  18. import java.util.concurrent.atomic.AtomicInteger;
  19. import java.util.concurrent.atomic.AtomicLong;
  20. public class DeserializeBeanInfo
  21. {
  22. private final Class<?> clazz;
  23. private Constructor<?> creatorConstructor;
  24. private Constructor<?> defaultConstructor;
  25. private Method factoryMethod;
  26. private final List<FieldInfo> fieldList = new ArrayList();
  27. private final List<FieldInfo> sortedFieldList = new ArrayList();
  28. public DeserializeBeanInfo(Class<?> paramClass)
  29. {
  30. this.clazz = paramClass;
  31. }
  32. public static DeserializeBeanInfo computeSetters(Class<?> paramClass, Type paramType)
  33. {
  34. DeserializeBeanInfo localDeserializeBeanInfo = new DeserializeBeanInfo(paramClass);
  35. Object localObject1 = getDefaultConstructor(paramClass);
  36. Object localObject4;
  37. label44: Object localObject5;
  38. if (localObject1 != null)
  39. {
  40. ((Constructor)localObject1).setAccessible(true);
  41. localDeserializeBeanInfo.setDefaultConstructor((Constructor)localObject1);
  42. localObject4 = paramClass.getMethods();
  43. j = localObject4.length;
  44. i = 0;
  45. if (i >= j)
  46. break label881;
  47. localObject5 = localObject4[i];
  48. localObject3 = ((Method)localObject5).getName();
  49. if (((String)localObject3).length() >= 4)
  50. break label477;
  51. }
  52. Object localObject2;
  53. label853:
  54. while (true)
  55. {
  56. i += 1;
  57. break label44;
  58. if ((localObject1 != null) || (paramClass.isInterface()) || (Modifier.isAbstract(paramClass.getModifiers())))
  59. break;
  60. localObject2 = getCreatorConstructor(paramClass);
  61. if (localObject2 != null)
  62. {
  63. ((Constructor)localObject2).setAccessible(true);
  64. localDeserializeBeanInfo.setCreatorConstructor((Constructor)localObject2);
  65. i = 0;
  66. while (i < ((Constructor)localObject2).getParameterTypes().length)
  67. {
  68. localObject3 = localObject2.getParameterAnnotations()[i];
  69. localObject1 = null;
  70. k = localObject3.length;
  71. j = 0;
  72. while (true)
  73. {
  74. paramType = (Type)localObject1;
  75. if (j < k)
  76. {
  77. paramType = localObject3[j];
  78. if ((paramType instanceof JSONField))
  79. paramType = (JSONField)paramType;
  80. }
  81. else
  82. {
  83. if (paramType != null)
  84. break;
  85. throw new JSONException("illegal json creator");
  86. }
  87. j += 1;
  88. }
  89. localObject1 = localObject2.getParameterTypes()[i];
  90. localObject3 = localObject2.getGenericParameterTypes()[i];
  91. localObject4 = getField(paramClass, paramType.name());
  92. localDeserializeBeanInfo.add(new FieldInfo(paramType.name(), paramClass, (Class)localObject1, (Type)localObject3, (Field)localObject4));
  93. i += 1;
  94. }
  95. }
  96. localObject2 = getFactoryMethod(paramClass);
  97. if (localObject2 != null)
  98. {
  99. ((Method)localObject2).setAccessible(true);
  100. localDeserializeBeanInfo.setFactoryMethod((Method)localObject2);
  101. i = 0;
  102. while (i < ((Method)localObject2).getParameterTypes().length)
  103. {
  104. localObject3 = localObject2.getParameterAnnotations()[i];
  105. localObject1 = null;
  106. k = localObject3.length;
  107. j = 0;
  108. while (true)
  109. {
  110. paramType = (Type)localObject1;
  111. if (j < k)
  112. {
  113. paramType = localObject3[j];
  114. if ((paramType instanceof JSONField))
  115. paramType = (JSONField)paramType;
  116. }
  117. else
  118. {
  119. if (paramType != null)
  120. break;
  121. throw new JSONException("illegal json creator");
  122. }
  123. j += 1;
  124. }
  125. localObject1 = localObject2.getParameterTypes()[i];
  126. localObject3 = localObject2.getGenericParameterTypes()[i];
  127. localObject4 = getField(paramClass, paramType.name());
  128. localDeserializeBeanInfo.add(new FieldInfo(paramType.name(), paramClass, (Class)localObject1, (Type)localObject3, (Field)localObject4));
  129. i += 1;
  130. }
  131. }
  132. throw new JSONException("default constructor not found. " + paramClass);
  133. label477: if ((!Modifier.isStatic(((Method)localObject5).getModifiers())) && ((((Method)localObject5).getReturnType().equals(Void.TYPE)) || (((Method)localObject5).getReturnType().equals(paramClass))) && (((Method)localObject5).getParameterTypes().length == 1))
  134. {
  135. localObject2 = (JSONField)((Method)localObject5).getAnnotation(JSONField.class);
  136. localObject1 = localObject2;
  137. if (localObject2 == null)
  138. localObject1 = TypeUtils.getSupperMethodAnnotation(paramClass, (Method)localObject5);
  139. if (localObject1 != null)
  140. {
  141. if (((JSONField)localObject1).deserialize())
  142. if (((JSONField)localObject1).name().length() != 0)
  143. {
  144. localDeserializeBeanInfo.add(new FieldInfo(((JSONField)localObject1).name(), (Method)localObject5, null, paramClass, paramType));
  145. ((Method)localObject5).setAccessible(true);
  146. }
  147. }
  148. else if (((String)localObject3).startsWith("set"))
  149. {
  150. char c = ((String)localObject3).charAt(3);
  151. if (Character.isUpperCase(c))
  152. if (TypeUtils.compatibleWithJavaBean)
  153. localObject1 = Introspector.decapitalize(((String)localObject3).substring(3));
  154. while (true)
  155. {
  156. localObject3 = getField(paramClass, (String)localObject1);
  157. localObject2 = localObject3;
  158. if (localObject3 == null)
  159. {
  160. localObject2 = localObject3;
  161. if (localObject5.getParameterTypes()[0] == Boolean.TYPE)
  162. localObject2 = getField(paramClass, "is" + Character.toUpperCase(((String)localObject1).charAt(0)) + ((String)localObject1).substring(1));
  163. }
  164. if (localObject2 == null)
  165. break label853;
  166. localObject3 = (JSONField)((Field)localObject2).getAnnotation(JSONField.class);
  167. if ((localObject3 == null) || (((JSONField)localObject3).name().length() == 0))
  168. break label853;
  169. localDeserializeBeanInfo.add(new FieldInfo(((JSONField)localObject3).name(), (Method)localObject5, (Field)localObject2, paramClass, paramType));
  170. break;
  171. localObject1 = Character.toLowerCase(((String)localObject3).charAt(3)) + ((String)localObject3).substring(4);
  172. continue;
  173. if (c == '_')
  174. {
  175. localObject1 = ((String)localObject3).substring(4);
  176. }
  177. else
  178. {
  179. if (c != 'f')
  180. break;
  181. localObject1 = ((String)localObject3).substring(3);
  182. }
  183. }
  184. localDeserializeBeanInfo.add(new FieldInfo((String)localObject1, (Method)localObject5, null, paramClass, paramType));
  185. ((Method)localObject5).setAccessible(true);
  186. }
  187. }
  188. }
  189. label881: Object localObject3 = paramClass.getFields();
  190. int k = localObject3.length;
  191. int i = 0;
  192. if (i < k)
  193. {
  194. localObject4 = localObject3[i];
  195. if (Modifier.isStatic(((Field)localObject4).getModifiers()));
  196. while (true)
  197. {
  198. i += 1;
  199. break;
  200. j = 0;
  201. localObject1 = localDeserializeBeanInfo.getFieldList().iterator();
  202. while (((Iterator)localObject1).hasNext())
  203. if (((FieldInfo)((Iterator)localObject1).next()).getName().equals(((Field)localObject4).getName()))
  204. j = 1;
  205. if (j == 0)
  206. {
  207. localObject2 = ((Field)localObject4).getName();
  208. localObject5 = (JSONField)((Field)localObject4).getAnnotation(JSONField.class);
  209. localObject1 = localObject2;
  210. if (localObject5 != null)
  211. {
  212. localObject1 = localObject2;
  213. if (((JSONField)localObject5).name().length() != 0)
  214. localObject1 = ((JSONField)localObject5).name();
  215. }
  216. localDeserializeBeanInfo.add(new FieldInfo((String)localObject1, null, (Field)localObject4, paramClass, paramType));
  217. }
  218. }
  219. }
  220. localObject1 = paramClass.getMethods();
  221. int j = localObject1.length;
  222. i = 0;
  223. if (i < j)
  224. {
  225. localObject2 = localObject1[i];
  226. localObject3 = ((Method)localObject2).getName();
  227. if (((String)localObject3).length() < 4);
  228. while (true)
  229. {
  230. i += 1;
  231. break;
  232. if ((!Modifier.isStatic(((Method)localObject2).getModifiers())) && (((String)localObject3).startsWith("get")) && (Character.isUpperCase(((String)localObject3).charAt(3))) && (((Method)localObject2).getParameterTypes().length == 0) && ((Collection.class.isAssignableFrom(((Method)localObject2).getReturnType())) || (Map.class.isAssignableFrom(((Method)localObject2).getReturnType())) || (AtomicBoolean.class == ((Method)localObject2).getReturnType()) || (AtomicInteger.class == ((Method)localObject2).getReturnType()) || (AtomicLong.class == ((Method)localObject2).getReturnType())))
  233. {
  234. localObject3 = Character.toLowerCase(((String)localObject3).charAt(3)) + ((String)localObject3).substring(4);
  235. if (localDeserializeBeanInfo.getField((String)localObject3) == null)
  236. {
  237. localDeserializeBeanInfo.add(new FieldInfo((String)localObject3, (Method)localObject2, null, paramClass, paramType));
  238. ((Method)localObject2).setAccessible(true);
  239. }
  240. }
  241. }
  242. }
  243. return localDeserializeBeanInfo;
  244. }
  245. public static Constructor<?> getCreatorConstructor(Class<?> paramClass)
  246. {
  247. Object localObject = null;
  248. Constructor[] arrayOfConstructor = paramClass.getDeclaredConstructors();
  249. int j = arrayOfConstructor.length;
  250. int i = 0;
  251. while (true)
  252. {
  253. paramClass = localObject;
  254. if (i < j)
  255. {
  256. paramClass = arrayOfConstructor[i];
  257. if ((JSONCreator)paramClass.getAnnotation(JSONCreator.class) == null)
  258. break label55;
  259. if (0 != 0)
  260. throw new JSONException("multi-json creator");
  261. }
  262. return paramClass;
  263. label55: i += 1;
  264. }
  265. }
  266. public static Constructor<?> getDefaultConstructor(Class<?> paramClass)
  267. {
  268. Object localObject2;
  269. if (Modifier.isAbstract(paramClass.getModifiers()))
  270. localObject2 = null;
  271. label28: Object localObject1;
  272. do
  273. {
  274. do
  275. {
  276. do
  277. {
  278. return localObject2;
  279. localObject2 = null;
  280. arrayOfConstructor = paramClass.getDeclaredConstructors();
  281. j = arrayOfConstructor.length;
  282. i = 0;
  283. localObject1 = localObject2;
  284. if (i < j)
  285. {
  286. localObject1 = arrayOfConstructor[i];
  287. if (((Constructor)localObject1).getParameterTypes().length != 0)
  288. break;
  289. }
  290. localObject2 = localObject1;
  291. }
  292. while (localObject1 != null);
  293. localObject2 = localObject1;
  294. }
  295. while (!paramClass.isMemberClass());
  296. localObject2 = localObject1;
  297. }
  298. while (Modifier.isStatic(paramClass.getModifiers()));
  299. Constructor[] arrayOfConstructor = paramClass.getDeclaredConstructors();
  300. int j = arrayOfConstructor.length;
  301. int i = 0;
  302. while (true)
  303. {
  304. localObject2 = localObject1;
  305. if (i >= j)
  306. break;
  307. localObject2 = arrayOfConstructor[i];
  308. if ((((Constructor)localObject2).getParameterTypes().length == 1) && (localObject2.getParameterTypes()[0].equals(paramClass.getDeclaringClass())))
  309. {
  310. return localObject2;
  311. i += 1;
  312. break label28;
  313. }
  314. i += 1;
  315. }
  316. }
  317. public static Method getFactoryMethod(Class<?> paramClass)
  318. {
  319. Object localObject2 = null;
  320. Method[] arrayOfMethod = paramClass.getDeclaredMethods();
  321. int j = arrayOfMethod.length;
  322. int i = 0;
  323. Object localObject1 = localObject2;
  324. if (i < j)
  325. {
  326. localObject1 = arrayOfMethod[i];
  327. if (!Modifier.isStatic(((Method)localObject1).getModifiers()));
  328. while ((!paramClass.isAssignableFrom(((Method)localObject1).getReturnType())) || ((JSONCreator)((Method)localObject1).getAnnotation(JSONCreator.class) == null))
  329. {
  330. i += 1;
  331. break;
  332. }
  333. if (0 != 0)
  334. throw new JSONException("multi-json creator");
  335. }
  336. return localObject1;
  337. }
  338. public static Field getField(Class<?> paramClass, String paramString)
  339. {
  340. try
  341. {
  342. paramClass = paramClass.getDeclaredField(paramString);
  343. return paramClass;
  344. }
  345. catch (Exception paramClass)
  346. {
  347. }
  348. return null;
  349. }
  350. public boolean add(FieldInfo paramFieldInfo)
  351. {
  352. Iterator localIterator = this.fieldList.iterator();
  353. while (localIterator.hasNext())
  354. if (((FieldInfo)localIterator.next()).getName().equals(paramFieldInfo.getName()))
  355. return false;
  356. this.fieldList.add(paramFieldInfo);
  357. this.sortedFieldList.add(paramFieldInfo);
  358. Collections.sort(this.sortedFieldList);
  359. return true;
  360. }
  361. public Class<?> getClazz()
  362. {
  363. return this.clazz;
  364. }
  365. public Constructor<?> getCreatorConstructor()
  366. {
  367. return this.creatorConstructor;
  368. }
  369. public Constructor<?> getDefaultConstructor()
  370. {
  371. return this.defaultConstructor;
  372. }
  373. public Method getFactoryMethod()
  374. {
  375. return this.factoryMethod;
  376. }
  377. public FieldInfo getField(String paramString)
  378. {
  379. Iterator localIterator = this.fieldList.iterator();
  380. while (localIterator.hasNext())
  381. {
  382. FieldInfo localFieldInfo = (FieldInfo)localIterator.next();
  383. if (localFieldInfo.getName().equals(paramString))
  384. return localFieldInfo;
  385. }
  386. return null;
  387. }
  388. public List<FieldInfo> getFieldList()
  389. {
  390. return this.fieldList;
  391. }
  392. public List<FieldInfo> getSortedFieldList()
  393. {
  394. return this.sortedFieldList;
  395. }
  396. public void setCreatorConstructor(Constructor<?> paramConstructor)
  397. {
  398. this.creatorConstructor = paramConstructor;
  399. }
  400. public void setDefaultConstructor(Constructor<?> paramConstructor)
  401. {
  402. this.defaultConstructor = paramConstructor;
  403. }
  404. public void setFactoryMethod(Method paramMethod)
  405. {
  406. this.factoryMethod = paramMethod;
  407. }
  408. }
  409. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  410. * Qualified Name: com.alibaba.fastjson.util.DeserializeBeanInfo
  411. * JD-Core Version: 0.6.2
  412. */