You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectorBundle.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.widgetsetutils.metadata;
  17. import java.io.Serializable;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. import java.util.Collections;
  21. import java.util.HashMap;
  22. import java.util.HashSet;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Set;
  27. import com.google.gwt.core.ext.TreeLogger;
  28. import com.google.gwt.core.ext.TreeLogger.Type;
  29. import com.google.gwt.core.ext.UnableToCompleteException;
  30. import com.google.gwt.core.ext.typeinfo.JArrayType;
  31. import com.google.gwt.core.ext.typeinfo.JClassType;
  32. import com.google.gwt.core.ext.typeinfo.JEnumType;
  33. import com.google.gwt.core.ext.typeinfo.JMethod;
  34. import com.google.gwt.core.ext.typeinfo.JParameterizedType;
  35. import com.google.gwt.core.ext.typeinfo.JType;
  36. import com.google.gwt.core.ext.typeinfo.NotFoundException;
  37. import com.google.gwt.core.ext.typeinfo.TypeOracle;
  38. import com.google.gwt.json.client.JSONValue;
  39. import com.vaadin.client.ApplicationConnection;
  40. import com.vaadin.client.ComponentConnector;
  41. import com.vaadin.client.ServerConnector;
  42. import com.vaadin.client.communication.JSONSerializer;
  43. import com.vaadin.client.ui.UnknownComponentConnector;
  44. import com.vaadin.client.ui.grid.renderers.AbstractRendererConnector;
  45. import com.vaadin.shared.communication.ClientRpc;
  46. import com.vaadin.shared.communication.ServerRpc;
  47. import com.vaadin.shared.ui.Connect;
  48. public class ConnectorBundle {
  49. private static final String FAIL_IF_NOT_SERIALIZABLE = "vFailIfNotSerializable";
  50. private final String name;
  51. private final ConnectorBundle previousBundle;
  52. private final Collection<TypeVisitor> visitors;
  53. private final Map<JType, JClassType> customSerializers;
  54. private final Set<JType> hasSerializeSupport = new HashSet<JType>();
  55. private final Set<JType> needsSerializeSupport = new HashSet<JType>();
  56. private final Map<JType, GeneratedSerializer> serializers = new HashMap<JType, GeneratedSerializer>();
  57. private final Map<JClassType, JType> presentationTypes = new HashMap<JClassType, JType>();
  58. private final Set<JClassType> needsSuperClass = new HashSet<JClassType>();
  59. private final Set<JClassType> needsGwtConstructor = new HashSet<JClassType>();
  60. private final Set<JClassType> visitedTypes = new HashSet<JClassType>();
  61. private final Set<JClassType> needsProxySupport = new HashSet<JClassType>();
  62. private final Map<JClassType, Set<String>> identifiers = new HashMap<JClassType, Set<String>>();
  63. private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>();
  64. private final Map<JClassType, Set<JMethod>> needsInvoker = new HashMap<JClassType, Set<JMethod>>();
  65. private final Map<JClassType, Set<JMethod>> needsParamTypes = new HashMap<JClassType, Set<JMethod>>();
  66. private final Map<JClassType, Set<JMethod>> needsDelayedInfo = new HashMap<JClassType, Set<JMethod>>();
  67. private final Map<JClassType, Set<JMethod>> needsOnStateChange = new HashMap<JClassType, Set<JMethod>>();
  68. private final Set<Property> needsProperty = new HashSet<Property>();
  69. private final Set<Property> needsDelegateToWidget = new HashSet<Property>();
  70. private ConnectorBundle(String name, ConnectorBundle previousBundle,
  71. Collection<TypeVisitor> visitors,
  72. Map<JType, JClassType> customSerializers) {
  73. this.name = name;
  74. this.previousBundle = previousBundle;
  75. this.visitors = visitors;
  76. this.customSerializers = customSerializers;
  77. }
  78. public ConnectorBundle(String name, ConnectorBundle previousBundle) {
  79. this(name, previousBundle, previousBundle.visitors,
  80. previousBundle.customSerializers);
  81. }
  82. public ConnectorBundle(String name, Collection<TypeVisitor> visitors,
  83. TypeOracle oracle) throws NotFoundException {
  84. this(name, null, visitors, findCustomSerializers(oracle));
  85. }
  86. private static Map<JType, JClassType> findCustomSerializers(
  87. TypeOracle oracle) throws NotFoundException {
  88. Map<JType, JClassType> serializers = new HashMap<JType, JClassType>();
  89. JClassType serializerInterface = oracle.findType(JSONSerializer.class
  90. .getName());
  91. JType[] deserializeParamTypes = new JType[] {
  92. oracle.findType(com.vaadin.client.metadata.Type.class.getName()),
  93. oracle.findType(JSONValue.class.getName()),
  94. oracle.findType(ApplicationConnection.class.getName()) };
  95. String deserializeMethodName = "deserialize";
  96. // Just test that the method exists
  97. serializerInterface.getMethod(deserializeMethodName,
  98. deserializeParamTypes);
  99. for (JClassType serializer : serializerInterface.getSubtypes()) {
  100. JMethod deserializeMethod = serializer.findMethod(
  101. deserializeMethodName, deserializeParamTypes);
  102. if (deserializeMethod == null) {
  103. continue;
  104. }
  105. JType returnType = deserializeMethod.getReturnType();
  106. serializers.put(returnType, serializer);
  107. }
  108. return serializers;
  109. }
  110. public void setNeedsGwtConstructor(JClassType type) {
  111. if (!needsGwtConstructor(type)) {
  112. needsGwtConstructor.add(type);
  113. }
  114. }
  115. private boolean needsGwtConstructor(JClassType type) {
  116. if (needsGwtConstructor.contains(type)) {
  117. return true;
  118. } else {
  119. return previousBundle != null
  120. && previousBundle.needsGwtConstructor(type);
  121. }
  122. }
  123. public void setIdentifier(JClassType type, String identifier) {
  124. if (!hasIdentifier(type, identifier)) {
  125. addMapping(identifiers, type, identifier);
  126. }
  127. }
  128. private boolean hasIdentifier(JClassType type, String identifier) {
  129. if (hasMapping(identifiers, type, identifier)) {
  130. return true;
  131. } else {
  132. return previousBundle != null
  133. && previousBundle.hasIdentifier(type, identifier);
  134. }
  135. }
  136. public ConnectorBundle getPreviousBundle() {
  137. return previousBundle;
  138. }
  139. public String getName() {
  140. return name;
  141. }
  142. public Map<JClassType, Set<String>> getIdentifiers() {
  143. return Collections.unmodifiableMap(identifiers);
  144. }
  145. public Set<JClassType> getGwtConstructors() {
  146. return Collections.unmodifiableSet(needsGwtConstructor);
  147. }
  148. public void processTypes(TreeLogger logger, Collection<JClassType> types)
  149. throws UnableToCompleteException {
  150. for (JClassType type : types) {
  151. processType(logger, type);
  152. }
  153. }
  154. public void processType(TreeLogger logger, JClassType type)
  155. throws UnableToCompleteException {
  156. if (!isTypeVisited(type)) {
  157. for (TypeVisitor typeVisitor : visitors) {
  158. invokeVisitor(logger, type, typeVisitor);
  159. }
  160. visitedTypes.add(type);
  161. purgeSerializeSupportQueue(logger);
  162. }
  163. }
  164. private boolean isTypeVisited(JClassType type) {
  165. if (visitedTypes.contains(type)) {
  166. return true;
  167. } else {
  168. return previousBundle != null && previousBundle.isTypeVisited(type);
  169. }
  170. }
  171. private void purgeSerializeSupportQueue(TreeLogger logger)
  172. throws UnableToCompleteException {
  173. while (!needsSerializeSupport.isEmpty()) {
  174. Iterator<JType> iterator = needsSerializeSupport.iterator();
  175. JType type = iterator.next();
  176. iterator.remove();
  177. if (hasSerializeSupport(type)) {
  178. continue;
  179. }
  180. addSerializeSupport(logger, type);
  181. }
  182. }
  183. private void addSerializeSupport(TreeLogger logger, JType type)
  184. throws UnableToCompleteException {
  185. hasSerializeSupport.add(type);
  186. JParameterizedType parametrized = type.isParameterized();
  187. if (parametrized != null) {
  188. for (JClassType parameterType : parametrized.getTypeArgs()) {
  189. setNeedsSerialize(parameterType);
  190. }
  191. }
  192. if (serializationHandledByFramework(type)) {
  193. return;
  194. }
  195. JClassType customSerializer = customSerializers.get(type);
  196. JClassType typeAsClass = type.isClass();
  197. JEnumType enumType = type.isEnum();
  198. JArrayType arrayType = type.isArray();
  199. if (customSerializer != null) {
  200. logger.log(Type.INFO, "Will serialize " + type + " using "
  201. + customSerializer.getName());
  202. setSerializer(type, new CustomSerializer(customSerializer));
  203. } else if (arrayType != null) {
  204. logger.log(Type.INFO, "Will serialize " + type + " as an array");
  205. setSerializer(type, new ArraySerializer(arrayType));
  206. setNeedsSerialize(arrayType.getComponentType());
  207. } else if (enumType != null) {
  208. logger.log(Type.INFO, "Will serialize " + type + " as an enum");
  209. setSerializer(type, new EnumSerializer(enumType));
  210. } else if (typeAsClass != null) {
  211. // Bean
  212. checkSerializable(logger, typeAsClass);
  213. logger.log(Type.INFO, "Will serialize " + type + " as a bean");
  214. JClassType needsSuperClass = typeAsClass;
  215. while (needsSuperClass != null) {
  216. if (needsSuperClass.isPublic()) {
  217. setNeedsSuperclass(needsSuperClass);
  218. }
  219. needsSuperClass = needsSuperClass.getSuperclass();
  220. }
  221. setNeedsGwtConstructor(typeAsClass);
  222. for (Property property : getProperties(typeAsClass)) {
  223. setNeedsProperty(property);
  224. JType propertyType = property.getPropertyType();
  225. setNeedsSerialize(propertyType);
  226. }
  227. }
  228. }
  229. private void checkSerializable(TreeLogger logger, JClassType type)
  230. throws UnableToCompleteException {
  231. JClassType javaSerializable = type.getOracle().findType(
  232. Serializable.class.getName());
  233. boolean serializable = type.isAssignableTo(javaSerializable);
  234. if (!serializable) {
  235. boolean abortCompile = "true".equals(System
  236. .getProperty(FAIL_IF_NOT_SERIALIZABLE));
  237. logger.log(
  238. abortCompile ? Type.ERROR : Type.WARN,
  239. type
  240. + " is used in RPC or shared state but does not implement "
  241. + Serializable.class.getName()
  242. + ". Communication will work but the Application on server side cannot be serialized if it refers to objects of this type. "
  243. + "If the system property "
  244. + FAIL_IF_NOT_SERIALIZABLE
  245. + " is set to \"true\", this causes the compilation to fail instead of just emitting a warning.");
  246. if (abortCompile) {
  247. throw new UnableToCompleteException();
  248. }
  249. }
  250. }
  251. private void setSerializer(JType type, GeneratedSerializer serializer) {
  252. if (!hasSerializer(type)) {
  253. serializers.put(type, serializer);
  254. }
  255. }
  256. private boolean hasSerializer(JType type) {
  257. if (serializers.containsKey(type)) {
  258. return true;
  259. } else {
  260. return previousBundle != null && previousBundle.hasSerializer(type);
  261. }
  262. }
  263. public Map<JType, GeneratedSerializer> getSerializers() {
  264. return Collections.unmodifiableMap(serializers);
  265. }
  266. public void setPresentationType(JClassType type, JType presentationType) {
  267. if (!hasPresentationType(type)) {
  268. presentationTypes.put(type, presentationType);
  269. }
  270. }
  271. private boolean hasPresentationType(JClassType type) {
  272. if (presentationTypes.containsKey(type)) {
  273. return true;
  274. } else {
  275. return previousBundle != null
  276. && previousBundle.hasPresentationType(type);
  277. }
  278. }
  279. public Map<JClassType, JType> getPresentationTypes() {
  280. return Collections.unmodifiableMap(presentationTypes);
  281. }
  282. private void setNeedsSuperclass(JClassType typeAsClass) {
  283. if (!isNeedsSuperClass(typeAsClass)) {
  284. needsSuperClass.add(typeAsClass);
  285. }
  286. }
  287. private boolean isNeedsSuperClass(JClassType typeAsClass) {
  288. if (needsSuperClass.contains(typeAsClass)) {
  289. return true;
  290. } else {
  291. return previousBundle != null
  292. && previousBundle.isNeedsSuperClass(typeAsClass);
  293. }
  294. }
  295. public Set<JClassType> getNeedsSuperclass() {
  296. return Collections.unmodifiableSet(needsSuperClass);
  297. }
  298. private void setNeedsProperty(Property property) {
  299. if (!isNeedsProperty(property)) {
  300. needsProperty.add(property);
  301. }
  302. }
  303. private boolean isNeedsProperty(Property property) {
  304. if (needsProperty.contains(property)) {
  305. return true;
  306. } else {
  307. return previousBundle != null
  308. && previousBundle.isNeedsProperty(property);
  309. }
  310. }
  311. public Set<Property> getNeedsProperty() {
  312. return Collections.unmodifiableSet(needsProperty);
  313. }
  314. public Collection<Property> getProperties(JClassType type) {
  315. HashSet<Property> properties = new HashSet<Property>();
  316. properties.addAll(MethodProperty.findProperties(type));
  317. properties.addAll(FieldProperty.findProperties(type));
  318. return properties;
  319. }
  320. private void invokeVisitor(TreeLogger logger, JClassType type,
  321. TypeVisitor typeVisitor) throws UnableToCompleteException {
  322. TreeLogger subLogger = logger.branch(Type.TRACE,
  323. "Visiting " + type.getName() + " with "
  324. + typeVisitor.getClass().getSimpleName());
  325. if (isConnectedConnector(type)) {
  326. typeVisitor.visitConnector(subLogger, type, this);
  327. }
  328. if (isClientRpc(type)) {
  329. typeVisitor.visitClientRpc(subLogger, type, this);
  330. }
  331. if (isServerRpc(type)) {
  332. typeVisitor.visitServerRpc(subLogger, type, this);
  333. }
  334. }
  335. public void processSubTypes(TreeLogger logger, JClassType type)
  336. throws UnableToCompleteException {
  337. processTypes(logger, Arrays.asList(type.getSubtypes()));
  338. }
  339. public void setNeedsReturnType(JClassType type, JMethod method) {
  340. if (!isNeedsReturnType(type, method)) {
  341. addMapping(needsReturnType, type, method);
  342. }
  343. }
  344. private boolean isNeedsReturnType(JClassType type, JMethod method) {
  345. if (hasMapping(needsReturnType, type, method)) {
  346. return true;
  347. } else {
  348. return previousBundle != null
  349. && previousBundle.isNeedsReturnType(type, method);
  350. }
  351. }
  352. public Map<JClassType, Set<JMethod>> getMethodReturnTypes() {
  353. return Collections.unmodifiableMap(needsReturnType);
  354. }
  355. private static boolean isClientRpc(JClassType type) {
  356. return isInterfaceType(type, ClientRpc.class);
  357. }
  358. private static boolean isServerRpc(JClassType type) {
  359. return isInterfaceType(type, ServerRpc.class);
  360. }
  361. public static boolean isConnectedConnector(JClassType type) {
  362. return isConnected(type) && isType(type, ServerConnector.class);
  363. }
  364. private static boolean isConnected(JClassType type) {
  365. return type.isAnnotationPresent(Connect.class)
  366. || type.getQualifiedSourceName().equals(
  367. UnknownComponentConnector.class.getCanonicalName());
  368. }
  369. public static boolean isConnectedComponentConnector(JClassType type) {
  370. return isConnected(type) && isType(type, ComponentConnector.class);
  371. }
  372. public static boolean isConnectedRendererConnector(JClassType type) {
  373. return isConnected(type)
  374. && isType(type, AbstractRendererConnector.class);
  375. }
  376. private static boolean isInterfaceType(JClassType type, Class<?> class1) {
  377. return type.isInterface() != null && isType(type, class1);
  378. }
  379. private static boolean isType(JClassType type, Class<?> class1) {
  380. try {
  381. return type.getOracle().getType(class1.getName())
  382. .isAssignableFrom(type);
  383. } catch (NotFoundException e) {
  384. throw new RuntimeException("Could not find " + class1.getName(), e);
  385. }
  386. }
  387. public void setNeedsInvoker(JClassType type, JMethod method) {
  388. if (!isNeedsInvoker(type, method)) {
  389. addMapping(needsInvoker, type, method);
  390. }
  391. }
  392. private <K, V> void addMapping(Map<K, Set<V>> map, K key, V value) {
  393. Set<V> set = map.get(key);
  394. if (set == null) {
  395. set = new HashSet<V>();
  396. map.put(key, set);
  397. }
  398. set.add(value);
  399. }
  400. private <K, V> boolean hasMapping(Map<K, Set<V>> map, K key, V value) {
  401. return map.containsKey(key) && map.get(key).contains(value);
  402. }
  403. private boolean isNeedsInvoker(JClassType type, JMethod method) {
  404. if (hasMapping(needsInvoker, type, method)) {
  405. return true;
  406. } else {
  407. return previousBundle != null
  408. && previousBundle.isNeedsInvoker(type, method);
  409. }
  410. }
  411. public Map<JClassType, Set<JMethod>> getNeedsInvoker() {
  412. return Collections.unmodifiableMap(needsInvoker);
  413. }
  414. public void setNeedsParamTypes(JClassType type, JMethod method) {
  415. if (!isNeedsParamTypes(type, method)) {
  416. addMapping(needsParamTypes, type, method);
  417. }
  418. }
  419. private boolean isNeedsParamTypes(JClassType type, JMethod method) {
  420. if (hasMapping(needsParamTypes, type, method)) {
  421. return true;
  422. } else {
  423. return previousBundle != null
  424. && previousBundle.isNeedsParamTypes(type, method);
  425. }
  426. }
  427. public Map<JClassType, Set<JMethod>> getNeedsParamTypes() {
  428. return Collections.unmodifiableMap(needsParamTypes);
  429. }
  430. public void setNeedsProxySupport(JClassType type) {
  431. if (!isNeedsProxySupport(type)) {
  432. needsProxySupport.add(type);
  433. }
  434. }
  435. private boolean isNeedsProxySupport(JClassType type) {
  436. if (needsProxySupport.contains(type)) {
  437. return true;
  438. } else {
  439. return previousBundle != null
  440. && previousBundle.isNeedsProxySupport(type);
  441. }
  442. }
  443. public Set<JClassType> getNeedsProxySupport() {
  444. return Collections.unmodifiableSet(needsProxySupport);
  445. }
  446. public void setNeedsDelayedInfo(JClassType type, JMethod method) {
  447. if (!isNeedsDelayedInfo(type, method)) {
  448. addMapping(needsDelayedInfo, type, method);
  449. }
  450. }
  451. private boolean isNeedsDelayedInfo(JClassType type, JMethod method) {
  452. if (hasMapping(needsDelayedInfo, type, method)) {
  453. return true;
  454. } else {
  455. return previousBundle != null
  456. && previousBundle.isNeedsDelayedInfo(type, method);
  457. }
  458. }
  459. public Map<JClassType, Set<JMethod>> getNeedsDelayedInfo() {
  460. return Collections.unmodifiableMap(needsDelayedInfo);
  461. }
  462. public void setNeedsSerialize(JType type) {
  463. if (!hasSerializeSupport(type)) {
  464. needsSerializeSupport.add(type);
  465. }
  466. }
  467. private static Set<Class<?>> frameworkHandledTypes = new HashSet<Class<?>>();
  468. {
  469. frameworkHandledTypes.add(String.class);
  470. frameworkHandledTypes.add(Boolean.class);
  471. frameworkHandledTypes.add(Integer.class);
  472. frameworkHandledTypes.add(Float.class);
  473. frameworkHandledTypes.add(Double.class);
  474. frameworkHandledTypes.add(Long.class);
  475. frameworkHandledTypes.add(Enum.class);
  476. frameworkHandledTypes.add(String[].class);
  477. frameworkHandledTypes.add(Object[].class);
  478. frameworkHandledTypes.add(Map.class);
  479. frameworkHandledTypes.add(List.class);
  480. frameworkHandledTypes.add(Set.class);
  481. frameworkHandledTypes.add(Byte.class);
  482. frameworkHandledTypes.add(Character.class);
  483. }
  484. private boolean serializationHandledByFramework(JType setterType) {
  485. // Some types are handled by the framework at the moment. See #8449
  486. // This method should be removed at some point.
  487. if (setterType.isPrimitive() != null) {
  488. return true;
  489. }
  490. String qualifiedName = setterType.getQualifiedSourceName();
  491. for (Class<?> cls : frameworkHandledTypes) {
  492. if (qualifiedName.equals(cls.getName())) {
  493. return true;
  494. }
  495. }
  496. return false;
  497. }
  498. private boolean hasSerializeSupport(JType type) {
  499. if (hasSerializeSupport.contains(type)) {
  500. return true;
  501. } else {
  502. return previousBundle != null
  503. && previousBundle.hasSerializeSupport(type);
  504. }
  505. }
  506. public void setNeedsDelegateToWidget(Property property) {
  507. if (!isNeedsDelegateToWidget(property)) {
  508. needsDelegateToWidget.add(property);
  509. }
  510. }
  511. private boolean isNeedsDelegateToWidget(Property property) {
  512. if (needsDelegateToWidget.contains(property)) {
  513. return true;
  514. } else {
  515. return previousBundle != null
  516. && previousBundle.isNeedsDelegateToWidget(property);
  517. }
  518. }
  519. public Set<Property> getNeedsDelegateToWidget() {
  520. return Collections.unmodifiableSet(needsDelegateToWidget);
  521. }
  522. public void setNeedsOnStateChangeHandler(JClassType type, JMethod method) {
  523. if (!isNeedsOnStateChangeHandler(type, method)) {
  524. addMapping(needsOnStateChange, type, method);
  525. }
  526. }
  527. private boolean isNeedsOnStateChangeHandler(JClassType type, JMethod method) {
  528. if (hasMapping(needsOnStateChange, type, method)) {
  529. return true;
  530. } else {
  531. return previousBundle != null
  532. && previousBundle.isNeedsOnStateChangeHandler(type, method);
  533. }
  534. }
  535. public Map<JClassType, Set<JMethod>> getNeedsOnStateChangeHandler() {
  536. return Collections.unmodifiableMap(needsOnStateChange);
  537. }
  538. public static JMethod findInheritedMethod(JClassType type,
  539. String methodName, JType... params) {
  540. JClassType currentType = type;
  541. while (currentType != null) {
  542. JMethod method = currentType.findMethod(methodName, params);
  543. if (method != null) {
  544. return method;
  545. }
  546. currentType = currentType.getSuperclass();
  547. }
  548. JClassType[] interfaces = type.getImplementedInterfaces();
  549. for (JClassType iface : interfaces) {
  550. JMethod method = iface.findMethod(methodName, params);
  551. if (method != null) {
  552. return method;
  553. }
  554. }
  555. return null;
  556. }
  557. }