當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratorContext.tryCreate方法代碼示例

本文整理匯總了Java中com.google.gwt.core.ext.GeneratorContext.tryCreate方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorContext.tryCreate方法的具體用法?Java GeneratorContext.tryCreate怎麽用?Java GeneratorContext.tryCreate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gwt.core.ext.GeneratorContext的用法示例。


在下文中一共展示了GeneratorContext.tryCreate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
/**
 * get source writer for the generator.
 *
 * @param pclassType class type
 * @param pcontext generator context
 * @param plogger tree logger
 * @return SourceWriter to write the generated sources to
 */
private SourceWriter getSourceWriter(final JClassType pclassType, final GeneratorContext pcontext,
    final TreeLogger plogger) {
  final String packageName = this.getClassPackage(pclassType);
  final String simpleName = this.getClassName(pclassType);
  final ClassSourceFileComposerFactory composer =
      new ClassSourceFileComposerFactory(packageName, simpleName);
  composer
      .addImplementedInterface("de.knightsoftnet.validators.client.GwtReflectGetterInterface");

  final PrintWriter printWriter = pcontext.tryCreate(plogger, packageName, simpleName);
  if (printWriter == null) {
    return null;
  }
  return composer.createSourceWriter(pcontext, printWriter);
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-bean-validators,代碼行數:24,代碼來源:GwtReflectGetterGenerator.java

示例2: create

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
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;
}
 
開發者ID:Putnami,項目名稱:putnami-web-toolkit,代碼行數:25,代碼來源:ProxyViewCreator.java

示例3: create

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
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;
}
 
開發者ID:Putnami,項目名稱:putnami-web-toolkit,代碼行數:17,代碼來源:AbstractInjectorCreator.java

示例4: getFactorySourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
public SourceWriter getFactorySourceWriter(Class<?> classType,
		GeneratorContext context, TreeLogger logger, Collection<String> imports) {
	String packageName = classType.getPackage().getName();
	String simpleName = classType.getSimpleName() + "FactoryGenerated";
	
	ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);

	// Need to add whatever imports your generated class needs.
	composer.addImport("com.google.gwt.xml.client.*");
	composer.addImport("com.peterfranza.gwt.jaxb.client.parser.*");
	composer.addImport("com.peterfranza.gwt.jaxb.client.parser.utils.*");
	composer.addImport("java.util.*");
	
	for(String s: imports) {
		composer.addImport(s);
		debug("Augmenting Imports: +" + s);
	}
			
	PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
	if (printWriter == null) {
		return null;
	} else {
		SourceWriter sw = composer.createSourceWriter(context, printWriter);
		return sw;
	}
}
 
開發者ID:pfranza,項目名稱:gwtjaxb,代碼行數:27,代碼來源:JAXBParserGenerator.java

示例5: createSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
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;
}
 
開發者ID:google,項目名稱:gwteventbinder,代碼行數:26,代碼來源:EventBinderGenerator.java

示例6: createSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
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.addImplementedInterface(eventBinderType.getName());
  composer.addImport(EventHandlerMethod.class.getCanonicalName());
  composer.addImport(LinkedList.class.getCanonicalName());
  composer.addImport(List.class.getCanonicalName());
  composer.addImport(MultiEvent.class.getCanonicalName());

  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  return printWriter != null ? composer.createSourceWriter(context, printWriter) : null;
}
 
開發者ID:ekuefler,項目名稱:gwt-supereventbus,代碼行數:17,代碼來源:EventRegistrationGenerator.java

