PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/core/petra/petra-reflect/src/test/java/com/liferay/petra/reflect/AnnotationLocatorTest.java

http://github.com/liferay/liferay-portal
Java | 899 lines | 568 code | 175 blank | 156 comment | 35 complexity | fe7697a185b845d1c5fe5bb2093a7a99 MD5 | raw file
Possible License(s): LGPL-2.0
  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.petra.reflect;
  15. import com.liferay.petra.string.StringBundler;
  16. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  17. import com.liferay.portal.kernel.test.rule.CodeCoverageAssertor;
  18. import com.liferay.portal.test.rule.LiferayUnitTestRule;
  19. import java.lang.annotation.Annotation;
  20. import java.lang.annotation.ElementType;
  21. import java.lang.annotation.Retention;
  22. import java.lang.annotation.RetentionPolicy;
  23. import java.lang.annotation.Target;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.LinkedList;
  27. import java.util.List;
  28. import java.util.Queue;
  29. import org.junit.Assert;
  30. import org.junit.ClassRule;
  31. import org.junit.Rule;
  32. import org.junit.Test;
  33. /**
  34. * <p>
  35. * <table>
  36. * <tr>
  37. * <th colspan = 3>
  38. * Test Classes Inherited Hierarchy
  39. * </th>
  40. * </tr>
  41. * <tr valign="top">
  42. * <td>
  43. * <pre>
  44. * &#64;Type(value = 5)
  45. * OriginClass { -------->
  46. * &#64;Method(value = 5)
  47. * &#64;Mix(value = 5)
  48. * originMethod1()
  49. * originMethod2()
  50. * }
  51. * </pre></td>
  52. * <td>
  53. * <pre>
  54. * &#64;Mix(value = 8)
  55. * OriginInterface2 { -------->
  56. * &#64;Method(value = 8)
  57. * originMethod2()
  58. * }
  59. * </pre></td>
  60. * <td>
  61. * <pre>
  62. * &#64;Type(value = 9)
  63. * OriginInterface1 {
  64. * &#64;Method(value = 9)
  65. * &#64;Mix(value = 9)
  66. * originMethod1()
  67. * }
  68. * </pre></td>
  69. * </tr>
  70. * <tr valign="top">
  71. * <td>
  72. * <pre>
  73. * ^
  74. * |
  75. * </pre></td>
  76. * <td>
  77. * <pre>
  78. * </pre></td>
  79. * <td>
  80. * <pre>
  81. * ^
  82. * |
  83. * </pre></td>
  84. * </tr>
  85. * <tr valign="top">
  86. * <td>
  87. * <pre>
  88. * &#64;Mix(value = 2)
  89. * SuperClass { -------->
  90. * &#64;Method(value = 2)
  91. * originMethod2()
  92. * &#64;Method(value = 2)
  93. * superMethod1()
  94. * superMethod2()
  95. * }
  96. * </pre></td>
  97. * <td>
  98. * <pre>
  99. * &#64;Type(value = 6)
  100. * SuperInterface2 { -------->
  101. * &#64;Method(value = 6)
  102. * &#64;Mix(value = 6)
  103. * originMethod1()
  104. * &#64;Method(value = 6)
  105. * &#64;Mix(value = 6)
  106. * superMethod2()
  107. * }
  108. * </pre></td>
  109. * <td>
  110. * <pre>
  111. * &#64;Mix(value = 7)
  112. * SuperInterface1 {
  113. * &#64;Method(value = 7)
  114. * superMethod1()
  115. * }
  116. * </pre></td>
  117. * </tr>
  118. * <tr valign="top">
  119. * <td>
  120. * <pre>
  121. * ^
  122. * |
  123. * </pre></td>
  124. * <td>
  125. * <pre>
  126. * ^
  127. * |
  128. * </pre></td>
  129. * <td>
  130. * <pre>
  131. * </pre></td>
  132. * </tr>
  133. * <tr valign="top">
  134. * <td>
  135. * <pre>
  136. * &#64;Type(value = 1)
  137. * TestClass { -------->
  138. * &#64;Method(value = 1)
  139. * &#64;Method(value = 1)
  140. * &#64;Mix(value = 1)
  141. * originMethod1()
  142. * &#64;Method(value = 1)
  143. * &#64;Mix(value = 1)
  144. * superMethod2()
  145. * &#64;Method(value = 1)
  146. * &#64;Mix(value = 1)
  147. * testMethod1()
  148. * testMethod2()
  149. * }
  150. * </pre></td>
  151. * <td>
  152. * <pre>
  153. * &#64;Mix(value = 3)
  154. * TestInterface2 { -------->
  155. * &#64;Method(value = 3)
  156. * superMethod1()
  157. * &#64;Method(value = 3)
  158. * testMethod2()
  159. * }
  160. * </pre></td>
  161. * <td>
  162. * <pre>
  163. * &#64;Type(value = 4)
  164. * TestInterface1 {
  165. * &#64;Method(value = 4)
  166. * &#64;Mix(value = 4)
  167. * testMethod1()
  168. * }
  169. * </pre></td>
  170. * </tr>
  171. * </table>
  172. * </p>
  173. *
  174. * @author Shuyang Zhou
  175. */
  176. public class AnnotationLocatorTest {
  177. @ClassRule
  178. @Rule
  179. public static final AggregateTestRule aggregateTestRule =
  180. new AggregateTestRule(
  181. CodeCoverageAssertor.INSTANCE, LiferayUnitTestRule.INSTANCE);
  182. @Test
  183. public void testClassListLocate() {
  184. _classListLocate(TestClass.class, Arrays.asList(_type(1), _mix(2)));
  185. _classListLocate(SuperClass.class, Arrays.asList(_mix(2), _type(5)));
  186. _classListLocate(
  187. TestInterface2.class, Arrays.asList(_mix(3), _type(4)));
  188. _classListLocate(TestInterface1.class, Arrays.asList(_type(4)));
  189. _classListLocate(OriginClass.class, Arrays.asList(_type(5), _mix(8)));
  190. _classListLocate(
  191. SuperInterface2.class, Arrays.asList(_type(6), _mix(7)));
  192. _classListLocate(
  193. SuperInterface1.class, Arrays.asList(_mix(7), _type(9)));
  194. _classListLocate(
  195. OriginInterface2.class, Arrays.asList(_mix(8), _type(9)));
  196. _classListLocate(OriginInterface1.class, Arrays.asList(_type(9)));
  197. }
  198. @Test
  199. public void testClassSingleLocate() {
  200. _classSingleLocate(TestClass.class, 2, 1);
  201. _classSingleLocate(SuperClass.class, 2, 5);
  202. _classSingleLocate(TestInterface2.class, 3, 4);
  203. _classSingleLocate(TestInterface1.class, -1, 4);
  204. _classSingleLocate(OriginClass.class, 8, 5);
  205. _classSingleLocate(SuperInterface2.class, 7, 6);
  206. _classSingleLocate(SuperInterface1.class, 7, 9);
  207. _classSingleLocate(OriginInterface2.class, 8, 9);
  208. _classSingleLocate(OriginInterface1.class, -1, 9);
  209. }
  210. @Test
  211. public void testConstructor() {
  212. new AnnotationLocator();
  213. }
  214. @Test
  215. public void testInheritedHierarchyWalking() throws Exception {
  216. List<Class<?>> expectedClassHierarchy = Arrays.asList(
  217. TestClass.class, SuperClass.class, TestInterface2.class,
  218. TestInterface1.class, OriginClass.class, SuperInterface2.class,
  219. SuperInterface1.class, OriginInterface2.class,
  220. OriginInterface1.class);
  221. List<Class<?>> actualClassHierarchy = new ArrayList<>();
  222. Queue<Class<?>> queue = new LinkedList<>();
  223. queue.offer(TestClass.class);
  224. Class<?> clazz = null;
  225. while ((clazz = queue.poll()) != null) {
  226. actualClassHierarchy.add(clazz);
  227. _QUEUE_SUPER_TYPES_METHOD.invoke(null, queue, clazz);
  228. }
  229. Assert.assertEquals(expectedClassHierarchy, actualClassHierarchy);
  230. }
  231. @Test
  232. public void testMethodListLocate() {
  233. _methodListLocate(
  234. TestClass.class,
  235. Arrays.asList(
  236. new Annotation[] {_method(1), _mix(1), _type(1)},
  237. new Annotation[] {_type(1), _method(2), _mix(2)},
  238. new Annotation[] {_type(1), _method(2), _mix(2)},
  239. new Annotation[] {_method(1), _mix(1), _type(1)},
  240. new Annotation[] {_method(1), _mix(1), _type(1)},
  241. new Annotation[] {_type(1), _method(3), _mix(3)}));
  242. _methodListLocate(
  243. SuperClass.class,
  244. Arrays.asList(
  245. new Annotation[] {_mix(2), _method(5), _type(5)},
  246. new Annotation[] {_method(2), _mix(2), _type(5)},
  247. new Annotation[] {_method(2), _mix(2), _type(6)},
  248. new Annotation[] {_mix(2), _method(6), _type(6)},
  249. new Annotation[0], new Annotation[0]));
  250. _methodListLocate(
  251. TestInterface2.class,
  252. Arrays.asList(
  253. new Annotation[] {_mix(3), _method(6), _type(6)},
  254. new Annotation[0],
  255. new Annotation[] {_method(3), _mix(3), _type(6)},
  256. new Annotation[] {_mix(3), _method(6), _type(6)},
  257. new Annotation[] {_mix(3), _method(4), _type(4)},
  258. new Annotation[] {_method(3), _mix(3)}));
  259. _methodListLocate(
  260. TestInterface1.class,
  261. Arrays.asList(
  262. new Annotation[0], new Annotation[0], new Annotation[0],
  263. new Annotation[0],
  264. new Annotation[] {_method(4), _mix(4), _type(4)},
  265. new Annotation[0]));
  266. _methodListLocate(
  267. OriginClass.class,
  268. Arrays.asList(
  269. new Annotation[] {_method(5), _mix(5), _type(5)},
  270. new Annotation[] {_type(5), _method(8), _mix(8)},
  271. new Annotation[0], new Annotation[0], new Annotation[0],
  272. new Annotation[0]));
  273. _methodListLocate(
  274. SuperInterface2.class,
  275. Arrays.asList(
  276. new Annotation[] {_method(6), _mix(6), _type(6)},
  277. new Annotation[0],
  278. new Annotation[] {_type(6), _method(7), _mix(7)},
  279. new Annotation[] {_method(6), _mix(6), _type(6)},
  280. new Annotation[0], new Annotation[0]));
  281. _methodListLocate(
  282. SuperInterface1.class,
  283. Arrays.asList(
  284. new Annotation[] {_mix(7), _method(9), _type(9)},
  285. new Annotation[0], new Annotation[] {_method(7), _mix(7)},
  286. new Annotation[0], new Annotation[0], new Annotation[0]));
  287. _methodListLocate(
  288. OriginInterface2.class,
  289. Arrays.asList(
  290. new Annotation[] {_mix(8), _method(9), _type(9)},
  291. new Annotation[] {_method(8), _mix(8)}, new Annotation[0],
  292. new Annotation[0], new Annotation[0], new Annotation[0]));
  293. _methodListLocate(
  294. OriginInterface1.class,
  295. Arrays.asList(
  296. new Annotation[] {_method(9), _mix(9), _type(9)},
  297. new Annotation[0], new Annotation[0], new Annotation[0],
  298. new Annotation[0], new Annotation[0]));
  299. }
  300. @Test
  301. public void testMethodSingleLocate() {
  302. _methodSingleLocate(
  303. TestClass.class, new int[] {1, 2, 2, 1, 1, 3},
  304. new int[] {1, 2, 2, 1, 1, 3}, new int[] {1, 1, 1, 1, 1, 1});
  305. _methodSingleLocate(
  306. SuperClass.class, new int[] {5, 2, 2, 6, -1, -1},
  307. new int[] {2, 2, 2, 2, -1, -1}, new int[] {5, 5, 6, 6, -1, -1});
  308. _methodSingleLocate(
  309. TestInterface2.class, new int[] {6, -1, 3, 6, 4, 3},
  310. new int[] {3, -1, 3, 3, 3, 3}, new int[] {6, -1, 6, 6, 4, -1});
  311. _methodSingleLocate(
  312. TestInterface1.class, new int[] {-1, -1, -1, -1, 4, -1},
  313. new int[] {-1, -1, -1, -1, 4, -1},
  314. new int[] {-1, -1, -1, -1, 4, -1});
  315. _methodSingleLocate(
  316. OriginClass.class, new int[] {5, 8, -1, -1, -1, -1},
  317. new int[] {5, 8, -1, -1, -1, -1}, new int[] {5, 5, -1, -1, -1, -1});
  318. _methodSingleLocate(
  319. SuperInterface2.class, new int[] {6, -1, 7, 6, -1, -1},
  320. new int[] {6, -1, 7, 6, -1, -1}, new int[] {6, -1, 6, 6, -1, -1});
  321. _methodSingleLocate(
  322. SuperInterface1.class, new int[] {9, -1, 7, -1, -1, -1},
  323. new int[] {7, -1, 7, -1, -1, -1},
  324. new int[] {9, -1, -1, -1, -1, -1});
  325. _methodSingleLocate(
  326. OriginInterface2.class, new int[] {9, 8, -1, -1, -1, -1},
  327. new int[] {8, 8, -1, -1, -1, -1},
  328. new int[] {9, -1, -1, -1, -1, -1});
  329. _methodSingleLocate(
  330. OriginInterface1.class, new int[] {9, -1, -1, -1, -1, -1},
  331. new int[] {9, -1, -1, -1, -1, -1},
  332. new int[] {9, -1, -1, -1, -1, -1});
  333. }
  334. private void _classListLocate(
  335. Class<?> clazz, List<? extends Annotation> expectedAnnotations) {
  336. List<Annotation> actualAnnotations = AnnotationLocator.locate(clazz);
  337. Assert.assertEquals(
  338. clazz.getName(), expectedAnnotations.size(),
  339. actualAnnotations.size());
  340. for (int i = 0; i < expectedAnnotations.size(); i++) {
  341. Annotation expectedAnnotation = expectedAnnotations.get(i);
  342. Annotation actualAnnotation = actualAnnotations.get(i);
  343. Assert.assertEquals(
  344. clazz.getName(), expectedAnnotation.annotationType(),
  345. actualAnnotation.annotationType());
  346. if (expectedAnnotation.annotationType() == Mix.class) {
  347. Mix expectedMix = (Mix)expectedAnnotation;
  348. Mix actualMix = (Mix)actualAnnotation;
  349. Assert.assertEquals(
  350. "@Mix : " + clazz.getName(), expectedMix.value(),
  351. actualMix.value());
  352. }
  353. else {
  354. Type expectedType = (Type)expectedAnnotation;
  355. Type actualType = (Type)actualAnnotation;
  356. Assert.assertEquals(
  357. "@Type : ", expectedType.value(), actualType.value());
  358. }
  359. }
  360. }
  361. private void _classSingleLocate(
  362. Class<?> clazz, int expectedMixValue, int expectedTypeValue) {
  363. Mix actualMix = AnnotationLocator.locate(clazz, Mix.class);
  364. if (expectedMixValue == -1) {
  365. Assert.assertNull("@Mix : " + clazz.getName(), actualMix);
  366. }
  367. else {
  368. Assert.assertEquals(
  369. "@Mix : " + clazz.getName(), expectedMixValue,
  370. actualMix.value());
  371. }
  372. Type actualType = AnnotationLocator.locate(clazz, Type.class);
  373. if (expectedTypeValue == -1) {
  374. Assert.assertNull("@Type : " + clazz.getName(), actualType);
  375. }
  376. else {
  377. Assert.assertEquals(
  378. "@Type : " + clazz.getName(), expectedTypeValue,
  379. actualType.value());
  380. }
  381. }
  382. private Method _method(final int value) {
  383. return new Method() {
  384. @Override
  385. public Class<? extends Annotation> annotationType() {
  386. return Method.class;
  387. }
  388. @Override
  389. public int value() {
  390. return value;
  391. }
  392. };
  393. }
  394. private void _methodListLocate(
  395. Class<?> clazz, List<Annotation[]> expectedAnnotationsList) {
  396. for (int i = 0; i < _interfaceMethods.length; i++) {
  397. Annotation[] expectedAnnotations = expectedAnnotationsList.get(i);
  398. java.lang.reflect.Method method = _interfaceMethods[i];
  399. List<Annotation> actualAnnotations = AnnotationLocator.locate(
  400. method, clazz);
  401. Assert.assertEquals(
  402. method.getName() + "()@" + clazz.getName(),
  403. expectedAnnotations.length, actualAnnotations.size());
  404. for (int j = 0; j < expectedAnnotations.length; j++) {
  405. Annotation expectedAnnotation = expectedAnnotations[j];
  406. Annotation actualAnnotation = actualAnnotations.get(j);
  407. Assert.assertEquals(
  408. method.getName() + "()@" + clazz.getName(),
  409. expectedAnnotation.annotationType(),
  410. actualAnnotation.annotationType());
  411. if (expectedAnnotation.annotationType() == Mix.class) {
  412. Mix expectedMix = (Mix)expectedAnnotation;
  413. Mix actualMix = (Mix)actualAnnotation;
  414. Assert.assertEquals(
  415. StringBundler.concat(
  416. "@Mix : ", method.getName(), "()@",
  417. clazz.getName()),
  418. expectedMix.value(), actualMix.value());
  419. }
  420. else if (expectedAnnotation.annotationType() == Method.class) {
  421. Method expectedType = (Method)expectedAnnotation;
  422. Method actualMethod = (Method)actualAnnotation;
  423. Assert.assertEquals(
  424. StringBundler.concat(
  425. "@Method : ", method.getName(), "()@",
  426. clazz.getName()),
  427. expectedType.value(), actualMethod.value());
  428. }
  429. else {
  430. Type expectedType = (Type)expectedAnnotation;
  431. Type actualType = (Type)actualAnnotation;
  432. Assert.assertEquals(
  433. StringBundler.concat(
  434. "@Type : ", method.getName(), "()@",
  435. clazz.getName()),
  436. expectedType.value(), actualType.value());
  437. }
  438. }
  439. try {
  440. method = clazz.getDeclaredMethod(
  441. method.getName(), method.getParameterTypes());
  442. actualAnnotations = AnnotationLocator.locate(method, null);
  443. Assert.assertEquals(
  444. method.getName() + "()@" + clazz.getName(),
  445. expectedAnnotations.length, actualAnnotations.size());
  446. for (int j = 0; j < expectedAnnotations.length; j++) {
  447. Annotation expectedAnnotation = expectedAnnotations[j];
  448. Annotation actualAnnotation = actualAnnotations.get(j);
  449. Assert.assertEquals(
  450. method.getName() + "()@" + clazz.getName(),
  451. expectedAnnotation.annotationType(),
  452. actualAnnotation.annotationType());
  453. if (expectedAnnotation.annotationType() == Mix.class) {
  454. Mix expectedMix = (Mix)expectedAnnotation;
  455. Mix actualMix = (Mix)actualAnnotation;
  456. Assert.assertEquals(
  457. StringBundler.concat(
  458. "@Mix : ", method.getName(), "()@",
  459. clazz.getName()),
  460. expectedMix.value(), actualMix.value());
  461. }
  462. else if (expectedAnnotation.annotationType() ==
  463. Method.class) {
  464. Method expectedType = (Method)expectedAnnotation;
  465. Method actualMethod = (Method)actualAnnotation;
  466. Assert.assertEquals(
  467. StringBundler.concat(
  468. "@Method : ", method.getName(), "()@",
  469. clazz.getName()),
  470. expectedType.value(), actualMethod.value());
  471. }
  472. else {
  473. Type expectedType = (Type)expectedAnnotation;
  474. Type actualType = (Type)actualAnnotation;
  475. Assert.assertEquals(
  476. StringBundler.concat(
  477. "@Type : ", method.getName(), "()@",
  478. clazz.getName()),
  479. expectedType.value(), actualType.value());
  480. }
  481. }
  482. }
  483. catch (Exception exception) {
  484. }
  485. }
  486. }
  487. private void _methodSingleLocate(
  488. Class<?> clazz, int[] expectedMethodValues, int[] expectedMixValues,
  489. int[] expectedTypeValues) {
  490. for (int i = 0; i < 6; i++) {
  491. java.lang.reflect.Method method = _interfaceMethods[i];
  492. int expectedMethodValue = expectedMethodValues[i];
  493. Method methodAnnotation = AnnotationLocator.locate(
  494. method, clazz, Method.class);
  495. if (methodAnnotation == null) {
  496. Assert.assertEquals(
  497. "@Method : " + clazz.getName(), -1, expectedMethodValue);
  498. continue;
  499. }
  500. Assert.assertEquals(
  501. StringBundler.concat(
  502. "@Method : ", method.getName(), "()@", clazz.getName()),
  503. expectedMethodValue, methodAnnotation.value());
  504. try {
  505. method = clazz.getDeclaredMethod(
  506. method.getName(), method.getParameterTypes());
  507. methodAnnotation = AnnotationLocator.locate(
  508. method, null, Method.class);
  509. Assert.assertEquals(
  510. method.getName() + "()@" + clazz.getName(),
  511. expectedMethodValue, methodAnnotation.value());
  512. }
  513. catch (Exception exception) {
  514. }
  515. }
  516. for (int i = 0; i < 6; i++) {
  517. java.lang.reflect.Method method = _interfaceMethods[i];
  518. int expectedMixValue = expectedMixValues[i];
  519. Mix mixAnnotation = AnnotationLocator.locate(
  520. method, clazz, Mix.class);
  521. if (mixAnnotation == null) {
  522. Assert.assertEquals(
  523. "@Mix : " + clazz.getName(), -1, expectedMixValue);
  524. continue;
  525. }
  526. Assert.assertEquals(
  527. StringBundler.concat(
  528. "@Mix : ", method.getName(), "()@", clazz.getName()),
  529. expectedMixValue, mixAnnotation.value());
  530. try {
  531. method = clazz.getDeclaredMethod(
  532. method.getName(), method.getParameterTypes());
  533. mixAnnotation = AnnotationLocator.locate(
  534. method, null, Mix.class);
  535. Assert.assertEquals(
  536. method.getName() + "()@" + clazz.getName(),
  537. expectedMixValue, mixAnnotation.value());
  538. }
  539. catch (Exception exception) {
  540. }
  541. }
  542. for (int i = 0; i < 6; i++) {
  543. java.lang.reflect.Method method = _interfaceMethods[i];
  544. int expectedTypeValue = expectedTypeValues[i];
  545. Type typeAnnotation = AnnotationLocator.locate(
  546. method, clazz, Type.class);
  547. if (typeAnnotation == null) {
  548. Assert.assertEquals(
  549. "@Type : " + clazz.getName(), -1, expectedTypeValue);
  550. continue;
  551. }
  552. Assert.assertEquals(
  553. StringBundler.concat(
  554. "@Type : ", method.getName(), "()@", clazz.getName()),
  555. expectedTypeValue, typeAnnotation.value());
  556. try {
  557. method = clazz.getDeclaredMethod(
  558. method.getName(), method.getParameterTypes());
  559. typeAnnotation = AnnotationLocator.locate(
  560. method, null, Type.class);
  561. Assert.assertEquals(
  562. method.getName() + "()@" + clazz.getName(),
  563. expectedTypeValue, typeAnnotation.value());
  564. }
  565. catch (Exception exception) {
  566. }
  567. }
  568. }
  569. private Mix _mix(final int value) {
  570. return new Mix() {
  571. @Override
  572. public Class<? extends Annotation> annotationType() {
  573. return Mix.class;
  574. }
  575. @Override
  576. public int value() {
  577. return value;
  578. }
  579. };
  580. }
  581. private Type _type(final int value) {
  582. return new Type() {
  583. @Override
  584. public Class<? extends Annotation> annotationType() {
  585. return Type.class;
  586. }
  587. @Override
  588. public int value() {
  589. return value;
  590. }
  591. };
  592. }
  593. private static final java.lang.reflect.Method _QUEUE_SUPER_TYPES_METHOD;
  594. private static final java.lang.reflect.Method[] _interfaceMethods;
  595. static {
  596. try {
  597. _interfaceMethods = new java.lang.reflect.Method[6];
  598. _interfaceMethods[0] = OriginInterface1.class.getDeclaredMethod(
  599. "originMethod1");
  600. _interfaceMethods[1] = OriginInterface2.class.getDeclaredMethod(
  601. "originMethod2");
  602. _interfaceMethods[2] = SuperInterface1.class.getDeclaredMethod(
  603. "superMethod1");
  604. _interfaceMethods[3] = SuperInterface2.class.getDeclaredMethod(
  605. "superMethod2");
  606. _interfaceMethods[4] = TestInterface1.class.getDeclaredMethod(
  607. "testMethod1");
  608. _interfaceMethods[5] = TestInterface2.class.getDeclaredMethod(
  609. "testMethod2");
  610. java.lang.reflect.Method queueSuperTypesMethod =
  611. AnnotationLocator.class.getDeclaredMethod(
  612. "_queueSuperTypes", Queue.class, Class.class);
  613. queueSuperTypesMethod.setAccessible(true);
  614. _QUEUE_SUPER_TYPES_METHOD = queueSuperTypesMethod;
  615. }
  616. catch (Exception exception) {
  617. throw new ExceptionInInitializerError(exception);
  618. }
  619. }
  620. @Type(value = 5)
  621. private static class OriginClass
  622. implements OriginInterface2, OriginInterface1 {
  623. @Method(value = 5)
  624. @Mix(value = 5)
  625. @Override
  626. public void originMethod1() {
  627. }
  628. @Override
  629. public void originMethod2() {
  630. }
  631. }
  632. @Mix(value = 2)
  633. private static class SuperClass
  634. extends OriginClass implements SuperInterface2, SuperInterface1 {
  635. @Method(value = 2)
  636. @Override
  637. public void originMethod2() {
  638. }
  639. @Method(value = 2)
  640. @Override
  641. public void superMethod1() {
  642. }
  643. @Override
  644. public void superMethod2() {
  645. }
  646. }
  647. @Type(value = 1)
  648. private static class TestClass
  649. extends SuperClass implements TestInterface2, TestInterface1 {
  650. @Method(value = 1)
  651. @Mix(value = 1)
  652. @Override
  653. public void originMethod1() {
  654. }
  655. @Method(value = 1)
  656. @Mix(value = 1)
  657. @Override
  658. public void superMethod2() {
  659. }
  660. @Method(value = 1)
  661. @Mix(value = 1)
  662. @Override
  663. public void testMethod1() {
  664. }
  665. @Override
  666. public void testMethod2() {
  667. }
  668. }
  669. @Retention(RetentionPolicy.RUNTIME)
  670. @Target(ElementType.METHOD)
  671. private @interface Method {
  672. public int value();
  673. }
  674. @Retention(RetentionPolicy.RUNTIME)
  675. @Target({ElementType.METHOD, ElementType.TYPE})
  676. private @interface Mix {
  677. public int value();
  678. }
  679. @Type(value = 9)
  680. private interface OriginInterface1 {
  681. @Method(value = 9)
  682. @Mix(value = 9)
  683. public void originMethod1();
  684. }
  685. @Mix(value = 8)
  686. private interface OriginInterface2 extends OriginInterface1 {
  687. @Method(value = 8)
  688. public void originMethod2();
  689. }
  690. @Mix(value = 7)
  691. private interface SuperInterface1 extends OriginInterface1 {
  692. @Method(value = 7)
  693. void superMethod1();
  694. }
  695. @Type(value = 6)
  696. private interface SuperInterface2 extends SuperInterface1 {
  697. @Method(value = 6)
  698. @Mix(value = 6)
  699. @Override
  700. void originMethod1();
  701. @Method(value = 6)
  702. @Mix(value = 6)
  703. void superMethod2();
  704. }
  705. @Type(value = 4)
  706. private interface TestInterface1 {
  707. @Method(value = 4)
  708. @Mix(value = 4)
  709. public void testMethod1();
  710. }
  711. @Mix(value = 3)
  712. private interface TestInterface2 extends TestInterface1, SuperInterface2 {
  713. @Method(value = 3)
  714. @Override
  715. public void superMethod1();
  716. @Method(value = 3)
  717. public void testMethod2();
  718. }
  719. @Retention(RetentionPolicy.RUNTIME)
  720. @Target(ElementType.TYPE)
  721. private @interface Type {
  722. public int value();
  723. }
  724. }