com.google.gwt.core.ext.GeneratorContext Java Examples

The following examples show how to use com.google.gwt.core.ext.GeneratorContext. 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: Mvp4gGenerator.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
private boolean checkEventBus(TreeLogger logger,
                              GeneratorContext ctx) {

  long lastTimeGenerated = ctx.getCachedGeneratorResult()
                              .getTimeGenerated();

  JClassType sourceType = ctx.getTypeOracle()
                             .findType(EventBusElement.class.getName());
  if (sourceType == null) {
    logger.log(TreeLogger.TRACE,
               "Found previously dependent type that's no longer present: " + EventBusElement.class.getName());
    return false;
  }
  assert sourceType instanceof JRealClassType;
  JRealClassType realClass = (JRealClassType) sourceType;
  if (realClass == null || realClass.getLastModifiedTime() > lastTimeGenerated) {
    return false;
  }

  return true;
}
 
Example #2
Source File: ProxyViewCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String create(TreeLogger logger, GeneratorContext context) {
	PrintWriter printWriter = context.tryCreate(logger, this.packageName, this.viewProxySimpleName);
	if (printWriter == null) {
		return this.viewProxyQualifiedName;
	}

	SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

	srcWriter.indent();
	this.generateProxy(logger, srcWriter);
	srcWriter.println();
	this.generateTokenPrefixes(logger, srcWriter);
	srcWriter.println();
	if (this.placeTokenizerClass == null) {
		this.generateInternalTokenizer(logger, srcWriter);
	} else {
		this.generateDelegateTokenizer(logger, srcWriter);
	}
	this.generateActivityFactory(logger, srcWriter);
	srcWriter.outdent();

	srcWriter.commit(logger);
	return this.viewProxyQualifiedName;
}
 
Example #3
Source File: AbstractInjectorGenerator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
	TypeOracle typeOracle = context.getTypeOracle();
	assert typeOracle != null;

	JClassType viewType = typeOracle.findType(typeName);
	if (viewType == null) {
		logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
		throw new UnableToCompleteException();
	}

	C injectorCreator = this.newCreator(viewType);
	if (injectorCreator.shallRebind()) {
		return injectorCreator.create(logger, context);
	}
	return typeName;
}
 
Example #4
Source File: UiBinderLocalizedCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Resource getTemplateResource(GeneratorContext context) {
	String packageResourcePath = this.targetType.getPackage().getName().replace('.', '/') + "/";
	ResourceOracle resourceOracle = context.getResourcesOracle();
	Map<String, Resource> reourceMap = new HashMap<>();
	for (Resource resource : resourceOracle.getResources()) {
		reourceMap.put(resource.getPath(), resource);
	}
	String templatePath =
		packageResourcePath + this.templateName + "_" + this.locale + UiBinderLocalizedCreator.TEMPLATE_SUFFIX;
	Resource templateResource = reourceMap.get(templatePath);
	if (templateResource == null) {
		this.locale = null;
		templatePath = packageResourcePath + this.templateName + UiBinderLocalizedCreator.TEMPLATE_SUFFIX;
		templateResource = reourceMap.get(templatePath);
	}
	if (templateResource != null) {
		this.templateName = templatePath.replace(packageResourcePath, "");
	}
	return templateResource;
}
 
Example #5
Source File: UiBinderLocalizedCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {

		String packageName = this.binderType.getPackage().getName();
		String className = this.binderProxySimpleName;

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

		composerFactory.addImport(GWT.class.getName());
		composerFactory.addImport(UiBinder.class.getName());
		composerFactory.addImport(UiBinderLocalized.class.getName());
		composerFactory.addImport(UiTemplate.class.getName());

		composerFactory.addImport(this.binderType.getQualifiedSourceName());
		composerFactory.addImport(this.widgetType.getQualifiedSourceName());
		composerFactory.addImport(this.targetType.getQualifiedSourceName());

		composerFactory.addImplementedInterface(UiBinderLocalized.class.getSimpleName() + "<"
			+ this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">");
		composerFactory.addImplementedInterface(UiBinder.class.getSimpleName() + "<"
			+ this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">");
		composerFactory.addImplementedInterface(this.binderType.getSimpleSourceName());

		return composerFactory.createSourceWriter(ctx, printWriter);
	}
 
