Java Code Examples for com.google.gwt.core.ext.typeinfo.JClassType#getImplementedInterfaces()
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JClassType#getImplementedInterfaces() .
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: UiBinderLocalizedCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public UiBinderLocalizedCreator(JClassType binderType, GwtLocale locale) { this.binderType = binderType; this.locale = locale; for (JClassType interfaceType : binderType.getImplementedInterfaces()) { if (interfaceType.getQualifiedSourceName().equals(UiBinderLocalized.class.getCanonicalName()) && interfaceType instanceof JParameterizedType) { JParameterizedType paramType = (JParameterizedType) interfaceType; this.widgetType = paramType.getTypeArgs()[0]; this.targetType = paramType.getTypeArgs()[1]; } } UiTemplate templateAnnotation = binderType.getAnnotation(UiTemplate.class); if (templateAnnotation != null) { this.templateName = templateAnnotation.value().replace(UiBinderLocalizedCreator.TEMPLATE_SUFFIX, ""); } if (this.templateName == null) { this.templateName = this.targetType.getSimpleSourceName(); } }
Example 2
Source File: PropertyParser.java From gwt-jackson with Apache License 2.0 | 6 votes |
private static void parse( RebindConfiguration configuration, TreeLogger logger, JClassType type, Map<String, PropertyAccessorsBuilder> propertiesMap, boolean mixin ) { if ( null == type ) { return; } if ( !mixin ) { Optional<JClassType> mixinAnnotation = configuration.getMixInAnnotations( type ); if ( mixinAnnotation.isPresent() ) { parse( configuration, logger, mixinAnnotation.get(), propertiesMap, true ); } } parseFields( logger, type, propertiesMap, mixin ); parseMethods( logger, type, propertiesMap, mixin ); for ( JClassType interf : type.getImplementedInterfaces() ) { parse( configuration, logger, interf, propertiesMap, mixin ); } parse( configuration, logger, type.getSuperclass(), propertiesMap, mixin ); }
Example 3
Source File: ObjectMapperCreator.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * Extract the type to map from the interface. * * @param interfaceClass the interface * * @return the extracted type to map * @throws UnableToCompleteException if we don't find the type */ private JClassType extractMappedType( JClassType interfaceClass ) throws UnableToCompleteException { JClassType intf = interfaceClass.isInterface(); if ( intf == null ) { logger.log( TreeLogger.Type.ERROR, "Expected " + interfaceClass + " to be an interface." ); throw new UnableToCompleteException(); } JClassType[] intfs = intf.getImplementedInterfaces(); for ( JClassType t : intfs ) { if ( t.getQualifiedSourceName().equals( OBJECT_MAPPER_CLASS ) ) { return extractParameterizedType( OBJECT_MAPPER_CLASS, t.isParameterized() ); } else if ( t.getQualifiedSourceName().equals( OBJECT_READER_CLASS ) ) { return extractParameterizedType( OBJECT_READER_CLASS, t.isParameterized() ); } else if ( t.getQualifiedSourceName().equals( OBJECT_WRITER_CLASS ) ) { return extractParameterizedType( OBJECT_WRITER_CLASS, t.isParameterized() ); } } logger.log( TreeLogger.Type.ERROR, "Expected " + interfaceClass + " to extend one of the following interface : " + OBJECT_MAPPER_CLASS + ", " + OBJECT_READER_CLASS + " or " + OBJECT_WRITER_CLASS ); throw new UnableToCompleteException(); }
Example 4
Source File: CreatorUtils.java From gwt-jackson with Apache License 2.0 | 5 votes |
/** * Browse all the hierarchy of the type and return the first corresponding annotation it found * * @param type type * @param annotation annotation to find * @param <T> type of the annotation * @param ignoreType type to ignore when browsing the hierarchy * * @return the annotation if found, null otherwise */ private static <T extends Annotation> Optional<T> findFirstEncounteredAnnotationsOnAllHierarchy( RebindConfiguration configuration, JClassType type, Class<T> annotation, Optional<JClassType> ignoreType ) { JClassType currentType = type; while ( null != currentType ) { Optional<JClassType> mixin = configuration.getMixInAnnotations( currentType ); if ( mixin.isPresent() && mixin.get().isAnnotationPresent( annotation ) ) { return Optional.of( mixin.get().getAnnotation( annotation ) ); } if ( currentType.isAnnotationPresent( annotation ) ) { return Optional.of( currentType.getAnnotation( annotation ) ); } for ( JClassType interf : currentType.getImplementedInterfaces() ) { if (!ignoreType.isPresent() || !ignoreType.get().equals( interf )) { Optional<T> annot = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, interf, annotation ); if ( annot.isPresent() ) { return annot; } } } currentType = currentType.getSuperclass(); if ( ignoreType.isPresent() && ignoreType.get().equals( currentType ) ) { currentType = null; } } return Optional.absent(); }
Example 5
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 6
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; }