示例7: writeTopSerializer

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
private void writeTopSerializer(TreeLogger logger,
    GeneratorContext context, JClassType typeFor, JClassType subType) {
    ClassSourceFileComposerFactory mcf = new ClassSourceFileComposerFactory(typeFor.getPackage()
                                                                                   .getName(),
            typeFor.getSimpleSourceName() + "_Impl");
    mcf.addImplementedInterface(typeFor.getParameterizedQualifiedSourceName());
    mcf.setSuperclass(subType.getParameterizedQualifiedSourceName() +
        "_JSONCodec");

    PrintWriter printWriter = context.tryCreate(logger,
            typeFor.getPackage().getName(),
            typeFor.getSimpleSourceName() + "_Impl");

    if (printWriter == null) {
        logger.log(Type.INFO,
            "Already genned " + typeFor.getSimpleSourceName() + "_Impl");

        return;
    }

    SourceWriter writer = mcf.createSourceWriter(context, printWriter);
    writer.println(" public String getMimeType() { return MIME_TYPE; }");
    writer.println("}");
    context.commit(logger, printWriter);
}
 
開發者ID:kebernet,項目名稱:gwittir,代碼行數:26,代碼來源:JSONCodecGenerator.java

示例8: createSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
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(AbstractDomEventBinder.class.getCanonicalName() + "<" + targetType.getName() + ">");
    composer.addImplementedInterface(eventBinderType.getName());

    composer.addImport(LinkedList.class.getCanonicalName());
    composer.addImport(List.class.getCanonicalName());
    composer.addImport(Element.class.getCanonicalName());
    composer.addImport(HandlerRegistration.class.getCanonicalName());
    composer.addImport(IsWidget.class.getCanonicalName());

    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    return (printWriter != null) ? composer.createSourceWriter(context, printWriter) : null;
}
 
開發者ID:rfilippone,項目名稱:gwt-dom-event-binder,代碼行數:18,代碼來源:DomEventBinderGenerator.java