Example #6
Source File: UiBinderLocalizedGenerator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
	TypeOracle typeOracle = context.getTypeOracle();
	assert typeOracle != null;

	JClassType viewType = typeOracle.findType(typeName);
	if (viewType == null) {
		logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
		throw new UnableToCompleteException();
	}

	PropertyOracle propertyOracle = context.getPropertyOracle();
	LocaleUtils localeUtils = LocaleUtils.getInstance(logger, propertyOracle, context);
	GwtLocale locale = localeUtils.getCompileLocale();

	UiBinderLocalizedCreator creator = new UiBinderLocalizedCreator(viewType, locale);
	return creator.create(logger, context);
}
 
Example #7
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createSubModels(TreeLogger logger, GeneratorContext context) {
	for (JType jType : this.imports) {
		if (jType == null) {
			continue;
		}
		if (jType.isEnum() != null) {
			continue;
		}
		if (ModelCreator.DISCARD_MODEL_TYPES.contains(jType.getQualifiedSourceName())) {
			continue;
		}
		if (jType instanceof JClassType) {
			ModelCreator creator = new ModelCreator((JClassType) jType);
			String subModelType = creator.create(logger, context);
			this.subModels.put(jType, subModelType);
		}
	}
}
 
Example #8
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String create(TreeLogger logger, GeneratorContext context) {
	PrintWriter printWriter = this.getPrintWriter(logger, context);
	if (printWriter == null) {
		return this.proxyModelQualifiedName;
	}

	this.collectImports();

	SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

	srcWriter.indent();
	srcWriter.println();
	this.generateCreateService(srcWriter);
	srcWriter.println();
	this.generateServiceImplementation(logger, srcWriter);
	this.generateServiceImplementationWithCallback(srcWriter);

	srcWriter.outdent();
	srcWriter.commit(logger);
	return this.proxyModelQualifiedName;
}
 
Example #9
Source File: ServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String create(TreeLogger logger, GeneratorContext context) throws UnableToCompleteException, NotFoundException {
	PrintWriter printWriter = this.getPrintWriter(logger, context);
	if (printWriter == null) {
		return this.proxyModelQualifiedName;
	}

	this.serializerTypeName = this.createSerializer(logger, context);
	this.collectImports();

	SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

	srcWriter.indent();
	srcWriter.println();
	this.generateSerializer(srcWriter);
	srcWriter.println();
	this.generateServiceImplementation(logger, srcWriter);
	this.generateServiceImplementationWithCallback(logger, srcWriter);

	srcWriter.outdent();
	srcWriter.commit(logger);
	return this.proxyModelQualifiedName;
}
 
Example #10
Source File: Mvp4gGenerator.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
private boolean checkSet(TreeLogger logger,
                         GeneratorContext ctx,
                         Set<? extends Mvp4gElement> setOfElements) {

  long lastTimeGenerated = ctx.getCachedGeneratorResult()
                              .getTimeGenerated();

  for (Mvp4gElement element : setOfElements) {
    JClassType sourceType = ctx.getTypeOracle()
                               .findType(element.getProperty("class"));
    if (sourceType == null) {
      logger.log(TreeLogger.TRACE,
                 "Found previously dependent type that's no longer present: " + element.getProperty("class"));
      return false;
    }
    assert sourceType instanceof JRealClassType;
    JRealClassType realClass = (JRealClassType) sourceType;
    if (realClass == null || realClass.getLastModifiedTime() > lastTimeGenerated) {
      return false;
    }
  }
  return true;
}
 
Example #11
Source File: Mvp4gGenerator.java    From mvp4g with Apache License 2.0 6 votes vote down vote up
private boolean checkModule(TreeLogger logger,
                            GeneratorContext ctx,
                            JClassType module) {

  long lastTimeGenerated = ctx.getCachedGeneratorResult()
                              .getTimeGenerated();

  if (module == null) {
    logger.log(TreeLogger.TRACE,
               "Found previously dependent type that's no longer present: " + Mvp4gModule.class.getName());
    return false;
  }
  assert module instanceof JRealClassType;
  JRealClassType realClass = (JRealClassType) module;
  if (realClass == null || realClass.getLastModifiedTime() > lastTimeGenerated) {
    return false;
  }

  return true;
}
 
