com.google.gwt.core.ext.typeinfo.JPackage类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(18.8k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中com.google.gwt.core.ext.typeinfo.JPackage类的一些代码示例,展示了JPackage类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPackage类的具体详情如下:
包路径:com.google.gwt.core.ext.typeinfo.JPackage
类名称:JPackage

JPackage介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

private void createProxy (JClassType type) {
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(type.getPackage().getName(),
    type.getSimpleSourceName() + "Proxy");
  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  if (printWriter == null) {
    return;
  }
  SourceWriter writer = composer.createSourceWriter(context, printWriter);
  writer.commit(logger);
}

代码示例来源:origin: libgdx/libgdx

private void generateLookups () {
  TypeOracle typeOracle = context.getTypeOracle();
  JPackage[] packages = typeOracle.getPackages();
    for (JClassType t : p.getTypes()) {
      gatherTypes(t.getErasedType(), types);
    ConfigurationProperty prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.include");
    for (String s : prop.getValues()) {
      JClassType type = typeOracle.findType(s);
      if (type != null) gatherTypes(type.getErasedType(), types);
  gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types);
  gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types);
  gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types);
  logger.log(Type.INFO, types.size() + " types reflected");

代码示例来源:origin: seanchenxi/gwt-storage

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
 TypeOracle oracle = context.getTypeOracle();
 JClassType keyProviderIntf = oracle.findType(typeName);
 JClassType toGenerate = keyProviderIntf.isInterface();
 if (toGenerate == null) {
  logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
  throw new UnableToCompleteException();
 }
 String packageName = toGenerate.getPackage().getName();
 simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl";
 PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName);
 if (pw == null) {
  return packageName + "." + simpleSourceName;
 }
 model = new StorageKeyProviderModel(logger, toGenerate);
 model.loadMethods();
 ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
 factory.setSuperclass(AbstractStorageKeyProvider.class.getCanonicalName());
 factory.addImplementedInterface(typeName);
 SourceWriter sw = factory.createSourceWriter(context, pw);
 writeMethods(sw);
 sw.commit(logger);
 return factory.getCreatedClassName();
}

代码示例来源:origin: thothbot/parallax

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
  String packageName = toGenerate.getPackage().getName();
  String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl";
  PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName);
  if (pw == null) {
    return packageName + "." + simpleSourceName;
  ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
  factory.addImplementedInterface(typeName);
  factory.addImport(JsonBindFactory.class.getName());
  factory.addImport(AutoBeanFactory.class.getName());
  factory.addImport(GWT.class.getName());
  for (JPackage pack : oracle.getPackages())
    for (JClassType classtype : pack.getTypes())
  SourceWriter sw = factory.createSourceWriter(context, pw);
  sw.println("private static final FastMap<AutoBeanFactory> MAP = new FastMap<AutoBeanFactory>(){{");
    sw.println("put(\"%s\", new %s() );", entry.getValue().getQualifiedSourceName(), entry.getKey());
  sw.println("}};");

代码示例来源:origin: ekuefler/gwt-supereventbus

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;
}

代码示例来源:origin: cromwellian/angulargwt

throws UnableToCompleteException {
AngularGwtTypes types = AngularGwtTypes.getInstanceFor(context);
JClassType type = context.getTypeOracle().findType(typeName);
ClassSourceFileComposerFactory fac = new ClassSourceFileComposerFactory(
    type.getPackage().getName(), type.getName() + AngularConventions.FACTORY);
fac.addImplementedInterface(types.factoryType.getQualifiedSourceName());
fac.addImport(JsJsonObject.class.getName());
fac.addImport(Util.class.getName());
PrintWriter pw = context.tryCreate(logger, type.getPackage().getName(),
    type.getName() + AngularConventions.FACTORY);
SourceWriter sw = null;
sw.indent();
sw.println("public native " + ModelGenerator.generateModelType(logger, context, types, type)
    + " create() /*-{");
sw.indent();
sw.println("return {};");
sw.outdent();
sw.commit(logger);
logger.log(TreeLogger.Type.DEBUG, "Generated " + factoryTypeName);
return factoryTypeName;

代码示例来源:origin: dankurka/gwtphonegap

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
  PropertyOracle propertyOracle = context.getPropertyOracle();
  ConfigurationProperty property = null;
  int value = 100;
        value = Integer.parseInt(stringValue);
      } catch (Exception e) {
        logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
    logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
  String packageName = classType.getPackage().getName();
  String simpleName = classType.getSimpleSourceName() + "_" + value;
  String fullName = packageName + "." + simpleName;
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
  composer.addImplementedInterface(typeName);
  composer.addImport(typeName);
  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  SourceWriter writer = composer.createSourceWriter(context, printWriter);
  writer.commit(logger);

代码示例来源:origin: org.jboss.errai/errai-workspaces

public String generate(TreeLogger logger, GeneratorContext context,
            String typeName) throws UnableToCompleteException {
 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 sendNowWith logger that Map generation threw an exception
  logger.log(TreeLogger.ERROR, "Error generating icon factory", e);
 }
 // return the fully qualifed name of the class generated
 return packageName + "." + className;
}

