Java Code Examples for com.google.gwt.core.ext.typeinfo.JClassType#getSimpleSourceName()
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JClassType#getSimpleSourceName() .
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: ProductConfigGenerator.java From core with GNU Lesser General Public License v2.1 | 6 votes |
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 2
Source File: ObjectMapperCreator.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * Build the constructor. * * @param mappedTypeClass the type to map * * @return the constructor method */ private MethodSpec buildConstructor( JClassType mappedTypeClass ) { Optional<JsonRootName> jsonRootName = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, mappedTypeClass, JsonRootName.class ); String rootName; if ( !jsonRootName.isPresent() || Strings.isNullOrEmpty( jsonRootName.get().value() ) ) { rootName = mappedTypeClass.getSimpleSourceName(); } else { rootName = jsonRootName.get().value(); } return MethodSpec.constructorBuilder() .addModifiers( Modifier.PUBLIC ) .addStatement( "super($S)", rootName ) .build(); }
Example 3
Source File: MayStopActivityCreatorFactory.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void createDelegates(JClassType injectableType, Collection<InjectorCreatorDelegate> delegates) { Collection<JMethod> methods = InjectCreatorUtil.listMethod(injectableType, MayStopActivityHandler.class); if (!methods.isEmpty()) { String injectorName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; delegates.add(new InjectMayStopActivityCreator(methods, injectorName)); } }
Example 4
Source File: ApplicationMetaDataGenerator.java From core with GNU Lesser General Public License v2.1 | 5 votes |
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 5
Source File: GssResourceGenerator.java From gss.gwt with Apache License 2.0 | 5 votes |
/** * Returns the import prefix for a type, including the trailing hyphen. */ private String getImportPrefix(JClassType importType) { String prefix = importType.getSimpleSourceName(); ImportedWithPrefix exp = importType.getAnnotation(ImportedWithPrefix.class); if (exp != null) { prefix = exp.value(); } return prefix + "-"; }
Example 6
Source File: InjectTemplateCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public InjectTemplateCreator(JClassType viewType) { this.viewType = viewType; this.templateInterfaceName = viewType.getSimpleSourceName() + "TemplateBinder"; Templated templateAnnotation = viewType.getAnnotation(Templated.class); if (Templated.DEFAULT_VALUE.equals(templateAnnotation.value())) { this.templateName = null; } else { this.templateName = templateAnnotation.value(); } }
Example 7
Source File: InjectErrorManagerCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public InjectErrorManagerCreator(JClassType injectableType, ErrorManagmentDescription errorManagmentDescritpion) { this.injectorName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; this.errorDisplay = errorManagmentDescritpion.errorDisplay(); this.errorHandlers = errorManagmentDescritpion.errorHandlers(); this.handlerMethods = InjectCreatorUtil.listMethod(injectableType, fr.putnami.pwt.core.inject.client.annotation.ErrorHandler.class); }
Example 8
Source File: ErrorHandlerCreatorFactory.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void createDelegates(JClassType injectableType, Collection<InjectorCreatorDelegate> delegates) { Collection<JMethod> methods = InjectCreatorUtil.listMethod(injectableType, ErrorHandler.class); if (!methods.isEmpty()) { String injectorName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; delegates.add(new InjectErrorHandlerCreator(methods, injectorName)); } }
Example 9
Source File: PresenterCreatorFactory.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void createDelegates(JClassType injectableType, Collection<InjectorCreatorDelegate> delegates) { Collection<JMethod> methods = InjectCreatorUtil.listMethod(injectableType, PresentHandler.class); delegates.add(new InjectPresenterCreator(methods)); Collection<JField> services = InjectCreatorUtil.listFields(injectableType, InjectService.class); String injectorName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; delegates.add(new SuspendServiceOnPresentCreator(injectorName, !services.isEmpty())); }
Example 10
Source File: StopActivityCreatorFactory.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void createDelegates(JClassType injectableType, Collection<InjectorCreatorDelegate> delegates) { Collection<JMethod> methods = InjectCreatorUtil.listMethod(injectableType, StopActivityHandler.class); if (!methods.isEmpty()) { String injectorName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; delegates.add(new InjectStopActivityCreator(methods, injectorName)); } }
Example 11
Source File: TextBinderGenerator.java From EasyML with Apache License 2.0 | 4 votes |
@Override public String generate(TreeLogger logger, GeneratorContext context, String requestedClass) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); JClassType objectType = typeOracle.findType(requestedClass); if (objectType == null) { logger.log(TreeLogger.ERROR, "Could not find type: " + requestedClass); throw new UnableToCompleteException(); } implTypeName = objectType.getSimpleSourceName() + "Impl"; implPackageName = objectType.getPackage().getName(); JClassType[] implementedTypes = objectType.getImplementedInterfaces(); // Can only implement one interface if (implementedTypes == null || implementedTypes.length != 1 || !implementedTypes[0].getQualifiedSourceName().equals( TextBinder.class.getName())) { logger .log( TreeLogger.ERROR, "The type: " + requestedClass + " Must implement only one interface: " + TextBinder.class.getName()); throw new UnableToCompleteException(); } // Get parameterized type JParameterizedType parameterType = implementedTypes[0].isParameterized(); if (parameterType == null) { logger.log(TreeLogger.ERROR, "The type: " + requestedClass + " Must implement only one parameterized interface: " + TextBinder.class.getName()); throw new UnableToCompleteException(); } if (parameterType.getTypeArgs() == null || parameterType.getTypeArgs().length != 2) { logger.log(TreeLogger.ERROR, "The type: " + requestedClass + " Must implement two parameterized interface: " + TextBinder.class.getName() + " with two Parameter"); throw new UnableToCompleteException(); } parameterizedType1 = parameterType.getTypeArgs()[0]; parameterizedType2 = parameterType.getTypeArgs()[1]; // logger.log(TreeLogger.INFO , // parameterizedType2.getParameterizedQualifiedSourceName() +"\n" // + parameterizedType2.getQualifiedSourceName()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory( implPackageName, implTypeName); composerFactory.addImport(Map.class.getCanonicalName()); composerFactory.addImport(List.class.getCanonicalName()); // composerFactory.addImport(Field.class.getCanonicalName()); composerFactory .addImplementedInterface(objectType.getQualifiedSourceName()); PrintWriter printWriter = context.tryCreate(logger, implPackageName, implTypeName); if (printWriter != null) { SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter); composeBindMethod(logger, sourceWriter); composeSyncMethod(logger, sourceWriter); sourceWriter.commit(logger); } return implPackageName + "." + implTypeName; }
Example 12
Source File: ObjectMapperCreator.java From gwt-jackson with Apache License 2.0 | 4 votes |
/** * Creates the implementation of the interface denoted by interfaceClass and extending {@link ObjectMapper} * * @param interfaceClass the interface to generate an implementation * @return the fully qualified name of the created class * @throws com.google.gwt.core.ext.UnableToCompleteException if any. */ public String create( JClassType interfaceClass ) throws UnableToCompleteException { // We concatenate the name of all the enclosing class. StringBuilder builder = new StringBuilder( interfaceClass.getSimpleSourceName() + "Impl" ); JClassType enclosingType = interfaceClass.getEnclosingType(); while ( null != enclosingType ) { builder.insert( 0, enclosingType.getSimpleSourceName() + "_" ); enclosingType = enclosingType.getEnclosingType(); } String mapperClassSimpleName = builder.toString(); String packageName = interfaceClass.getPackage().getName(); String qualifiedMapperClassName = packageName + "." + mapperClassSimpleName; PrintWriter printWriter = getPrintWriter( packageName, mapperClassSimpleName ); // The class already exists, no need to continue. if ( printWriter == null ) { return qualifiedMapperClassName; } try { // Extract the type of the object to map. JClassType mappedTypeClass = extractMappedType( interfaceClass ); boolean reader = typeOracle.isObjectReader( interfaceClass ); boolean writer = typeOracle.isObjectWriter( interfaceClass ); Class<?> abstractClass; if ( reader ) { if ( writer ) { abstractClass = AbstractObjectMapper.class; } else { abstractClass = AbstractObjectReader.class; } } else { abstractClass = AbstractObjectWriter.class; } TypeSpec.Builder mapperBuilder = TypeSpec.classBuilder( mapperClassSimpleName ) .addModifiers( Modifier.PUBLIC, Modifier.FINAL ) .addSuperinterface( typeName( interfaceClass ) ) .superclass( parameterizedName( abstractClass, mappedTypeClass ) ) .addMethod( buildConstructor( mappedTypeClass ) ); if ( reader ) { mapperBuilder.addMethod( buildNewDeserializerMethod( mappedTypeClass ) ); } if ( writer ) { mapperBuilder.addMethod( buildNewSerializerMethod( mappedTypeClass ) ); } write( packageName, mapperBuilder.build(), printWriter ); } finally { printWriter.close(); } return qualifiedMapperClassName; }
Example 13
Source File: AbstractInjectorCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
public AbstractInjectorCreator(JClassType injectableType) { this.injectableType = injectableType; this.packageName = injectableType.getPackage().getName(); this.proxyName = injectableType.getSimpleSourceName() + AbstractInjectorCreator.PROXY_SUFFIX; this.proxyQualifiedName = injectableType.getPackage().getName() + "." + this.proxyName; }
Example 14
Source File: AbstractCreator.java From gwt-jackson with Apache License 2.0 | 4 votes |
/** * Returns the mapper information for the given type. The result is cached. * * @param beanType the type * @return the mapper information * @throws com.google.gwt.core.ext.UnableToCompleteException if an exception occured while processing the type */ protected final BeanJsonMapperInfo getMapperInfo( JClassType beanType ) throws UnableToCompleteException { BeanJsonMapperInfo mapperInfo = typeOracle.getBeanJsonMapperInfo( beanType ); if ( null != mapperInfo ) { return mapperInfo; } boolean samePackage = true; String packageName = beanType.getPackage().getName(); // We can't create classes in the java package so we prefix it. if ( packageName.startsWith( "java." ) ) { packageName = "gwtjackson." + packageName; samePackage = false; } // Retrieve the informations on the beans and its properties. BeanInfo beanInfo = BeanProcessor.processBean( logger, typeOracle, configuration, beanType ); PropertiesContainer properties = PropertyProcessor .findAllProperties( configuration, logger, typeOracle, beanInfo, samePackage ); beanInfo = BeanProcessor.processProperties( configuration, logger, typeOracle, beanInfo, properties ); // We concatenate the name of all the enclosing classes. StringBuilder builder = new StringBuilder( beanType.getSimpleSourceName() ); JClassType enclosingType = beanType.getEnclosingType(); while ( null != enclosingType ) { builder.insert( 0, enclosingType.getSimpleSourceName() + "_" ); enclosingType = enclosingType.getEnclosingType(); } // If the type is specific to the mapper, we concatenate the name and hash of the mapper to it. boolean isSpecificToMapper = configuration.isSpecificToMapper( beanType ); if ( isSpecificToMapper ) { JClassType rootMapperClass = configuration.getRootMapperClass(); builder.insert( 0, '_' ).insert( 0, configuration.getRootMapperHash() ).insert( 0, '_' ).insert( 0, rootMapperClass .getSimpleSourceName() ); } String simpleSerializerClassName = builder.toString() + "BeanJsonSerializerImpl"; String simpleDeserializerClassName = builder.toString() + "BeanJsonDeserializerImpl"; mapperInfo = new BeanJsonMapperInfo( beanType, packageName, samePackage, simpleSerializerClassName, simpleDeserializerClassName, beanInfo, properties .getProperties() ); typeOracle.addBeanJsonMapperInfo( beanType, mapperInfo ); return mapperInfo; }
Example 15
Source File: Mvp4gGenerator.java From mvp4g with Apache License 2.0 | 4 votes |
private RebindResult create(TreeLogger logger, GeneratorContext context, String moduleName) throws UnableToCompleteException { Date start = new Date(); String generatedClassQualifiedName; try { TypeOracle typeOracle = context.getTypeOracle(); JClassType module = typeOracle.findType(moduleName); if (module == null) { logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + moduleName + "'", null); throw new UnableToCompleteException(); } @SuppressWarnings("unchecked") Map<Class<? extends Annotation>, List<JClassType>> scanResult = AnnotationScanner.scan(logger, typeOracle, new Class[] { Presenter.class, History.class, Events.class, Service.class, EventHandler.class }); Mvp4gConfiguration configuration = new Mvp4gConfiguration(logger, context); String suffix = "Impl" + configuration.load(module, scanResult); generatedClassQualifiedName = module.getParameterizedQualifiedSourceName() + suffix; String packageName = module.getPackage() .getName(); String originalClassName = module.getSimpleSourceName(); String generatedClassName = originalClassName + suffix; // check weather there is a usual version or not. if (checkAlreadyGenerated(logger, context, configuration)) { // Log logger.log(TreeLogger.INFO, "Reuse already generated files", null); // stop generating return new RebindResult(RebindMode.USE_EXISTING, packageName + "." + generatedClassName); } // Log logger.log(TreeLogger.INFO, "Start generate files ... ", null); // No, there is non. Create a new one. SourceWriter sourceWriter = getSourceWriter(logger, context, module, packageName, generatedClassName); if (sourceWriter != null) { logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null); Mvp4gConfigurationFileWriter writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration); writer.writeConf(); sourceWriter.commit(logger); } else { // don't expect this to occur, but could happen if an instance was // recently generated but not yet committed new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName); } Date end = new Date(); logger.log(TreeLogger.INFO, "Mvp4g Compilation: " + (end.getTime() - start.getTime()) + "ms."); return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + generatedClassName); } catch (InvalidMvp4gConfigurationException e) { logger.log(TreeLogger.ERROR, e.getMessage(), e); throw new UnableToCompleteException(); } }
Example 16
Source File: Mvp4gRunAsyncGenerator.java From mvp4g with Apache License 2.0 | 4 votes |
private RebindResult create(JClassType originalType, TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { Date start = new Date(); String packageName = originalType.getPackage() .getName(); String originalClassName = originalType.getSimpleSourceName(); String generatedClassName = originalClassName + "Impl"; String generatedClassQualifiedName = packageName + "." + generatedClassName; // check weather there is a usual version or not. if (checkAlreadyGenerated(logger, context, generatedClassQualifiedName)) { // Log logger.log(TreeLogger.INFO, "reuse already generated files", null); // stop generating return new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName); } logger.log(TreeLogger.INFO, "Generating writer for " + packageName + "." + generatedClassName, null); PrintWriter printWriter = context.tryCreate(logger, packageName, generatedClassName); ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName, generatedClassName); classFactory.addImplementedInterface(originalType.getName()); String[] classesToImport = getClassesToImport(); for (String classToImport : classesToImport) { classFactory.addImport(classToImport); } if (printWriter != null) { SourceWriter sourceWriter = classFactory.createSourceWriter(context, printWriter); logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null); writeClass(sourceWriter, getRunAsync(originalType)); sourceWriter.commit(logger); } Date end = new Date(); logger.log(TreeLogger.INFO, "Mvp4g Module Cretor: " + (end.getTime() - start.getTime()) + "ms."); return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, generatedClassQualifiedName); }
Example 17
Source File: ExtendedServiceProxyGenerator.java From appinventor-extensions with Apache License 2.0 | 4 votes |
/** * Generates a wrapper around the proxy generated by * {@link ServiceInterfaceProxyGenerator}. * * @param logger log interface * @param context generator context * @param typeName name of the interface that was passed to * {@link com.google.gwt.core.client.GWT#create(Class)} * @param proxyTypeName the name of the wrapped proxy class * @return the name of the extended proxy class */ private String generateExtendedProxy(TreeLogger logger, GeneratorContext context, String typeName, String proxyTypeName) { JClassType type = context.getTypeOracle().findType(typeName); String packageName = type.getPackage().getName(); String className = type.getSimpleSourceName() + PROXY_SUFFIX; String asyncName = typeName + ASYNC_SUFFIX; String classNameExtendedServiceProxy = "com.google.appinventor.client.ExtendedServiceProxy"; // The generator can be invoked for the same class name more than once. // In this case the GeneratorContext.tryCreate method will return null to // indicate that the file already exists. This is not an error. PrintWriter out = context.tryCreate(logger, packageName, className); if (out != null) { out.println("package " + packageName + ";"); out.println("class " + className); out.println(" extends " + classNameExtendedServiceProxy + "<" + typeName + ">"); out.println(" implements " + ServiceDefTarget.class.getName() + ", " + asyncName + " {"); out.println(" private " + proxyTypeName + " proxy = new " + proxyTypeName + "();"); out.println(" public String getServiceEntryPoint() {"); out.println(" return proxy.getServiceEntryPoint();"); out.println(" }"); out.println(" public void setRpcRequestBuilder(" + RpcRequestBuilder.class.getName() + " builder) {"); out.println(" proxy.setRpcRequestBuilder(builder);"); out.println(" }"); out.println(" public void setServiceEntryPoint(String address) {"); out.println(" proxy.setServiceEntryPoint(address);"); out.println(" }"); out.println(" public String getSerializationPolicyName() {"); out.println(" return proxy.getSerializationPolicyName();"); out.println(" }"); for (JMethod method : type.getMethods()) { printMethod(out, method, typeName); } out.println("}"); context.commit(logger, out); } return packageName + "." + className; }