Example #12
Source File: AbstractInjectorCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String create(TreeLogger logger, GeneratorContext context) {
	PrintWriter writer = context.tryCreate(logger, this.packageName, this.proxyName);
	if (writer == null) {
		return this.proxyQualifiedName;
	}

	SourceWriter srcWriter = this.getSourceWriter(writer, context);
	srcWriter.indent();

	this.doCreate(logger, context, srcWriter);

	srcWriter.outdent();
	srcWriter.commit(logger);

	return this.proxyQualifiedName;
}
 
Example #13
Source File: EventBinderGenerator.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context,
    String typeName) throws UnableToCompleteException {
  try {
    JClassType eventBinderType = context.getTypeOracle().getType(typeName);
    JClassType targetType = getTargetType(eventBinderType, context.getTypeOracle());
    SourceWriter writer = createSourceWriter(logger, context, eventBinderType, targetType);
    if (writer != null) { // Otherwise the class was already created
      new EventBinderWriter(
          logger,
          context.getTypeOracle().getType(GenericEvent.class.getCanonicalName()))
              .writeDoBindEventHandlers(targetType, writer, context.getTypeOracle());
      writer.commit(logger);
    }
    return getFullyQualifiedGeneratedClassName(eventBinderType);
  } catch (NotFoundException e) {
    logger.log(Type.ERROR, "Error generating " + typeName, e);
    throw new UnableToCompleteException();
  }
}
 
Example #14
Source File: EventBinderGenerator.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
private SourceWriter createSourceWriter(
    TreeLogger logger,
    GeneratorContext context,
    JClassType eventBinderType,
    JClassType targetType) {
  String simpleName = getSimpleGeneratedClassName(eventBinderType);
  String packageName = eventBinderType.getPackage().getName();
  ClassSourceFileComposerFactory composer =
      new ClassSourceFileComposerFactory(packageName, simpleName);

  composer.setSuperclass(AbstractEventBinder.class.getCanonicalName()
      + "<" + targetType.getQualifiedSourceName() + ">");
  composer.addImplementedInterface(eventBinderType.getName());

  composer.addImport(EventBinder.class.getCanonicalName());
  composer.addImport(EventBus.class.getCanonicalName());
  composer.addImport(GenericEvent.class.getCanonicalName());
  composer.addImport(GenericEventHandler.class.getCanonicalName());
  composer.addImport(HandlerRegistration.class.getCanonicalName());
  composer.addImport(LinkedList.class.getCanonicalName());
  composer.addImport(List.class.getCanonicalName());

  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  return (printWriter != null) ? composer.createSourceWriter(context, printWriter) : null;
}
 
Example #15
Source File: ProductConfigGenerator.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    try {
        // get classType and save instance variables
        JClassType classType = typeOracle.getType(typeName);
        packageName = classType.getPackage().getName();
        className = classType.getSimpleSourceName() + "Impl";

        // Generate class source code
        generateClass(logger, context);

    } catch (Throwable e) {
        // record to logger that Map generation threw an exception
        e.printStackTrace(System.out);
        logger.log(TreeLogger.ERROR, "Failed to generate product config", e);
    }

    // return the fully qualified name of the class generated
    return packageName + "." + className;
}
 
Example #16
Source File: ProxyViewGenerator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
	TypeOracle typeOracle = context.getTypeOracle();
	assert typeOracle != null;

	JClassType placeType = typeOracle.findType(typeName);
	if (placeType == null) {
		logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
		throw new UnableToCompleteException();
	}

	ProxyViewCreator proxyCreator = new ProxyViewCreator(placeType);
	return proxyCreator.create(logger, context);
}
 
