Java Code Examples for com.google.gwt.core.ext.typeinfo.JParameterizedType#getTypeArgs()
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JParameterizedType#getTypeArgs() .
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: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private String typeAsString(JType type, boolean translatePrimitives) { StringBuilder sb = new StringBuilder(); if (translatePrimitives && type instanceof JPrimitiveType) { sb.append(((JPrimitiveType) type).getQualifiedBoxedSourceName()); } else { sb.append(type.getSimpleSourceName()); if (type instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) type; sb.append("<"); int i = 0; for (JType paramType : parameterizedType.getTypeArgs()) { if (i++ > 0) { sb.append(", "); } sb.append(this.typeAsString(paramType, false)); } sb.append(">"); } } return sb.toString(); }
Example 2
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void collectImports() { Collection<JType> toImports = Sets.newHashSet(); for (JMethod method : this.serviceType.getOverridableMethods()) { toImports.add(method.getReturnType()); for (JParameter parameter : method.getParameters()) { toImports.add(parameter.getType()); } } this.imports.addAll(toImports); for (JType importType : this.imports) { if (importType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) importType; for (JType paramType : parameterizedType.getTypeArgs()) { toImports.add(paramType); } } } this.imports.addAll(toImports); }
Example 3
Source File: InjectPresenterCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void initComposer(ClassSourceFileComposerFactory composerFactory) { composerFactory.addImport(Place.class.getName()); composerFactory.addImport(Presenter.class.getName()); for (JMethod presenterMethod : this.presenterMethods) { if (presenterMethod.getParameters().length > 0) { JType placeType = presenterMethod.getParameters()[0].getType(); composerFactory.addImport(placeType.getQualifiedSourceName()); if (placeType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) placeType; for (JType paramType : parameterizedType.getTypeArgs()) { composerFactory.addImport(paramType.getQualifiedSourceName()); } } } } composerFactory.addImplementedInterface(Presenter.class.getSimpleName()); composerFactory.addImport(AcceptsOneWidget.class.getName()); }
Example 4
Source File: InitializeFormCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public InitializeFormCreator(JField modelField) { this.modelField = modelField; this.fieldType = modelField.getType(); Initialize initializeAnnotation = modelField.getAnnotation(Initialize.class); this.constantClassName = initializeAnnotation.constantsClass(); if (ConstantsWithLookup.class.equals(this.constantClassName)) { this.constantClassName = null; } if (this.fieldType instanceof JParameterizedType) { JParameterizedType paramType = (JParameterizedType) this.fieldType; this.beanType = paramType.getTypeArgs()[0]; } else { throw new RuntimeException("modelField can not be injected as Model"); } }
Example 5
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 6
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private String typeAsString(JType type, boolean translatePrimitives) { StringBuilder sb = new StringBuilder(); if (translatePrimitives && type instanceof JPrimitiveType) { sb.append(((JPrimitiveType) type).getQualifiedBoxedSourceName()); } else { sb.append(type.getSimpleSourceName()); if (type instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) type; sb.append("<"); int i = 0; for (JType paramType : parameterizedType.getTypeArgs()) { if (i++ > 0) { sb.append(", "); } sb.append(this.typeAsString(paramType, false)); } sb.append(">"); } } return sb.toString(); }
Example 7
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void collectImports() { Collection<JType> toImports = Sets.newHashSet(); for (JMethod method : this.serviceType.getOverridableMethods()) { toImports.add(method.getReturnType()); for (JParameter parameter : method.getParameters()) { toImports.add(parameter.getType()); } } this.imports.addAll(toImports); for (JType importType : this.imports) { if (importType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) importType; for (JType paramType : parameterizedType.getTypeArgs()) { toImports.add(paramType); } } } this.imports.addAll(toImports); }
Example 8
Source File: InjectModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public InjectModelCreator(JField modelField) { this.modelField = modelField; this.fieldType = modelField.getType(); if (this.fieldType instanceof JParameterizedType) { JParameterizedType paramType = (JParameterizedType) this.fieldType; this.beanType = paramType.getTypeArgs()[0]; } else { throw new RuntimeException("modelField can not be injected as Model"); } }
Example 9
Source File: ObjectMapperCreator.java From gwt-jackson with Apache License 2.0 | 5 votes |
/** * Extract the parameter's type. * * @param clazz the name of the interface * @param parameterizedType the parameterized type * * @return the extracted type * @throws UnableToCompleteException if the type contains zero or more than one parameter */ private JClassType extractParameterizedType( String clazz, JParameterizedType parameterizedType ) throws UnableToCompleteException { if ( parameterizedType == null ) { logger.log( TreeLogger.Type.ERROR, "Expected the " + clazz + " declaration to specify a parameterized type." ); throw new UnableToCompleteException(); } JClassType[] typeParameters = parameterizedType.getTypeArgs(); if ( typeParameters == null || typeParameters.length != 1 ) { logger.log( TreeLogger.Type.ERROR, "Expected the " + clazz + " declaration to specify 1 parameterized type." ); throw new UnableToCompleteException(); } return typeParameters[0]; }
Example 10
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 11
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void generateStaticInitializer(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("protected static final Map<String, PropertyDescription> PROPERTIES = Maps.newHashMap();"); srcWriter.println("static{"); srcWriter.indent(); for (String propertyName : this.propertyTypes.keySet()) { JType propertyType = this.propertyTypes.get(propertyName); String simplePropertyTypeName = propertyType.getSimpleSourceName(); String modelName = this.subModels.get(propertyType); if (modelName != null) { modelName += ".INSTANCE"; } try { if (propertyType.isPrimitive() == null) { Class<?> propertyClass = Class.forName(propertyType.getQualifiedSourceName()); if (Collection.class.isAssignableFrom(propertyClass)) { JParameterizedType parametrizedType = propertyType.isParameterized(); JType subType = propertyType; if (parametrizedType != null) { subType = parametrizedType.getTypeArgs()[0]; String submodelName = this.subModels.get(subType); if (submodelName != null) { submodelName += ".INSTANCE"; } else { submodelName = subType.getSimpleSourceName() + ".class"; } modelName = String.format("new ModelCollection<%s>(%s.class, %s)", subType.getSimpleSourceName(), propertyType.getSimpleSourceName(), submodelName); } else { logger.branch(Type.WARN, String.format( "Property [%s] on bean %s is a raw collection type. You cannot use it on editors.", propertyName, this.beanType.getQualifiedSourceName())); modelName = "new ModelCollection((Model) null)"; } } } } catch (ClassNotFoundException e) { logger.branch(Type.WARN, String.format( "%s class not found.", propertyType.getQualifiedSourceName())); } Boolean getter = this.getters.containsKey(propertyName); Boolean setter = this.setters.containsKey(propertyName); srcWriter.print("PROPERTIES.put(\"%s\", newPropertyDescription(\"%s\", %s.class, %s, %s, %s", propertyName, propertyName, simplePropertyTypeName, modelName, getter, setter); this.generateValidators(srcWriter, propertyName); srcWriter.println("));"); } srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("protected Map<String, PropertyDescription> getProperties(){"); srcWriter.println(" return PROPERTIES;"); srcWriter.println("}"); }
Example 12
Source File: JacksonTypeOracle.java From gwt-jackson with Apache License 2.0 | 4 votes |
/** * <p>replaceType</p> * * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object. * @param type a {@link com.google.gwt.core.ext.typeinfo.JType} object. * @param deserializeAs a {@link java.lang.annotation.Annotation} object. * @return a {@link com.google.gwt.core.ext.typeinfo.JType} object. * @throws com.google.gwt.core.ext.UnableToCompleteException if any. */ public JType replaceType( TreeLogger logger, JType type, Annotation deserializeAs ) throws UnableToCompleteException { JClassType classType = type.isClassOrInterface(); if ( null == classType ) { return type; } Optional<JClassType> typeAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "as" ); Optional<JClassType> keyAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "keyAs" ); Optional<JClassType> contentAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "contentAs" ); if ( !typeAs.isPresent() && !keyAs.isPresent() && !contentAs.isPresent() ) { return type; } JArrayType arrayType = type.isArray(); if ( null != arrayType ) { if ( contentAs.isPresent() ) { return typeOracle.getArrayType( contentAs.get() ); } else if ( typeAs.isPresent() ) { return typeOracle.getArrayType( typeAs.get() ); } else { return classType; } } JParameterizedType parameterizedType = type.isParameterized(); if ( null != parameterizedType ) { JGenericType genericType; if ( typeAs.isPresent() ) { genericType = typeAs.get().isGenericType(); } else { genericType = parameterizedType.getBaseType(); } if ( !keyAs.isPresent() && !contentAs.isPresent() ) { return typeOracle.getParameterizedType( genericType, parameterizedType.getTypeArgs() ); } else if ( contentAs.isPresent() && isIterable( parameterizedType ) ) { return typeOracle.getParameterizedType( genericType, new JClassType[]{contentAs.get()} ); } else if ( isMap( parameterizedType ) ) { JClassType key; if ( keyAs.isPresent() ) { key = keyAs.get(); } else { key = parameterizedType.getTypeArgs()[0]; } JClassType content; if ( contentAs.isPresent() ) { content = contentAs.get(); } else { content = parameterizedType.getTypeArgs()[1]; } return typeOracle.getParameterizedType( genericType, new JClassType[]{key, content} ); } } if ( typeAs.isPresent() ) { return typeAs.get(); } return type; }