com.google.gwt.core.ext.typeinfo.JField Java Examples
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JField.
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: FieldAccessor.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * <p>Constructor for FieldAccessor.</p> * * @param propertyName a {@link java.lang.String} object. * @param samePackage a boolean. * @param fieldAutoDetect a boolean. * @param fieldAutoDetect a boolean. * @param field a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object. * @param methodAutoDetect a boolean. * @param methodAutoDetect a boolean. * @param method a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object. */ protected FieldAccessor( String propertyName, boolean samePackage, boolean fieldAutoDetect, Optional<JField> field, boolean methodAutoDetect, Optional<JMethod> method ) { Preconditions.checkNotNull( propertyName ); Preconditions.checkArgument( field.isPresent() || method.isPresent(), "At least one of the field or method must be given" ); this.propertyName = propertyName; this.samePackage = samePackage; this.field = field; this.method = method; // We first test if we can use the method if ( method.isPresent() && (methodAutoDetect || !fieldAutoDetect || !field.isPresent()) ) { useMethod = true; } // else use the field else { useMethod = false; } }
Example #2
Source File: PropertyParser.java From gwt-jackson with Apache License 2.0 | 6 votes |
private static void parseFields( TreeLogger logger, JClassType type, Map<String, PropertyAccessorsBuilder> propertiesMap, boolean mixin ) { if ( type.getQualifiedSourceName().equals( "java.lang.Object" ) ) { return; } for ( JField field : type.getFields() ) { if ( field.isStatic() ) { continue; } String fieldName = field.getName(); PropertyAccessorsBuilder property = propertiesMap.get( fieldName ); if ( null == property ) { property = new PropertyAccessorsBuilder( fieldName ); propertiesMap.put( fieldName, property ); } if ( property.getField().isPresent() && !mixin ) { // we found an other field with the same name on a superclass. we ignore it logger.log( Type.INFO, "A field with the same name as '" + field .getName() + "' has already been found on child class" ); } else { property.addField( field, mixin ); } } }
Example #3
Source File: PropertyProcessor.java From gwt-jackson with Apache License 2.0 | 6 votes |
private static boolean isFieldAutoDetected( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info ) { if ( !propertyAccessors.getField().isPresent() ) { return false; } for ( Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS ) { if ( propertyAccessors.isAnnotationPresentOnField( annotation ) ) { return true; } } JField field = propertyAccessors.getField().get(); JsonAutoDetect.Visibility visibility = info.getFieldVisibility(); if ( Visibility.DEFAULT == visibility ) { visibility = configuration.getDefaultFieldVisibility(); } return isAutoDetected( visibility, field.isPrivate(), field.isProtected(), field.isPublic(), field .isDefaultAccess() ); }
Example #4
Source File: InjectCreatorUtil.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public static Collection<JField> listFields(JClassType type, Class<? extends Annotation> annotationClass) { Collection<JField> methodAnnoted = Lists.newArrayList(); JField[] fields = type.getFields(); for (JField field : fields) { Annotation annotation = field.getAnnotation(annotationClass); if (annotation != null) { methodAnnoted.add(field); } } // Recurse to superclass JClassType superclass = type.getSuperclass(); if (superclass != null) { methodAnnoted.addAll(InjectCreatorUtil.listFields(superclass, annotationClass)); } return methodAnnoted; }
Example #5
Source File: InjectServiceCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public InjectServiceCreator(JType viewType, JField serviceField) { this.viewType = viewType; this.serviceField = serviceField; this.serviceName = serviceField.getType().getQualifiedSourceName(); Class fieldClass; try { fieldClass = this.getClass().getClassLoader().loadClass(serviceField.getType().getQualifiedBinaryName()); if (ServiceProxy.class.isAssignableFrom(fieldClass)) { this.declareProxy = false; this.proxyTypeName = serviceField.getType().getQualifiedSourceName(); } else { this.proxyTypeName = "_" + serviceField.getName() + "ServiceProxy"; } } catch (ClassNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } }
Example #6
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 #7
Source File: ModelCreatorFactory.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<JField> fields = InjectCreatorUtil.listFields(injectableType, InjectModel.class); for (JField field : fields) { delegates.add(new InjectModelCreator(field)); } }
Example #8
Source File: PropertyAccessorsBuilder.java From gwt-jackson with Apache License 2.0 | 5 votes |
void addField( JField field, boolean mixin ) { if ( this.fields.size() > 1 || (mixin && !this.field.isPresent() && this.fields.size() == 1) || (!mixin && this.field .isPresent()) ) { // we already found one mixin and one field type hierarchy // or we want to add a mixin but we have already one // or we want to add a field but we have already one return; } if ( !mixin ) { this.field = Optional.of( field ); } this.fields.add( field ); this.accessors.add( field ); }
Example #9
Source File: PropertyAccessors.java From gwt-jackson with Apache License 2.0 | 5 votes |
PropertyAccessors( String propertyName, Optional<JField> field, Optional<JMethod> getter, Optional<JMethod> setter, Optional<JParameter> parameter, ImmutableList<JField> fields, ImmutableList<JMethod> getters, ImmutableList<JMethod> setters, ImmutableList<HasAnnotations> accessors ) { this.propertyName = propertyName; this.field = field; this.getter = getter; this.setter = setter; this.parameter = parameter; this.fields = fields; this.getters = getters; this.setters = setters; this.accessors = accessors; }
Example #10
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 #11
Source File: ServiceCreatorFactory.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<JField> fields = InjectCreatorUtil.listFields(injectableType, InjectService.class); for (JField field : fields) { delegates.add(new InjectServiceCreator(injectableType, field)); } }
Example #12
Source File: InitializeFormCreatorFactory.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<JField> fields = InjectCreatorUtil.listFields(injectableType, Initialize.class); for (JField field : fields) { delegates.add(new InitializeFormCreator(field)); } }
Example #13
Source File: TextBinderGenerator.java From EasyML with Apache License 2.0 | 5 votes |
/** * Generate method bind */ private void composeBindMethod(TreeLogger logger, SourceWriter sourceWriter) { logger.log(TreeLogger.INFO, ""); String line = "public void bind(" + parameterizedType1.getQualifiedSourceName() + " text, " + parameterizedType2.getQualifiedSourceName() + " obj){"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); line = " System.out.println(\"Implement it now:)\");"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); ArrayList<JField> fields = new ArrayList<JField>(); JClassType curtype = parameterizedType2; do { for (JField filed : curtype.getFields()) { fields.add(filed); } curtype = curtype.getSuperclass(); } while (!curtype.getName().equals("Object")); for (JField field : fields) { String name = field.getName(); String Name = name.substring(0, 1).toUpperCase() + name.substring(1); line = " text.setText(\"" + name + "\", obj.get" + Name + "().toString() );"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); } line = "}"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); }
Example #14
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 #15
Source File: ResourceCreatorFactory.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<JField> fields = InjectCreatorUtil.listFields(injectableType, InjectResource.class); for (JField field : fields) { delegates.add(new InjectResourceCreator(field)); } }
Example #16
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void listPublicFields(JField[] fields) { for (JField field : fields) { if (field.isPublic() && !field.isFinal()) { this.publicFields.put(field.getName(), field.getType()); this.propertyTypes.put(field.getName(), field.getType()); this.addImport(field.getType()); } } }
Example #17
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter printWriter = this.getPrintWriter(logger, context, this.proxyModelQualifiedName); if (printWriter == null) { return this.proxyModelQualifiedName; } JField[] fields = this.beanType.getFields(); JMethod[] methods = this.beanType.getMethods(); this.parentType = this.beanType.getSuperclass(); this.imports.add(this.parentType); this.listPublicFields(fields); this.listGetters(methods); this.listSetters(methods); this.createSubModels(logger, context); SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.indent(); srcWriter.println(); this.generateSingleton(logger, srcWriter); srcWriter.println(); srcWriter.println(); this.generateStaticInitializer(logger, srcWriter); srcWriter.println(); this.generateConstructor(logger, srcWriter); srcWriter.println(); this.generateCreate(logger, srcWriter); srcWriter.println(); this.generateInternalSet(logger, srcWriter); srcWriter.println(); this.generateInternalGet(logger, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyModelQualifiedName; }
Example #18
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateValidators(SourceWriter w, String propertyName) { JField field = this.beanType.getField(propertyName); if (field != null) { appendTrueValidator(w, field); appendFalseValidator(w, field); appendFutureValidator(w, field); appendMaxValidator(w, field); appendMinValidator(w, field); appendNotNullValidator(w, field); appendNullValidator(w, field); appendPastValidator(w, field); appendPatternValidator(w, field); appendSizeValidator(w, field); } }
Example #19
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void appendSizeValidator(SourceWriter w, JField field) { Size sizeAnnotation = field.getAnnotation(Size.class); if (sizeAnnotation != null) { w.println(", new SizeValidator(\"%s\", %s, %s)", sizeAnnotation.message(), sizeAnnotation.min(), sizeAnnotation.max()); } }
Example #20
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void appendPatternValidator(SourceWriter w, JField field) { Pattern patternAnnotation = field.getAnnotation(Pattern.class); if (patternAnnotation != null) { w.println(", new PatternValidator(\"%s\", \"%s\")", patternAnnotation.message(), patternAnnotation.regexp() .replace("\\", "\\\\"), patternAnnotation.flags()); } }
Example #21
Source File: TextBinderGenerator.java From EasyML with Apache License 2.0 | 4 votes |
/** * Generate method sync */ private void composeSyncMethod(TreeLogger logger, SourceWriter sourceWriter) { logger.log(TreeLogger.INFO, ""); String line = "public void sync(" + parameterizedType1.getQualifiedSourceName() + " text, " + parameterizedType2.getQualifiedSourceName() + " obj){"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); line = " System.out.println(\"Implement it now:)\");"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); ArrayList<JField> fields = new ArrayList<JField>(); JClassType curtype = parameterizedType2; do { for (JField filed : curtype.getFields()) { fields.add(filed); } curtype = curtype.getSuperclass(); } while (!curtype.getName().equals("Object")); for (JField field : fields) { String name = field.getName(); String Name = name.substring(0, 1).toUpperCase() + name.substring(1); String type = field.getType().getQualifiedSourceName(); String simType = field.getType().getSimpleSourceName(); if ("java.lang.String".equals(type)) line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name + "( text.getText(\"" + name + "\") );"; else line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name + "( " + type + ".parse" + simType + "( text.getText(\"" + name + "\")) );"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); } line = "}"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); }
Example #22
Source File: PropertyAccessorsBuilder.java From gwt-jackson with Apache License 2.0 | 4 votes |
Optional<JField> getField() { return field; }
Example #23
Source File: FieldWriteAccessor.java From gwt-jackson with Apache License 2.0 | 4 votes |
FieldWriteAccessor( String propertyName, boolean samePackage, boolean fieldAutoDetect, Optional<JField> field, boolean setterAutoDetect, Optional<JMethod> setter ) { super( propertyName, samePackage, fieldAutoDetect, field, setterAutoDetect, setter ); }
Example #24
Source File: FieldReadAccessor.java From gwt-jackson with Apache License 2.0 | 4 votes |
FieldReadAccessor( String propertyName, boolean samePackage, boolean fieldAutoDetect, Optional<JField> field, boolean getterAutoDetect, Optional<JMethod> getter ) { super( propertyName, samePackage, fieldAutoDetect, field, getterAutoDetect, getter ); }
Example #25
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void appendPastValidator(SourceWriter w, JField field) { Past pastAnnotation = field.getAnnotation(Past.class); if (pastAnnotation != null) { w.println(", new PastValidator(\"%s\")", pastAnnotation.message()); } }
Example #26
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void appendNullValidator(SourceWriter w, JField field) { Null nullAnnotation = field.getAnnotation(Null.class); if (nullAnnotation != null) { w.println(", new NullValidator(\"%s\")", nullAnnotation.message()); } }
Example #27
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void appendNotNullValidator(SourceWriter w, JField field) { NotNull notNullAnnotation = field.getAnnotation(NotNull.class); if (notNullAnnotation != null) { w.println(", new NotNullValidator(\"%s\")", notNullAnnotation.message()); } }
Example #28
Source File: InjectResourceCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
public InjectResourceCreator(JField resourceField) { this.resourceField = resourceField; }
Example #29
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void appendMinValidator(SourceWriter w, JField field) { Min minAnnotation = field.getAnnotation(Min.class); if (minAnnotation != null) { w.println(", new MinValidator(\"%s\", %s)", minAnnotation.message(), minAnnotation.value()); } }
Example #30
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void appendMaxValidator(SourceWriter w, JField field) { Max maxAnnotation = field.getAnnotation(Max.class); if (maxAnnotation != null) { w.println(", new MaxValidator(\"%s\", %s)", maxAnnotation.message(), maxAnnotation.value()); } }