Example #17
Source File: AbstractInjectorCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {
	ClassSourceFileComposerFactory composerFactory =
		new ClassSourceFileComposerFactory(this.packageName, this.proxyName);

	composerFactory.addImport(GWT.class.getName());
	composerFactory.addImport(this.injectableType.getQualifiedSourceName());

	composerFactory.setSuperclass(this.injectableType.getSimpleSourceName());

	for (InjectorWritterInit delegate : Iterables.filter(this.delegates, InjectorWritterInit.class)) {
		delegate.initComposer(composerFactory);
	}

	return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example #18
Source File: AbstractInjectorCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void writeConstructor(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) {
	srcWriter.println("public %s() {", this.proxyName);
	srcWriter.indent();
	for (InjectorWritterConstructor delegate : Iterables.filter(this.delegates, InjectorWritterConstructor.class)) {
		delegate.writeConstructor(srcWriter);
	}
	srcWriter.outdent();
	srcWriter.println("}");
}
 
Example #19
Source File: ProxyViewCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {
	ClassSourceFileComposerFactory composerFactory =
		new ClassSourceFileComposerFactory(this.packageName, this.viewProxySimpleName);

	composerFactory.setSuperclass(this.placeType.getSimpleSourceName());

	composerFactory.addImport(GWT.class.getName());
	composerFactory.addImport(RunAsyncCallback.class.getName());
	composerFactory.addImport(ViewProxy.class.getName());
	composerFactory.addImport(Place.class.getName());
	composerFactory.addImport(ViewPlace.class.getName());
	composerFactory.addImport(Activity.class.getName());
	composerFactory.addImport(ViewActivity.class.getName());
	composerFactory.addImport(ApplicationUnreachableException.class.getName());
	composerFactory.addImport(this.placeType.getQualifiedSourceName());
	composerFactory.addImport(this.activityDescrition.view().getCanonicalName());
	if (this.placeTokenizerClass != null) {
		composerFactory.addImport(this.placeTokenizerClass.getCanonicalName());
	}
	if (this.viewDecoratorClass != null) {
		composerFactory.addImport(this.viewDecoratorClass.getCanonicalName());
	}

	composerFactory.addImplementedInterface(
		ViewProxy.class.getSimpleName() + "<" + this.placeType.getSimpleSourceName() + ">");

	return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example #20
Source File: ModelGenerator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String modelClass)
	throws UnableToCompleteException {
	TypeOracle typeOracle = context.getTypeOracle();
	assert typeOracle != null;

	JClassType modelType = typeOracle.findType(modelClass);
	if (modelType == null) {
		logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + modelClass + "'", null);
		throw new UnableToCompleteException();
	}

	JClassType beanType = null;
	for (JClassType interfaceType : modelType.getImplementedInterfaces()) {
		if (interfaceType.getQualifiedSourceName().equals(Model.class.getCanonicalName())
			&& interfaceType instanceof JParameterizedType) {
			JParameterizedType paramType = (JParameterizedType) interfaceType;
			beanType = paramType.getTypeArgs()[0];
		}
	}
	if (beanType == null) {
		logger.log(TreeLogger.ERROR, modelType.getQualifiedSourceName() + " must implement "
			+ Model.class.getCanonicalName(), null);
		throw new UnableToCompleteException();
	}

	ModelCreator modelCreator = new ModelCreator(beanType);
	return modelCreator.create(logger, context);
}
 
Example #21
Source File: ExtendedServiceProxyGenerator.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
    throws UnableToCompleteException {
  // Delegate the creation of the "normal" proxy
  String proxyTypeName = PROXY_GENERATOR.generate(logger, context, typeName);

  // Wrap the generated proxy in an extended proxy
  return generateExtendedProxy(logger, context, typeName, proxyTypeName);
}
 
