com.google.gwt.core.ext.typeinfo.TypeOracle Java Examples
The following examples show how to use
com.google.gwt.core.ext.typeinfo.TypeOracle.
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: EventsAnnotationsLoader.java From mvp4g with Apache License 2.0 | 6 votes |
/** * Build event bus element according to the implemented interface. * * @param c annoted class type * @param configuration configuration containing loaded elements of the application * @return event bus corresponding to the implemented interface (null if none of the interfaces * are implemented) */ private EventBusElement buildEventBusElement(JClassType c, Mvp4gConfiguration configuration) { TypeOracle oracle = configuration.getOracle(); EventBusElement eventBus = null; if (c.isAssignableTo(oracle.findType(EventBusWithLookup.class.getCanonicalName()))) { eventBus = new EventBusElement(c.getQualifiedSourceName(), BaseEventBusWithLookUp.class.getCanonicalName(), true); } else if (c.isAssignableTo(oracle.findType(EventBus.class.getCanonicalName()))) { eventBus = new EventBusElement(c.getQualifiedSourceName(), BaseEventBus.class.getCanonicalName(), false); } return eventBus; }
Example #2
Source File: JacksonTypeOracle.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * <p>Constructor for JacksonTypeOracle.</p> * * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object. * @param typeOracle a {@link com.google.gwt.core.ext.typeinfo.TypeOracle} object. */ public JacksonTypeOracle( TreeLogger logger, TypeOracle typeOracle ) { this.logger = logger; this.typeOracle = typeOracle; this.objectReaderType = typeOracle.findType( ObjectReader.class.getCanonicalName() ); this.objectWriterType = typeOracle.findType( ObjectWriter.class.getCanonicalName() ); this.keySerializerType = typeOracle.findType( KeySerializer.class.getCanonicalName() ); this.keyDeserializerType = typeOracle.findType( KeyDeserializer.class.getCanonicalName() ); this.jsonSerializerType = typeOracle.findType( JsonSerializer.class.getCanonicalName() ); this.jsonDeserializerType = typeOracle.findType( JsonDeserializer.class.getCanonicalName() ); this.mapType = typeOracle.findType( Map.class.getCanonicalName() ); this.iterableType = typeOracle.findType( Iterable.class.getCanonicalName() ); this.jsoType = typeOracle.findType( JavaScriptObject.class.getCanonicalName() ); this.enumType = typeOracle.findType( Enum.class.getCanonicalName() ); this.stringType = typeOracle.findType( String.class.getCanonicalName() ); }
Example #3
Source File: EventBinderWriterTest.java From gwteventbinder with Apache License 2.0 | 6 votes |
private TypeOracle createTypeOracle() { TypeOracle typeOracle = mock(TypeOracle.class); when(typeOracle.findType(anyString())).then(new Answer<JClassType>() { @Override public JClassType answer(InvocationOnMock invocationOnMock) throws Throwable { String parameter = (String) invocationOnMock.getArguments()[0]; Class<? extends GenericEvent> klass; try { klass = (Class<? extends GenericEvent>) Class.forName(parameter); } catch (ClassNotFoundException ex) { char[] klassName = parameter.toCharArray(); klassName[parameter.lastIndexOf('.')] = '$'; klass = (Class<? extends GenericEvent>) Class.forName(String.valueOf(klassName)); } return getEventType(klass); } }); return typeOracle; }
Example #4
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 #5
Source File: XMLElement.java From gwt-material-demo with Apache License 2.0 | 5 votes |
XMLElement(Element elem, AttributeParsers attributeParsers, TypeOracle oracle, MortalLogger logger, DesignTimeUtils designTime, XMLElementProvider provider) { this.elem = elem; this.attributeParsers = attributeParsers; this.oracle = oracle; this.logger = logger; this.designTime = designTime; this.provider = provider; this.debugString = getOpeningTag(); }
Example #6
Source File: Mvp4gRunAsyncGenerator.java From mvp4g with Apache License 2.0 | 5 votes |
@Override public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext generatorContext, String typeName) throws UnableToCompleteException { TypeOracle typeOracle = generatorContext.getTypeOracle(); assert (typeOracle != null); JClassType originalType = typeOracle.findType(typeName); if (originalType == null) { logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'"); throw new UnableToCompleteException(); } if (originalType.isInterface() == null) { logger.log(TreeLogger.ERROR, "'" + typeName + "' is not a interface"); throw new UnableToCompleteException(); } TreeLogger moduleLogger = logger.branch(TreeLogger.DEBUG, "Generating client proxy for remote service interface '" + originalType.getQualifiedSourceName() + "'", null); return create(originalType, moduleLogger, generatorContext, typeName); }
Example #7
Source File: Mvp4gGenerator.java From mvp4g with Apache License 2.0 | 5 votes |
@Override public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext generatorContext, String moduleClass) throws UnableToCompleteException { TypeOracle typeOracle = generatorContext.getTypeOracle(); assert (typeOracle != null); JClassType module = typeOracle.findType(moduleClass); if (module == null) { logger.log(TreeLogger.ERROR, "Unable to find metadata for module class '" + moduleClass + "'"); throw new UnableToCompleteException(); } if (module.isInterface() == null) { logger.log(TreeLogger.ERROR, "'" + moduleClass + "' is not a interface"); throw new UnableToCompleteException(); } TreeLogger moduleLogger = logger.branch(TreeLogger.DEBUG, "Generating mvp4g configuration for module class '" + module.getQualifiedSourceName() + "'", null); return create(moduleLogger, generatorContext, moduleClass); }
Example #8
Source File: EventBinderGenerator.java From gwteventbinder with Apache License 2.0 | 5 votes |
private JClassType getTargetType(JClassType interfaceType, TypeOracle typeOracle) { JClassType[] superTypes = interfaceType.getImplementedInterfaces(); JClassType eventBinderType = typeOracle.findType(EventBinder.class.getCanonicalName()); if (superTypes.length != 1 || !superTypes[0].isAssignableFrom(eventBinderType) || superTypes[0].isParameterized() == null) { throw new IllegalArgumentException( interfaceType + " must extend EventBinder with a type parameter"); } return superTypes[0].isParameterized().getTypeArgs()[0]; }
Example #9
Source File: EventBinderWriter.java From gwteventbinder with Apache License 2.0 | 5 votes |
void writeDoBindEventHandlers(JClassType target, SourceWriter writer, TypeOracle typeOracle) throws UnableToCompleteException { writeBindMethodHeader(writer, target.getQualifiedSourceName()); for (JMethod method : target.getInheritableMethods()) { EventHandler annotation = method.getAnnotation(EventHandler.class); if (annotation != null) { writeHandlerForBindMethod(annotation, writer, method, typeOracle); } } writeBindMethodFooter(writer); }
Example #10
Source File: GssResourceGenerator.java From gss.gwt with Apache License 2.0 | 5 votes |
private SortedSet<JClassType> computeOperableTypes(ResourceContext context) { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType baseInterface = typeOracle.findType(GssResource.class.getCanonicalName()); SortedSet<JClassType> toReturn = new TreeSet<JClassType>(new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) { toReturn.add(type); } } return toReturn; }
Example #11
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 #12
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 #13
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 #14
Source File: GeneratorContextStub.java From mvp4g with Apache License 2.0 | 4 votes |
public TypeOracle getTypeOracle() { return typeOracle; }
Example #15
Source File: EventBinderWriter.java From gwteventbinder with Apache License 2.0 | 4 votes |
private void writeHandlerForBindMethod(EventHandler annotation, SourceWriter writer, JMethod method, TypeOracle typeOracle) throws UnableToCompleteException { JClassType eventParameter = null; if (method.getParameterTypes().length == 1) { eventParameter = method.getParameterTypes()[0].isClassOrInterface(); } if (annotation.handles().length == 0 && !isAConcreteGenericEvent(eventParameter)) { logger.log(Type.ERROR, "Method " + method.getName() + " annotated with @EventHandler without event classes must have exactly " + "one argument of a concrete type assignable to GenericEvent"); throw new UnableToCompleteException(); } List<String> eventTypes = new ArrayList<String>(); if (annotation.handles().length != 0) { for (Class<? extends GenericEvent> event : annotation.handles()) { String eventTypeName = event.getCanonicalName(); JClassType eventClassType = typeOracle.findType(eventTypeName); if (eventClassType == null) { logger.log(Type.ERROR, "Can't resolve " + eventTypeName); throw new UnableToCompleteException(); } if (eventParameter != null && !eventClassType.isAssignableTo(eventParameter)) { logger.log(Type.ERROR, "Event " + eventTypeName + " isn't assignable to " + eventParameter.getName() + " in method: " + method.getName()); throw new UnableToCompleteException(); } eventTypes.add(eventClassType.getQualifiedSourceName()); } } else { eventTypes.add(eventParameter.getQualifiedSourceName()); } for (String eventType : eventTypes) { writer.println("bind(eventBus, registrations, %s.class, new GenericEventHandler() {", eventType); if (eventParameter != null) { writer.indentln("public void handleEvent(GenericEvent event) { target.%s((%s) event); }", method.getName(), eventType); } else { writer.indentln("public void handleEvent(GenericEvent event) { target.%s(); }", method.getName()); } writer.println("});"); } }