Java Code Examples for com.google.gwt.core.ext.typeinfo.JClassType#getQualifiedSourceName()

The following examples show how to use com.google.gwt.core.ext.typeinfo.JClassType#getQualifiedSourceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoryAnnotationsLoader.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
@Override
Mvp4gWithServicesElement loadElementWithServices(JClassType c,
                                                 History annotation,
                                                 Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {

  String className = c.getQualifiedSourceName();
  String historyName = buildElementNameIfNeeded(annotation.name(),
                                                className,
                                                "");
  String type = annotation.type()
                          .name();

  HistoryConverterElement historyConverter = new HistoryConverterElement();
  historyConverter.setName(historyName);
  historyConverter.setClassName(className);
  historyConverter.setType(type);

  addElement(configuration.getHistoryConverters(),
             historyConverter,
             c,
             null);

  return historyConverter;
}
 
Example 2
Source File: EventsAnnotationsLoader.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
/**
 * Build event bus element according to the implemented interface.
 *
 * @param c             annoted class type
 * @param configuration configuration containing loaded elements of the application
 * @return event bus corresponding to the implemented interface (null if none of the interfaces
 * are implemented)
 */
private EventBusElement buildEventBusElement(JClassType c,
                                             Mvp4gConfiguration configuration) {

  TypeOracle oracle = configuration.getOracle();

  EventBusElement eventBus = null;
  if (c.isAssignableTo(oracle.findType(EventBusWithLookup.class.getCanonicalName()))) {
    eventBus = new EventBusElement(c.getQualifiedSourceName(),
                                   BaseEventBusWithLookUp.class.getCanonicalName(),
                                   true);
  } else if (c.isAssignableTo(oracle.findType(EventBus.class.getCanonicalName()))) {
    eventBus = new EventBusElement(c.getQualifiedSourceName(),
                                   BaseEventBus.class.getCanonicalName(),
                                   false);
  }

  return eventBus;
}
 
Example 3
Source File: EventsAnnotationsLoader.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
/**
 * Build history converter of an event. If the converter class name is given, first it tries to
 * find an instance of this class, and if none is found, create one.
 *
 * @param c             annoted class
 * @param method        method that defines the event
 * @param annotation    Event annotation
 * @param element       Event element
 * @param configuration configuration containing loaded elements of the application
 * @throws Mvp4gAnnotationException
 */
private void loadHistory(JClassType c,
                         JMethod method,
                         Event annotation,
                         EventElement element,
                         Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {
  String hcName = annotation.historyConverterName();
  Class<?> hcClass = annotation.historyConverter();
  if ((hcName != null) && (hcName.length() > 0)) {
    element.setHistory(hcName);
  } else if (!Event.NoHistoryConverter.class.equals(hcClass)) {
    String hcClassName = hcClass.getCanonicalName();
    Set<HistoryConverterElement> historyConverters = configuration.getHistoryConverters();
    hcName = getElementName(historyConverters,
                            hcClassName);
    if (hcName == null) {
      String err = "No instance of " + hcClassName + " is defined. Have you forgotten to annotate your history converter with @History?";
      throw new Mvp4gAnnotationException(c.getQualifiedSourceName(),
                                         method.getName(),
                                         err);
    }
    element.setHistory(hcName);
  }
}
 
Example 4
Source File: PresenterAnnotationsLoader.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
@Override
protected PresenterElement loadHandler(JClassType c,
                                       Presenter annotation,
                                       Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {

  String className = c.getQualifiedSourceName();
  String viewName = buildElementNameIfNeeded(annotation.viewName(),
                                             className,
                                             "View");

  PresenterElement presenter = new PresenterElement();
  presenter.setView(viewName);

  ViewElement view = new ViewElement();
  view.setClassName(annotation.view()
                              .getCanonicalName());
  view.setName(viewName);

  addElement(configuration.getViews(),
             view,
             c,
             null);

  return presenter;
}
 
Example 5
Source File: AbstractHandlerAnnotationsLoader.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
@Override
Mvp4gWithServicesElement loadElementWithServices(JClassType c,
                                                 A annotation,
                                                 Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {

  String className = c.getQualifiedSourceName();

  String eventHandlerName = buildElementNameIfNeeded(getAnnotationName(annotation),
                                                     className,
                                                     "");

  T eventHandler = loadHandler(c,
                               annotation,
                               configuration);
  eventHandler.setName(eventHandlerName);
  eventHandler.setClassName(className);
  eventHandler.setMultiple(Boolean.toString(isAnnotationMultiple(annotation)));

  Class<? extends Mvp4gSplitter> splitter = getAnnotationSplitter(annotation);
  if (!splitter.equals(NotAsync.class)) {
    eventHandler.setAsync(splitter.getCanonicalName());
  }

  addElement(getConfigList(configuration),
             eventHandler,
             c,
             null);

  return eventHandler;
}
 
Example 6
Source File: Mvp4gAnnotationsLoader.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
/**
 * Control if the class can accept the annotation.
 *
 * @param c
 *   class to control
 * @param mandatoryInterface
 *   interface that the class must implement
 *
 * @throws Mvp4gAnnotationException
 *   if the class don't implement the interface
 */
@SuppressWarnings("unchecked")
protected void controlType(JClassType c,
                           JClassType mandatoryInterface)
  throws Mvp4gAnnotationException {
  if (!c.isAssignableTo(mandatoryInterface)) {
    String annotationClassName = ((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).getCanonicalName();
    throw new Mvp4gAnnotationException(c.getQualifiedSourceName(),
                                       null,
                                       "this class must implement " + mandatoryInterface.getQualifiedSourceName() + " since it is annoted with " + annotationClassName + ".");
  }
}
 
Example 7
Source File: EventHandlerAnnotationsLoader.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
@Override
protected EventHandlerElement loadHandler(JClassType c,
                                          EventHandler annotation,
                                          Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {
  if (c.getAnnotation(Presenter.class) != null) {
    String err = "You can't annotate a class with @Presenter and @EventHandler.";
    throw new Mvp4gAnnotationException(c.getQualifiedSourceName(),
                                       null,
                                       err);
  }
  return new EventHandlerElement();
}
 
Example 8
Source File: EventsAnnotationsLoader.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
/**
 * Build handler of the events. If the class name of the handler is given, try to find if an
 * instance of this class exists, otherwise throw an error.
 *
 * @param c             annoted class
 * @param method        method that defines the event
 * @param event         Event Annotation of the method
 * @param configuration configuration containing loaded elements of the application
 * @return array of handlers' names
 * @throws Mvp4gAnnotationException if no instance of a given handler class can be found
 */
private String[] buildPresentersAndEventHandlers(JClassType c,
                                                 JMethod method,
                                                 Class<? extends EventHandlerInterface<? extends EventBus>>[] presenterAndEventHandlerClasses,
                                                 String[] presenterAndEventHandlerNames,
                                                 Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {

  Set<EventHandlerElement> presentersAndEventHandlers = new HashSet<EventHandlerElement>(configuration.getPresenters());
  presentersAndEventHandlers.addAll(configuration.getEventHandlers());
  String[] handlers = new String[presenterAndEventHandlerNames.length + presenterAndEventHandlerClasses.length];

  String handlerName = null;
  int index = 0;
  for (Class<?> handler : presenterAndEventHandlerClasses) {
    handlerName = getElementName(presentersAndEventHandlers,
                                 handler.getCanonicalName());
    if (handlerName == null) {
      String err = "No instance of " + handler.getCanonicalName() + " is defined. Have you forgotten to annotate your event handler with @Presenter or @EventHandler?";
      throw new Mvp4gAnnotationException(c.getQualifiedSourceName(),
                                         method.getName(),
                                         err);
    }
    handlers[index] = handlerName;
    index++;
  }

  for (String h : presenterAndEventHandlerNames) {
    handlers[index] = h;
    index++;
  }

  return handlers;
}
 
Example 9
Source File: ServiceAnnotationsLoader.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadElement(JClassType c,
                           Service annotation,
                           Mvp4gConfiguration configuration)
  throws Mvp4gAnnotationException {

  String className = c.getQualifiedSourceName();

  String serviceName = buildElementNameIfNeeded(annotation.name(),
                                                className,
                                                "");
  String         path           = annotation.path();
  Class<?>       generatedClass = annotation.generatedClass();
  ServiceElement service        = new ServiceElement();
  service.setName(serviceName);
  service.setClassName(className);
  if ((path != null) && (path.length() > 0)) {
    service.setPath(annotation.path());
  }
  if (!Void.class.equals(generatedClass)) {
    service.setGeneratedClassName(generatedClass.getCanonicalName());
  }

  addElement(configuration.getServices(),
             service,
             c,
             null);

}
 
Example 10
Source File: EventsAnnotationsLoaderTest.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
@Test
public void testParentEventBusOtherModule()
  throws Mvp4gAnnotationException {
  List<JClassType> annotedClasses = new ArrayList<JClassType>();
  annotedClasses.add(oracle.addClass(PresenterWithName.class));
  new PresenterAnnotationsLoader().load(annotedClasses,
                                        configuration);

  annotedClasses.clear();

  JClassType parentEventBus = oracle.addClass(Events.EventBusWithChildren.class);
  annotedClasses.add(oracle.addClass(Events.EventBusForOtherModule.class));
  annotedClasses.add(parentEventBus);

  JClassType otherModule          = oracle.addClass(Modules.Module01.class);
  String     otherModuleClassName = otherModule.getQualifiedSourceName();
  configuration.setModule(otherModule);
  loader.load(annotedClasses,
              configuration);

  Map<String, ChildModuleElement> othersParentEventBusClassMap = configuration.getModuleParentEventBusClassMap();
  assertEquals(2,
               othersParentEventBusClassMap.size());
  ChildModuleElement element = othersParentEventBusClassMap.get(otherModuleClassName);
  assertEquals(parentEventBus,
               element.getParentEventBus());
  assertEquals(otherModuleClassName,
               element.getClassName());
  assertEquals(Mvp4gModule.class.getCanonicalName(),
               element.getParentModuleClass());
  assertTrue(element.isAutoDisplay());
}
 
Example 11
Source File: Mvp4gConfigurationFileWriter.java    From mvp4g with Apache License 2.0 4 votes vote down vote up
private void writeLoadChildModule(EventElement event,
                                  String param) {

  boolean passive = event.isPassive();

  ChildModuleElement      module             = null;
  Set<ChildModuleElement> modules            = configuration.getChildModules();
  String[]                eventObjectClasses = null;
  String                  eventObject        = null;
  List<String>            modulesToLoad      = event.getForwardToModules();
  if (modulesToLoad != null) {
    if (passive) {
      sourceWriter.println("Mvp4gModule module;");
    }
    for (String moduleName : modulesToLoad) {
      module = getElement(moduleName,
                          modules);
      eventObjectClasses = event.getEventObjectClass();

      JClassType eventBusType = configuration.getOthersEventBusClassMap()
                                             .get(module.getClassName());
      String eventBusClass = eventBusType.getQualifiedSourceName();

      if (passive) {
        eventObject = param;
        sourceWriter.print("module = modules.get(\"");
        sourceWriter.print(module.getClassName());
        sourceWriter.println("\");");
        sourceWriter.println("if(module != null){");
      } else {
        if ((eventObjectClasses == null) || (eventObjectClasses.length == 0)) {
          eventObject = null;
        } else {
          int           nbParam            = eventObjectClasses.length;
          StringBuilder eventObjectBuilder = new StringBuilder(nbParam * 70);

          int i;
          for (i = 0; i < (nbParam - 1); i++) {
            eventObjectBuilder.append("(");
            eventObjectBuilder.append(getAssociatedClass(eventObjectClasses[i]));
            eventObjectBuilder.append(") eventObjects[");
            eventObjectBuilder.append(i);
            eventObjectBuilder.append("],");
          }
          eventObjectBuilder.append("(");
          eventObjectBuilder.append(getAssociatedClass(eventObjectClasses[i]));
          eventObjectBuilder.append(") eventObjects[");
          eventObjectBuilder.append(i);
          eventObjectBuilder.append("]");
          eventObject = eventObjectBuilder.toString();
        }
        sourceWriter.print("load");
        sourceWriter.print(module.getName());
        sourceWriter.print("(\"");
        sourceWriter.print(event.getName());
        sourceWriter.print("\", new Mvp4gEventPasser(");
        if (param != null) {
          sourceWriter.print("new Object[]{");
          sourceWriter.print(param);
          sourceWriter.print("}");
        }
        sourceWriter.println("){");
        sourceWriter.indent();
        sourceWriter.println("public void pass(Mvp4gModule module){");

      }

      sourceWriter.indent();
      sourceWriter.print(eventBusClass);
      sourceWriter.print(" eventBus = (");
      sourceWriter.print(eventBusClass);
      sourceWriter.println(") module.getEventBus();");
      writeDispatchEvent(event.getType(),
                         eventObject);
      sourceWriter.outdent();
      sourceWriter.println("}");
      if (!passive) {
        sourceWriter.outdent();
        sourceWriter.println("});");
      }

    }
  }

}
 
Example 12
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ModelCreator(JClassType beanType) {
	this.beanType = beanType;
	this.proxyModelQualifiedName = beanType.getQualifiedSourceName() + "_Model";
	this.proxyModelQualifiedName = this.proxyModelQualifiedName
		.replace(beanType.getName(), beanType.getName().replace('.', '_'));
}
 
Example 13
Source File: Mvp4gAnnotationsLoader.java    From mvp4g with Apache License 2.0 3 votes vote down vote up
/**
 * Check if an element is already present in a set
 *
 * @param <E>
 *   type of the elements
 * @param loadedElements
 *   set of elements where the check is done
 * @param element
 *   searched element
 * @param c
 *   annoted class that asks for this element to be added (can be null, only for error
 *   information purpose)
 * @param m
 *   annoted method that ask for this element to be added (can be null, only for error
 *   information purpose)
 *
 * @throws Mvp4gAnnotationException
 *   if the element is already in the set
 */
private <E extends Mvp4gElement> void checkForDuplicates(Set<E> loadedElements,
                                                         E element,
                                                         JClassType c,
                                                         JMethod m)
  throws Mvp4gAnnotationException {
  if (loadedElements.contains(element)) {
    String err = "Duplicate " + element.getTagName() + " identified by " + "'" + element.getUniqueIdentifierName() + "' found in configuration file.";
    throw new Mvp4gAnnotationException(c.getQualifiedSourceName(),
                                       (m == null) ?
                                       null :
                                       m.getName(),
                                       err);
  }
}