Example #22
Source File: InjectorModuleCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doCreate(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) {
	super.doCreate(logger, context, srcWriter);

	srcWriter.println("@Override public void onModuleLoad() {");
	srcWriter.indent();

	try {
		if (this.injectableType.getMethod("onModuleLoad", new JType[] {}) != null) {
			srcWriter.println("super.onModuleLoad();");
		}
	} catch (NotFoundException e) {
		srcWriter.println("");
	}

	for (InjectorWritterEntryPoint delegate : Iterables.filter(this.delegates, InjectorWritterEntryPoint.class)) {
		delegate.writeEntryPoint(srcWriter);
		srcWriter.println();
	}

	for (JMethod method : InjectCreatorUtil.listMethod(this.injectableType, EntryPointHandler.class)) {
		srcWriter.println("super.%s();", method.getName());
	}

	srcWriter.println();
	MvpDescription mvpAnnotation = this.injectableType.getAnnotation(MvpDescription.class);
	if (mvpAnnotation != null && mvpAnnotation.handleCurrentHistory()) {
		srcWriter.println("MvpController.get().handleCurrentHistory();");
	}
	srcWriter.outdent();
	srcWriter.println("}");
}
 
Example #23
Source File: UiBinderLocalizedCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String create(TreeLogger logger, GeneratorContext context) {
	Resource templateResource = this.getTemplateResource(context);
	if (templateResource == null) {
		throw new NullPointerException("no template found");
	}
	this.binderProxySimpleName =
		this.targetType.getSimpleSourceName() + "_" + this.binderType.getSimpleSourceName()
			+ UiBinderLocalizedCreator.PROXY_SUFFIX;
	if (this.locale != null) {
		this.binderProxySimpleName += "_" + this.locale.toString();
	}
	this.binderProxyQualifiedName = this.targetType.getPackage().getName() + "." + this.binderProxySimpleName;

	PrintWriter printWriter = this.getPrintWriter(logger, context, this.binderProxyQualifiedName);
	if (printWriter == null) {
		return this.binderProxyQualifiedName;
	}

	SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

	srcWriter.println();
	srcWriter.indent();
	this.generateProxy(logger, srcWriter);
	srcWriter.println();
	srcWriter.outdent();

	srcWriter.commit(logger);

	return this.binderProxyQualifiedName;
}
 
Example #24
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {

		String packageName = this.handlerType.getPackage().getName();
		String className =
			this.proxyModelQualifiedName.indexOf('.') == -1 ?
				this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring(
					this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length());

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

		composerFactory.addImport(AbstractServiceBinder.class.getName());
		composerFactory.addImport(Arrays.class.getName());
		composerFactory.addImport(Lists.class.getName());
		composerFactory.addImport(MethodCallbackAdapter.class.getName());
		composerFactory.addImport(Method.class.getName());
		composerFactory.addImport(CompositeMethodCallback.class.getName());
		composerFactory.addImport(CallbackAdapter.class.getName());
		composerFactory.addImport(REST.class.getName());
		composerFactory.addImport(GWT.class.getName());

		composerFactory.addImport(this.serviceType.getQualifiedSourceName());
		composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName());

		for (JType jType : this.imports) {
			if (jType.isPrimitive() != null) {
				continue;
			}
			composerFactory.addImport(jType.getQualifiedSourceName());
		}

		composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName()
			+ "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">");

		composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName());
		composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName());

		return composerFactory.createSourceWriter(ctx, printWriter);
	}
 
Example #25
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private PrintWriter getPrintWriter(TreeLogger logger, GeneratorContext ctx) {
	String packageName =
		this.proxyModelQualifiedName.indexOf('.') == -1 ? "" : this.proxyModelQualifiedName.substring(0,
			this.proxyModelQualifiedName.lastIndexOf('.'));
	String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName :
		this.proxyModelQualifiedName.substring(
			this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length());

	return ctx.tryCreate(logger, packageName, className);
}
 
Example #26
Source File: RestServiceBinderGenerator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context, String restServiceClassName)
	throws UnableToCompleteException {
	TypeOracle typeOracle = context.getTypeOracle();
	assert typeOracle != null;

	JClassType restServiceType = typeOracle.findType(restServiceClassName);
	if (restServiceType == null) {
		logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + restServiceClassName + "'", null);
		throw new UnableToCompleteException();
	}

	JClassType handlerType = null;
	JClassType serviceType = null;
	for (JClassType interfaceType : restServiceType.getImplementedInterfaces()) {
		if (interfaceType.getQualifiedSourceName().equals(ServiceProxy.class.getCanonicalName())
			&& interfaceType instanceof JParameterizedType) {
			JParameterizedType paramType = (JParameterizedType) interfaceType;
			handlerType = paramType.getTypeArgs()[0];
			serviceType = paramType.getTypeArgs()[1];
		}
	}
	if (serviceType == null) {
		logger.log(TreeLogger.ERROR,
			restServiceType.getQualifiedSourceName() + " must implement " + ServiceProxy.class.getCanonicalName()
				+ " with explicit Type Parameters", null);
		throw new UnableToCompleteException();
	}

	RestServiceBinderCreator serviceBinderCreator =
		new RestServiceBinderCreator(restServiceType, serviceType, handlerType);
	return serviceBinderCreator.create(logger, context);
}
 
