use of cz.habarta.typescript.generator.compiler.SymbolTable in project typescript-generator by vojtechhabarta.
the class ClassEnumExtension method getTransformers.
@Override
public List<TransformerDefinition> getTransformers() {
return Arrays.asList(new TransformerDefinition(ModelCompiler.TransformationPhase.BeforeEnums, new ModelTransformer() {
@Override
public TsModel transformModel(SymbolTable symbolTable, TsModel model) {
List<TsBeanModel> beans = model.getBeans();
List<TsBeanModel> classEnums = new ArrayList<>();
for (TsBeanModel bean : beans) {
if (bean.getName().getSimpleName().contains(classEnumPattern))
classEnums.add(bean);
}
List<TsEnumModel> stringEnums = new ArrayList<>();
for (TsBeanModel tsBeanModel : classEnums) {
List<EnumMemberModel> members = new ArrayList<>();
for (Field declaredField : tsBeanModel.getOrigin().getDeclaredFields()) {
if (declaredField.getType().getName().equals(tsBeanModel.getOrigin().getName())) {
members.add(new EnumMemberModel(declaredField.getName(), declaredField.getName(), null));
}
}
TsEnumModel temp = new TsEnumModel(tsBeanModel.getOrigin(), tsBeanModel.getName(), EnumKind.StringBased, members, null);
stringEnums.add(temp);
}
return model.withEnums(stringEnums).withoutBeans(classEnums);
}
}));
}
Aggregations