List of usage examples for com.google.gwt.core.ext.typeinfo JParameterizedType getMethods
JMethod[] getMethods();
From source file:com.mvp4g.rebind.config.Mvp4gConfiguration.java
License:Apache License
/** * Checks that all history converter names associated to each event is a configured mvp4g * element. Verify that these elements are valid. Remove all history converters that aren't used * by an event.//from w w w . ja v a 2s . c o m * * @throws InvalidMvp4gConfigurationException */ void validateHistoryConverters() throws InvalidMvp4gConfigurationException { Map<String, List<EventElement>> historyConverterMap = new HashMap<String, List<EventElement>>(); List<EventElement> eventList = null; String hcName = null; String historyName; List<String> historyNames = new ArrayList<String>(); for (EventElement event : events) { if (event.hasHistory()) { hcName = event.getHistory(); eventList = historyConverterMap.get(hcName); if (eventList == null) { eventList = new ArrayList<EventElement>(); historyConverterMap.put(hcName, eventList); } eventList.add(event); historyName = event.getName(); if (isRootModule() && (historyName.length() == 0)) { throw new InvalidMvp4gConfigurationException( String.format(EMPTY_HISTORY_NAME_ROOT, event.getType())); } validateHistoryName(historyName, event); if (historyNames.contains(historyName)) { throw new InvalidMvp4gConfigurationException( String.format(SAME_HISTORY_NAME, event.getType(), event.getName(), historyName)); } historyNames.add(historyName); } else if (event.isWithTokenGeneration()) { if (isRootModule() || !checkIfParentEventReturnsString(event)) { throw new InvalidMvp4gConfigurationException( String.format(TOKEN_WITH_NO_CONVERTER, event.getType())); } else { event.setTokenGenerationFromParent(Boolean.toString(Boolean.TRUE)); } } else if (event.getName() != event.getType()) { throw new InvalidMvp4gConfigurationException( String.format(NAME_WITH_NO_CONVERTER, event.getType())); } } JGenericType hcGenType = getType(null, HistoryConverter.class.getCanonicalName()).isGenericType(); JClassType eventBusType = getType(null, eventBus.getInterfaceClassName()); String clearHistoryClassName = ClearHistory.class.getCanonicalName(); JClassType clearHistoryType = getType(null, clearHistoryClassName); JClassType hcType = null; JClassType eventBusParam = null; JMethod[] methods = null; JParameterizedType genHC = null; HistoryConverterElement clearHistoryToRemove = null; Set<HistoryConverterElement> toRemove = new HashSet<HistoryConverterElement>(); for (HistoryConverterElement history : historyConverters) { eventList = historyConverterMap.remove(history.getName()); if (eventList != null) { hcType = getType(history, history.getClassName()); // if historyConverter is a ClearHistory instance, no control // needed if (!clearHistoryType.equals(hcType)) { genHC = hcType.asParameterizationOf(hcGenType); if (genHC == null) { throw new InvalidClassException(history, HistoryConverter.class.getCanonicalName()); } methods = genHC.getMethods(); eventBusParam = (JClassType) methods[0].getParameters()[2].getType(); // Control if history converter event bus is compatible with // module event bus if (!eventBusType.isAssignableTo(eventBusParam)) { throw new InvalidTypeException(history, "Event Bus", eventBusParam.getQualifiedSourceName(), eventBus.getInterfaceClassName()); } } } else { if (!clearHistoryClassName.equals(history.getClassName())) { // this object is not used, you can remove it toRemove.add(history); } else { clearHistoryToRemove = history; } } } // Missing history converter if (!historyConverterMap.isEmpty()) { String it = historyConverterMap.keySet().iterator().next(); throw new UnknownConfigurationElementException(historyConverterMap.get(it).get(0), it); } // remove clear history (you don't want this to appear on log) if (clearHistoryToRemove != null) { historyConverters.remove(clearHistoryToRemove); } removeUselessElements(historyConverters, toRemove); }
From source file:com.mvp4g.rebind.config.Mvp4gConfiguration.java
License:Apache License
/** * Verify that filters are valid./*from w w w . jav a 2 s . c o m*/ * * @throws InvalidMvp4gConfigurationException */ void validateEventFilters() throws InvalidMvp4gConfigurationException { JGenericType filterGenType = getType(null, EventFilter.class.getCanonicalName()).isGenericType(); JClassType eventBusType = getType(null, eventBus.getInterfaceClassName()); JClassType filterType, eventBusParam; JParameterizedType genEventFilter; for (EventFilterElement filter : eventFilters) { filterType = getType(filter, filter.getClassName()); genEventFilter = filterType.asParameterizationOf(filterGenType); if (genEventFilter == null) { throw new InvalidClassException(filter, EventFilter.class.getCanonicalName()); } eventBusParam = (JClassType) genEventFilter.getMethods()[0].getParameters()[2].getType(); // Control if filter event bus is compatible with module // event bus if (!eventBusType.isAssignableTo(eventBusParam)) { throw new InvalidTypeException(filter, "Event Bus", eventBus.getInterfaceClassName(), eventBusParam.getQualifiedSourceName()); } } }
From source file:com.mvp4g.rebind.config.Mvp4gConfiguration.java
License:Apache License
String validateLoaderAndAdd(JClassType moduleType, JClassType eventBus, Mvp4gElement element)
throws NotFoundClassException, InvalidTypeException {
String name = null;/* w w w .jav a 2 s . c o m*/
Loader loaderAnnotation = moduleType.getAnnotation(Loader.class);
if (loaderAnnotation != null) {
JClassType loaderType = getType(element, loaderAnnotation.value().getCanonicalName());
JGenericType loaderGenType = getType(null, Mvp4gLoader.class.getCanonicalName()).isGenericType();
JParameterizedType genLoader = loaderType.asParameterizationOf(loaderGenType);
JClassType eventBusParam = (JClassType) genLoader.getMethods()[0].getParameters()[0].getType();
if (!eventBus.isAssignableTo(eventBusParam)) {
throw new InvalidTypeException(element, "Loader, event bus not compatible",
eventBusParam.getQualifiedSourceName(), eventBus.getQualifiedSourceName());
}
name = "loader" + loaderType.getQualifiedSourceName().replace(".", "_");
LoaderElement loader = getElement(name, loaders);
if (loader == null) {
loader = new LoaderElement();
loader.setName(name);
loader.setClassName(loaderType.getQualifiedSourceName());
loaders.add(loader);
}
}
return name;
}
From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java
License:Apache License
/** * @param srcWriter//from ww w . j a v a 2 s .com * @param serviceAsync * @throws UnableToCompleteException */ private void generateProxyWrapperMethods(SourceWriter srcWriter, JClassType serviceAsync) throws UnableToCompleteException { JMethod[] asyncMethods = serviceAsync.getOverridableMethods(); for (JMethod asyncMethod : asyncMethods) { JClassType enclosingType = asyncMethod.getEnclosingType(); JParameterizedType isParameterizedType = enclosingType.isParameterized(); if (isParameterizedType != null) { JMethod[] methods = isParameterizedType.getMethods(); for (int i = 0; i < methods.length; ++i) { if (methods[i] == asyncMethod) { asyncMethod = isParameterizedType.getBaseType().getMethods()[i]; } } } generateProxyWrapperMethod(srcWriter, asyncMethod); } }