Example #27
Source File: JsonGwtJacksonGenerator.java    From requestor with Apache License 2.0 5 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext ctx, String typeName) throws UnableToCompleteException {
    TypeOracle typeOracle = ctx.getTypeOracle();
    assert typeOracle != null;

    JClassType intfType = typeOracle.findType(typeName);
    if (intfType == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }

    if (intfType.isInterface() == null) {
        logger.log(TreeLogger.ERROR, intfType.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }

    // TODO: check if type was already generated and reuse it
    TreeLogger typeLogger = logger.branch(TreeLogger.ALL, "Generating Json SerDes powered by Gwt Jackson...", null);
    final SourceWriter sourceWriter = getSourceWriter(typeLogger, ctx, intfType);

    if (sourceWriter != null) {
        sourceWriter.println();

        final ArrayList<String> serdes = new ArrayList<String>();
        for (JClassType type : typeOracle.getTypes()) {
            Json annotation = type.getAnnotation(Json.class);
            if (annotation != null) {
                serdes.add(generateSerdes(sourceWriter, type, annotation));
            }
        }

        generateFields(sourceWriter);
        generateConstructor(sourceWriter, serdes);
        generateMethods(sourceWriter);

        sourceWriter.commit(typeLogger);
    }

    return typeName + "Impl";
}
 
Example #28
Source File: ObjectMapperGenerator.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public final String generate( TreeLogger logger, GeneratorContext context, String typeName ) throws UnableToCompleteException {
    JacksonTypeOracle typeOracle = new JacksonTypeOracle( logger, context.getTypeOracle() );
    JClassType rootMapperClass = typeOracle.getType( typeName );
    RebindConfiguration configuration = new RebindConfiguration( logger, context, typeOracle, rootMapperClass );
    ObjectMapperCreator creator = new ObjectMapperCreator( logger, context, configuration, typeOracle );
    return creator.create( rootMapperClass );
}
 
Example #29
Source File: ApplicationMetaDataGenerator.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException
{
    this.typeName = typeName;
    TypeOracle typeOracle = context.getTypeOracle();

    try
    {
        // get classType and save instance variables
        JClassType classType = typeOracle.getType(typeName);
        packageName = classType.getPackage().getName();
        className = classType.getSimpleSourceName() + "Impl";

        // Generate class source code
        generateClass(logger, context);

    }
    catch (Exception e)
    {
        // record to logger that Map generation threw an exception
        e.printStackTrace(System.out);
        logger.log(TreeLogger.ERROR, "Failed to generate property meta data", e);
    }

    // return the fully qualified name of the class generated
    return packageName + "." + className;
}
 
Example #30
Source File: ProductConfigGenerator.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generate source code for new class. Class extends
 * <code>HashMap</code>.
 *
 * @param logger  Logger object
 * @param context Generator context
 */
private void generateClass(TreeLogger logger, GeneratorContext context) throws Throwable {

    // get print writer that receives the source code
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) { return; }

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, className);

    // Imports
    composerFactory.addImport("org.jboss.as.console.client.Console");
    composerFactory.addImport("org.jboss.as.console.client.ProductConfig");

    composerFactory.addImport("java.util.*");

    // Interfaces
    composerFactory.addImplementedInterface("org.jboss.as.console.client.ProductConfig");

    // SourceWriter
    SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

    // ctor
    generateConstructor(sourceWriter);

    // Methods
    generateMethods(logger, sourceWriter, context);

    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);
}