1 package spoon.examples.nton.template; 2 3 import spoon.reflect.reference.CtTypeReference; 4 import spoon.template.Local; 5 import spoon.template.Parameter; 6 import spoon.template.Template; 7 8 public class NtonCodeTemplate implements Template, _TargetType_ { 9 @Parameter 10 static int _n_; 11 12 @Parameter 13 CtTypeReference _TargetType_; 14 15 static _TargetType_[] instances = new _TargetType_[_n_]; 16 17 static int instanceCount = 0; 18 19 @Local 20 public NtonCodeTemplate(CtTypeReference targetType, int n) { 21 _n_ = n; 22 _TargetType_ = targetType; 23 } 24 25 @Local 26 public void initializer() { 27 if (instanceCount >= _n_) { 28 throw new RuntimeException ("max number of instances reached"); 29 } 30 instances[instanceCount++] = this; 31 } 32 33 public int getInstanceCount() { 34 return instanceCount; 35 } 36 37 public _TargetType_ getInstance(int i) { 38 if (i > _n_) 39 throw new RuntimeException ("instance number greater than " + _n_); 40 return instances[i]; 41 } 42 43 public int getMaxInstanceCount() { 44 return _n_; 45 } 46 47 class Test { 48 public void _name_() {} 49 } 50 } 51 52 interface _TargetType_ { 53 54 } | Popular Tags |