1 package spoon.examples.fieldaccess.template; 2 3 import spoon.examples.fieldaccess.annotation.Getter; 4 import spoon.examples.fieldaccess.annotation.Setter; 5 import spoon.reflect.code.CtExpression; 6 import spoon.reflect.code.CtFieldAccess; 7 import spoon.reflect.reference.CtTypeReference; 8 import spoon.template.Local; 9 import spoon.template.Parameter; 10 import spoon.template.Template; 11 12 16 public class FieldAccessTemplate<_FieldType_> implements Template { 17 18 @Parameter 19 CtTypeReference _FieldType_; 20 21 @Parameter("_field_") 22 String __field_; 23 24 @Parameter 25 String _Field_; 26 27 @Parameter 28 CtExpression<_FieldType_> _setExpression_; 29 30 @Parameter 31 CtExpression<FieldAccessTemplate<_FieldType_>> _target_; 32 33 @SuppressWarnings ("unchecked") 34 @Local 35 public FieldAccessTemplate(CtTypeReference type, String field, 36 CtFieldAccess<_FieldType_> fieldAccess, 37 CtExpression<_FieldType_> setExpression) { 38 _FieldType_ = type; 39 __field_ = field; 40 char[] chars = field.toCharArray(); 41 chars[0] = Character.toUpperCase(chars[0]); 42 _Field_ = new String (chars); 43 if (fieldAccess != null) { 44 _target_ = (CtExpression<FieldAccessTemplate<_FieldType_>>) fieldAccess 45 .getTarget(); 46 if (!fieldAccess.getVariable().isStatic() && _target_ == null) { 47 _target_ = (CtExpression<FieldAccessTemplate<_FieldType_>>) fieldAccess 48 .getFactory().Code().createThisAccess( 49 fieldAccess.getVariable().getDeclaringType()); 50 } 51 } 52 _setExpression_ = setExpression; 53 } 54 55 @Local 56 _FieldType_ _field_; 57 58 64 @Setter 65 public void set_Field_(_FieldType_ _field_) { 66 this._field_ = _field_; 67 } 68 69 75 @Getter 76 public _FieldType_ get_Field_() { 77 return _field_; 78 } 79 80 86 @Local 87 void setterInvocation() { 88 _target_.S().set_Field_(_setExpression_.S()); 89 } 90 91 95 @Local 96 void getterInvocation() { 97 _target_.S().get_Field_(); 98 } 99 100 } 101 | Popular Tags |