Property template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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