代码示例来源:origin: net.wetheinter/gwt-user

@Override
public String generate(TreeLogger logger, GeneratorContext genCtx,
  String fqInterfaceName) throws UnableToCompleteException {
 TypeOracle oracle = genCtx.getTypeOracle();
 JClassType interfaceType;
 try {
  interfaceType = oracle.getType(fqInterfaceName);
 } catch (NotFoundException e) {
  logger.log(TreeLogger.ERROR, "Unexpected error: " + e.getMessage(), e);
  throw new UnableToCompleteException();
 String implName = interfaceType.getName();
 implName = implName.replace('.', '_') + "Impl";
 String packageName = interfaceType.getPackage().getName();
 PrintWriter printWriter = genCtx.tryCreate(logger, packageName, implName);
    new ClassSourceFileComposerFactory(packageName, implName);
  factory.addImplementedInterface(interfaceType.getQualifiedSourceName());
  SourceWriter sourceWriter =
    factory.createSourceWriter(genCtx, printWriter);
  implCreator.emitClass(logger, null);
  genCtx.commit(logger, printWriter);

代码示例来源:origin: fr.lteconsulting/hexa.core

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
  logger.log( Type.ERROR, "On me demande de générer : " + typeName );
  oracle = context.getTypeOracle();
  JClassType type = oracle.findType( typeName );
  PrintWriter pw = context.tryCreate(logger, type.getPackage().getName(), type.getSimpleSourceName()+"Impl");
  if( pw == null )
    return generatedClass;
  logger.log(Type.ERROR, "PKNAME:"+type.getPackage().getName()+" / CLSNAME:"+type.getSimpleSourceName()+"Impl" );
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory( type.getPackage().getName(), type.getSimpleSourceName()+"Impl" );
  composer.addImplementedInterface(typeName);
  composer.addImport( "com.google.gwt.json.client.JSONValue" );
  composer.addImport( "com.google.gwt.json.client.JSONObject" );
  composer.addImport( "com.google.gwt.json.client.JSONString" );
  logger.log(Type.ERROR, "Composer: " + composer);
  sourceWriter = composer.createSourceWriter( context, pw );
    generateMethod( methods[m] );
  sourceWriter.commit(logger);

代码示例来源:origin: net.wetheinter/gwt-reflect

public String getOrMakeFieldFactory(TreeLogger logger, GeneratorContext ctx, com.google.gwt.core.ext.typeinfo.JField field,
  com.google.gwt.core.ext.typeinfo.JType classType, ReflectionManifest manifest, boolean declaredOnly) throws UnableToCompleteException {
 // get cached manifest for this type
 String clsName = classType.getQualifiedSourceName();
 TypeOracle oracle = ctx.getTypeOracle();
 String name = field.getName();
 JClassType cls = oracle.findType(clsName);
 if (cls == null) {
  logger.log(Type.ERROR, "Unable to find enclosing class "+clsName);
  throw new UnableToCompleteException();
 }
  
 String fieldFactoryName = getFieldFactoryName(cls, name);
 JClassType factory;
 String pkgName = field.getEnclosingType().getPackage().getName();
 factory = oracle.findType(pkgName, fieldFactoryName);
 if (factory == null) {
  return generateFieldFactory(logger, ctx, field, fieldFactoryName, manifest);
 } else 
  return (pkgName.length()==0?"":pkgName+".")+ fieldFactoryName;
}

代码示例来源:origin: com.extjs/gxt

public String generate(String typeName) throws UnableToCompleteException {
 TypeOracle oracle = context.getTypeOracle();
  type = oracle.getType(typeName);
  elementType = oracle.getType(Element.class.getName());
  templatesType = oracle.getType(Templates.class.getName());
  templateType = oracle.getType(Template.class.getName());
  stringType = oracle.getType(String.class.getName());
  elType = oracle.getType(El.class.getName());
 } catch (NotFoundException e) {
  logger.log(TreeLogger.ERROR, "Class " + typeName + " not found.", e);
  throw new UnableToCompleteException();
 final String genPackageName = type.getPackage().getName();
 final String genClassName = (type.getName().replace('.', '_')) + "Impl";
 composer.addImplementedInterface(type.getQualifiedSourceName());
 composer.addImport(TemplatesCache.class.getName());
 PrintWriter pw = context.tryCreate(logger, genPackageName, genClassName);
  sw.commit(logger);
 return composer.getCreatedClassName();

代码示例来源:origin: com.googlecode.gwtquery/gwtquery

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
  throws UnableToCompleteException {
 TypeOracle oracle = context.getTypeOracle();
 PropertyOracle propOracle = context.getPropertyOracle();
  ua = propOracle.getSelectionProperty(logger, "user.agent").getCurrentValue();
 } catch (BadPropertyValueException e) {
  logger.log(TreeLogger.ERROR, "Can not resolve user.agent property", e);
  throw new UnableToCompleteException();
 JClassType clz = oracle.findType(typeName);
 String pName = clz.getPackage().getName();
 String cName = clz.getName() + "_" + ua;
 PrintWriter pWriter = context.tryCreate(logger, pName, cName);
  ClassSourceFileComposerFactory cFact = new ClassSourceFileComposerFactory(pName, cName);
  cFact.setSuperclass(pName + "." + clz.getName());
  SourceWriter writer = cFact.createSourceWriter(context, pWriter);
  writer.println("protected boolean isWebkit() {return " + "safari".equals(ua) + ";}");
  writer.println("protected boolean isSafari() {return " + "safari".equals(ua) + ";}");
  writer.println("protected boolean isOpera() {return " + "opera".equals(ua) + ";}");
  writer.println("protected boolean isMozilla() {return " + ua.contains("gecko") + ";}");
  writer.println("protected boolean isMsie() {return " + ua.contains("ie") + ";}");

代码示例来源:origin: sk.seges.acris/acris-widgets-beantable

private void generateMessagesClass(JMethod[] methods) {
  String packageName = classType.getPackage().getName();
  String simpleName = messagesTypeName();
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
  composer.makeInterface();
  composer.addImplementedInterface(Constants.class.getCanonicalName());
  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  if (logger.isLoggable(Type.DEBUG)) {
    logger.log(Type.DEBUG, "Creating messages source writer for " + simpleName + ", packageName = "
        + packageName + ", simpleName = " + simpleName + ", printWriter = " + printWriter);
  }
  if (printWriter == null) {
    return;
  } else {
    SourceWriter sw = composer.createSourceWriter(context, printWriter);
    for (JMethod method : methods) {
      sw.println("String " + method.getName() + "();");
    }
    sw.commit(logger);
  }
}

代码示例来源:origin: dankurka/mgwt

private String buildOnImplementation(TreeLogger logger, GeneratorContext context, JClassType classType, String typeName, ConfigurationProperty superDevModeServer) {
  if(superDevModeServer.getValues().get(0) == null){
    //use default impl!
    return "com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnDefaultImpl";
  }
  // get the package name
  String packageName = classType.getPackage().getName();
  // build name for implementation class
  String simpleName = classType.getSimpleSourceName() + "_generated";
  // combine package name and simple name to full qualified
  String fullName = packageName + "." + simpleName;
  ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
  composer.setSuperclass("com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnImpl");
  composer.addImport("com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnImpl");
  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  if (printWriter == null) {
    return fullName;
  }
  // start writing the implementation
  SourceWriter writer = composer.createSourceWriter(context, printWriter);
  writer.println("protected String getServerUrl() {");
  writer.println("return \"" + superDevModeServer.getValues().get(0) + "\";");
  writer.println("}");
  writer.commit(logger);
  return fullName;
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

throws UnableToCompleteException {
if (!BASE_CLASS.equals(typeName)) {
 logger.log(TreeLogger.ERROR, "This generator may only be used with " + BASE_CLASS, null);
 throw new UnableToCompleteException();
 requestedClass = context.getTypeOracle().getType(typeName);
} catch (NotFoundException e) {
 logger.log(
   TreeLogger.ERROR,
   "Could not find type '"
     + "'; please see the log, as this usually indicates a previous error ",
   e);
 throw new UnableToCompleteException();
 ConfigurationProperty prop = context.getPropertyOracle().getConfigurationProperty(
   "junit.moduleName");
 moduleName = prop.getValues().get(0);
} catch (BadPropertyValueException e) {
 logger.log(TreeLogger.ERROR,
   "Could not resolve junit.moduleName property", e);
 throw new UnableToCompleteException();
String packageName = requestedClass.getPackage().getName();
String generatedClass = requestedClass.getName() + "Impl";
 sourceWriter.commit(logger);

代码示例来源:origin: net.wetheinter/gwt-reflect

ReflectionStrategy defaultStrategy = ConstPoolInjector.class.getAnnotation(ReflectionStrategy.class);
TypeOracle oracle = ctx.getTypeOracle();
boolean doLog = logger.isLoggable(logLevel);
if (doLog)
 logger = logger.branch(logLevel, "Injecting all remaining members into ClassPool");
for (com.google.gwt.core.ext.typeinfo.JClassType type : oracle.getTypes()) {
 ReflectionStrategy strategy = type.getAnnotation(ReflectionStrategy.class);
 if (strategy == null) {
  JPackage pkg = packages.get(type.getPackage().getName());
  if (pkg == null) {
   pkg = type.getPackage();
   packages.put(pkg.getName(), pkg);
  strategy = pkg.getAnnotation(ReflectionStrategy.class);
  if (strategy == null) {
   if (type.findAnnotationInTypeHierarchy(GwtRetention.class) != null) {
   logger.log(logLevel, "Adding type to ConstPool: "+type.getJNISignature());
 logger.log(Type.ERROR, "Unable to get a handle on GwtReflect.magicClass");
 throw new UnableToCompleteException();

代码示例来源:origin: libgdx/libgdx

public ReflectionCacheSourceCreator (TreeLogger logger, GeneratorContext context, JClassType type) {
  this.logger = logger;
  this.context = context;
  this.type = type;
  this.packageName = type.getPackage().getName();
  this.simpleName = type.getSimpleSourceName() + "Generated";
  logger.log(Type.INFO, type.getQualifiedSourceName());
}

代码示例来源:origin: org.switchyard.console.wildfly/switchyard-console-wildfly-component-core

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
    throws UnableToCompleteException {
  TypeOracle typeOracle = context.getTypeOracle();
  JClassType componentExtensionManager = typeOracle.findType(typeName);
  if (componentExtensionManager == null) {
    logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
    throw new UnableToCompleteException();
  if (componentExtensionManager.isInterface() == null) {
    logger.log(TreeLogger.ERROR, componentExtensionManager.getQualifiedSourceName() + " is not an interface",
        null);
    throw new UnableToCompleteException();
  JClassType componentProvider = typeOracle.findType(ComponentProvider.class.getCanonicalName());
  if (componentProvider == null) {
    logger.log(TreeLogger.ERROR, "Unable to find metadata for type 'ComponentProvider'", null);
    throw new UnableToCompleteException();
  for (JClassType type : typeOracle.getTypes()) {
    if (type.isAnnotationPresent(ComponentExtension.class)) {
      if (type.isClass() == null || type.isAbstract()) {
  String packageName = componentExtensionManager.getPackage().getName();
  String className = componentExtensionManager.getSimpleSourceName() + "Impl";

代码示例来源:origin: ekuefler/gwt-supereventbus

@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 EventRegistrationWriter(logger).writeGetMethods(targetType, writer);
   writer.commit(logger);
  }
  return new StringBuilder()
    .append(eventBinderType.getPackage().getName())
    .append('.')
    .append(getSimpleGeneratedClassName(eventBinderType))
    .toString();
 } catch (NotFoundException e) {
  logger.log(Type.ERROR, "Error generating " + typeName, e);
  throw new UnableToCompleteException();
 }
}

相关文章