Skip to content

Instantly share code, notes, and snippets.

@christophe-dooapp
Created November 20, 2013 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophe-dooapp/7566822 to your computer and use it in GitHub Desktop.
Save christophe-dooapp/7566822 to your computer and use it in GitHub Desktop.
Property template
package com.dooapp.template.property;
import javafx.beans.property.ObjectProperty;
import spoon.reflect.reference.CtTypeReference;
import spoon.template.Local;
import spoon.template.Parameter;
import spoon.template.Template;
/**
* Main template to handle all getter setter updater and properties into wrappers<br>
* <br>
* Created at 05/11/2013 14:22.<br>
*
* @author Christophe DUFOUR
*/
public class ReadTemplate<_BasicType_, _PropertyType_ extends ObjectProperty<_BasicType_>> implements Template {
/**
* The type of the field into the bean
*/
@Local
@Parameter
CtTypeReference _BasicType_;
/**
* The type of the field into the wrapper (eg. if in the bean it was boolean,
* then into wrapper it's BooleanProperty)
*/
@Local
@Parameter
CtTypeReference _PropertyType_;
/**
* The name of the field (like toto)
*/
@Parameter("_field_")
String __field_;
/**
* The name of the field with first uppercase (like Toto)
*/
@Parameter
String _Field_;
/**
* @return the bean used in the Wrapper pattern, it annotated with @Local, so it's not generated here.
*/
@Local
private Bean getBean() {
return new Bean();
}
/**
* A fake bean class to make this Template compile
*/
@Local
private class Bean {
public _BasicType_ _field_;
}
/**
* Constructor used by processor to inject value into this template
*
* @param field the name of the filed (like toto)
*/
@SuppressWarnings("unchecked")
@Local
public ReadTemplate(CtTypeReference basicType, CtTypeReference propertyType, String field) {
_BasicType_ = basicType;
_PropertyType_ = propertyType;
__field_ = field;
char[] chars = field.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
_Field_ = new String(chars);
}
private _PropertyType_ _field_Property;
/**
* creator pattern for #_field_Property()
*
* @see #_field_Property()
*/
protected _PropertyType_ create_Field_Property() {
return null;
}
@Local
public _PropertyType_ _field_Property() {
return _field_Property;
}
/**
* getter for #_field_Property()
*
* @return #_field_Property().get()
* @see #_field_Property()
*/
public _BasicType_ get_Field_() {
return _field_Property().get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment