下面列出了javax.validation.constraints.Past#com.google.gwt.core.ext.typeinfo.JField 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
}
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);
}
}
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;
}
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() );
}
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 );
}
}
}
/**
* <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;
}
}
/**
* 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);
}
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;
}
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);
}
}
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());
}
}
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());
}
}
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());
}
}
}
@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));
}
}
@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()));
}
@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));
}
}
@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));
}
}
@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));
}
}
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");
}
}
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;
}
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 );
}
/**
* 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);
}
private void appendPastValidator(SourceWriter w, JField field) {
Past pastAnnotation = field.getAnnotation(Past.class);
if (pastAnnotation != null) {
w.println(", new PastValidator(\"%s\")", pastAnnotation.message());
}
}
private void appendNullValidator(SourceWriter w, JField field) {
Null nullAnnotation = field.getAnnotation(Null.class);
if (nullAnnotation != null) {
w.println(", new NullValidator(\"%s\")", nullAnnotation.message());
}
}
private void appendNotNullValidator(SourceWriter w, JField field) {
NotNull notNullAnnotation = field.getAnnotation(NotNull.class);
if (notNullAnnotation != null) {
w.println(", new NotNullValidator(\"%s\")", notNullAnnotation.message());
}
}
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());
}
}
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());
}
}
private void appendFutureValidator(SourceWriter w, JField field) {
Future futureAnnotation = field.getAnnotation(Future.class);
if (futureAnnotation != null) {
w.println(", new FutureValidator(\"%s\")", futureAnnotation.message());
}
}
private void appendFalseValidator(SourceWriter w, JField field) {
AssertFalse falseAnnotation = field.getAnnotation(AssertFalse.class);
if (falseAnnotation != null) {
w.println(", new AssertFalseValidator(\"%s\")", falseAnnotation.message());
}
}
private void appendTrueValidator(SourceWriter w, JField field) {
AssertTrue trueAnnotation = field.getAnnotation(AssertTrue.class);
if (trueAnnotation != null) {
w.println(", new AssertTrueValidator(\"%s\")", trueAnnotation.message());
}
}
public InjectResourceCreator(JField resourceField) {
this.resourceField = resourceField;
}