示例9: GinjectorFragmentOutputter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
@Inject
GinjectorFragmentOutputter(GeneratorContext ctx, GinjectorFragmentContext.Factory ginjectorFragmentContextFactory, ErrorManager errorManager,
                           TreeLogger logger, SourceWriteUtil.Factory sourceWriteUtilFactory, @Assisted GinjectorBindings bindings,
                           @Assisted FragmentPackageName fragmentPackageName, @Assisted("ginjectorPackageName") String ginjectorPackageName,
                           @Assisted("ginjectorClassName") String ginjectorClassName) {

    this.ctx = ctx;
    this.errorManager = errorManager;
    this.logger = logger;
    this.sourceWriteUtil = sourceWriteUtilFactory.create(bindings);

    this.fragmentPackageName = fragmentPackageName;
    this.ginjectorClassName = ginjectorClassName;
    this.nameGenerator = bindings.getNameGenerator();

    fragmentClassName = nameGenerator.getFragmentClassName(ginjectorClassName, fragmentPackageName);
    if (fragmentClassName.contains(".")) {
        errorManager.logError("Internal error: the fragment class name \"%s\" contains a full stop.", fragmentClassName);
    }

    PrintWriter printWriter = ctx.tryCreate(logger, fragmentPackageName.toString(), fragmentClassName);
    if (printWriter == null) {
        // Something is very wrong! We already created this fragment, but the
        // GinjectorBindingsOutputter should only create each fragment once.
        // Something bad will probably happen later on if we continue, so just
        // abort.
        logger.log(TreeLogger.Type.ERROR, "The fragment " + fragmentPackageName + "." + fragmentClassName + " already exists.");
        throw new IllegalStateException("The fragment " + fragmentClassName + " already exists.");
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(fragmentPackageName.toString(), fragmentClassName);

    composerFactory.addImport(GWT.class.getCanonicalName());
    composerFactory.addImport(ginjectorPackageName + "." + ginjectorClassName);
    writer = composerFactory.createSourceWriter(ctx, printWriter);

    injectorWriteContext = ginjectorFragmentContextFactory.create(bindings, fragmentPackageName, writer);
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:39,代碼來源:GinjectorFragmentOutputter.java

示例10: generate

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
@Override
public String generate(TreeLogger logger, GeneratorContext generatorContext, String typeName)
throws UnableToCompleteException
{
    TypeOracle types = generatorContext.getTypeOracle();

    ClassName componentTypeName = ClassName.bestGuess(typeName.substring(0,
        typeName.length() - COMPONENT_TEMPLATE_SUFFIX.length()));

    JClassType componentJsType;
    try
    {
        componentJsType =
            types.getType(componentJsTypeName(componentTypeName).reflectionName());
    }
    catch (NotFoundException nfe)
    {
        logger.log(Type.ERROR, "Not Found", nfe);
        throw new UnableToCompleteException();
    }

    ClassName templateImplTypeName = componentTemplateImplName(componentTypeName);
    PrintWriter printWriter = generatorContext.tryCreate(logger,
        templateImplTypeName.packageName(),
        templateImplTypeName.simpleName());

    if (printWriter != null)
    {
        generateOnce(printWriter, logger, generatorContext, componentJsType, componentTypeName);
    }

    return templateImplTypeName.reflectionName();
}
 
開發者ID:Axellience,項目名稱:vue-gwt,代碼行數:34,代碼來源:TemplateGwtGenerator.java

示例11: getSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext context, JClassType classType) {
	String packageName = packageNameFrom(classType);
	String simpleName = simpleNameFrom(classType);
	ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
	composer.addImplementedInterface(classType.getName());
	composer.addImport(classType.getQualifiedSourceName());
	PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
	if (printWriter == null) {
		return null; 
	} else {
		return composer.createSourceWriter(context, printWriter);
	} 
}
 
開發者ID:TOMOTON,項目名稱:gwt-dagger2,代碼行數:14,代碼來源:VersionGenerator.java

示例12: generateClass

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
/**
 * Generate the content of the class
 *
 * @param logger
 * @param context
 * @param packageName
 * @param className
 * @param extensions
 * @throws UnableToCompleteException
 */
private void generateClass(
    TreeLogger logger,
    GeneratorContext context,
    String packageName,
    String className,
    List<JClassType> extensions)
    throws UnableToCompleteException {
  PrintWriter pw = context.tryCreate(logger, packageName, className);
  if (pw == null) {
    return;
  }

  ClassSourceFileComposerFactory composerFactory =
      new ClassSourceFileComposerFactory(packageName, className);
  // generate imports
  generateImports(extensions, composerFactory);

  // interface
  composerFactory.addImplementedInterface(ExtensionRegistry.class.getCanonicalName());

  // get source writer
  SourceWriter sw = composerFactory.createSourceWriter(context, pw);
  // begin class definition
  // fields
  sw.println("private final Map<String, ExtensionDescription> extensions = new HashMap<>();");

  generateConstructor(className, extensions, sw);

  // methods
  generateGetExtensionsMethod(sw);
  // close it out
  sw.outdent();
  sw.println("}");

  context.commit(logger, pw);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:47,代碼來源:ExtensionRegistryGenerator.java

示例13: generate

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
/**
 * Generate Java code for factory class capable of returning instance for a class name.
 * <p>
 * It is not true introspection. In fact the whole factory class is a mapper; mapping class name
 * to constructor call. Like {@code if (className=="my.code.Foo1") return new my.code.Foo1();}
 * Only small section of classes can be instantiable this way. Supported classes are filtered
 * based marker interface, annotation or regex. This implementation is uses marker interface
 * {@link EntryPoint}.
 * 
 * @param logger
 * @param context
 *            provides list of all visible classes, see {@link GeneratorContext#getTypeOracle()}
 *            , and stream for printing the Java code, see {@link SourceWriter}.
 * @param typeName
 *            example: "my.code.client.reflection.ClassFromStringFactory" ???
 * @return implementation class name, example:
 *         my.code.client.reflection.ClassFromStringFactoryImpl
 */
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
  throws UnableToCompleteException
{
  // Filter all classes visible to GWT client side and return only supported ones
  List<JClassType> allInstantiableClasses = getAllInstantiableClassesByThisfactory(context);

  final String genPackageName = EntityFactory.class.getPackage().getName();
  logger.log(Type.INFO, "genPackageName: " + genPackageName);

  final String genClassName = EntityFactory.class.getSimpleName() + "Impl";

  // prepare Composer. Composer prepares shell of the Java code, so we need to set package and class name
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(genPackageName, genClassName);
  
  // register (add) required imports to Composer 
  // but the generated class uses fully qualified names everywhere, no imports required
  
  PrintWriter printWriter = context.tryCreate(logger, genPackageName, genClassName);
  if (printWriter != null) {
    composer.addImplementedInterface(EntityFactory.class.getSimpleName());

    // Get source stream from Composer. It already contains shell of the new class
    // like package, imports and full class signature
    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    // generate class content, content of the Java file, contructor and factory method
    generateFactoryClass(genClassName, composer, sourceWriter, logger, allInstantiableClasses);
  }
  return composer.getCreatedClassName();
}
 
開發者ID:KnowledgeCaptureAndDiscovery,項目名稱:ontosoft,代碼行數:50,代碼來源:EntityGenerator.java

示例14: getSourceWriter

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
private SourceWriter getSourceWriter(TreeLogger logger,
                                     GeneratorContext context,
                                     JClassType originalType,
                                     String packageName,
                                     String generatedClassName)
  throws UnableToCompleteException {

  logger.log(TreeLogger.INFO,
             "Generating writer for " + packageName + "." + generatedClassName,
             null);

  PrintWriter printWriter = context.tryCreate(logger,
                                              packageName,
                                              generatedClassName);
  if (printWriter == null) {
    return null;
  }

  ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName,
                                                                                   generatedClassName);

  classFactory.addImplementedInterface(originalType.getName());
  String[] classesToImport = getClassesToImport();
  for (String classToImport : classesToImport) {
    classFactory.addImport(classToImport);
  }

  return classFactory.createSourceWriter(context,
                                         printWriter);
}
 
開發者ID:mvp4g,項目名稱:mvp4g,代碼行數:31,代碼來源:Mvp4gGenerator.java

示例15: writeInterface

import com.google.gwt.core.ext.GeneratorContext; //導入方法依賴的package包/類
/**
 * Write an Empty Interface implementing
 * {@link de.knightsoftnet.validators.client.impl.GwtSpecificValidator} with Generic parameter of
 * the bean type.
 */
private void writeInterface(final GeneratorContext context, final TreeLogger logger,
    final BeanHelper bean) {
  final PrintWriter pw = context.tryCreate(logger, bean.getPackage(), bean.getValidatorName());
  if (pw != null) {
    final TreeLogger interfaceLogger = logger.branch(TreeLogger.TRACE,
        "Creating the interface for " + bean.getFullyQualifiedValidatorName());

    final ClassSourceFileComposerFactory factory =
        new ClassSourceFileComposerFactory(bean.getPackage(), bean.getValidatorName());
    factory.addImplementedInterface(
        GwtSpecificValidator.class.getCanonicalName() + " <" + bean.getTypeCanonicalName() + ">");
    factory.addImport(GWT.class.getCanonicalName());
    factory.makeInterface();
    final SourceWriter sw = factory.createSourceWriter(context, pw);

    // static MyValidator INSTANCE = GWT.create(MyValidator.class);
    sw.print("static ");
    sw.print(bean.getValidatorName());
    sw.print(" INSTANCE = GWT.create(");
    sw.print(bean.getValidatorName());
    sw.println(".class);");

    sw.commit(interfaceLogger);
    pw.close();
  }
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-bean-validators,代碼行數:32,代碼來源:BeanHelperCache.java


注:本文中的com.google.gwt.core.ext.GeneratorContext.tryCreate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。